Commit d8d77bf7 authored by Romain Loth's avatar Romain Loth

rm unnecessary number casting and other minor fixes

parent aebf89e8
...@@ -44,7 +44,7 @@ var TW = {} ...@@ -44,7 +44,7 @@ var TW = {}
// *and* subdirectory to import if true // *and* subdirectory to import if true
// see also ProcessDivsFlags() // see also ProcessDivsFlags()
TW.DivsFlags["histogramModule"] = false ; TW.DivsFlags["histogramModule"] = false ;
TW.DivsFlags["histogramDailyVariantModule"] = true ; TW.DivsFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE // TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TW.DivsFlags["crowdsourcingModule"] = true ; TW.DivsFlags["crowdsourcingModule"] = true ;
...@@ -107,11 +107,12 @@ TW.filterSliders = false ...@@ -107,11 +107,12 @@ TW.filterSliders = false
TW.histogramStartThreshold = 10 ; TW.histogramStartThreshold = 10 ;
TW.defaultNodeColor = "rgb(40,40,40)"
TW.edgeDefaultOpacity = 0.5 // opacity when true_color TW.edgeDefaultOpacity = 0.5 // opacity when true_color
TW.edgeGreyColor = "rgba(150, 150, 150, 0.2)"; TW.edgeGreyColor = "rgba(150, 150, 150, 0.2)";
TW.nodesGreyBorderColor = "rgba(100, 100, 100, 0.5)"; TW.nodesGreyBorderColor = "rgba(100, 100, 100, 0.5)";
TW.selectedColor = "node" // "node" for a background like the node's color, TW.selectedColor = "node" // "node" for a background like the node's color,
// "default" for note-like yellow // "default" for note-like yellow
TW.overSampling = true // costly hi-def rendering (true => pixelRatio x 2) TW.overSampling = true // costly hi-def rendering (true => pixelRatio x 2)
......
...@@ -8,26 +8,19 @@ function SelectionEngine() { ...@@ -8,26 +8,19 @@ function SelectionEngine() {
// console.log("addvalue, prevsels, currsels",addvalue, prevsels, currsels) // console.log("addvalue, prevsels, currsels",addvalue, prevsels, currsels)
var targeted = [] var targeted = []
var buffer = Object.keys(prevsels).map(Number).sort(this.sortNumber); var buffer = Object.keys(prevsels);
// currsels = bunch of nodes from a click in the map // currsels = bunch of nodes from a click in the map
currsels = currsels.map(Number).sort(this.sortNumber);
if(addvalue) { if(addvalue) {
// FOR SIMPLE ADD WITHOUT COMPLEMENT
targeted = currsels.concat(buffer.filter(function (item) { targeted = currsels.concat(buffer.filter(function (item) {
return currsels.indexOf(item) < 0; return currsels.indexOf(item) < 0;
})); }));
} else targeted = currsels; } else targeted = currsels;
targeted = targeted.map(Number)
// debug
// console.log("targeted::", targeted)
// NB new sigma: my REFA deprecated clicktype=="double"
if(targeted.length==0) return []; if(targeted.length==0) return [];
targeted = targeted.sort(); // ------------ FOR SETWISE COMPLEMENT ---------------------->8---------
// if(buffer.length>0) { // if(buffer.length>0) {
// if(JSON.stringify(buffer)==JSON.stringify(targeted)) { // if(JSON.stringify(buffer)==JSON.stringify(targeted)) {
// // this is just effective for Add[ ] ... // // this is just effective for Add[ ] ...
...@@ -51,16 +44,17 @@ function SelectionEngine() { ...@@ -51,16 +44,17 @@ function SelectionEngine() {
// whitelist[n] = true; // whitelist[n] = true;
// } // }
// } // }
// targeted = Object.keys(whitelist).map(Number); // targeted = Object.keys(whitelist);
// } else {// inter = 0 ==> click in other portion of the graph (!= current selection) // } else {// inter = 0 ==> click in other portion of the graph (!= current selection)
// // Union! // // Union!
// if(addvalue) { // if(addvalue) {
// targeted = targeted.concat(buffer.filter(function (item) { // targeted = currsels.concat(buffer.filter(function (item) {
// return targeted.indexOf(item) < 0; // return currsels.indexOf(item) < 0;
// })); // }));
// } // }
// } // }
// } // }
// ---------------------------------------------------------->8---------
return targeted; return targeted;
}).index(); }).index();
...@@ -125,6 +119,8 @@ function SelectionEngine() { ...@@ -125,6 +119,8 @@ function SelectionEngine() {
//Util //Util
this.intersect_safe = function(a, b) { this.intersect_safe = function(a, b) {
a.sort()
b.sort()
var ai=0, bi=0; var ai=0, bi=0;
var result = new Array(); var result = new Array();
...@@ -181,10 +177,13 @@ function SelectionEngine() { ...@@ -181,10 +177,13 @@ function SelectionEngine() {
selections = {} selections = {}
// targeted arg 'nodes' can be nid array or single nid
var ndsids=[] var ndsids=[]
if(nodes) { if(nodes) {
if(! $.isArray(nodes)) ndsids.push(nodes); if(! $.isArray(nodes)) ndsids.push(nodes);
else ndsids=nodes; else ndsids=nodes;
for(var i in ndsids) { for(var i in ndsids) {
var s = ndsids[i]; var s = ndsids[i];
...@@ -261,7 +260,7 @@ function SelectionEngine() { ...@@ -261,7 +260,7 @@ function SelectionEngine() {
// show the button to remove selection // show the button to remove selection
$("#unselectbutton").show() ; $("#unselectbutton").show() ;
var the_new_sels = Object.keys(selections).map(Number) var the_new_sels = Object.keys(selections)
TW.partialGraph.states.slice(-1)[0].selections = the_new_sels; TW.partialGraph.states.slice(-1)[0].selections = the_new_sels;
TW.partialGraph.states.slice(-1)[0].setState( { sels: the_new_sels} ) TW.partialGraph.states.slice(-1)[0].setState( { sels: the_new_sels} )
...@@ -279,11 +278,12 @@ function SelectionEngine() { ...@@ -279,11 +278,12 @@ function SelectionEngine() {
}); });
// console.log("Event [gotNodeSet] sent from Tinaweb MultipleSelection2") // console.log("Event [gotNodeSet] sent from Tinaweb MultipleSelection2")
// TODO REFA this used for bipartite case but needs testing with correct typestring case // £TODO REFA this used for bipartite case but needs testing with correct typestring case
//
if(TW.Relations["1|1"]) { if(TW.Relations["1|1"]) {
for(var s in the_new_sels) { for(var s in the_new_sels) {
var bipaNeighs = TW.Relations["1|1"][the_new_sels[s]]; var bipaNeighs = TW.Relations["1|1"][the_new_sels[s]];
for(var n in neighs) { for(var n in bipaNeighs) {
if (typeof oppositeSideNeighbors[bipaNeighs[n]] == "undefined") if (typeof oppositeSideNeighbors[bipaNeighs[n]] == "undefined")
oppositeSideNeighbors[bipaNeighs[n]] = 0; oppositeSideNeighbors[bipaNeighs[n]] = 0;
oppositeSideNeighbors[bipaNeighs[n]]++; oppositeSideNeighbors[bipaNeighs[n]]++;
...@@ -308,9 +308,9 @@ function SelectionEngine() { ...@@ -308,9 +308,9 @@ function SelectionEngine() {
return b-a return b-a
}); });
// console.debug('oppos', oppos) console.debug('selections', selections)
// console.debug('same', same) console.debug('oppos', oppos)
// console.debug('same', same)
overNodes=true; overNodes=true;
......
...@@ -687,7 +687,7 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -687,7 +687,7 @@ function prepareNodesRenderingProperties(nodesDict) {
} }
} }
// hex color ex "#eee or #AA00AA" // hex color ex "#eee or #AA00AA"
else if (/^#[A-Fa-f0-1]{3,6}$/.test(n.color)) { else if (/^#[A-Fa-f0-9]{3,6}$/.test(n.color)) {
rgba = hex2rgba(n.color) rgba = hex2rgba(n.color)
rgbStr = rgba.splice(0, 3).join(','); rgbStr = rgba.splice(0, 3).join(',');
} }
...@@ -695,12 +695,23 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -695,12 +695,23 @@ function prepareNodesRenderingProperties(nodesDict) {
invalidFormat = true invalidFormat = true
} }
} }
else {
invalidFormat = true
}
if (!invalidFormat) {
n.color = `rgb(${rgbStr})`
}
else {
n.color = TW.defaultNodeColor
rgbStr = TW.defaultNodeColor.split(',').splice(0, 3).join(',');
}
n.customAttrs = { n.customAttrs = {
grey: false, grey: false,
highlight: false, highlight: false,
true_color : n.color, true_color : n.color,
defgrey_color : "rgba("+rgbStr+",.4)" defgrey_color : "rgba("+rgbStr+",.5)"
} }
// POSS n.type: distinguish rendtype and twtype // POSS n.type: distinguish rendtype and twtype
......
...@@ -899,7 +899,8 @@ function dictfyJSON( data , categories ) { ...@@ -899,7 +899,8 @@ function dictfyJSON( data , categories ) {
node.y = (n.y)? n.y : Math.random(); node.y = (n.y)? n.y : Math.random();
node.color = (n.color)? n.color : "#FFFFFF" ; node.color = (n.color)? n.color : "#FFFFFF" ;
if(n.shape) node.shape = n.shape; if(n.shape) node.shape = n.shape;
if(n.attributes) node.attributes = n.attributes; if(n.attributes) node.attributes = n.attributes
else node.attributes = {}
node.type = (n.type)? n.type : categories[0] ; node.type = (n.type)? n.type : categories[0] ;
// node.shape = "square"; // node.shape = "square";
......
...@@ -553,8 +553,8 @@ SigmaUtils = function () { ...@@ -553,8 +553,8 @@ SigmaUtils = function () {
// (TODO REFA make them inside TW.- ns) // (TODO REFA make them inside TW.- ns)
// not often necessary + costly in mem because is a clone // getnodes => preferably use TW.partialGraph.graph.nodes(some_node_id) as accessor
// => preferably use TW.partialGraph.graph.nodes(some_node_id) as accessor // (not often necessary + costly in mem because is a clone)
function getnodes(){ function getnodes(){
// new sigma.js // new sigma.js
return TW.partialGraph.graph.nodes(); return TW.partialGraph.graph.nodes();
...@@ -610,10 +610,9 @@ function find(lquery){ ...@@ -610,10 +610,9 @@ function find(lquery){
} }
function exactfind(label) { function exactfind(label) {
nds=getnodes();
if (typeof lquery == 'string' && lquery.length > 0) { if (typeof lquery == 'string' && lquery.length > 0) {
for(var i in nds){ for(var i in TW.nodeIds){
n=nds[i]; n=TW.partialGraph.graph.nodes(TW.nodeIds[i]);
if(!n.hidden){ if(!n.hidden){
if (n.label==label) { if (n.label==label) {
return n; return n;
......
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