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 ) {
// create colormenu
var ty = getActivetypesName()
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
for (var att_s in TW.Clusters[ty]) {
var actypes = getActivetypes()
for (var tid in actypes) {
let ty = actypes[tid]
// POSS here distinguish [ty][att_s].classes.length and ranges.length
var att_c = TW.Clusters[ty][att_s].length
var the_method = "clustersBy"
// each facet family or clustering type was already prepared
for (var att_s in TW.Clusters[ty]) {
// variants
if(att_s.indexOf("clust")>-1||att_s.indexOf("class")>-1) {
// for classes and clusters
the_method = "colorsBy"
}
if(att_s == "growth_rate") the_method = "colorsRelByBins"
if(att_s == "age") the_method = "colorsRelByBins"
// POSS here distinguish [ty][att_s].classes.length and ranges.length
var att_c = TW.Clusters[ty][att_s].length
var the_method = "clustersBy"
// variants
if(att_s.indexOf("clust")>-1||att_s.indexOf("class")>-1) {
// for classes and clusters
the_method = "colorsBy"
}
if(att_s == "growth_rate") the_method = "colorsRelByBins"
if(att_s == "age") the_method = "colorsRelByBins"
// family label :)
var lab_att_s ;
if (AttsTranslations[att_s]) lab_att_s = AttsTranslations[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>'
// family label :)
var lab_att_s ;
if (AttsTranslations[att_s]) lab_att_s = AttsTranslations[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>'
}
}
$("#colorgraph-menu").html(color_menu_info)
......@@ -213,17 +218,20 @@ function graphResetColor(){
// reset each node's color and label
for (var j in TW.nodeIds) {
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.altgrey_color = false
n.customAttrs.alt_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
n.size = TW.Nodes[n.id].size
}
// some colorings also modified size
n.size = TW.Nodes[n.id].size
}
}
// if (TW.partialGraph.settings('drawEdges')) {
// for(var x in eds){
// e=eds[x];
......@@ -249,8 +257,14 @@ function set_ClustersLegend ( daclass, groupedByTicks ) {
if (daclass=="clust_louvain")
daclass = "louvain"
// usually 'terms' or current display among TW.categories
var curType = 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")
}
// current display among TW.categories (ex: 'terms')
var curType = actypes[0]
// all infos in a bin array
var legendInfo = []
......
......@@ -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
// - 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)
// TODO transform result into array in all cases
function getActivetypesName() {
function getActivetypes() {
let currentTypes = []
let currentTypeIdx
let lastState = TW.partialGraph.states.slice(-1)[0]
......@@ -103,9 +102,8 @@ function getActivetypesName() {
}
}
// ex: 'Document' or 'Ngrams' or 'Document-Ngrams'
return currentTypes.join('-')
// ex: ['Document'] or ['Ngrams'] or ['Document','Ngrams']
return currentTypes
}
function getActivetypesKey() {
......
......@@ -858,10 +858,13 @@ function repaintEdges() {
let src = TW.partialGraph.graph.nodes(idPair[0])
let tgt = TW.partialGraph.graph.nodes(idPair[1])
let src_color = src.customAttrs.alt_color || '#555'
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
if (src && tgt) {
let src_color = src.customAttrs.alt_color || '#555'
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() {
function colorsRelByBins(daclass) {
var binColors
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
var tickThresholds = TW.Clusters[ty][daclass]
......@@ -1157,6 +1167,7 @@ function colorsBy(daclass) {
console.log(" = = = = = = = = = = = = = = = = = ")
console.log("")
// louvain needs preparation
if(daclass=="clust_louvain") {
if(!TW.partialGraph.states.slice(-1)[0].LouvainFait) {
RunLouvain()
......@@ -1164,9 +1175,6 @@ function colorsBy(daclass) {
}
}
var v_nodes = getVisibleNodes();
if (daclass=="clust_default") {
for(var j in TW.nodeIds) {
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