Commit c618d77d authored by Romain Loth's avatar Romain Loth

bipartite display works for typestring '1|1'

fixed sigma port changes for bipartite states, and more casts removed for non numeric-ids
parent 20f8ee97
......@@ -127,6 +127,12 @@ TW.customLegendsBins = {
'age': 8,
'growth_rate': 12
}
TW.debugFlags = {
initialShowAll: false,
}
// ============ < / DEVELOPER OPTIONS > ============
......
......@@ -261,6 +261,11 @@ function SelectionEngine() {
$("#unselectbutton").show() ;
var the_new_sels = Object.keys(selections)
if (the_new_sels.length && the_new_sels[0] == 'NaN') {
console.error("NaN selection key error")
}
TW.partialGraph.states.slice(-1)[0].selections = the_new_sels;
TW.partialGraph.states.slice(-1)[0].setState( { sels: the_new_sels} )
......
......@@ -3,9 +3,6 @@
// always useful
var theHtml = document.getElementsByTagName('html')[0]
TW.anynodegoes = true
// TW.anynodegoes = true
function writeBrand (brandString) {
document.getElementById('twbrand').innerHTML = brandString
}
......@@ -25,6 +22,9 @@ function changeType() {
var type_t0 = present.type;
var str_type_t0 = type_t0.map(Number).join("|")
console.debug("CHANGE TYPE, present.selections", present.selections)
var selsbackup = present.selections.slice();
......@@ -167,8 +167,8 @@ function changeType() {
if(sels.length>0) { // and if there's some selection:
console.log("active selection 01:")
console.log(sels)
// console.log("active selection 01:")
// console.log(sels)
// Defining the new selection (if it's necessary)
var sumCats = type_t0.map(Number).reduce(function(a, b){return a+b;})
......@@ -202,12 +202,13 @@ function changeType() {
// else newsels[sels[i]]=true;
}
sels = Object.keys(newsels).map(Number);
sels = Object.keys(newsels);
// output: newsels=[opposite-neighs]
} // [ / ChangeType: incremental selection ]
console.log("new virtually selected nodes:")
console.log(sels)
// console.log("new virtually selected nodes:")
// console.log(sels)
var selDict={}
for(var i in sels) // useful for case: (sumNextState==2)
selDict[sels[i]]=true
......@@ -233,7 +234,7 @@ function changeType() {
if(sumNextState==2) { // we're moving to bipartite subgraph
for(var i in TW.Edges) {
n = i.split(";").map(Number)
n = i.split(";")
if( selDict[ n[0] ] || selDict[ n[1] ] ) {
nodes_2_colour[n[0]]=false;
nodes_2_colour[n[1]]=false;
......@@ -252,6 +253,8 @@ function changeType() {
add1Elem(eid)
}
// to recreate the selection in the new type graph
var SelInst = new SelectionEngine();
SelInst.MultipleSelection2({
nodesDict:nodes_2_colour,
......@@ -270,12 +273,12 @@ function changeType() {
TW.partialGraph.states[lastpos].setState({
type: nextState,
level: level,
sels: Object.keys(selections).map(Number),
sels: Object.keys(selections),
oppos: []
})
// REFA new sigma.js
TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.5, angle: 0})
TW.partialGraph.camera.goTo({x:0, y:0, ratio:1, angle: 0})
TW.partialGraph.refresh()
// recreates FA2 nodes array from new nodes
......@@ -350,7 +353,7 @@ function changeLevel() {
edges_2_colour[s+";"+t]=true;
edges_2_colour[t+";"+s]=true;
if( !selections[t] )
voisinage[ Number(t) ] = true;
voisinage[ t ] = true;
}
}
}
......@@ -425,7 +428,7 @@ function changeLevel() {
TW.partialGraph.states[lastpos].setState({
type: present.type,
level: futurelevel,
sels: Object.keys(selections).map(Number),
sels: Object.keys(selections),
oppos: []
})
......@@ -959,7 +962,7 @@ function AlgorithmForSliders( elements , type_attrb , type , criteria) {
}
if(IDs.length==0) break;
finalarray[i] = (edgeflag)? IDs : IDs.map(Number);
finalarray[i] = IDs
}
// console.log("finalarray: ")
return {"steps":finalarray.length,"finalarray":finalarray}
......
......@@ -502,6 +502,9 @@ else {
});
// ==================================================================
// NB the list of nodes and edges from TW.graphData will be changed
// by changeLevel, changeType or subset sliders
// shortcuts to the renderer and camera
TW.cam = TW.partialGraph.camera
TW.rend = TW.partialGraph.renderers[0]
......@@ -509,10 +512,6 @@ else {
// NB : camera positions are fix if the node is fixed => they only depend on layout
// renderer position depend on viewpoint/zoom (like ~ html absolute positions of the node in the div)
// use for loops
TW.nNodes = TW.partialGraph.graph.nodes().length
TW.nEdges = TW.partialGraph.graph.edges().length
// POSS make it TW.states
TW.partialGraph.states = []
......@@ -536,7 +535,7 @@ else {
TW.partialGraph.states[1].setState = (function( type , level , sels , oppos ) {
var bistate=false, typestring=false;
console.log("IN THE SET STATE METHOD:")
console.log("IN THE SET STATE METHOD:", this)
if(!isUndef(type)) {
this.type = type;
bistate= type.map(Number).reduce(function(a, b){return a+b;})
......
......@@ -31,7 +31,7 @@ function cancelSelection (fromTagCloud, settings) {
}
//Nodes colors go back to previous
for(let j=0;j<TW.nNodes;j++){
for(let j in TW.nodeIds){
let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
// console.log("cancelSelection: node", n)
if (n) {
......@@ -83,20 +83,24 @@ function cancelSelection (fromTagCloud, settings) {
}
}
// returns the name(s) of active types
// this area is quite underspecified so we assume here
// - that all typenames have a mapping to cat[0] (terms) or cat[1] (contexts)
// - that currentState.type is an array of 2 bools for the currently displayed cat(s)
// TODO transform result into array in all cases
function getCurrentType() {
let currentTypeName
let currentTypes = []
let currentTypeIdx
let typeIdxs = Object.keys(TW.partialGraph.states.slice(-1)[0].type)
for (var m in typeIdxs) {
if (TW.partialGraph.states.slice(-1)[0].type[m]) {
currentTypeIdx = m
break
let lastState = TW.partialGraph.states.slice(-1)[0]
for (var possType in TW.catDict) {
currentTypeIdx = TW.catDict[possType]
if (lastState.type[currentTypeIdx]) {
currentTypes.push(possType)
}
}
currentTypeName = TW.categories[currentTypeIdx]
return currentTypeName
return currentTypes.join('-')
}
......@@ -581,7 +585,7 @@ function graphTagCloudElem(nodes) {
TW.partialGraph.states[lastpos].setState({
type: next_state,
level: futurelevel,
sels: Object.keys(selections).map(Number),
sels: Object.keys(selections),
oppos: []
})
......@@ -604,7 +608,7 @@ function unHide(nodeId) {
// renderer will see the flags and handle the case accordingly
function greyEverything(){
for(var j=0 ; j<TW.nNodes ; j++){
for(var j in TW.nodeIds){
let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
if (n && !n.hidden) {
......@@ -619,7 +623,7 @@ function greyEverything(){
}
if (TW.partialGraph.settings('drawEdges')) {
for(var i=0;i<TW.nEdges;i++){
for(var i in TW.edgeIds){
let e = TW.partialGraph.graph.edges(TW.edgeIds[i])
if (e && !e.hidden && !e.customAttrs.grey) {
e.customAttrs.grey = 1
......@@ -752,8 +756,10 @@ function prepareEdgesRenderingProperties(edgesDict, nodesDict) {
// use case: slider, changeLevel re-add nodes
function add1Elem(id) {
id = ""+id;
if(id.split(";").length==1) { // i've received a NODE
id = parseInt(id)
// if already exists
if(!isUndef(TW.partialGraph.graph.nodes(id))) return;
if(TW.Nodes[id]) {
......
......@@ -902,6 +902,8 @@ function dictfyJSON( data , categories ) {
if(n.attributes) node.attributes = n.attributes
else node.attributes = {}
node.type = (n.type)? n.type : categories[0] ;
// £TODO REFA new sigma.js: shape is not attr but custom type linked to a renderer's name
// node.shape = "square";
// £TODO generalize some alternate names in here and maybe gexf
......@@ -912,6 +914,7 @@ function dictfyJSON( data , categories ) {
if (!catCount[node.type]) catCount[node.type] = 0
catCount[node.type]++;
nodes[node.id] = node;
}
......
......@@ -14,7 +14,7 @@ SigmaUtils = function () {
var n = nodes[i];
// console.debug('tr >>> fgr node', n)
if(initialState[catDict[n.type]] || TW.anynodegoes) {
if(initialState[catDict[n.type]] || TW.debugFlags.initialShowAll) {
// var node = {
// id : n.id,
// label : n.label,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment