Commit 5e6cc941 authored by Romain Loth's avatar Romain Loth

use SystemState to store global selections

global var selections removed and stored inside SystemState + transformed into an array everywhere (was inconsistent) + fixed changeType selection materialization ; possible TODOES: better setState function, possible integration of opposite side neighbors in SystemState too
parent 846d1d9f
...@@ -505,33 +505,6 @@ function RenderTweet( tweet) { ...@@ -505,33 +505,6 @@ function RenderTweet( tweet) {
return html; return html;
} }
//FOR UNI-PARTITE
// function selectionUni(currentNode){
// console.log("\tin selectionUni:"+currentNode.id);
// if(TW.gui.checkBox==false && TW.gui.circleSize==0) {
// highlightSelectedNodes(false);
// opossites = [];
// selections = [];
// }
//
// if((typeof selections[currentNode.id])=="undefined"){
// selections[currentNode.id] = 1;
// currentNode.active=true;
// }
// else {
// delete selections[currentNode.id];
// currentNode.active=false;
// }
// //highlightOpossites(nodes1[currentNode.id].neighbours);
// // currentNode.color = currentNode.customAttrs['true_color'];
// // currentNode.customAttrs['grey'] = 0;
// //
// //
//
//
// TW.partialGraph.zoomTo(TW.partialGraph._core.width / 2, TW.partialGraph._core.height / 2, 0.8);
// TW.partialGraph.render();
// }
//JUST ADEME //JUST ADEME
function camaraButton(){ function camaraButton(){
......
This diff is collapsed.
...@@ -197,14 +197,14 @@ function changeType() { ...@@ -197,14 +197,14 @@ function changeType() {
var level = present.level; var level = present.level;
var sels = present.selections var sels = present.selectionNids
var t0Activetypes = present.activetypes; var t0Activetypes = present.activetypes;
var t0ActivetypesKey = t0Activetypes.map(Number).join("|") var t0ActivetypesKey = t0Activetypes.map(Number).join("|")
console.debug("CHANGE TYPE, present.selections", present.selections) // console.debug("CHANGE TYPE, present.selections", present.selectionNids)
var selsbackup = present.selections.slice(); var selsbackup = present.selectionNids.slice();
// type "grammar" // type "grammar"
...@@ -359,7 +359,7 @@ function changeType() { ...@@ -359,7 +359,7 @@ function changeType() {
str_nextState = nextState.map(Number).join("|") str_nextState = nextState.map(Number).join("|")
var sumNextState = nextState.map(Number).reduce(function(a, b){return a+b;}) var sumNextState = nextState.map(Number).reduce(function(a, b){return a+b;})
// [ ChangeType: incremental selection ] // [ ChangeType: incremental selection ;]
if(sumCats==1 && sumNextState<2) { if(sumCats==1 && sumNextState<2) {
var indexCat = str_binSumCats;//(level)? t1ActivetypesKey : str_binSumCats ; var indexCat = str_binSumCats;//(level)? t1ActivetypesKey : str_binSumCats ;
...@@ -385,8 +385,8 @@ function changeType() { ...@@ -385,8 +385,8 @@ function changeType() {
// output: newsels=[opposite-neighs] // output: newsels=[opposite-neighs]
} // [ / ChangeType: incremental selection ] } // [ / ChangeType: incremental selection ]
// console.log("new virtually selected nodes:") if (TW.conf.debug.logSelections)
// console.log(sels) console.log("new virtually selected nodes:", sels)
var selDict={} var selDict={}
for(var i in sels) // useful for case: (sumNextState==2) for(var i in sels) // useful for case: (sumNextState==2)
...@@ -434,25 +434,26 @@ function changeType() { ...@@ -434,25 +434,26 @@ function changeType() {
// to recreate the selection in the new type graph // to recreate the selection in the new type graph
// TW.instance.selNgn.MultipleSelection2({ TW.instance.selNgn.MultipleSelection2({
// nodesDict:nodes_2_colour, nodes: sels,
// edgesDict:edges_2_colour nodesDict:nodes_2_colour,
// }); edgesDict:edges_2_colour
TW.instance.selNgn.MultipleSelection2({ nodes: sels }); });
TW.gui.selectionActive=true; TW.gui.selectionActive=true;
} }
// £TODO this should be done by setState()
TW.states[avantlastpos] = {}; TW.states[avantlastpos] = {};
TW.states[avantlastpos].LouvainFait = false; TW.states[avantlastpos].LouvainFait = false;
TW.states[avantlastpos].level = present.level; TW.states[avantlastpos].level = present.level;
TW.states[avantlastpos].selections = selsbackup; TW.states[avantlastpos].selectionNids = selsbackup;
TW.states[avantlastpos].activetypes = present.activetypes; TW.states[avantlastpos].activetypes = present.activetypes;
TW.states[avantlastpos].opposites = present.opposites; // possible: integrated highlighted opposite- and same-side neighbours from MS2
// (var used to exist but wasn't filled and used consistently)
TW.setState({ TW.setState({
activetypes: nextState, activetypes: nextState,
level: level, level: level,
sels: Object.keys(selections), sels: sels,
oppos: [] oppos: []
}) })
...@@ -492,8 +493,12 @@ function changeLevel() { ...@@ -492,8 +493,12 @@ function changeLevel() {
var avantlastpos = lastpos-1; var avantlastpos = lastpos-1;
var level = present.level; var level = present.level;
var sels = present.selections;//[144, 384, 543]//TW.states.selections; var sels = present.selectionNids ;//[144, 384, 543]//TW.states[last].selectionNids;
let selsChecker = {}
for (let i in sels) {
selsChecker[sels[i]] = true
}
// type "grammar" // type "grammar"
// used to distinguish types in TW.Relations // used to distinguish types in TW.Relations
...@@ -526,7 +531,7 @@ function changeLevel() { ...@@ -526,7 +531,7 @@ function changeLevel() {
nodes_2_colour[t]=false; nodes_2_colour[t]=false;
edges_2_colour[s+";"+t]=true; edges_2_colour[s+";"+t]=true;
edges_2_colour[t+";"+s]=true; edges_2_colour[t+";"+s]=true;
if( !selections[t] ) if( !selsChecker[t] )
voisinage[ t ] = true; voisinage[ t ] = true;
} }
} }
...@@ -535,7 +540,6 @@ function changeLevel() { ...@@ -535,7 +540,6 @@ function changeLevel() {
nodes_2_colour[sels[i]]=true; nodes_2_colour[sels[i]]=true;
var futurelevel = [] var futurelevel = []
if(present.level) { // [Change to Local] when level=Global(1) if(present.level) { // [Change to Local] when level=Global(1)
...@@ -590,18 +594,15 @@ function changeLevel() { ...@@ -590,18 +594,15 @@ function changeLevel() {
} }
// console.log("enviroment changeLevel nodes_2_colour", nodes_2_colour) // console.log("enviroment changeLevel nodes_2_colour", nodes_2_colour)
TW.states[avantlastpos] = {}; TW.states[avantlastpos] = {};
TW.states[avantlastpos].level = present.level; TW.states[avantlastpos].level = present.level;
TW.states[avantlastpos].selections = present.selections;
TW.states[avantlastpos].activetypes = present.activetypes; TW.states[avantlastpos].activetypes = present.activetypes;
TW.states[avantlastpos].opposites = present.opposites; TW.states[avantlastpos].selectionNids = present.selectionNids;
TW.setState({ TW.setState({
activetypes: present.activetypes, activetypes: present.activetypes,
level: futurelevel, level: futurelevel,
sels: Object.keys(selections), sels: sels,
oppos: [] oppos: []
}) })
......
...@@ -17,10 +17,9 @@ TW.catDict = {}; ...@@ -17,10 +17,9 @@ TW.catDict = {};
// SystemState is a summary of current situation // SystemState is a summary of current situation
TW.SystemState = {} TW.SystemState = {}
TW.SystemState.activetypes = [] // <== filled from TW.categories
TW.SystemState.level = true; TW.SystemState.level = true;
TW.SystemState.activetypes = [] // will be filled from TW.categories TW.SystemState.selectionNids = []; // <== current selection !!
TW.SystemState.selections = [];
TW.SystemState.opposites = [];
TW.SystemState.LouvainFait = false; TW.SystemState.LouvainFait = false;
// states[] is an array of SystemStates for future CTRL+Z or usage track // states[] is an array of SystemStates for future CTRL+Z or usage track
...@@ -28,21 +27,13 @@ TW.states = [] ...@@ -28,21 +27,13 @@ TW.states = []
TW.states[0] = false; TW.states[0] = false;
TW.states[1] = TW.SystemState TW.states[1] = TW.SystemState
// -------------------------------8<--------------
// £TODO should become TW.* or TW.SystemState.* // £TODO remove deprecated here and in parseCustom
var selections = [];
var deselections={};
var opossites = {};
var opos=[];
var oposMAX;
var matches = [];
var nodes1 = {}; var nodes1 = {};
var nodes2 = {}; var nodes2 = {};
var bipartiteD2N = {}; var bipartiteD2N = {};
var bipartiteN2D = {}; var bipartiteN2D = {};
// -------------------------------8<--------------
// ======== [ what to do at start ] ========= // // ======== [ what to do at start ] ========= //
console.log("Starting TWJS") console.log("Starting TWJS")
......
...@@ -12,7 +12,7 @@ TW.setState = function( args ) { ...@@ -12,7 +12,7 @@ TW.setState = function( args ) {
var present = TW.states.slice(-1)[0]; // Last var present = TW.states.slice(-1)[0]; // Last
var past = TW.states.slice(-2)[0] // avant Last var past = TW.states.slice(-2)[0] // avant Last
console.log("setState args: ", args); if (TW.conf.debug.logSelections) console.log("setState args: ", args);
if(!isUndef(args.activetypes)) { if(!isUndef(args.activetypes)) {
...@@ -28,15 +28,14 @@ TW.setState = function( args ) { ...@@ -28,15 +28,14 @@ TW.setState = function( args ) {
// console.log("printing the typesKey:", typesKey) // console.log("printing the typesKey:", typesKey)
if(!isUndef(args.level)) present.level = args.level; if(!isUndef(args.level)) present.level = args.level;
if(!isUndef(args.sels)) present.selections = args.sels; if(!isUndef(args.sels)) present.selectionNids = args.sels;
if(!isUndef(args.oppos)) present.opposites = args.oppos;
present.LouvainFait = false; present.LouvainFait = false;
// change level needs a selection // change level needs a selection
LevelButtonDisable(false); // £TODO rename toggleLevelButton LevelButtonDisable(false); // £TODO rename toggleLevelButton
if( present.level if( present.level
&& present.selections && present.selectionNids
&& present.selections.length==0) && present.selectionNids.length==0)
LevelButtonDisable(true); LevelButtonDisable(true);
// case to go back // case to go back
...@@ -88,12 +87,9 @@ function cancelSelection (fromTagCloud, settings) { ...@@ -88,12 +87,9 @@ function cancelSelection (fromTagCloud, settings) {
if (!settings) settings = {} if (!settings) settings = {}
highlightSelectedNodes(false); //Unselect the selected ones :D highlightSelectedNodes(false); //Unselect the selected ones :D
opossites = [];
selections = [];
//selections.length = 0;
selections.splice(0, selections.length);
TW.states.slice(-1)[0].selections=[] // clear the current state's selection and neighbors arrays
TW.SystemState.selectionNids.splice(0, TW.SystemState.selectionNids.length)
// global flag // global flag
TW.gui.selectionActive = false TW.gui.selectionActive = false
...@@ -143,19 +139,6 @@ function cancelSelection (fromTagCloud, settings) { ...@@ -143,19 +139,6 @@ function cancelSelection (fromTagCloud, settings) {
$('#searchinput').trigger("tw:eraseNodeSet"); $('#searchinput').trigger("tw:eraseNodeSet");
// (signal for plugins that any selection behavior is finished) // (signal for plugins that any selection behavior is finished)
for(var nid in deselections){
let n = TW.partialGraph.graph.nodes(nid)
if( !isUndef(n) ) {
n.customAttrs.forceLabel = false;
n.customAttrs.highlight = false;
n.customAttrs.grey=false
// like old graphResetColor but now rather graphResetFlags...
n.active=false;
}
}
deselections={};
if(TW.states.slice(-1)[0].level) if(TW.states.slice(-1)[0].level)
LevelButtonDisable(true); LevelButtonDisable(true);
...@@ -213,11 +196,10 @@ function swActual(aNodetype) { ...@@ -213,11 +196,10 @@ function swActual(aNodetype) {
function highlightSelectedNodes(flag){ function highlightSelectedNodes(flag){
if (TW.conf.debug.logSelections) if (TW.conf.debug.logSelections)
console.log("\t***methods.js:highlightSelectedNodes(flag)"+flag+" selEmpty:"+is_empty(selections)) console.log("\t***methods.js:highlightSelectedNodes(flag)"+flag+" sel:"+TW.SystemState.selectionNids)
if(!is_empty(selections)){ for(let i in TW.SystemState.selectionNids) {
for(var i in selections) { let nid = TW.SystemState.selectionNids[i]
TW.partialGraph.graph.nodes(i).active = flag TW.partialGraph.graph.nodes(nid).active = flag
}
} }
} }
...@@ -425,6 +407,9 @@ function htmlfied_nodesatts(elems){ ...@@ -425,6 +407,9 @@ function htmlfied_nodesatts(elems){
var socnodes=[] var socnodes=[]
var semnodes=[] var semnodes=[]
if (TW.conf.debug.logSelections) console.log("htmlfied_nodesatts", elems)
for(var i in elems) { for(var i in elems) {
var information=[] var information=[]
...@@ -516,21 +501,6 @@ function htmlProportionalLabels(elems , limit, selectableFlag) { ...@@ -516,21 +501,6 @@ function htmlProportionalLabels(elems , limit, selectableFlag) {
//considering complete graphs case! <= maybe i should mv it //considering complete graphs case! <= maybe i should mv it
function updateRelatedNodesPanel( sels , same, oppos ) { function updateRelatedNodesPanel( sels , same, oppos ) {
// debug
// neiLabls = []
// for (var l in same) {
// var neiId = same[l].key
// if (TW.Nodes[neiId]) {
//
// neiLabls.push(TW.Nodes[neiId].label)
// }
// else {
// console.warn("missing entry for neiId", neiId)
// }
// }
// console.log("updateRelatedNodesPanel, same:",neiLabls)
var namesDIV='' var namesDIV=''
var alterNodesDIV='' var alterNodesDIV=''
var informationDIV='' var informationDIV=''
...@@ -548,7 +518,7 @@ function updateRelatedNodesPanel( sels , same, oppos ) { ...@@ -548,7 +518,7 @@ function updateRelatedNodesPanel( sels , same, oppos ) {
alterNodesDIV+= '</div>'; alterNodesDIV+= '</div>';
} }
if(getNodeIDs(sels).length>0) { if(sels.length>0) {
sameNodesDIV+='<div id="sameNodes">';//tagcloud sameNodesDIV+='<div id="sameNodes">';//tagcloud
var sameNeighTagcloudHtml = htmlProportionalLabels( same , TW.conf.tagcloudSameLimit, true ) var sameNeighTagcloudHtml = htmlProportionalLabels( same , TW.conf.tagcloudSameLimit, true )
sameNodesDIV+= (sameNeighTagcloudHtml!=false) ? sameNeighTagcloudHtml.join("\n") : "No related items."; sameNodesDIV+= (sameNeighTagcloudHtml!=false) ? sameNeighTagcloudHtml.join("\n") : "No related items.";
...@@ -558,7 +528,7 @@ function updateRelatedNodesPanel( sels , same, oppos ) { ...@@ -558,7 +528,7 @@ function updateRelatedNodesPanel( sels , same, oppos ) {
// getTopPapers("semantic"); // getTopPapers("semantic");
informationDIV += '<br><h4>Information:</h4><ul>'; informationDIV += '<br><h4>Information:</h4><ul>';
informationDIV += htmlfied_nodesatts( getNodeIDs(sels) ).join("<br>\n") informationDIV += htmlfied_nodesatts( sels ).join("<br>\n")
informationDIV += '</ul><br>'; informationDIV += '</ul><br>';
//using the readmore.js //using the readmore.js
...@@ -585,9 +555,11 @@ function printStates() { ...@@ -585,9 +555,11 @@ function printStates() {
console.log("\t\t\t\tswActual: "+swclickActual+" | swPrev: "+swclickPrev) console.log("\t\t\t\tswActual: "+swclickActual+" | swPrev: "+swclickPrev)
console.log("\t\t\t\tNOW: "+NOW+" | PAST: "+PAST) console.log("\t\t\t\tNOW: "+NOW+" | PAST: "+PAST)
console.log("\t\t\t\tselections: ") console.log("\t\t\t\tselections: ")
console.log(Object.keys(selections)) console.log(TW.SystemState.selectionNids)
console.log("\t\t\t\topposites: ") console.log("\t\t\t\topposites neighbors: ")
console.log(Object.keys(opossites)) console.log(TW.SystemState.opposideSortdNeighs)
console.log("\t\t\t\tsame neighbors: ")
console.log(TW.SystemState.samesideSortdNeighs)
console.log("\t\t\t\t------------------------------------") console.log("\t\t\t\t------------------------------------")
} }
...@@ -609,6 +581,11 @@ function graphTagCloudElem(nodes) { ...@@ -609,6 +581,11 @@ function graphTagCloudElem(nodes) {
if(! $.isArray(nodes)) ndsids.push(nodes); if(! $.isArray(nodes)) ndsids.push(nodes);
else ndsids=nodes; else ndsids=nodes;
let newselsChecker = {}
for (let i in ndsids) {
newselsChecker[ndsids[i]] = true
}
var vars = [] var vars = []
var catDict = TW.catDict; var catDict = TW.catDict;
...@@ -635,7 +612,7 @@ function graphTagCloudElem(nodes) { ...@@ -635,7 +612,7 @@ function graphTagCloudElem(nodes) {
edges_2_colour[nid+";"+t]=true; edges_2_colour[nid+";"+t]=true;
edges_2_colour[t+";"+s]=true; edges_2_colour[t+";"+s]=true;
if( !selections[t] ) if( !newselsChecker[t] )
voisinage[ Number(t) ] = true; voisinage[ Number(t) ] = true;
} }
} }
...@@ -644,7 +621,7 @@ function graphTagCloudElem(nodes) { ...@@ -644,7 +621,7 @@ function graphTagCloudElem(nodes) {
} }
// old strategy recreated a graph with the selected and its neighbors: // old strategy recreated a graph with the selected and its neighbors:
// we know do it only if type is different // we now do it only if type is different
if (nextTypesKey != getActivetypesKey()) { if (nextTypesKey != getActivetypesKey()) {
TW.partialGraph.graph.clear(); TW.partialGraph.graph.clear();
for(var nid in nodes_2_colour) for(var nid in nodes_2_colour)
...@@ -657,7 +634,7 @@ function graphTagCloudElem(nodes) { ...@@ -657,7 +634,7 @@ function graphTagCloudElem(nodes) {
for(var i=0;i<voisinage.length;i++) { for(var i=0;i<voisinage.length;i++) {
for(var j=1;j<voisinage.length;j++) { for(var j=1;j<voisinage.length;j++) {
if( voisinage[i]!=voisinage[j] ) { if( voisinage[i]!=voisinage[j] ) {
// console.log( "\t" + voisinage[i] + " vs " + voisinage[j] ) console.log( "\t" + voisinage[i] + " vs " + voisinage[j] )
add1Elem( voisinage[i]+";"+voisinage[j] ) add1Elem( voisinage[i]+";"+voisinage[j] )
} }
} }
...@@ -682,17 +659,15 @@ function graphTagCloudElem(nodes) { ...@@ -682,17 +659,15 @@ function graphTagCloudElem(nodes) {
// £TODO setState should be doing this shifting // £TODO setState should be doing this shifting
var avantlastpos = lastpos-1; var avantlastpos = lastpos-1;
TW.states[avantlastpos] = {}; TW.states[avantlastpos] = {};
TW.states[avantlastpos].selections = present.selections; TW.states[avantlastpos].selectionNids = present.selectionNids;
TW.states[avantlastpos].level = present.level; TW.states[avantlastpos].level = present.level;
TW.states[avantlastpos].activetypes = present.activetypes; TW.states[avantlastpos].activetypes = present.activetypes;
TW.states[avantlastpos].opposites = present.opposites;
// recording the new state // recording the new state
TW.setState({ TW.setState({
activetypes: nextTypes, activetypes: nextTypes,
level: false, // forced macro level: false, // forced macro
sels: Object.keys(selections), sels: present.selectionNids
oppos: []
}) })
TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.9, angle: 0}) TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.9, angle: 0})
......
...@@ -687,29 +687,20 @@ function exactfind(label) { ...@@ -687,29 +687,20 @@ function exactfind(label) {
function getNodeLabels(elems){ function getNodeLabels(elems){
var labelss=[] var labelss=[]
for(var i in elems){ for(let i in elems){
labelss.push(TW.Nodes[elems[i]].label)
console.debug(i, elems[i])
var id=(!isUndef(elems[i].id))?elems[i].id:i
labelss.push(TW.Nodes[id].label)
} }
return labelss return labelss
} }
function getNodeIDs(elems){
return Object.keys(elems)
}
function getSelections(){ function getSelections(){
let params=[]; let selLabels=[];
for(var i in selections){ for(let i in TW.SystemState.selectionNids){
params.push(TW.Nodes[i].label); let nid = TW.SystemState.selectionNids[i]
selLabels.push(TW.Nodes[nid].label);
} }
return params; return selLabels;
} }
......
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