Export to GitHub

flot - issue #193

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


Posted on Jul 17, 2009 by Swift Panda

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]; }

Comment #1

Posted on Oct 7, 2009 by Quick Wombat

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.

Comment #2

Posted on May 8, 2012 by Happy Wombat

(No comment was entered for this change.)

Status: Accepted

Labels:
Type-Enhancement Priority-Medium