Percentages in labels
Opened this issue · 3 comments
Is there any way to use the convert_flow_labels_callback to draw a percentage (i.e. the flow divided by its parent) in the label? I've experimented with things like:
Sankey.convert_flow_labels_callback = function(flow) {
return flow/this.dy;
};
to no avail.
Thanks!
Hmm. Turns out there was no easy way, because this was referring to the Sankey class rather than the flow box class. I've created a version of sankey.js that provides more information to the callback and an example of it doing what you are looking for. Take a look at the above commit bbeac19.
I won't merge the branch just yet. I'd like:
- To know it works for you
- To reflect on whether this is the best way to implement
Thanks
Tom
Interesting... I actually came up with the following just a few minutes ago:
Changed:
FlowLine.prototype.labelText = function() {
return this.sankey.convert_flow_labels_callback(this.flow);
};
to:
FlowLine.prototype.labelText = function() {
return this.sankey.convert_flow_labels_callback( this.flow + "M (" + ((this.flow/(this.left_box.size()_1.333))_100).toFixed(1) + "%)" );
};
But I will take a look at your commit. Thanks a ton!
That is a much more direct solution. I'll leave my tweaks on hold, and this issue open. One of these days I'm going to gather all the comments I've received and see if the api needs improving as a whole.