nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.07k forks source link

Sort Treemap Blocks, start with largest first #845

Open vedbhawsar opened 6 years ago

vedbhawsar commented 6 years ago

Hi @nicolaskruchten , I just want to know if you already have a way to place the largest value for treemap blocks first in order then the smaller ones.

mcn dashboard 12-21-2017 6-40-04 pm

vedbhawsar commented 6 years ago

@nicolaskruchten I have done a workaround for this by updating the d3_renderers.js file by adding below code, Reference The default sort is:

.sort(function(a,b) {
    return b.value - a.value;
})

Changing this to the reverse:

.sort(function(a,b) {
    return a.value - b.value;
})

So now the treemap call in renderers file look like this:

var treemap = d3.layout.treemap()
.size([width, height])
.sticky(true)
.sort(function(a,b) {
    return a.value - b.value;
})
.value(function(d) { return d.size; });

can we do something to have the treemap sorting feature through options?