edisona / flot

Automatically exported from code.google.com/p/flot
MIT License
1 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by b1gg...@gmail.com on 17 Jul 2009 at 6:26

GoogleCodeExporter commented 9 years ago
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.

Original comment by olau%iol...@gtempaccount.com on 7 Oct 2009 at 3:31

GoogleCodeExporter commented 9 years ago

Original comment by dnsch...@gmail.com on 8 May 2012 at 12:02