I’m trying to create a plugin for flot that will draw axis that cross the origin (0,0) instead of only being shown at the edge of the plot. One thing I’d like to do is, when using my plugin, the drawing of the regular axis (the ones at the edge) should be suppressed. So I added some logic to a function that hooks into processOptions like this:
plot.hooks.processOptions.push(processOptions);
function processOptions(plot, options) {
if (options.crossOrigin) {
if (options.xaxis.crossOrigin) {
options.xaxis.show = false;
plot.hooks.drawBackground.push(drawXAxis);
}
if (options.yaxis.crossOrigin) {
options.yaxis.show = false;
plot.hooks.drawBackground.push(drawYAxis);
}
}
}
By setting options.xaxis.show to false (and the same for the yaxis), this is supposed to stop the axis from appearing, but it doesn’t work. The option gets set, but flot ignores it when it draws the graph. The only way I can get it to not plot the regular axes is to explicitly set the show option when setting up the plot.
Any ideas why this doesn’t work? Is there a way to make it work?
Update: So after playing around with this for a while, I think what is happening is that there is, for example, an options.xaxis and an options.xaxes (an array) which contains just 1 entry. For some reason, flot wants to use the 1 axis in the options.xaxes[0] instead of options.xaxis. But I’m not quite sure what the logic here is supposed to be. They both get my custom “crossOrigin” option merged in, but only the options.xaxis gets it’s “show” property set.
Using xaxes[0] instead of xaxis seems to fix the problem, although it’s not clear when and how flot is processing this stuff.