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 ) { ...@@ -20,6 +20,8 @@ function ChangeGraphAppearanceByAtt( manualflag ) {
// Seeing all the possible attributes! // Seeing all the possible attributes!
var AttsDict = {} var AttsDict = {}
// for GUI html: if present, rename raw attribute key by a proper label
var AttsTranslations = { var AttsTranslations = {
'clust_louvain': 'Groupes de voisins, méthode de Louvain', 'clust_louvain': 'Groupes de voisins, méthode de Louvain',
'pageranks': 'Importance dans le réseau, méthode Google', 'pageranks': 'Importance dans le réseau, méthode Google',
...@@ -259,12 +261,16 @@ function set_ClustersLegend ( daclass ) { ...@@ -259,12 +261,16 @@ function set_ClustersLegend ( daclass ) {
if(daclass==null) return; if(daclass==null) return;
var ClustNB_CurrentColor = {} 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() var nodesV = getVisibleNodes()
for(var i in nodesV) { for(var i in nodesV) {
n = nodesV[i] n = nodesV[i]
color = n.color color = n.color
type = TW.Nodes[n.id].type type = TW.Nodes[n.id].type
clstNB = TW.Nodes[n.id].attributes[daclass] clstNB = TW.Nodes[n.id].attributes[daclass]
// joining properties in a "ClusterCode"
ClustNB_CurrentColor[type+"||"+daclass+"||"+clstNB] = color ClustNB_CurrentColor[type+"||"+daclass+"||"+clstNB] = color
} }
...@@ -275,7 +281,21 @@ function set_ClustersLegend ( daclass ) { ...@@ -275,7 +281,21 @@ function set_ClustersLegend ( daclass ) {
if (daclass=="clust_louvain") if (daclass=="clust_louvain")
daclass = "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 // TODO allow external cluster legends dict
if( daclass.indexOf("clust")>-1 ) { if( daclass.indexOf("clust")>-1 ) {
...@@ -291,7 +311,7 @@ function set_ClustersLegend ( daclass ) { ...@@ -291,7 +311,7 @@ function set_ClustersLegend ( daclass ) {
} }
var Color = ClustNB_CurrentColor[IDx] var Color = ClustNB_CurrentColor[IDx]
// console.log ( Color+" : ", Type, ClustType, ClustID ) // console.log ( Color+" : ", Type, ClustType, ClustID )
pr ( Color+" : "+ legTxt ) console.log ( Color+" : "+ legTxt )
var ColorDiv = '<span style="background:'+Color+';"></span>' var ColorDiv = '<span style="background:'+Color+';"></span>'
LegendDiv += '<li onclick=\'SomeEffect("'+IDx+'")\'>'+ColorDiv+ legTxt+"</li>"+"\n" LegendDiv += '<li onclick=\'SomeEffect("'+IDx+'")\'>'+ColorDiv+ legTxt+"</li>"+"\n"
} }
......
...@@ -210,6 +210,18 @@ TW.Nodes = []; ...@@ -210,6 +210,18 @@ TW.Nodes = [];
TW.Edges = []; TW.Edges = [];
TW.Clusters = []; 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 nodeslength=0;
var labels = []; var labels = [];
......
...@@ -456,7 +456,7 @@ if(RES["OK"]) { ...@@ -456,7 +456,7 @@ if(RES["OK"]) {
NodeWeightFilter( this.categories , "#slidercat1nodesweight" , this.categories[1], "type" ,"size"); NodeWeightFilter( this.categories , "#slidercat1nodesweight" , this.categories[1], "type" ,"size");
EdgeWeightFilter("#slidercat1edgesweight", "label" , "nodes2", "weight"); EdgeWeightFilter("#slidercat1edgesweight", "label" , "nodes2", "weight");
} }
// set_ClustersLegend ( "clust_default" ) set_ClustersLegend ( "clust_default" )
} }
if(typestring=="1|0") { if(typestring=="1|0") {
...@@ -473,7 +473,7 @@ if(RES["OK"]) { ...@@ -473,7 +473,7 @@ if(RES["OK"]) {
NodeWeightFilter( this.categories , "#slidercat0nodesweight" , this.categories[0], "type" ,"size"); NodeWeightFilter( this.categories , "#slidercat0nodesweight" , this.categories[0], "type" ,"size");
EdgeWeightFilter("#slidercat0edgesweight", "label" , "nodes1", "weight"); EdgeWeightFilter("#slidercat0edgesweight", "label" , "nodes1", "weight");
} }
// set_ClustersLegend ( "clust_default" ) set_ClustersLegend ( "clust_default" )
} }
if(typestring=="1|1") { if(typestring=="1|1") {
...@@ -561,7 +561,8 @@ if(RES["OK"]) { ...@@ -561,7 +561,8 @@ if(RES["OK"]) {
console.error(e) console.error(e)
} }
// set_ClustersLegend ( "clust_default" ) // set the default legend
set_ClustersLegend ( "clust_default" )
} else alert("error: "+RES["data"]) } else alert("error: "+RES["data"])
......
...@@ -201,7 +201,8 @@ function pushSWClick(arg){ ...@@ -201,7 +201,8 @@ function pushSWClick(arg){
swclickActual = arg; swclickActual = arg;
} }
// tag cloud div // tag cloud div
// [but not used in monopart case]
function htmlfied_alternodes(elems) { function htmlfied_alternodes(elems) {
var oppositesNodes=[] var oppositesNodes=[]
var js1='onclick="graphTagCloudElem(\''; var js1='onclick="graphTagCloudElem(\'';
...@@ -670,7 +671,7 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -670,7 +671,7 @@ function prepareNodesRenderingProperties(nodesDict) {
// customFlags : { // customFlags : {
// // our status flags // // our status flags
// grey: false, // grey: false,
// neighbor: false, // highlight: false,
// // forceLabel: false, // // forceLabel: false,
// } // }
} }
......
...@@ -213,7 +213,10 @@ function scanGexf(gexfContent) { ...@@ -213,7 +213,10 @@ function scanGexf(gexfContent) {
catDict["Document"] = 0; catDict["Document"] = 0;
} }
if(categories.length==1) { 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; catDict[categories[0]] = 0;
// console.log("-----cat unique =>0")
} }
if(categories.length>1) { if(categories.length>1) {
var newcats = [] var newcats = []
...@@ -402,11 +405,14 @@ function dictfyGexf( gexf , categories ){ ...@@ -402,11 +405,14 @@ function dictfyGexf( gexf , categories ){
// console.log("parseCustom(gexf) sizeStats:", sizeStats) // console.log("parseCustom(gexf) sizeStats:", sizeStats)
// ------------- /debug: for local stats ---------------- // ------------- /debug: for local stats ----------------
var attention = false
console.warn('---> dictfyGexf <---\n, begin TW.Clusters :', TW.Clusters )
var gotClusters = false
if( TW.Clusters.length == 0 ) { if( TW.Clusters.length == 0 ) {
for( var i in nodes ) { for( var i in nodes ) {
if( nodes[i].attributes["cluster_index"] ) { if( nodes[i].attributes["cluster_index"] || nodes[i].attributes[TW.nodeClusAtt] ) {
attention = true; gotClusters = true;
} }
break break
} }
...@@ -415,15 +421,20 @@ function dictfyGexf( gexf , categories ){ ...@@ -415,15 +421,20 @@ function dictfyGexf( gexf , categories ){
TW.Clusters = {} TW.Clusters = {}
//New scale for node size: now, between 2 and 5 instead [1,70] //New scale for node size: now, between 2 and 5 instead [1,70]
for(var it in nodes){ for(var it in nodes){
console.log("dictfyGexf node", it)
nodes[it].size = desirableNodeSizeMIN+ (parseInt(nodes[it].size)-1)*((desirableNodeSizeMAX-desirableNodeSizeMIN) / (maxNodeSize-minNodeSize)); 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_type = nodes[it].type
var t_cnumber = nodes[it].attributes["cluster_index"] var t_cnumber
if (!t_cnumber) { if (TW.nodeClusAtt != undefined) {
t_cnumber = nodes[it].attributes[TW.nodeClusAtt] t_cnumber = nodes[it].attributes[TW.nodeClusAtt]
} }
else {
t_cnumber = nodes[it].attributes["cluster_index"]
}
nodes[it].attributes["clust_default"] = t_cnumber; 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]) { if(!TW.Clusters[t_type]) {
TW.Clusters[t_type] = {} TW.Clusters[t_type] = {}
TW.Clusters[t_type]["clust_default"] = {} TW.Clusters[t_type]["clust_default"] = {}
...@@ -433,6 +444,8 @@ function dictfyGexf( gexf , categories ){ ...@@ -433,6 +444,8 @@ function dictfyGexf( gexf , categories ){
// TW.partialGraph._core.graph.nodesIndex[it].size=Nodes[it].size; // TW.partialGraph._core.graph.nodesIndex[it].size=Nodes[it].size;
} }
console.warn('---> dictfyGexf <---\n, after TW.Clusters :', TW.Clusters )
var edgeId = 0; var edgeId = 0;
var edgesNodes = gexf.getElementsByTagName('edges'); var edgesNodes = gexf.getElementsByTagName('edges');
for(i=0; i<edgesNodes.length; i++) { for(i=0; i<edgesNodes.length; i++) {
......
...@@ -717,6 +717,8 @@ function clustersBy(daclass) { ...@@ -717,6 +717,8 @@ function clustersBy(daclass) {
var real_max = -1; var real_max = -1;
var themult = Math.pow(10,min_pow); var themult = Math.pow(10,min_pow);
// console.log('themult', themult)
for(var j in TW.nodeIds) { for(var j in TW.nodeIds) {
var the_node = TW.Nodes[ TW.nodeIds[j] ] var the_node = TW.Nodes[ TW.nodeIds[j] ]
var attval = the_node.attributes[daclass]; var attval = the_node.attributes[daclass];
...@@ -729,7 +731,7 @@ function clustersBy(daclass) { ...@@ -729,7 +731,7 @@ function clustersBy(daclass) {
if (round_number>real_max) real_max = round_number; if (round_number>real_max) real_max = round_number;
} }
console.log("NodeID_Val", NodeID_Val)
console.log(" - - - - - - - - -- - - ") console.log(" - - - - - - - - -- - - ")
console.log(real_min) console.log(real_min)
...@@ -762,7 +764,7 @@ function clustersBy(daclass) { ...@@ -762,7 +764,7 @@ function clustersBy(daclass) {
// Edge precompute alt_rgb by new source-target nodes-colours combination // Edge precompute alt_rgb by new source-target nodes-colours combination
repaintEdges() repaintEdges()
// set_ClustersLegend ( daclass ) set_ClustersLegend ( daclass )
TW.partialGraph.render(); TW.partialGraph.render();
} }
...@@ -988,12 +990,12 @@ function colorsBy(daclass) { ...@@ -988,12 +990,12 @@ function colorsBy(daclass) {
if (daclass=="clust_default") { if (daclass=="clust_default") {
for(var i in v_nodes) { for(var j in TW.nodeIds) {
var original_node_color = TW.Nodes[ v_nodes[i].id ].color var original_node_color = TW.Nodes[ TW.nodeIds[j] ].color
TW.partialGraph.graph.nodes(v_nodes[i].id).color = original_node_color TW.partialGraph.graph.nodes(TW.nodeIds[j]).color = original_node_color
// reset the alt_color valflag // 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 // reset the global state
...@@ -1003,12 +1005,12 @@ function colorsBy(daclass) { ...@@ -1003,12 +1005,12 @@ function colorsBy(daclass) {
// shuffle on entire array is better than random sorting function on each element // shuffle on entire array is better than random sorting function on each element
var randomColorList = shuffle(colorList) var randomColorList = shuffle(colorList)
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 = ( 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(v_nodes[i].id).color = randomColorList[ attval ] TW.partialGraph.graph.nodes(TW.nodeIds[j]).color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(v_nodes[i].id).customAttrs.alt_color = randomColorList[ attval ] TW.partialGraph.graph.nodes(TW.nodeIds[j]).customAttrs.alt_color = randomColorList[ attval ]
TW.partialGraph.graph.nodes(v_nodes[i].id).customAttrs.altgrey_color = false TW.partialGraph.graph.nodes(TW.nodeIds[j]).customAttrs.altgrey_color = false
} }
// set the global state // set the global state
TW.handpickedcolor = true TW.handpickedcolor = true
...@@ -1017,8 +1019,7 @@ function colorsBy(daclass) { ...@@ -1017,8 +1019,7 @@ function colorsBy(daclass) {
// Edge precompute alt_rgb by new source-target nodes-colours combination // Edge precompute alt_rgb by new source-target nodes-colours combination
repaintEdges() repaintEdges()
// £TODO fix ClustersLegend set_ClustersLegend ( daclass )
// set_ClustersLegend ( daclass )
TW.partialGraph.render(); 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