Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A custom tick formatter has no way to know what axis it is being run on for multi-series data. #272

Open
dnschnur opened this issue Sep 28, 2012 · 1 comment

Comments

@dnschnur
Copy link
Member

Original author: b1gg...@gmail.com (July 17, 2009 18:26:21)

Problem:
Currently a custom tick tickFormatter is passed a value and an axis object.
The axis object doe not provide any information on which axis it is. So for
example a graph could have two series, on is altitude in meters and the
other is speed in km/hr. In the custom formater there is no way to add the
correct unit to the tick.

Recommendation: The axis objects need to have a 'key' that identifies them.
I have a simple fix:

Existing code:
...
canvas = null, // the canvas for the plot itself
overlay = null, // canvas for interactive stuff on top of plot
eventHolder = null, // jQuery object that events should be bound to
ctx = null, octx = null,
target = $(target_),
-> axes = { xaxis: {}, yaxis: {}, x2axis: {}, y2axis: {} },
plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
canvasWidth = 0, canvasHeight = 0,
plotWidth = 0, plotHeight = 0,
...

Proposed change:
...
canvas = null, // the canvas for the plot itself
overlay = null, // canvas for interactive stuff on top of plot
eventHolder = null, // jQuery object that events should be bound to
ctx = null, octx = null,
target = $(target_),
-> axes = {
-> xaxis: {
-> axisName: 'x',
-> axisIndex: 0},
-> yaxis: {
-> axisName: 'y',
-> axisIndex: 0},
-> x2axis: {
-> axisName: 'x',
-> axisIndex: 1},
-> y2axis: {
-> axisName: 'y',
-> axisIndex: 1}
-> },
plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
canvasWidth = 0, canvasHeight = 0,
plotWidth = 0, plotHeight = 0,
...

This would allow a tickFormetter like this:

options.yaxis.tickFormatter = function(val,axis){
var unit_labels = new Array('meters','km/hr');
return (val|0) + " " + unit_labels[axis.axisIndex];
}

Original issue: http://code.google.com/p/flot/issues/detail?id=193

@dnschnur
Copy link
Member Author

From olau%iol...@gtempaccount.com on October 07, 2009 15:31:56
Hm, yes, something like that.

A complication is that some people want to add more axes than just the two possible
right now. This is a bit difficult because most of the critical places in Flot are
not prepared for dealing with more than two. We need to generalize that, and fix this
problem too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant