Commit 797b7bbb authored by Romain Loth's avatar Romain Loth

fix max k elts algo (:/) and add size as a default ranking metric

parent c764e903
...@@ -249,9 +249,6 @@ function graphResetLabelsAndSizes(){ ...@@ -249,9 +249,6 @@ function graphResetLabelsAndSizes(){
// @daclass: the name of a numeric/categorical attribute from node.attributes // @daclass: the name of a numeric/categorical attribute from node.attributes
// @groupingTicks: an optional threshold's array expressing ranges with their low/up bounds label and ref to matchin nodeIds // @groupingTicks: an optional threshold's array expressing ranges with their low/up bounds label and ref to matchin nodeIds
function set_ClustersLegend ( daclass, groupedByTicks ) { function set_ClustersLegend ( daclass, groupedByTicks ) {
//TW.partialGraph.states.slice(-1)[0].LouvainFait = true
$("#legend-for-clusters").removeClass( "my-legend" ) $("#legend-for-clusters").removeClass( "my-legend" )
$("#legend-for-clusters").html("") $("#legend-for-clusters").html("")
if(daclass==null) return; if(daclass==null) return;
...@@ -305,25 +302,39 @@ function set_ClustersLegend ( daclass, groupedByTicks ) { ...@@ -305,25 +302,39 @@ function set_ClustersLegend ( daclass, groupedByTicks ) {
// create the legend item // create the legend item
var preparedLabel = legendInfo[l]['labl'] var preparedLabel = legendInfo[l]['labl']
// we add a title to cluster classes // we add a title to cluster classes by ranking their nodes and taking k best labels
if (TW.conf.facetOptions[daclass] && TW.conf.facetOptions[daclass].col == 'cluster') { if (TW.conf.facetOptions[daclass] && TW.conf.facetOptions[daclass].col == 'cluster') {
// let t0 = performance.now() // let t0 = performance.now()
let titles = [] let titles = []
let theRankingAttr = TW.conf.facetOptions[daclass].titlingMetric let theRankingAttr = TW.conf.facetOptions[daclass].titlingMetric
let maxLen = TW.conf.facetOptions[daclass].titlingNTerms let maxLen = TW.conf.facetOptions[daclass].titlingNTerms || 2
// custom accessor (user settings or by default)
let getVal
if(theRankingAttr) {
getVal = function(node) {return node.attributes[theRankingAttr]}
}
else {
// default ranking: by size
getVal = function(node) {return node.size}
}
for (let j in legendInfo[l]['nids']) { for (let j in legendInfo[l]['nids']) {
let n = TW.partialGraph.graph.nodes(legendInfo[l]['nids'][j]) let n = TW.partialGraph.graph.nodes(legendInfo[l]['nids'][j])
let lastMax = 0 let theRankingVal = getVal(n)
if (titles.length) {
// we keep titles sorted for this if (titles.length < maxLen) {
lastMax = titles.slice(-1)[0].val titles.push({'key':n.label, 'val':theRankingVal})
} }
if (n.attributes[theRankingAttr] > lastMax) { else {
titles.push({'key':n.label, 'val':n.attributes[theRankingAttr]}) // we keep titles sorted for this
let lastMax = titles.slice(-1)[0].val
if (theRankingVal > lastMax) {
titles.push({'key':n.label, 'val':theRankingVal})
}
} }
titles.sort(function(a,b) {return b.val - a.val}) titles.sort(function(a,b) {return b.val - a.val})
......
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