PMSI-AlignAlytics / dimple

An object-oriented API for business analytics
Other
2.73k stars 556 forks source link

suggestion: addOrderRule("null") to mean "leave the order alone" #226

Open RichardNeill opened 8 years ago

RichardNeill commented 8 years ago

Consider the case of a basic bar chart, driven by a simple key-value json array:

[ {"Branch name":"Solihull","KPI value":"50"}, {"Branch name":"Bootle","KPI value":"70"}, {"Branch name":"Wolverhampton","KPI value":"32"}, {"Branch name":"Derby","KPI value":"82"}, ]

where we are trying to draw 4 bars, labelled with the branch names, and whose heights are respectively 50,70,32,82.

dimple.plot.bar will, by default, re-order these in descending order of value, drawing the bars from left- to right as: Derby, Bootle, Solihull, Wolverhampton.

Or, I can add an explicit: x.addOrderRule("Branch name");

and dimple.plot.bar will then order the bars alphabetically as Bootle, Derby, Solihull, Wolverhampton.

But I already generated the order that I wanted in Postgres, and emitted the JSON array in the desired order, which happens to be "Solihull, Bootle, Wolverhampton, Derby".

How can I tell Dimple: "Don't sort, it's already in the right order"? Perhaps the "obvious" way to do it might be to pass in an explicit "null" to addOrderRule()?

Thanks very much.

RichardNeill commented 8 years ago

Workaround: it is possible to force this, by creating a list of keys, by iterating over the data. Then: x.addOrderRule(["Solihull", "Bootle", "Wolverhampton", "Derby"]);