Zooming in x, autoranging in y
Posted: Sun Jun 03, 2012 6:28 pm
I have various financial charts, all XYPlots, all using a DateAxis for the x-axis. They may have several
datasets and several axes, for example an OHLC and one or two moving-averages mapped onto a
NumberAxis (price axis) on the left and a trading volume dataset, mapped onto another number axis
(volume axis) on the right.
When the chart is first displayed, autoranging does what I want, "shrink-wrapping" the whole chart,
so the DateAxis is scaled to the time interval from the earliest to the most recent datapoint, and
the Y axis is scaled to fit the min/max Y values found over that interval, plus a bit of margin.
(Incidentally I also want to show the volume in the lower 25% and the prices in the upper 75% but
I think I can get that with the margin parameters on the plot, so I think that's not a problem.)
Then the user zooms the chart, by dragging out a zoom rectangle. Now what I call "normal" zoom
behavior is that each axis is independently rescaled, so that the extent of the drag-rectangle in
that dimension (x or y) becomes the extent of the entire visible portion of the chart.
That's what i want in x (time). But in y (price, volume axes) what I want is that the y-axes rescale
to shrink wrap the new range of data captured. In other words, the Y-extent of the drag rectangle
is ignored; the max/min Y values over the visible time-extent are computed, and the Y axis is
scaled to fit that to the chart.
And panning: when the user pans the chart, I want the pan to shift the visible portion of the x axis
left or right, without rescaling it, and then the Y axes to autorange again, "shrink wrapping" the
Y data that falls into the new time-window.
What's the smartest way to set this up? I've read the code and the manual, a lot, and gotten rather
tangled up.
Thanks
Jim Goodwin
datasets and several axes, for example an OHLC and one or two moving-averages mapped onto a
NumberAxis (price axis) on the left and a trading volume dataset, mapped onto another number axis
(volume axis) on the right.
When the chart is first displayed, autoranging does what I want, "shrink-wrapping" the whole chart,
so the DateAxis is scaled to the time interval from the earliest to the most recent datapoint, and
the Y axis is scaled to fit the min/max Y values found over that interval, plus a bit of margin.
(Incidentally I also want to show the volume in the lower 25% and the prices in the upper 75% but
I think I can get that with the margin parameters on the plot, so I think that's not a problem.)
Then the user zooms the chart, by dragging out a zoom rectangle. Now what I call "normal" zoom
behavior is that each axis is independently rescaled, so that the extent of the drag-rectangle in
that dimension (x or y) becomes the extent of the entire visible portion of the chart.
That's what i want in x (time). But in y (price, volume axes) what I want is that the y-axes rescale
to shrink wrap the new range of data captured. In other words, the Y-extent of the drag rectangle
is ignored; the max/min Y values over the visible time-extent are computed, and the Y axis is
scaled to fit that to the chart.
And panning: when the user pans the chart, I want the pan to shift the visible portion of the x axis
left or right, without rescaling it, and then the Y axes to autorange again, "shrink wrapping" the
Y data that falls into the new time-window.
What's the smartest way to set this up? I've read the code and the manual, a lot, and gotten rather
tangled up.
Thanks
Jim Goodwin