Search code examples
javascriptflot

flot navigate plugin pan to the end of the yaxis


I want to pan to the end of the y-axis, I can call plot.pan({top: 100}), I just don't know how to get the distance in pixels between from my current view and the end of the. There are functions c2p() and p2c() on each axis, and they are canvas-2-point and point-2-canvas, but they don't really tell you what the value you get back means, what it's reference point is etc.

Help?


Solution

  • To pan to the end of an axis (or to the start) you do not need to know what the current position is. Just get the full height (or width) of the pan range in pixels and pan that amount. The plugin will automatically stop when it hits the end of the pan range. To get the full width (or height) use this:

    var axis = plot.getAxes().yaxis; // for x axis change yaxis to xaxis
    var amount = Math.abs(axis.datamax - axis.datamin)*axis.scale;
    plot.pan({top: amount}); // for x axis change top to left / for other direction use negative amount
    

    Here is a fiddle with a full example (x axis panning but works the same for y axis).