|
Graceful extrapolation of points outside of range of viewport |
Posted by Marc on Aug-27-2012 21:58 |
|
Hi,
I am trying to use multiple step lines with points sometimes outside the visible area. For
example my data may have points at the following values x:
line1: 10,15,16,17,35
line2: 12,14,16,17,18,20,24,31
When I want to show 15-20 the problem I get is:
line 1 starts at 15 and ends at 17
line 2 starts at 16 and ends at 20
What I want is:
Line 1 to start at 15 and end at 20 (where its the same flat from 17 as it would have had
if I was zoomed out)
Line 2 to start at 15 since there are points before it (where 15 is the value at 14, as
thats what it would have looked like zoomed out)
When I want to show 25-30, both sets are empty, but I really want to show a flat line
with the values from 17 for line 1 and 24 from line 2, as would have been there if I had
been more zoomed out.
I am trying the approach used in the zoom example of doing:
DoubleArray viewPortTimeStamps = DoubleArray(m_timeStamps.data + startIndex,
noOfPoints);
This cuts off points as its not passing enough data for chartviewer to extrapolate. Any
advise on the best way to show the extrapolations of missing points?
As a further problem, I can assume all my points end at the same time, so when I show
30-40 line 2 and line 1 should both end at 35 even though line 1's data does not end
there. I can solve this problem by faking a last point and making them all even, unless
there was a better built in method to handle this case.
As a final note, my data is being graphed and generated in real time, where I allow for scrolling and zooming and my data points are not at "nice" numbers, but their real
timestamps.
Thanks,
Marc |
Re: Graceful extrapolation of points outside of range of viewport |
Posted by Peter Kwan on Aug-28-2012 03:25 |
|
Hi Marc,
If you want to show x = 15 - 20, but line 1 starts at 15 and ends at 17, it is likely because the data array that is passed to ChartDirector starts at 15 and ends at 17.
If you are using zooming and scrolling, in the original ChartDirector for C++ sample code, it always select a data range that is wider than the axis range. The exact sample code on different version of ChartDirector is different. In ChartDirector Ver 5.1, it is like:
int startIndex = (int)floor(Chart::bSearch(m_timeStamps, viewPortStartDate));
int endIndex = (int)ceil(Chart::bSearch(m_timeStamps, viewPortEndDate));
int noOfPoints = endIndex - startIndex + 1;
Note the "floor" and "ceil" function above. If the x-axis range is 15 to 20, for the line 1 data {10,15,16,17,35}, the above code should have selected the data range 15 to 35.
When the data are actually plotted, the XYChart.setClipping method in the charting code would clip the line to 15 - 20.
You can try the original ChartDirector sample code to see how it works. When you zoom in the maximum, you can see the line are extrapolated to points outside the viewport range.
In fact, if you only have a few data points, you can just pass all of them to ChartDirector and there is no need to select them. (It is only necessary to select them if you have many thousands of points.)
Hope this can help.
Regards
Peter Kwan |
Re: Graceful extrapolation of points outside of range of viewport |
Posted by Marc on Aug-30-2012 02:55 |
|
Thanks - didn't notice that! Only issue left is forcing them all to extend to the same time,
but I think that may be non trivial for dynamic data. |
Re: Graceful extrapolation of points outside of range of viewport |
Posted by Peter Kwan on Aug-30-2012 17:41 |
|
Hi Marc,
You mentioned "forcing them all to extend to the same time". Do you mean to select the x-coordinates of your data series, so that all of them has the x-range ?
You do not need to "forcing them all to extend to the same time". You just need to ensure they are extended so that they are wider than the x-axis range. Different data series can use different x-data range. So longer as they are wider than the x-axis range, the lines will be extended for the entire plot area. (The XYChart.setClipping will clip them to the plot area.)
For example, suppose you have two series using different x-coordinates. You can do something like:
int startIndex1 = (int)floor(Chart::bSearch(m_timeStamps1, viewPortStartDate));
int endIndex1 = (int)ceil(Chart::bSearch(m_timeStamps1, viewPortEndDate));
int noOfPoints1 = endIndex1 - startIndex1 + 1;
int startIndex2 = (int)floor(Chart::bSearch(m_timeStamps2, viewPortStartDate));
int endIndex2 = (int)ceil(Chart::bSearch(m_timeStamps2, viewPortEndDate));
int noOfPoints2 = endIndex2 - startIndex2 + 1;
Then you use startIndex1, endIndex1 and noOfPoints1 for the first line layer, and startIndex2, endIndex2 and noOfPoints2 for the second line layer. The m_timeStamps1 and m_timeStamps2 do not have to be the same.
Regards
Peter Kwan |
|