Commit 05c57e8f authored by Romain Loth's avatar Romain Loth

fix rgba (less clear but works in more platforms now)

parent 6dbfd612
...@@ -216,6 +216,9 @@ function graphResetColor(){ ...@@ -216,6 +216,9 @@ function graphResetColor(){
let n = TW.partialGraph.graph.nodes(TW.nodeIds[j]) let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
n.color = n.customAttrs["true_color"]; n.color = n.customAttrs["true_color"];
n.customAttrs.alt_color = false
n.customAttrs.altgrey_color = false
n.label = TW.Nodes[n.id].label n.label = TW.Nodes[n.id].label
} }
......
...@@ -152,16 +152,19 @@ function getByID(elem) { ...@@ -152,16 +152,19 @@ function getByID(elem) {
} }
// hex can be RGB (3 or 6 chars after #) or RGBA (4 or 8 chars)
function hex2rga(sent_hex) { function hex2rgba(sent_hex) {
if (!sent_hex) {
return [0,0,0,1]
}
result = [] result = []
hex = ( sent_hex.charAt(0) === "#" ? sent_hex.substr(1) : sent_hex ); hex = ( sent_hex.charAt(0) === "#" ? sent_hex.substr(1) : sent_hex );
// check if 6 letters are provided // check if 6 letters are provided
if (hex.length === 6) { if (hex.length == 6 || hex.length == 8) {
result = calculateFull(hex); result = calculateFull(hex);
return result; return result;
} }
else if (hex.length === 3) { else if (hex.length == 3 || hex.length == 3) {
result = calculatePartial(hex); result = calculatePartial(hex);
return result; return result;
} }
...@@ -171,7 +174,12 @@ function calculateFull(hex) { ...@@ -171,7 +174,12 @@ function calculateFull(hex) {
var r = parseInt(hex.substring(0, 2), 16); var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16); var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16); var b = parseInt(hex.substring(4, 6), 16);
return [r,g,b];
var a = 0
if (hex.substring(6, 8)) {
a = parseInt(hex.substring(6, 8), 16) / 255;
}
return [r,g,b, a];
} }
...@@ -180,7 +188,12 @@ function calculatePartial(hex) { ...@@ -180,7 +188,12 @@ function calculatePartial(hex) {
var r = parseInt(hex.substring(0, 1) + hex.substring(0, 1), 16); var r = parseInt(hex.substring(0, 1) + hex.substring(0, 1), 16);
var g = parseInt(hex.substring(1, 2) + hex.substring(1, 2), 16); var g = parseInt(hex.substring(1, 2) + hex.substring(1, 2), 16);
var b = parseInt(hex.substring(2, 3) + hex.substring(2, 3), 16); var b = parseInt(hex.substring(2, 3) + hex.substring(2, 3), 16);
return [r,g,b]; var a = 0
if (hex.substring(3, 4)) {
a = parseInt(hex.substring(3, 4), 16) / 255;
}
return [r,g,b, a];
} }
function componentToHex(c) { function componentToHex(c) {
......
...@@ -599,8 +599,9 @@ function greyEverything(){ ...@@ -599,8 +599,9 @@ function greyEverything(){
n.customAttrs.highlight = false; n.customAttrs.highlight = false;
// special case after a coloredBy or clustersBy // special case after a coloredBy or clustersBy
// (now handled in renderer)
// if (TW.handpickedcolor) { // if (TW.handpickedcolor) {
// n.color = "rgba("+hex2rga(n.color)+",0.5)" // n.color = "rgba("+hex2rgba(n.color+"55").join(','))"
// } // }
} }
} }
...@@ -662,7 +663,7 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -662,7 +663,7 @@ function prepareNodesRenderingProperties(nodesDict) {
grey: false, grey: false,
highlight: false, highlight: false,
true_color : n.color, true_color : n.color,
defgrey_color : "rgba("+hex2rga(n.color)+",.4)" defgrey_color : "rgba("+hex2rgba(n.color)+",.4)"
} }
// POSS n.type: distinguish rendtype and twtype // POSS n.type: distinguish rendtype and twtype
...@@ -809,8 +810,10 @@ function saveGEXF(nodes,edges,atts){ ...@@ -809,8 +810,10 @@ function saveGEXF(nodes,edges,atts){
gexf += ' <viz:position x="'+nodes[n].x+'" y="'+nodes[n].y+'" z="0" />\n'; gexf += ' <viz:position x="'+nodes[n].x+'" y="'+nodes[n].y+'" z="0" />\n';
if(atts["color"]) gexf += ' <viz:size value="'+nodes[n].size+'" />\n'; if(atts["color"]) gexf += ' <viz:size value="'+nodes[n].size+'" />\n';
if(atts["color"]) { if(atts["color"]) {
col = hex2rga(nodes[n].color); if (nodes[n].color && nodes[n].color.charAt(0) == '#') {
gexf += ' <viz:color r="'+col[0]+'" g="'+col[1]+'" b="'+col[2]+'" a="1"/>\n'; col = hex2rgba(nodes[n].color);
gexf += ' <viz:color r="'+col[0]+'" g="'+col[1]+'" b="'+col[2]+'" a='+col[3]+'/>\n';
}
} }
gexf += ' <attvalues>\n'; gexf += ' <attvalues>\n';
gexf += ' <attvalue for="0" value="'+nodes[n].type+'"/>\n'; gexf += ' <attvalue for="0" value="'+nodes[n].type+'"/>\n';
......
...@@ -310,10 +310,11 @@ SigmaUtils = function () { ...@@ -310,10 +310,11 @@ SigmaUtils = function () {
else { else {
// #C01O3 += alpha 55 // #C01O3 += alpha 55
// => #C01O355 // => #C01O355
nodeColor = node.customAttrs.alt_color+"55"
// old way: if (!node.customAttrs.altgrey_color) {
// nodeColor = "rgba("+hex2rga(node.customAttrs.alt_color)+",0.5)" node.customAttrs.altgrey_color = "rgba("+(hex2rgba(node.customAttrs.alt_color).slice(0,3).join(','))+",0.4)"
}
nodeColor = node.customAttrs.altgrey_color
} }
// nice looking uniform grey // nice looking uniform grey
borderColor = TW.nodesGreyBorderColor borderColor = TW.nodesGreyBorderColor
...@@ -771,8 +772,8 @@ function repaintEdges() { ...@@ -771,8 +772,8 @@ function repaintEdges() {
// var e_id = v_edges[e].id; // var e_id = v_edges[e].id;
// var a = TW.partialGraph.graph.nodes(v_edges[e].source).color; // var a = TW.partialGraph.graph.nodes(v_edges[e].source).color;
// var b = TW.partialGraph.graph.nodes(v_edges[e].target).color; // var b = TW.partialGraph.graph.nodes(v_edges[e].target).color;
// a = hex2rga(a); // a = hex2rgba(a);
// b = hex2rga(b); // b = hex2rgba(b);
// var r = (a[0] + b[0]) >> 1; // var r = (a[0] + b[0]) >> 1;
// var g = (a[1] + b[1]) >> 1; // var g = (a[1] + b[1]) >> 1;
// var b = (a[2] + b[2]) >> 1; // var b = (a[2] + b[2]) >> 1;
...@@ -888,7 +889,7 @@ function colorsRelByBins(daclass) { ...@@ -888,7 +889,7 @@ function colorsRelByBins(daclass) {
var valSt = n.attributes[daclass] var valSt = n.attributes[daclass]
if (doModifyLabel) { if (doModifyLabel) {
n.label = `(${valSt}) ${n.label}` n.label = `(${valSt}) ${n.label}`
} }
var theVal = parseFloat(valSt) var theVal = parseFloat(valSt)
...@@ -987,23 +988,21 @@ function colorsBy(daclass) { ...@@ -987,23 +988,21 @@ function colorsBy(daclass) {
TW.handpickedcolor = false TW.handpickedcolor = false
} }
// £TODO remove another duplicate of edgeRGB
// [ Edge-colour by source-target nodes-colours combination ] // [ Edge-colour by source-target nodes-colours combination ]
var v_edges = getVisibleEdges(); // var v_edges = getVisibleEdges();
for(var e in v_edges) { // for(var e in v_edges) {
var e_id = v_edges[e].id; // var e_id = v_edges[e].id;
var a = v_edges[e].source.color; // var a = v_edges[e].source.color;
var b = v_edges[e].target.color; // var b = v_edges[e].target.color;
if (a && b) { // if (a && b) {
a = hex2rga(a); // a = hex2rgba(a);
b = hex2rga(b); // b = hex2rgba(b);
var r = (a[0] + b[0]) >> 1; // var r = (a[0] + b[0]) >> 1;
var g = (a[1] + b[1]) >> 1; // var g = (a[1] + b[1]) >> 1;
var b = (a[2] + b[2]) >> 1; // var b = (a[2] + b[2]) >> 1;
TW.partialGraph.graph.edges(e_id).color = "rgba("+[r,g,b].join(",")+",0.5)"; // TW.partialGraph.graph.edges(e_id).color = "rgba("+[r,g,b].join(",")+",0.5)";
} // }
} // }
// [ / Edge-colour by source-target nodes-colours combination ] // [ / Edge-colour by source-target nodes-colours combination ]
// £TODO fix ClustersLegend // £TODO fix ClustersLegend
......
...@@ -117,7 +117,7 @@ sigmaTools = (function(stools) { ...@@ -117,7 +117,7 @@ sigmaTools = (function(stools) {
a = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )]; a = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )];
} }
else { else {
a = hex2rga(a); a = hex2rgba(a);
} }
if(b.charAt(0)!="#") { if(b.charAt(0)!="#") {
...@@ -125,7 +125,7 @@ sigmaTools = (function(stools) { ...@@ -125,7 +125,7 @@ sigmaTools = (function(stools) {
b = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )]; b = [parseFloat( tmp[0] ) , parseFloat( tmp[1] ) , parseFloat( tmp[2] )];
} }
else { else {
b = hex2rga(b); b = hex2rgba(b);
} }
// console.log(source+" : "+a+"\t|\t"+target+" : "+b) // console.log(source+" : "+a+"\t|\t"+target+" : "+b)
......
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