Commit 9e4afff2 authored by Romain Loth's avatar Romain Loth

fix nodes(i) => nodes(id) and harmonize id names

parent 7a2cb67d
...@@ -135,11 +135,12 @@ var sigmaJsDrawingProperties = { ...@@ -135,11 +135,12 @@ var sigmaJsDrawingProperties = {
// twNodeRendBorderColor: "#eee", // twNodeRendBorderColor: "#eee",
// font: "Crete Round", // font: "Crete Round",
font: "Sahitya", // font: "Sahitya",
// fontStyle: "bold",
}; };
var sigmaJsGraphProperties = { var sigmaJsGraphProperties = {
minEdgeSize: 2, minEdgeSize: 1,
maxEdgeSize: 3 maxEdgeSize: 5
}; };
var sigmaJsMouseProperties = { var sigmaJsMouseProperties = {
minRatio: 0.1, minRatio: 0.1,
...@@ -221,10 +222,10 @@ var leftright=true; ...@@ -221,10 +222,10 @@ var leftright=true;
var edgesTF=false; var edgesTF=false;
//This variables will be updated in sigma.parseCustom.js //This variables will be updated in sigma.parseCustom.js
var minNodeSize=1.00; var minNodeSize=10000000;
var maxNodeSize=5.00; var maxNodeSize=0;
var minEdgeWeight=5.0; // var minEdgeWeight=5.0; // in fact never used...
var maxEdgeWeight=0.0; // var maxEdgeWeight=0.0;
//--------------------------------------------------- //---------------------------------------------------
var bipartite=false; var bipartite=false;
......
...@@ -186,22 +186,29 @@ function SelectionEngine() { ...@@ -186,22 +186,29 @@ function SelectionEngine() {
} }
} }
for(var i in nodes_2_colour) { for(var nid in nodes_2_colour) {
if(i) { if(nid) {
n = TW.partialGraph.graph.nodes(i) n = TW.partialGraph.graph.nodes(nid)
if(n) { if(n) {
n.color = n.customAttrs['true_color']; n.color = n.customAttrs['true_color'];
n.customAttrs['grey'] = 0; n.customAttrs['grey'] = 0;
if(nodes_2_colour[i]) { if(nodes_2_colour[nid]) {
n.active = nodes_2_colour[i]; n.active = true;
selections[i]=1 selections[nid]=1
} }
} }
} }
} }
for(var i in edges_2_colour) { console.log('edges_2_colour', edges_2_colour)
let an_edge = TW.partialGraph.graph.edges(i) for(var eid in edges_2_colour) {
// console.log(eid)
let an_edge = TW.partialGraph.graph.edges(eid)
if(!isUndef(an_edge) && !an_edge.hidden){ if(!isUndef(an_edge) && !an_edge.hidden){
// /!\ £TODO change only *flags* here, and then
// make all color etc changes in renderers depending on flags
an_edge.color = an_edge.customAttrs['true_color']; an_edge.color = an_edge.customAttrs['true_color'];
an_edge.customAttrs['grey'] = 0; an_edge.customAttrs['grey'] = 0;
} }
......
...@@ -623,6 +623,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit ...@@ -623,6 +623,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit
return; return;
} }
// ids per weight level
// £TODO make this into a type_attrb index (eg weight index) instead of recalculating each time // £TODO make this into a type_attrb index (eg weight index) instead of recalculating each time
var filterparams = AlgorithmForSliders ( TW.Nodes , type , type_attrb , criteria) var filterparams = AlgorithmForSliders ( TW.Nodes , type , type_attrb , criteria)
// console.log("NodeWeightFilter: "+type) // console.log("NodeWeightFilter: "+type)
...@@ -630,6 +631,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit ...@@ -630,6 +631,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit
var steps = filterparams["steps"] var steps = filterparams["steps"]
var finalarray = filterparams["finalarray"] var finalarray = filterparams["finalarray"]
if(steps<3) { if(steps<3) {
$(sliderDivID).freshslider({ $(sliderDivID).freshslider({
range: true, range: true,
......
...@@ -180,6 +180,8 @@ if(RES["OK"]) { ...@@ -180,6 +180,8 @@ if(RES["OK"]) {
var dicts = start.makeDicts(categories); var dicts = start.makeDicts(categories);
TW.Nodes = dicts.nodes; TW.Nodes = dicts.nodes;
TW.Edges = dicts.edges; TW.Edges = dicts.edges;
TW.nodeIds = Object.keys(dicts.nodes) // useful for loops
TW.edgeIds = Object.keys(dicts.edges)
if (the_data.clusters) TW.Clusters = the_data.clusters if (the_data.clusters) TW.Clusters = the_data.clusters
TW.nodes1 = dicts.n1;//not used TW.nodes1 = dicts.n1;//not used
...@@ -228,8 +230,7 @@ if(RES["OK"]) { ...@@ -228,8 +230,7 @@ if(RES["OK"]) {
drawLabels: true, drawLabels: true,
labelSize: "proportional", labelSize: "proportional",
font: "Ubuntu Condensed", // overridden by settings_explorer.js // font: "Ubuntu Condensed", // overridden by settings_explorer.js
fontStyle: "bold",
// labelColor: "node", // labelColor: "node",
// nodesPowRatio: .3, // nodesPowRatio: .3,
......
...@@ -15,7 +15,7 @@ function cancelSelection (fromTagCloud) { ...@@ -15,7 +15,7 @@ function cancelSelection (fromTagCloud) {
if (TW.partialGraph.settings('drawEdges')) { if (TW.partialGraph.settings('drawEdges')) {
for(let i=0;i<TW.nEdges;i++){ for(let i=0;i<TW.nEdges;i++){
let e = TW.partialGraph.graph.edges(i) let e = TW.partialGraph.graph.edges(TW.edgeIds[i])
// console.log("cancelSelection: edge", e) // console.log("cancelSelection: edge", e)
if (e) { if (e) {
e.color = e.customAttrs['grey'] ? e.customAttrs['true_color'] : e.color; e.color = e.customAttrs['grey'] ? e.customAttrs['true_color'] : e.color;
...@@ -26,7 +26,7 @@ function cancelSelection (fromTagCloud) { ...@@ -26,7 +26,7 @@ function cancelSelection (fromTagCloud) {
//Nodes colors go back to normal //Nodes colors go back to normal
for(let j=0;j<TW.nNodes;j++){ for(let j=0;j<TW.nNodes;j++){
let n = TW.partialGraph.graph.nodes(j) let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
// console.log("cancelSelection: node", n) // console.log("cancelSelection: node", n)
if (n) { if (n) {
n.active = false; n.active = false;
...@@ -52,11 +52,14 @@ function cancelSelection (fromTagCloud) { ...@@ -52,11 +52,14 @@ function cancelSelection (fromTagCloud) {
$('#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 i in deselections){ for(var nid in deselections){
let n = TW.partialGraph.graph.nodes(i) let n = TW.partialGraph.graph.nodes(nid)
if( !isUndef(n) ) { if( !isUndef(n) ) {
n.forceLabel=false; n.forceLabel=false;
n.neighbour=false; n.neighbour=false;
// like old graphResetColor but now rather graphResetFlags...
n.active=false;
n.grey=false
} }
} }
...@@ -544,22 +547,24 @@ function graphTagCloudElem(nodes) { ...@@ -544,22 +547,24 @@ function graphTagCloudElem(nodes) {
} }
// new sigma.js: is this at all used? // /!\ £TODO change only *flags* here, and then
// make all color etc changes in renderers depending on flags
function greyEverything(){ function greyEverything(){
for(let j=0 ; j<TW.nEdges ; j++){ for(let j=0 ; j<TW.nNodes ; j++){
let n = TW.partialGraph.graph.nodes(j) let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
if (n && !n.hidden && !n.customAttrs.grey) { if (n && !n.hidden && !n.customAttrs.grey) {
n.customAttrs.true_color = n.color n.customAttrs.true_color = n.color
// TODO check if no simpler strategy than reinvoke hex2rga each time // TODO check if no simpler strategy than reinvoke hex2rga each time
n.color = "rgba("+hex2rga(n.color)+",0.5)" // n.color = "rgba("+hex2rga(n.color)+",0.5)"
n.color = "rgba(15,15,15,0.5)"
n.customAttrs['grey'] = 1 n.customAttrs['grey'] = 1
} }
} }
if (TW.partialGraph.settings('drawEdges')) { if (TW.partialGraph.settings('drawEdges')) {
for(let i=0;i<TW.nEdges;i++){ for(let i=0;i<TW.nEdges;i++){
let e = TW.partialGraph.graph.edges(i) let e = TW.partialGraph.graph.edges(TW.edgeIds[i])
if (e && !e.hidden && !e.customAttrs.grey) { if (e && !e.hidden && !e.customAttrs.grey) {
e.customAttrs.true_color = e.color e.customAttrs.true_color = e.color
e.color = TW.edgeGreyColor e.color = TW.edgeGreyColor
...@@ -570,7 +575,7 @@ function greyEverything(){ ...@@ -570,7 +575,7 @@ function greyEverything(){
} }
// new sigma.js: is this at all used? // new sigma.js: TODO change logic (the reverse of greyEverything is done by redraw for the colors, and cancelSelection for the flags...)
// function graphResetColor(){ // function graphResetColor(){
// nds = TW.partialGraph.graph.nodes().filter(function(x) { // nds = TW.partialGraph.graph.nodes().filter(function(x) {
// return !x['hidden']; // return !x['hidden'];
......
...@@ -442,7 +442,8 @@ SigmaUtils = function () { ...@@ -442,7 +442,8 @@ SigmaUtils = function () {
// (TODO REFA make them inside TW.- ns) // (TODO REFA make them inside TW.- ns)
// not often necessary, use TW.partialGraph.graph.nodes(j) as accessor // not often necessary + costly in mem because is a clone
// => preferably use TW.partialGraph.graph.nodes(some_node_id) as accessor
function getnodes(){ function getnodes(){
// new sigma.js // new sigma.js
return TW.partialGraph.graph.nodes(); return TW.partialGraph.graph.nodes();
...@@ -582,6 +583,8 @@ function getArrSubkeys(arr,id) { ...@@ -582,6 +583,8 @@ function getArrSubkeys(arr,id) {
function clustersBy(daclass) { function clustersBy(daclass) {
cancelSelection(false); cancelSelection(false);
// TODO avoid this strategy and also double loop below
var v_nodes = getVisibleNodes(); var v_nodes = getVisibleNodes();
var min_pow = 0; var min_pow = 0;
for(var i in v_nodes) { for(var i in v_nodes) {
...@@ -629,17 +632,16 @@ function clustersBy(daclass) { ...@@ -629,17 +632,16 @@ function clustersBy(daclass) {
var Max_color = 255; var Max_color = 255;
var Min_size = 2; var Min_size = 2;
var Max_size= 6; var Max_size= 6;
for(var i in NodeID_Val) { for(var nid in NodeID_Val) {
var newval_color = Math.round( ( Min_color+(NodeID_Val[nid]["round"]-real_min)*((Max_color-Min_color)/(real_max-real_min)) ) );
var newval_color = Math.round( ( Min_color+(NodeID_Val[i]["round"]-real_min)*((Max_color-Min_color)/(real_max-real_min)) ) );
var hex_color = rgbToHex(255, (255-newval_color) , 0) var hex_color = rgbToHex(255, (255-newval_color) , 0)
TW.partialGraph.graph.nodes(i).color = hex_color TW.partialGraph.graph.nodes(nid).color = hex_color
var newval_size = Math.round( ( Min_size+(NodeID_Val[i]["round"]-real_min)*((Max_size-Min_size)/(real_max-real_min)) ) ); var newval_size = Math.round( ( Min_size+(NodeID_Val[nid]["round"]-real_min)*((Max_size-Min_size)/(real_max-real_min)) ) );
TW.partialGraph.graph.nodes(i).size = newval_size; TW.partialGraph.graph.nodes(nid).size = newval_size;
// console.log("real:"+ NodeID_Val[i]["real"] + " | newvalue: "+newval_size) // console.log("real:"+ NodeID_Val[i]["real"] + " | newvalue: "+newval_size)
TW.partialGraph.graph.nodes(i).label = "("+NodeID_Val[i]["real"].toFixed(min_pow)+") "+TW.Nodes[i].label TW.partialGraph.graph.nodes(nid).label = "("+NodeID_Val[nid]["real"].toFixed(min_pow)+") "+TW.Nodes[nid].label
} }
// [ / Scaling node colours(0-255) and sizes(3-5) ] // [ / Scaling node colours(0-255) and sizes(3-5) ]
......
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