Commit 8e111c66 authored by Romain Loth's avatar Romain Loth

fix deselections (actually commit 21064f3b went too far)

we need both neighbor agregated sums AND detailed info
parent f22f6272
...@@ -179,26 +179,29 @@ function SelectionEngine() { ...@@ -179,26 +179,29 @@ function SelectionEngine() {
// Dictionaries of: selection+neighbors for the new state and updateRelatedNodesPanel // Dictionaries of: selection+neighbors for the new state and updateRelatedNodesPanel
let selections = {} let selections = {}
// detailed relations sorted by types and srcid (for state cache, deselects etc)
let activeRelations = {} let activeRelations = {}
activeRelations[activetypesKey] = {} activeRelations[activetypesKey] = {}
// cumulated neighbor weights no matter what srcid (for tagCloud etc)
let sameSideNeighbors = {}
let oppoSideNeighbors = {}
// targeted arg 'nodes' can be nid array or single nid // targeted arg 'nodes' can be nid array or single nid
var ndsids=[] var ndsids=[]
if(args.nodes) { if(args.nodes) {
if(! $.isArray(args.nodes)) ndsids.push(args.nodes); if(! $.isArray(args.nodes)) ndsids.push(args.nodes);
else ndsids=args.nodes; else ndsids=args.nodes;
// for state cache
activeRelations[activetypesKey] = {}
// shortcut
var sameSideNeighbors = activeRelations[activetypesKey]
for(var i in ndsids) { for(var i in ndsids) {
var srcnid = ndsids[i]; var srcnid = ndsids[i];
if(TW.Relations[activetypesKey] && TW.Relations[activetypesKey][srcnid] ) { if(TW.Relations[activetypesKey] && TW.Relations[activetypesKey][srcnid] ) {
var neighs = TW.Relations[activetypesKey][srcnid] var neighs = TW.Relations[activetypesKey][srcnid]
activeRelations[activetypesKey][srcnid] = {}
if(neighs) { if(neighs) {
for(var j in neighs) { for(var j in neighs) {
var tgtnid = neighs[j] var tgtnid = neighs[j]
...@@ -223,14 +226,21 @@ function SelectionEngine() { ...@@ -223,14 +226,21 @@ function SelectionEngine() {
sameSideNeighbors[tgtnid]=0 sameSideNeighbors[tgtnid]=0
} }
// and the detailed info
if (typeof activeRelations[activetypesKey][srcnid][tgtnid] == 'undefined') {
activeRelations[activetypesKey][srcnid][tgtnid]=0
}
// **make the edge active** // **make the edge active**
if (e1 && !e1.hidden) { if (e1 && !e1.hidden) {
e1.customAttrs.activeEdge = 1; e1.customAttrs.activeEdge = 1;
sameSideNeighbors[tgtnid] += e1.weight || 1 sameSideNeighbors[tgtnid] += e1.weight || 1
activeRelations[activetypesKey][srcnid][tgtnid] += e1.weight || 1
} }
if (e2 && !e2.hidden) { if (e2 && !e2.hidden) {
e2.customAttrs.activeEdge = 1; e2.customAttrs.activeEdge = 1;
sameSideNeighbors[tgtnid] += e2.weight || 1 sameSideNeighbors[tgtnid] += e2.weight || 1
activeRelations[activetypesKey][srcnid][tgtnid] += e2.weight || 1
} }
// we add as neighbor to color it (except if already in targeted) // we add as neighbor to color it (except if already in targeted)
...@@ -263,12 +273,21 @@ function SelectionEngine() { ...@@ -263,12 +273,21 @@ function SelectionEngine() {
let srcnid = theSelection[i] let srcnid = theSelection[i]
var bipaNeighs = TW.Relations["1|1"][srcnid]; var bipaNeighs = TW.Relations["1|1"][srcnid];
activeRelations["1|1"][srcnid] = {}
for(var k in bipaNeighs) { for(var k in bipaNeighs) {
if (typeof activeRelations["1|1"][bipaNeighs[k]] == "undefined") if (typeof activeRelations["1|1"][srcnid][bipaNeighs[k]] == "undefined") {
activeRelations["1|1"][bipaNeighs[k]] = 0; activeRelations["1|1"][srcnid][bipaNeighs[k]] = 0;
}
if (typeof oppoSideNeighbors[bipaNeighs[k]] == "undefined") {
oppoSideNeighbors[bipaNeighs[k]] = 0 ;
}
// cumulated for all srcnids // cumulated for all srcnids
activeRelations["1|1"][bipaNeighs[k]]++; oppoSideNeighbors[bipaNeighs[k]]++
// and the details
activeRelations["1|1"][srcnid][bipaNeighs[k]]++;
} }
} }
} }
...@@ -279,12 +298,12 @@ function SelectionEngine() { ...@@ -279,12 +298,12 @@ function SelectionEngine() {
let same = [] let same = []
if (activeRelations["1|1"]) { if (activeRelations["1|1"]) {
oppos = ArraySortByValue(activeRelations["1|1"], function(a,b){ oppos = ArraySortByValue(oppoSideNeighbors, function(a,b){
return b-a return b-a
}); });
} }
same = ArraySortByValue(activeRelations[activetypesKey], function(a,b){ same = ArraySortByValue(sameSideNeighbors, function(a,b){
return b-a return b-a
}); });
...@@ -311,6 +330,7 @@ function SelectionEngine() { ...@@ -311,6 +330,7 @@ function SelectionEngine() {
TW.partialGraph.render(); TW.partialGraph.render();
updateRelatedNodesPanel( theSelection , same, oppos ) updateRelatedNodesPanel( theSelection , same, oppos )
if (TW.conf.debug.logSelections) { if (TW.conf.debug.logSelections) {
......
...@@ -427,6 +427,8 @@ function changeLevel() { ...@@ -427,6 +427,8 @@ function changeLevel() {
var sels = present.selectionNids ;//[144, 384, 543]//TW.states[last].selectionNids; var sels = present.selectionNids ;//[144, 384, 543]//TW.states[last].selectionNids;
deselectNodes()
let selsChecker = {} let selsChecker = {}
for (let i in sels) { for (let i in sels) {
selsChecker[sels[i]] = true selsChecker[sels[i]] = true
...@@ -448,7 +450,6 @@ function changeLevel() { ...@@ -448,7 +450,6 @@ function changeLevel() {
var nodes_2_colour = {} var nodes_2_colour = {}
var edges_2_colour = {} var edges_2_colour = {}
// £TODO: factorize with same strategy in MultipleSelection2 beginning
for(var i in sels) { for(var i in sels) {
s = sels[i]; s = sels[i];
neigh = TW.Relations[activetypesKey][s] neigh = TW.Relations[activetypesKey][s]
...@@ -463,9 +464,6 @@ function changeLevel() { ...@@ -463,9 +464,6 @@ function changeLevel() {
} }
} }
} }
for(var i in sels)
nodes_2_colour[sels[i]]=true;
var futurelevel = null var futurelevel = null
......
...@@ -1015,7 +1015,6 @@ function dictfyJSON( data , categories ) { ...@@ -1015,7 +1015,6 @@ function dictfyJSON( data , categories ) {
for(var nid in data.nodes) { for(var nid in data.nodes) {
let n = data.nodes[nid]; let n = data.nodes[nid];
console.log(">>", n)
let node = {} let node = {}
node.id = (n.id) ? n.id : nid ; // use the key if no id node.id = (n.id) ? n.id : nid ; // use the key if no id
......
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