|
Correct way to use chartdir to support Zoom in/out |
Posted by ouyang on Aug-13-2014 18:07 |
|
I use zoomTo and zoomAt to implement zoom in and out.
It works fine before I try to use user defined x-labels.
My code can be simplified as bellows:
1) call
viewer->syncLinearAxisWithViewPort("x", c->xAxis());
viewer->syncLinearAxisWithViewPort("y", c->yAxis());
2) use zoomTo(xxx), zoomAt(xxx), to implement zoom instead of setViewPortLeft /xxx
3) set full range according to labels width
int xRange = CharStr.size() > 1 ? CharStr.size() -1 : 1;
setFullRange("x", 0, xRange);
4) calculate labels range when zoom by call:
int start = static_cast<int>(floor(getValueAtViewPort("x", getViewPortLeft())));
int end = static_cast<int>(ceil(getValueAtViewPort("x",
getViewPortLeft() + getViewPortWidth())));
5) and try to addlabels if zoom in /out :
m_chart->xAxis()->setLinearScale(0, xRange, Chart::NoValue);
for (int i = start; i <= end; ++i) m_chart->xAxis()->addLabel(i, CharStr[i]);
6) But there is still numerical x-Axis labels and labels are not right as I expected.
When I try to use :
CDMLTable *table = m_chart->xAxis()->makeLabelTable();
The labels work fine!
But I don't want to use CDMLTable for some reason.
Any suggestion ? |
Re: Correct way to use chartdir to support Zoom in/out |
Posted by Peter Kwan on Aug-14-2014 02:34 |
|
Hi ouyang,
(a) Use the following code to set up the x view port during initialization:
viewer->setFullRange("x", 0, xRange);
(b)
int start = static_cast<int>(floor(getValueAtViewPort("x", getViewPortLeft())));
int end = static_cast<int>(ceil(getValueAtViewPort("x", getViewPortLeft() +
getViewPortWidth())));
(c)
m_chart->xAxis()->setLinearScale(start, end, Chart::NoValue);
for (int i = start; i <= end; ++i) {
if (CharStr.size() > i) m_chart->xAxis()->addLabel(i, CharStr[i]);
}
Alternatively, if your CharStr is of type "std::vector<char *>" or "std::vector<const char
*>", you can combine the above into one line:
m_chart->xAxis()->setLinearScale(start, end, (CharStr.size() > 0) ?
StringArray(&(CharStr[start]), end - start + 1) : StringArray(0, 0));
Note that there is no need to use the line "viewer->syncLinearAxisWithViewPort("x", c-
>xAxis());".
Hope this can help.
Regards
Peter Kwan |
Re: Correct way to use chartdir to support Zoom in/out |
Posted by ouyang on Aug-14-2014 08:48 |
|
Hi Peter,
Many thanks for your suggestion.
I've tried to remove the syncLinearAxisWithViewPort.
It seems the zoom in/out functionality doesn't work without syncLinearAxisWithViewPort.
I'm not sure the exact functionality of syncLinearAxisWithViewPort, will it recalculate the
coordinate aixs regardless of whether there is setLinearScale(start, end, Chart::NoValue) ?
Thanks,
Ouyang
|
Re: Correct way to use chartdir to support Zoom in/out |
Posted by Peter Kwan on Aug-15-2014 03:39 |
|
Hi ouyang,
I have attached an example below for your reference. It is based on the "Simple Zooming
and Scrolling (MFC)" sample code. To try it, please copy it to the ChartDirector/mfcdemo
subdirectory to replace the existing "Simple Zooming and Scrolling (MFC)" there. You can
then try to compile and run it to see how it works.
The purpose of "syncLinearAxisWithViewPort" is as follows:
(a) If the "full range" has not yet been defined, it will auto-scale the x-axis, and use it as
the full range. This typically occurs if setFullRange is not called, and the chart is
displayed for the first time.
(b) If the "full range" has already been defined, this method will configure the x-axis to be
a linear axis, in which the scale is based on the view port position and width.
For your case, (a) never occurs, because you are using setFullRange, and the
setFullRange should have been executed once before the chart is drawn, and should have
set the full range for "x". (b) is not necessary as well, as you are using custom labels,
and your code has already configure the x-axis scale and labels. So
"syncLinearAxisWithViewPort" is not needed. Using it will cause (b) to occur, and this will
inject additional labels to the x-axis.
For your case, would you mind to verify that setFullRange is called once before you draw
the chart or call the getValueAtViewPort method?
If the above still cannot solve the problem, is it possible to modify the attached sample
code to try to reproduce the problem, and attached the modified code?
Regards
Peter Kwan
|
|