Hello,
I never really understood how ZoomPercent works.
First the API doc says:
When PercentZoom is greater than 100%, Zoom Out is performed. When PercentZoom is lower than 100%, Zoom In is performed.
But it seems to be the other way around (which makes more sense to me too). Is this an error in the doc?
Second when I zoom in for e.g. 25% (i.e. ZoomPercent(125) and then zoom out for 20% (i.e. ZoomPercent(80) I should be at my starting position again but that doesn't seem to work. Is there an explanation for this behavior?
ZoomPercent method
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi ctusch,
The easiest way to set a chart to the initial scale is doing something like this:
Yes, it is and have added it to the defect list to be fixed for next releases.First the API doc says:
When PercentZoom is greater than 100%, Zoom Out is performed. When PercentZoom is lower than 100%, Zoom In is performed.
But it seems to be the other way around (which makes more sense to me too). Is this an error in the doc?
This is because after setting it to 125 the resulting chart is the new 100% so that you are zooming out an 80% of that new chart, not the initial chart.Second when I zoom in for e.g. 25% (i.e. ZoomPercent(125) and then zoom out for 20% (i.e. ZoomPercent(80) I should be at my starting position again but that doesn't seem to work. Is there an explanation for this behavior?
The easiest way to set a chart to the initial scale is doing something like this:
Code: Select all
tChart1.Axes.Left.SetMinMax(tChart1[0].MinYValue(), tChart1[0].MaxYValue());
tChart1.Axes.Bottom.SetMinMax(tChart1[0].MinXValue(), tChart1[0].MaxXValue());
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Hello narcis,
I'm aware that I'm zooming out of 'the new chart' and I have included this already in my values. If we assume the chart has a bottom axes which is 100 units long if I multiply it by 1.25 (zooming in) and then by 0.8 (zooming out) I have the 100 again. So it must be something else. Unfortunately I need to zoom in e.g. 5 times and then zoom out e.g. 3 times and the result must be the same as if I've zoomed in just 2 times. That's why your proposed solution is no option for me. What else could I do?
I'm aware that I'm zooming out of 'the new chart' and I have included this already in my values. If we assume the chart has a bottom axes which is 100 units long if I multiply it by 1.25 (zooming in) and then by 0.8 (zooming out) I have the 100 again. So it must be something else. Unfortunately I need to zoom in e.g. 5 times and then zoom out e.g. 3 times and the result must be the same as if I've zoomed in just 2 times. That's why your proposed solution is no option for me. What else could I do?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi ctusch,
In that case the only solution I can think of is saving axes mininum and maximum values to an array after each zoom step and retrive those values when unzooming.
In that case the only solution I can think of is saving axes mininum and maximum values to an array after each zoom step and retrive those values when unzooming.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Hi narcis,
I've finally worked myself through the source code and now I do understand how the ZoomPercentage works. The big thing is when you e.g. zoom in with 120% the 120% are applied to the lower _and_ to the upper border. So you actually zoom in for 140%. Same applies when zooming out. I've worked out the following formula:
zoomOut = 150 - 2500 / (150 - zoomIn)
And vice versa:
zoomIn = 150 - 2500 / (150 - zoomOut)
So you just put in the number you passed to the ZoomPercent method and get out the number you have to pass to get to your old position.
I've finally worked myself through the source code and now I do understand how the ZoomPercentage works. The big thing is when you e.g. zoom in with 120% the 120% are applied to the lower _and_ to the upper border. So you actually zoom in for 140%. Same applies when zooming out. I've worked out the following formula:
zoomOut = 150 - 2500 / (150 - zoomIn)
And vice versa:
zoomIn = 150 - 2500 / (150 - zoomOut)
So you just put in the number you passed to the ZoomPercent method and get out the number you have to pass to get to your old position.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi ctusch,
For completeness to previous reply, it is true that the following is correct:
X * 1.25 = Y
Y * 0.8 = Z
Y == Z
However, TeeChart zooming works in a slightly different way. Basically, TeeChart zooms on a chart by modifying Axis.Maximum and Axis.Minimum values using Axis.SetMinMax().
Let's take the bottom axis as an example, where we start with:
Axis.Minimum = 0
Axis.Maximum = 24
If you open the TeeChart.dll with Lutz Roeder's Reflector you can see that the values passed to the SetMinMax of each axis are calculated in CalcAxisScale. Using a zoom of 125 on the above values gives you:
tmp = (24 - 0) * 0.25 (this is the zoom value calculated by ((percentZoom -
100.0) * 0.01))
tmp = 6
Axis.Minimum = 0 + 6 == 6
Axis.Maximum = 24 - 6 == 18
So, the bottom axis Minimum becomes 6 and the bottom axis Maximum becomes 18. Now lets apply a zoom of 80 to these values:
tmp = (18 - 6) * -0.2 (this is the zoom value calculated by ((percentZoom -
100.0) * 0.01))
tmp = -2.4
Axis.Minimum = 6 + -2.4 == 3.6
Axis.Maximum = 18 - -2.4 == 20.4
In this case, the bottom axis Minimum becomes 3.6 and the bottom axis Maximum becomes 20.4. This means that the following will work as desired:
For completeness to previous reply, it is true that the following is correct:
X * 1.25 = Y
Y * 0.8 = Z
Y == Z
However, TeeChart zooming works in a slightly different way. Basically, TeeChart zooms on a chart by modifying Axis.Maximum and Axis.Minimum values using Axis.SetMinMax().
Let's take the bottom axis as an example, where we start with:
Axis.Minimum = 0
Axis.Maximum = 24
If you open the TeeChart.dll with Lutz Roeder's Reflector you can see that the values passed to the SetMinMax of each axis are calculated in CalcAxisScale. Using a zoom of 125 on the above values gives you:
tmp = (24 - 0) * 0.25 (this is the zoom value calculated by ((percentZoom -
100.0) * 0.01))
tmp = 6
Axis.Minimum = 0 + 6 == 6
Axis.Maximum = 24 - 6 == 18
So, the bottom axis Minimum becomes 6 and the bottom axis Maximum becomes 18. Now lets apply a zoom of 80 to these values:
tmp = (18 - 6) * -0.2 (this is the zoom value calculated by ((percentZoom -
100.0) * 0.01))
tmp = -2.4
Axis.Minimum = 6 + -2.4 == 3.6
Axis.Maximum = 18 - -2.4 == 20.4
In this case, the bottom axis Minimum becomes 3.6 and the bottom axis Maximum becomes 20.4. This means that the following will work as desired:
Code: Select all
private void button1_Click(object sender, EventArgs e) //apply zoom
{
tChart1.Zoom.ZoomPercent(125);
}
private void button2_Click(object sender, EventArgs e) //apply zoom to return to original
{
tChart1.Zoom.ZoomPercent(50);
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi ctusch,
No problem. I'm glad to hear you found a solution to the issue. As you say this can be helpful for future reference.
No problem. I'm glad to hear you found a solution to the issue. As you say this can be helpful for future reference.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |