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 = {
// twNodeRendBorderColor: "#eee",
// font: "Crete Round",
font: "Sahitya",
// font: "Sahitya",
// fontStyle: "bold",
};
var sigmaJsGraphProperties = {
minEdgeSize: 2,
maxEdgeSize: 3
minEdgeSize: 1,
maxEdgeSize: 5
};
var sigmaJsMouseProperties = {
minRatio: 0.1,
......@@ -221,10 +222,10 @@ var leftright=true;
var edgesTF=false;
//This variables will be updated in sigma.parseCustom.js
var minNodeSize=1.00;
var maxNodeSize=5.00;
var minEdgeWeight=5.0;
var maxEdgeWeight=0.0;
var minNodeSize=10000000;
var maxNodeSize=0;
// var minEdgeWeight=5.0; // in fact never used...
// var maxEdgeWeight=0.0;
//---------------------------------------------------
var bipartite=false;
......
......@@ -186,22 +186,29 @@ function SelectionEngine() {
}
}
for(var i in nodes_2_colour) {
if(i) {
n = TW.partialGraph.graph.nodes(i)
for(var nid in nodes_2_colour) {
if(nid) {
n = TW.partialGraph.graph.nodes(nid)
if(n) {
n.color = n.customAttrs['true_color'];
n.customAttrs['grey'] = 0;
if(nodes_2_colour[i]) {
n.active = nodes_2_colour[i];
selections[i]=1
if(nodes_2_colour[nid]) {
n.active = true;
selections[nid]=1
}
}
}
}
for(var i in edges_2_colour) {
let an_edge = TW.partialGraph.graph.edges(i)
console.log('edges_2_colour', edges_2_colour)
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){
// /!\ £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.customAttrs['grey'] = 0;
}
......
......@@ -623,6 +623,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit
return;
}
// ids per weight level
// £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)
// console.log("NodeWeightFilter: "+type)
......@@ -630,6 +631,7 @@ function NodeWeightFilter( categories , sliderDivID , type_attrb , type , crit
var steps = filterparams["steps"]
var finalarray = filterparams["finalarray"]
if(steps<3) {
$(sliderDivID).freshslider({
range: true,
......
......@@ -180,6 +180,8 @@ if(RES["OK"]) {
var dicts = start.makeDicts(categories);
TW.Nodes = dicts.nodes;
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
TW.nodes1 = dicts.n1;//not used
......@@ -228,8 +230,7 @@ if(RES["OK"]) {
drawLabels: true,
labelSize: "proportional",
font: "Ubuntu Condensed", // overridden by settings_explorer.js
fontStyle: "bold",
// font: "Ubuntu Condensed", // overridden by settings_explorer.js
// labelColor: "node",
// nodesPowRatio: .3,
......
......@@ -15,7 +15,7 @@ function cancelSelection (fromTagCloud) {
if (TW.partialGraph.settings('drawEdges')) {
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)
if (e) {
e.color = e.customAttrs['grey'] ? e.customAttrs['true_color'] : e.color;
......@@ -26,7 +26,7 @@ function cancelSelection (fromTagCloud) {
//Nodes colors go back to normal
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)
if (n) {
n.active = false;
......@@ -52,11 +52,14 @@ function cancelSelection (fromTagCloud) {
$('#searchinput').trigger("tw:eraseNodeSet");
// (signal for plugins that any selection behavior is finished)
for(var i in deselections){
let n = TW.partialGraph.graph.nodes(i)
for(var nid in deselections){
let n = TW.partialGraph.graph.nodes(nid)
if( !isUndef(n) ) {
n.forceLabel=false;
n.neighbour=false;
// like old graphResetColor but now rather graphResetFlags...
n.active=false;
n.grey=false
}
}
......@@ -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(){
for(let j=0 ; j<TW.nEdges ; j++){
let n = TW.partialGraph.graph.nodes(j)
for(let j=0 ; j<TW.nNodes ; j++){
let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
if (n && !n.hidden && !n.customAttrs.grey) {
n.customAttrs.true_color = n.color
// 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
}
}
if (TW.partialGraph.settings('drawEdges')) {
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) {
e.customAttrs.true_color = e.color
e.color = TW.edgeGreyColor
......@@ -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(){
// nds = TW.partialGraph.graph.nodes().filter(function(x) {
// return !x['hidden'];
......
......@@ -442,7 +442,8 @@ SigmaUtils = function () {
// (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(){
// new sigma.js
return TW.partialGraph.graph.nodes();
......@@ -582,6 +583,8 @@ function getArrSubkeys(arr,id) {
function clustersBy(daclass) {
cancelSelection(false);
// TODO avoid this strategy and also double loop below
var v_nodes = getVisibleNodes();
var min_pow = 0;
for(var i in v_nodes) {
......@@ -629,17 +632,16 @@ function clustersBy(daclass) {
var Max_color = 255;
var Min_size = 2;
var Max_size= 6;
for(var i in NodeID_Val) {
var newval_color = Math.round( ( Min_color+(NodeID_Val[i]["round"]-real_min)*((Max_color-Min_color)/(real_max-real_min)) ) );
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 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)) ) );
TW.partialGraph.graph.nodes(i).size = newval_size;
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(nid).size = 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) ]
......
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