Commit d06a320b authored by Romain Loth's avatar Romain Loth

activetypes is naturally an array

we adapt the functions that currently need only one element (ie colors, legends) instead of adapting activetypes expression
parent 17ad2bc8
...@@ -29,32 +29,37 @@ function changeGraphAppearanceByFacets( manualflag ) { ...@@ -29,32 +29,37 @@ function changeGraphAppearanceByFacets( manualflag ) {
// create colormenu // create colormenu
var ty = getActivetypesName()
var color_menu_info = '<li><a href="#" onclick="graphResetColor()">By Default</a></li>'; var color_menu_info = '<li><a href="#" onclick="graphResetColor()">By Default</a></li>';
if( $( "#colorgraph-menu" ).length>0 ){ if( $( "#colorgraph-menu" ).length>0 ) {
// each facet family or clustering type was already prepared var actypes = getActivetypes()
for (var att_s in TW.Clusters[ty]) { for (var tid in actypes) {
let ty = actypes[tid]
// POSS here distinguish [ty][att_s].classes.length and ranges.length // each facet family or clustering type was already prepared
var att_c = TW.Clusters[ty][att_s].length for (var att_s in TW.Clusters[ty]) {
var the_method = "clustersBy"
// variants // POSS here distinguish [ty][att_s].classes.length and ranges.length
if(att_s.indexOf("clust")>-1||att_s.indexOf("class")>-1) { var att_c = TW.Clusters[ty][att_s].length
// for classes and clusters var the_method = "clustersBy"
the_method = "colorsBy"
} // variants
if(att_s == "growth_rate") the_method = "colorsRelByBins" if(att_s.indexOf("clust")>-1||att_s.indexOf("class")>-1) {
if(att_s == "age") the_method = "colorsRelByBins" // for classes and clusters
the_method = "colorsBy"
}
if(att_s == "growth_rate") the_method = "colorsRelByBins"
if(att_s == "age") the_method = "colorsRelByBins"
// family label :) // family label :)
var lab_att_s ; var lab_att_s ;
if (AttsTranslations[att_s]) lab_att_s = AttsTranslations[att_s] if (AttsTranslations[att_s]) lab_att_s = AttsTranslations[att_s]
else lab_att_s = att_s else lab_att_s = att_s
color_menu_info += '<li><a href="#" onclick=\''+the_method+'("'+att_s+'")\'>By '+lab_att_s+'('+att_c+')'+'</a></li>' color_menu_info += '<li><a href="#" onclick=\''+the_method+'("'+att_s+'")\'>By '+lab_att_s+'('+att_c+')'+'</a></li>'
}
} }
$("#colorgraph-menu").html(color_menu_info) $("#colorgraph-menu").html(color_menu_info)
...@@ -213,17 +218,20 @@ function graphResetColor(){ ...@@ -213,17 +218,20 @@ function graphResetColor(){
// reset each node's color and label // reset each node's color and label
for (var j in TW.nodeIds) { for (var j in TW.nodeIds) {
let n = TW.partialGraph.graph.nodes(TW.nodeIds[j]) let n = TW.partialGraph.graph.nodes(TW.nodeIds[j])
n.color = n.customAttrs["true_color"]; // as usual, n can be absent if not in current subset !
if (n) {
n.color = n.customAttrs["true_color"];
n.customAttrs.alt_color = false n.customAttrs.alt_color = false
n.customAttrs.altgrey_color = false n.customAttrs.altgrey_color = false
n.label = TW.Nodes[n.id].label n.label = TW.Nodes[n.id].label
// some colorings also modified size // some colorings also modified size
n.size = TW.Nodes[n.id].size n.size = TW.Nodes[n.id].size
} }
}
// if (TW.partialGraph.settings('drawEdges')) { // if (TW.partialGraph.settings('drawEdges')) {
// for(var x in eds){ // for(var x in eds){
// e=eds[x]; // e=eds[x];
...@@ -249,8 +257,14 @@ function set_ClustersLegend ( daclass, groupedByTicks ) { ...@@ -249,8 +257,14 @@ function set_ClustersLegend ( daclass, groupedByTicks ) {
if (daclass=="clust_louvain") if (daclass=="clust_louvain")
daclass = "louvain" daclass = "louvain"
// usually 'terms' or current display among TW.categories var actypes = getActivetypes()
var curType = getActivetypesName()
// we have no specifications yet for colors (and legends) on multiple types
if (actypes.length > 1) {
console.warn("colors by bins will only color nodes of type 0")
}
// current display among TW.categories (ex: 'terms')
var curType = actypes[0]
// all infos in a bin array // all infos in a bin array
var legendInfo = [] var legendInfo = []
......
...@@ -86,12 +86,11 @@ function cancelSelection (fromTagCloud, settings) { ...@@ -86,12 +86,11 @@ function cancelSelection (fromTagCloud, settings) {
} }
} }
// returns the name(s) of active types // returns an array of the name(s) of active type(s)
// this area is quite underspecified so we assume here // this area is quite underspecified so we assume here
// - that all typenames have a mapping to cat[0] (terms) or cat[1] (contexts) // - that all typenames have a mapping to cat[0] (terms) or cat[1] (contexts)
// - that currentState.activetypes is an array of 2 bools for the currently displayed cat(s) // - that currentState.activetypes is an array of 2 bools for the currently displayed cat(s)
// TODO transform result into array in all cases function getActivetypes() {
function getActivetypesName() {
let currentTypes = [] let currentTypes = []
let currentTypeIdx let currentTypeIdx
let lastState = TW.partialGraph.states.slice(-1)[0] let lastState = TW.partialGraph.states.slice(-1)[0]
...@@ -103,9 +102,8 @@ function getActivetypesName() { ...@@ -103,9 +102,8 @@ function getActivetypesName() {
} }
} }
// ex: ['Document'] or ['Ngrams'] or ['Document','Ngrams']
// ex: 'Document' or 'Ngrams' or 'Document-Ngrams' return currentTypes
return currentTypes.join('-')
} }
function getActivetypesKey() { function getActivetypesKey() {
......
...@@ -858,10 +858,13 @@ function repaintEdges() { ...@@ -858,10 +858,13 @@ function repaintEdges() {
let src = TW.partialGraph.graph.nodes(idPair[0]) let src = TW.partialGraph.graph.nodes(idPair[0])
let tgt = TW.partialGraph.graph.nodes(idPair[1]) let tgt = TW.partialGraph.graph.nodes(idPair[1])
let src_color = src.customAttrs.alt_color || '#555'
let tgt_color = tgt.customAttrs.alt_color || '#555' if (src && tgt) {
e.customAttrs.alt_rgb = sigmaTools.edgeRGB(src_color,tgt_color) let src_color = src.customAttrs.alt_color || '#555'
// we don't set e.color because opacity may vary if selected or not 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
}
} }
} }
} }
...@@ -874,7 +877,14 @@ function repaintEdges() { ...@@ -874,7 +877,14 @@ function repaintEdges() {
function colorsRelByBins(daclass) { function colorsRelByBins(daclass) {
var binColors var binColors
var doModifyLabel = false var doModifyLabel = false
var ty = getActivetypesName() var actypes = getActivetypes()
// we have no specifications yet for colors and legends on multiple types
if (actypes.length > 1) {
console.warn("colors by bins will only color nodes of type 0")
}
var ty = actypes[0]
// our binning // our binning
var tickThresholds = TW.Clusters[ty][daclass] var tickThresholds = TW.Clusters[ty][daclass]
...@@ -1157,6 +1167,7 @@ function colorsBy(daclass) { ...@@ -1157,6 +1167,7 @@ function colorsBy(daclass) {
console.log(" = = = = = = = = = = = = = = = = = ") console.log(" = = = = = = = = = = = = = = = = = ")
console.log("") console.log("")
// louvain needs preparation
if(daclass=="clust_louvain") { if(daclass=="clust_louvain") {
if(!TW.partialGraph.states.slice(-1)[0].LouvainFait) { if(!TW.partialGraph.states.slice(-1)[0].LouvainFait) {
RunLouvain() RunLouvain()
...@@ -1164,9 +1175,6 @@ function colorsBy(daclass) { ...@@ -1164,9 +1175,6 @@ function colorsBy(daclass) {
} }
} }
var v_nodes = getVisibleNodes();
if (daclass=="clust_default") { if (daclass=="clust_default") {
for(var j in TW.nodeIds) { for(var j in TW.nodeIds) {
var original_node_color = TW.Nodes[ TW.nodeIds[j] ].color var original_node_color = TW.Nodes[ TW.nodeIds[j] ].color
......
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