Commit 703daa0d authored by Romain Loth's avatar Romain Loth

restore legends before fixing their input strategy, fix orderedClustDicts local var

parent 411b96bc
......@@ -20,6 +20,8 @@ function ChangeGraphAppearanceByAtt( manualflag ) {
// Seeing all the possible attributes!
var AttsDict = {}
// for GUI html: if present, rename raw attribute key by a proper label
var AttsTranslations = {
'clust_louvain': 'Groupes de voisins, méthode de Louvain',
'pageranks': 'Importance dans le réseau, méthode Google',
......@@ -259,12 +261,16 @@ function set_ClustersLegend ( daclass ) {
if(daclass==null) return;
var ClustNB_CurrentColor = {}
// TODO avoid this new loop by writing the census at coloring time in some var eg TW.Clusters.legends
var nodesV = getVisibleNodes()
for(var i in nodesV) {
n = nodesV[i]
color = n.color
type = TW.Nodes[n.id].type
clstNB = TW.Nodes[n.id].attributes[daclass]
// joining properties in a "ClusterCode"
ClustNB_CurrentColor[type+"||"+daclass+"||"+clstNB] = color
}
......@@ -275,7 +281,21 @@ function set_ClustersLegend ( daclass ) {
if (daclass=="clust_louvain")
daclass = "louvain"
OrderedClustDicts = Object.keys(ClustNB_CurrentColor).sort()
OrderedClustDicts = Object.keys(ClustNB_CurrentColor).sort(function (a,b) {
// mostly joined properties of the form "terms||pageranks||9.494E-4"
var aInfos = a.split('||')
var bInfos = b.split('||')
var compared
if (aInfos.length == 3 && bInfos.length == 3)
compared = (Number(aInfos[2]-Number(bInfos[2])))
else
compared = a-b
return compared
})
// console.log("set_ClustersLegend: OrderedClustDicts", OrderedClustDicts)
// TODO allow external cluster legends dict
if( daclass.indexOf("clust")>-1 ) {
......@@ -291,7 +311,7 @@ function set_ClustersLegend ( daclass ) {
}
var Color = ClustNB_CurrentColor[IDx]
// console.log ( Color+" : ", Type, ClustType, ClustID )
pr ( Color+" : "+ legTxt )
console.log ( Color+" : "+ legTxt )
var ColorDiv = '<span style="background:'+Color+';"></span>'
LegendDiv += '<li onclick=\'SomeEffect("'+IDx+'")\'>'+ColorDiv+ legTxt+"</li>"+"\n"
}
......
......@@ -210,6 +210,18 @@ TW.Nodes = [];
TW.Edges = [];
TW.Clusters = [];
// new TW.Clusters structure
// --------------------------
// was: built in separate loop from read of all attr values
// TW.Clusters[nodeType][clusterType][possibleValue] = clst_idx_of_possible_value
// from now on (WIP):
// built in parseCustom (when reading all nodes attributes anyway)
// if discrete attrvalues with < 15 classes (colorsBy, clustersBy)
// => TW.Clusters[nodeType][clusterType][possibleValue] = number of nodes with this value
// if continuous or many possible values (clustersBy, colorsRelByBins)
// => TW.Clusters[nodeType][clusterType][interval] = number of nodes in interval
var nodeslength=0;
var labels = [];
......
......@@ -456,7 +456,7 @@ if(RES["OK"]) {
NodeWeightFilter( this.categories , "#slidercat1nodesweight" , this.categories[1], "type" ,"size");
EdgeWeightFilter("#slidercat1edgesweight", "label" , "nodes2", "weight");
}
// set_ClustersLegend ( "clust_default" )
set_ClustersLegend ( "clust_default" )
}
if(typestring=="1|0") {
......@@ -473,7 +473,7 @@ if(RES["OK"]) {
NodeWeightFilter( this.categories , "#slidercat0nodesweight" , this.categories[0], "type" ,"size");
EdgeWeightFilter("#slidercat0edgesweight", "label" , "nodes1", "weight");
}
// set_ClustersLegend ( "clust_default" )
set_ClustersLegend ( "clust_default" )
}
if(typestring=="1|1") {
......@@ -561,7 +561,8 @@ if(RES["OK"]) {
console.error(e)
}
// set_ClustersLegend ( "clust_default" )
// set the default legend
set_ClustersLegend ( "clust_default" )
} else alert("error: "+RES["data"])
......
......@@ -201,7 +201,8 @@ function pushSWClick(arg){
swclickActual = arg;
}
// tag cloud div
// tag cloud div
// [but not used in monopart case]
function htmlfied_alternodes(elems) {
var oppositesNodes=[]
var js1='onclick="graphTagCloudElem(\'';
......@@ -670,7 +671,7 @@ function prepareNodesRenderingProperties(nodesDict) {
// customFlags : {
// // our status flags
// grey: false,
// neighbor: false,
// highlight: false,
// // forceLabel: false,
// }
}
......
......@@ -213,7 +213,10 @@ function scanGexf(gexfContent) {
catDict["Document"] = 0;
}
if(categories.length==1) {
// if we have only one category, it gets the same code 0 as Document
// but in practice it's more often terms. anyways doesn't affect much
catDict[categories[0]] = 0;
// console.log("-----cat unique =>0")
}
if(categories.length>1) {
var newcats = []
......@@ -402,11 +405,14 @@ function dictfyGexf( gexf , categories ){
// console.log("parseCustom(gexf) sizeStats:", sizeStats)
// ------------- /debug: for local stats ----------------
var attention = false
console.warn('---> dictfyGexf <---\n, begin TW.Clusters :', TW.Clusters )
var gotClusters = false
if( TW.Clusters.length == 0 ) {
for( var i in nodes ) {
if( nodes[i].attributes["cluster_index"] ) {
attention = true;
if( nodes[i].attributes["cluster_index"] || nodes[i].attributes[TW.nodeClusAtt] ) {
gotClusters = true;
}
break
}
......@@ -415,15 +421,20 @@ function dictfyGexf( gexf , categories ){
TW.Clusters = {}
//New scale for node size: now, between 2 and 5 instead [1,70]
for(var it in nodes){
console.log("dictfyGexf node", it)
nodes[it].size = desirableNodeSizeMIN+ (parseInt(nodes[it].size)-1)*((desirableNodeSizeMAX-desirableNodeSizeMIN) / (maxNodeSize-minNodeSize));
if(attention) {
if(gotClusters) {
console.warn('---> writing cluster labels <---')
var t_type = nodes[it].type
var t_cnumber = nodes[it].attributes["cluster_index"]
if (!t_cnumber) {
var t_cnumber
if (TW.nodeClusAtt != undefined) {
t_cnumber = nodes[it].attributes[TW.nodeClusAtt]
}
else {
t_cnumber = nodes[it].attributes["cluster_index"]
}
nodes[it].attributes["clust_default"] = t_cnumber;
var t_label = (nodes[it].attributes["cluster_label"])?nodes[it].attributes["cluster_label"]:"cluster_"+nodes[it].attributes["cluster_index"]
var t_label = (nodes[it].attributes["cluster_label"])?nodes[it].attributes["cluster_label"]:"cluster_"+t_cnumber
if(!TW.Clusters[t_type]) {
TW.Clusters[t_type] = {}
TW.Clusters[t_type]["clust_default"] = {}
......@@ -433,6 +444,8 @@ function dictfyGexf( gexf , categories ){
// TW.partialGraph._core.graph.nodesIndex[it].size=Nodes[it].size;
}
console.warn('---> dictfyGexf <---\n, after TW.Clusters :', TW.Clusters )
var edgeId = 0;
var edgesNodes = gexf.getElementsByTagName('edges');
for(i=0; i<edgesNodes.length; i++) {
......
......@@ -717,6 +717,8 @@ function clustersBy(daclass) {
var real_max = -1;
var themult = Math.pow(10,min_pow);
// console.log('themult', themult)
for(var j in TW.nodeIds) {
var the_node = TW.Nodes[ TW.nodeIds[j] ]
var attval = the_node.attributes[daclass];
......@@ -729,7 +731,7 @@ function clustersBy(daclass) {
if (round_number>real_max) real_max = round_number;
}
console.log("NodeID_Val", NodeID_Val)
console.log(" - - - - - - - - -- - - ")
console.log(real_min)
......@@ -762,7 +764,7 @@ function clustersBy(daclass) {
// Edge precompute alt_rgb by new source-target nodes-colours combination
repaintEdges()
// set_ClustersLegend ( daclass )
set_ClustersLegend ( daclass )
TW.partialGraph.render();
}
......@@ -988,12 +990,12 @@ function colorsBy(daclass) {
if (daclass=="clust_default") {
for(var i in v_nodes) {
var original_node_color = TW.Nodes[ v_nodes[i].id ].color
TW.partialGraph.graph.nodes(v_nodes[i].id).color = original_node_color
for(var j in TW.nodeIds) {
var original_node_color = TW.Nodes[ TW.nodeIds[j] ].color
TW.partialGraph.graph.nodes(TW.nodeIds[j]).color = original_node_color
// reset the alt_color valflag
TW.partialGraph.graph.nodes(v_nodes[i].id).customAttrs.alt_color = null
TW.partialGraph.graph.nodes(TW.nodeIds[j]).customAttrs.alt_color = null
}
// reset the global state
......@@ -1003,12 +1005,12 @@ function colorsBy(daclass) {
// shuffle on entire array is better than random sorting function on each element
var randomColorList = shuffle(colorList)
for(var i in v_nodes) {
var the_node = TW.Nodes[ v_nodes[i].id ]
var attval = ( isUndef(the_node.attributes) || isUndef(the_node.attributes[daclass]) )? v_nodes[i][daclass]: the_node.attributes[daclass];
TW.partialGraph.graph.nodes(v_nodes[i].id).color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(v_nodes[i].id).customAttrs.alt_color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(v_nodes[i].id).customAttrs.altgrey_color = false
for(var j in TW.nodeIds) {
var the_node = TW.Nodes[ TW.nodeIds[j] ]
var attval = ( isUndef(the_node.attributes) || isUndef(the_node.attributes[daclass]) )? TW.partialGraph.graph.nodes(TW.nodeIds[j])[daclass]: the_node.attributes[daclass];
TW.partialGraph.graph.nodes(TW.nodeIds[j]).color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(TW.nodeIds[j]).customAttrs.alt_color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(TW.nodeIds[j]).customAttrs.altgrey_color = false
}
// set the global state
TW.handpickedcolor = true
......@@ -1017,8 +1019,7 @@ function colorsBy(daclass) {
// Edge precompute alt_rgb by new source-target nodes-colours combination
repaintEdges()
// £TODO fix ClustersLegend
// set_ClustersLegend ( daclass )
set_ClustersLegend ( daclass )
TW.partialGraph.render();
}
......
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