Commit a28f43a8 authored by Romain Loth's avatar Romain Loth

after esth. choice to color edges, restore fixed repaintEdges

parent 8a89453d
...@@ -206,7 +206,7 @@ if(RES["OK"]) { ...@@ -206,7 +206,7 @@ if(RES["OK"]) {
// in-place: pre-compute all color/grey/size properties // in-place: pre-compute all color/grey/size properties
prepareNodesRenderingProperties(TW.Nodes) prepareNodesRenderingProperties(TW.Nodes)
prepareEdgesRenderingProperties(TW.Edges) prepareEdgesRenderingProperties(TW.Edges, TW.Nodes)
TW.selectionActive = false // changes rendering mode TW.selectionActive = false // changes rendering mode
......
...@@ -583,7 +583,7 @@ function unHide(nodeId) { ...@@ -583,7 +583,7 @@ function unHide(nodeId) {
// edges greyish color for unselected, when we have a selection // edges greyish color for unselected, when we have a selection
// NB: we just change the flags, not the colors // NB: we just change the flags, not the colors
// - renderer will see the flags and handle the case accordingly // renderer will see the flags and handle the case accordingly
function greyEverything(){ function greyEverything(){
for(var j=0 ; j<TW.nNodes ; j++){ for(var j=0 ; j<TW.nNodes ; j++){
...@@ -597,12 +597,6 @@ function greyEverything(){ ...@@ -597,12 +597,6 @@ function greyEverything(){
n.active = false n.active = false
n.customAttrs.forceLabel = false; n.customAttrs.forceLabel = false;
n.customAttrs.highlight = false; n.customAttrs.highlight = false;
// special case after a coloredBy or clustersBy
// (now handled in renderer)
// if (TW.handpickedcolor) {
// n.color = "rgba("+hex2rgba(n.color+"55").join(','))"
// }
} }
} }
...@@ -612,9 +606,6 @@ function greyEverything(){ ...@@ -612,9 +606,6 @@ function greyEverything(){
if (e && !e.hidden && !e.customAttrs.grey) { if (e && !e.hidden && !e.customAttrs.grey) {
e.customAttrs.grey = 1 e.customAttrs.grey = 1
e.customAttrs.activeEdge = 0 e.customAttrs.activeEdge = 0
// new specification: coloredBy does not affect edges
// (ie no special case for notDefaultColors)
} }
} }
} }
...@@ -681,14 +672,14 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -681,14 +672,14 @@ function prepareNodesRenderingProperties(nodesDict) {
} }
} }
function prepareEdgesRenderingProperties(edgesDict) { function prepareEdgesRenderingProperties(edgesDict, nodesDict) {
for (var eid in edgesDict) { for (var eid in edgesDict) {
var e = edgesDict[eid] var e = edgesDict[eid]
e.weight = Math.round(e.weight*1000)/1000 e.weight = Math.round(e.weight*1000)/1000
// e.size = e.weight // REFA s/weight/size/ ? // e.size = e.weight // REFA s/weight/size/ ?
var rgbStr = sigmaTools.edgeRGB(e.source, e.target) var rgbStr = sigmaTools.edgeRGB(nodesDict[e.source].color, nodesDict[e.target].color)
e.color = "rgba("+rgbStr+","+TW.edgeDefaultOpacity+")" e.color = "rgba("+rgbStr+","+TW.edgeDefaultOpacity+")"
e.customAttrs = { e.customAttrs = {
......
...@@ -201,12 +201,17 @@ SigmaUtils = function () { ...@@ -201,12 +201,17 @@ SigmaUtils = function () {
// console.warn("rendering edge", edge) // console.warn("rendering edge", edge)
var defSize = edge[prefix + 'size'] || settings("minEdgeSize") || 1 ; var defSize = edge[prefix + 'size'] || settings("minEdgeSize") || 1 ;
// precomputed color with no opacity
// cf. sigmaTools.edgeRGB
var baseRGB = TW.handpickedcolor ? edge.customAttrs.alt_rgb : edge.customAttrs.rgb
if (edge.customAttrs.activeEdge) { if (edge.customAttrs.activeEdge) {
size = (defSize * 2) + 1 size = (defSize * 2) + 1
// color with no opacity
// cf. sigmaTools.edgeRGB // active edges look well with no opacity
color = 'rgb('+edge.customAttrs.rgb+')' color = `rgb(${baseRGB})`
// console.log("drawing activeEdge with size", size)
// edge.customAttrs.activeEdge = false // for one-time // edge.customAttrs.activeEdge = false // for one-time
} }
else if (edge.customAttrs.grey) { else if (edge.customAttrs.grey) {
...@@ -214,8 +219,7 @@ SigmaUtils = function () { ...@@ -214,8 +219,7 @@ SigmaUtils = function () {
size = 1 size = 1
} }
else { else {
// color = "rgba( "+rgb.join()+" , "+TW.edgeDefaultOpacity+")"; color = "rgba( "+baseRGB+" , "+TW.edgeDefaultOpacity+")";
color = edge.customAttrs.true_color
size = defSize size = defSize
} }
...@@ -686,12 +690,10 @@ function clustersBy(daclass) { ...@@ -686,12 +690,10 @@ function clustersBy(daclass) {
TW.handpickedcolor = true TW.handpickedcolor = true
// TODO avoid this strategy and also double loop below
var v_nodes = getVisibleNodes();
var min_pow = 0; var min_pow = 0;
for(var i in v_nodes) { for(var j in TW.nodeIds) {
var the_node = TW.Nodes[ v_nodes[i].id ] var the_node = TW.Nodes[ TW.nodeIds[j] ]
var attval = ( isUndef(the_node.attributes) || isUndef(the_node.attributes[daclass]) )? v_nodes[i][daclass]: the_node.attributes[daclass]; var attval = the_node.attributes[daclass];
if( !isNaN(parseFloat(attval)) ) { //is float if( !isNaN(parseFloat(attval)) ) { //is float
while(true) { while(true) {
var themult = Math.pow(10,min_pow); var themult = Math.pow(10,min_pow);
...@@ -707,13 +709,14 @@ function clustersBy(daclass) { ...@@ -707,13 +709,14 @@ function clustersBy(daclass) {
var real_min = 1000000; var real_min = 1000000;
var real_max = -1; var real_max = -1;
var themult = Math.pow(10,min_pow); var themult = Math.pow(10,min_pow);
for(var i in v_nodes) {
var the_node = TW.Nodes[ v_nodes[i].id ] for(var j in TW.nodeIds) {
var attval = ( isUndef(the_node.attributes) || isUndef(the_node.attributes[daclass]) )? v_nodes[i][daclass]: the_node.attributes[daclass]; var the_node = TW.Nodes[ TW.nodeIds[j] ]
var attval = the_node.attributes[daclass];
var attnumber = Number(attval); var attnumber = Number(attval);
var round_number = Math.round( attnumber*themult ) ; var round_number = Math.round( attnumber*themult ) ;
NodeID_Val[v_nodes[i].id] = { "round":round_number , "real":attnumber }; NodeID_Val[TW.nodeIds[j]] = { "round":round_number , "real":attnumber };
if (round_number<real_min) real_min = round_number; if (round_number<real_min) real_min = round_number;
if (round_number>real_max) real_max = round_number; if (round_number>real_max) real_max = round_number;
...@@ -749,12 +752,8 @@ function clustersBy(daclass) { ...@@ -749,12 +752,8 @@ function clustersBy(daclass) {
} }
// [ / Scaling node colours(0-255) and sizes(3-5) ] // [ / Scaling node colours(0-255) and sizes(3-5) ]
// Edge precompute alt_rgb by new source-target nodes-colours combination
// [ Edge-colour by source-target nodes-colours combination ]
repaintEdges() repaintEdges()
// [ / Edge-colour by source-target nodes-colours combination ]
set_ClustersLegend ( null ) set_ClustersLegend ( null )
...@@ -765,26 +764,29 @@ function clustersBy(daclass) { ...@@ -765,26 +764,29 @@ function clustersBy(daclass) {
// for debug of colorsRelByBins // for debug of colorsRelByBins
var totalsPerBinMin = {} var totalsPerBinMin = {}
// Edge-colour by source-target nodes-colours combination // Edge-colour: precompute alt_rgb by source-target node.alt_color combination
// TODO rm because duplicate with edgeRGB
function repaintEdges() { function repaintEdges() {
console.log('skipping repaintEdges')
// var v_edges = getVisibleEdges(); for (var i in TW.edgeIds) {
// for(var e in v_edges) { let eid = TW.edgeIds[i]
// var e_id = v_edges[e].id;
// var a = TW.partialGraph.graph.nodes(v_edges[e].source).color; if (eid) {
// var b = TW.partialGraph.graph.nodes(v_edges[e].target).color; let idPair = eid.split(';')
// a = hex2rgba(a); if (idPair.length != 2) {
// b = hex2rgba(b); console.warn('skipping invalid edgeId', eid)
// var r = (a[0] + b[0]) >> 1; }
// var g = (a[1] + b[1]) >> 1; else {
// var b = (a[2] + b[2]) >> 1; let e = TW.partialGraph.graph.edges(eid)
// let src = TW.partialGraph.graph.nodes(idPair[0])
// TW.partialGraph.graph.edges(e_id).color = "rgba("+[r,g,b].join(",")+",0.5)"; let tgt = TW.partialGraph.graph.nodes(idPair[1])
//
// // also keep components array (useful if we change opacity when selected) let src_color = src.customAttrs.alt_color || '#555'
// TW.partialGraph.graph.edges(e_id).customAttrs.rgb = [r,g,b] let tgt_color = tgt.customAttrs.alt_color || '#555'
// } e.customAttrs.alt_rgb = sigmaTools.edgeRGB(src_color,tgt_color)
// we don't set e.color because opacity may vary if selected or not
}
}
}
} }
// rewrite of clustersBy with binning and for attributes that can have negative float values // rewrite of clustersBy with binning and for attributes that can have negative float values
...@@ -910,10 +912,11 @@ function colorsRelByBins(daclass) { ...@@ -910,10 +912,11 @@ function colorsRelByBins(daclass) {
if((theVal >= binMin) && (theVal < binMax)) { if((theVal >= binMin) && (theVal < binMax)) {
// TW.partialGraph._core.graph.nodesIndex[n.id].binMin = binMin // TW.partialGraph._core.graph.nodesIndex[n.id].binMin = binMin
// TW.partialGraph._core.graph.nodesIndex[n.id].color = binColors[j] // TW.partialGraph._core.graph.nodesIndex[n.id].color = binColors[j]
TW.partialGraph.graph.nodes(n.id).binMin = binMin
TW.partialGraph.graph.nodes(n.id).color = binColors[k] n.binMin = binMin
TW.partialGraph.graph.nodes(n.id).customAttrs.alt_color = binColors[k] n.color = binColors[k]
TW.partialGraph.graph.nodes(n.id).customAttrs.altgrey_color = false n.customAttrs.alt_color = binColors[k]
n.customAttrs.altgrey_color = false
foundBin = true foundBin = true
// console.log(`theVal ${theVal} => found its bin ${binMin} ... ${binColors[k]}`) // console.log(`theVal ${theVal} => found its bin ${binMin} ... ${binColors[k]}`)
...@@ -926,21 +929,22 @@ function colorsRelByBins(daclass) { ...@@ -926,21 +929,22 @@ function colorsRelByBins(daclass) {
break break
} }
} }
}
if (!foundBin) { // case no val or no bin
TW.partialGraph.graph.nodes(n.id).binMin = null if (!foundBin) {
TW.partialGraph.graph.nodes(n.id).color = '#555' // console.log('no val for', n.id)
TW.partialGraph.graph.nodes(n.id).customAttrs.alt_color = '#555' n.binMin = null
} n.color = '#555'
n.customAttrs.alt_color = '#555'
} }
} }
} }
console.info('coloring distribution per tick thresholds' , totalsPerBinMin[binMin]) console.info('coloring distribution per tick thresholds' , totalsPerBinMin)
// [ Edge-colour by source-target nodes-colours combination ] // Edge precompute alt_rgb by new source-target nodes-colours combination
// repaintEdges() repaintEdges()
// [ / Edge-colour by source-target nodes-colours combination ]
set_ClustersLegend ( null ) set_ClustersLegend ( null )
...@@ -996,22 +1000,8 @@ function colorsBy(daclass) { ...@@ -996,22 +1000,8 @@ function colorsBy(daclass) {
TW.handpickedcolor = true TW.handpickedcolor = true
} }
// [ Edge-colour by source-target nodes-colours combination ] // Edge precompute alt_rgb by new source-target nodes-colours combination
// var v_edges = getVisibleEdges(); repaintEdges()
// for(var e in v_edges) {
// var e_id = v_edges[e].id;
// var a = v_edges[e].source.color;
// var b = v_edges[e].target.color;
// if (a && b) {
// a = hex2rgba(a);
// b = hex2rgba(b);
// var r = (a[0] + b[0]) >> 1;
// var g = (a[1] + b[1]) >> 1;
// var b = (a[2] + b[2]) >> 1;
// TW.partialGraph.graph.edges(e_id).color = "rgba("+[r,g,b].join(",")+",0.5)";
// }
// }
// [ / Edge-colour by source-target nodes-colours combination ]
// £TODO fix ClustersLegend // £TODO fix ClustersLegend
set_ClustersLegend ( daclass ) set_ClustersLegend ( daclass )
......
...@@ -44,7 +44,7 @@ sigmaTools = (function(stools) { ...@@ -44,7 +44,7 @@ sigmaTools = (function(stools) {
for (var i in rawGexfEdges) { for (var i in rawGexfEdges) {
var rawEdge = rawGexfEdges[i] var rawEdge = rawGexfEdges[i]
var rgbStr = sigmaTools.edgeRGB(rawEdge.source, rawEdge.target, newNodes) var rgbStr = sigmaTools.edgeRGB(newNodes[rawEdge.source].color, newNodes[rawEdge.target].color)
var leColor = "rgba("+rgbStr+","+TW.edgeDefaultOpacity+")" var leColor = "rgba("+rgbStr+","+TW.edgeDefaultOpacity+")"
var newEid = rawEdge.source+";"+rawEdge.target; var newEid = rawEdge.source+";"+rawEdge.target;
...@@ -86,52 +86,35 @@ sigmaTools = (function(stools) { ...@@ -86,52 +86,35 @@ sigmaTools = (function(stools) {
}; };
// TODO check duplicate functionalities with repaintEdges // TODO check duplicate functionalities with repaintEdges
stools.edgeRGB = function(src_id, tgt_id, nodeIndex) { stools.edgeRGB = function(color_a, color_b) {
if (!nodeIndex) { //edge color will be the combination of the 2 node colors
nodeIndex = TW.Nodes
}
if (!Object.keys(nodeIndex).length) { // console.log("color a", color_a)
console.warn('empty nodeIndex') // console.log("color b", color_b)
}
// console.log('edgeRGB, src_id', src_id)
// console.log('edgeRGB, tgt_id', tgt_id)
//
if (!nodeIndex[src_id] || !nodeIndex[tgt_id]) {
return '0,0,0'
}
//edge color will be the combination of the 2 node colors
var a = nodeIndex[src_id]['color'];
var b = nodeIndex[tgt_id]['color'];
var tmp var tmp
// console.log("color a", a)
// console.log("color b", b)
if(a.charAt(0)!="#") { if(color_a.charAt(0)!="#") {
tmp = a.replace(/rgba?\(/,"").replace(")","").split(",") tmp = color_a.replace(/rgba?\(/,"").replace(")","").split(",")
// rgb array // rgb array
a = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )]; color_a = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )];
} }
else { else {
a = hex2rgba(a); color_a = hex2rgba(color_a);
} }
if(b.charAt(0)!="#") { if(color_b.charAt(0)!="#") {
tmp = b.replace(/rgba?\(/,"").replace(")","").split(",") tmp = color_b.replace(/rgba?\(/,"").replace(")","").split(",")
b = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )]; color_b = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )];
} }
else { else {
b = hex2rgba(b); color_b = hex2rgba(color_b);
} }
// console.log(source+" : "+a+"\t|\t"+target+" : "+b) var r = (color_a[0] + color_b[0]) >> 1;
var g = (color_a[1] + color_b[1]) >> 1;
var r = (a[0] + b[0]) >> 1; var b = (color_a[2] + color_b[2]) >> 1;
var g = (a[1] + b[1]) >> 1;
var b = (a[2] + b[2]) >> 1;
return [r,g,b].join(',') return [r,g,b].join(',')
} }
......
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