Recent

Author Topic: [ZoomDragTool] how to prevent to zoom out to full extent  (Read 6256 times)

Muso

  • Full Member
  • ***
  • Posts: 228
[ZoomDragTool] how to prevent to zoom out to full extent
« on: July 03, 2021, 05:14:32 pm »
I have a live dataset. To keep the overview, I made it scrolling, by setting a LogicalExtent.

I have now the problem that when the user zooms out (using the ZoomDragTool), the FullExtent of the chart is shown, not only the logical extent.
Is there a way to zoom out only to the current LogicalExtent?

Another issue: Could anybody who knows the ChartToolsets maybe add XML files with some short info about them? As it is one gets no info in the IDE about the different ool parameters. For example I wanted to know if the parameter "LimitToExtent" of the ZoomDragTool might help me, but without any info in the IDE one has to google and in the end I still haven't found the info how this parameter might be used.
« Last Edit: July 06, 2021, 01:13:53 am by Muso »

wp

  • Hero Member
  • *****
  • Posts: 8749
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #1 on: July 03, 2021, 07:09:13 pm »
You could use the FullExtent rather than the LogicalExtent to define the visible viewport of your scrolling chart. Maybe the attached demo gets close to what you need.

Regarding your second question I refer to my recent answer (https://forum.lazarus.freepascal.org/index.php/topic,55110.msg409620.html#msg409620). I must confess that writing help files is very boring work, and I always put it away from me...
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #2 on: July 03, 2021, 09:18:35 pm »
You could use the FullExtent rather than the LogicalExtent to define the visible viewport of your scrolling chart. Maybe the attached demo gets close to what you need.

Many thanks. This works for one series. Unfortunately I have 8 different series and the user is free to select which ones to use and when to start them.

But I think the solution is:

- in the ChartToolsetZoomDragTool event "OnAfterMouseUp" one has this code
Code: Pascal  [Select][+][-]
  1. Extent:= Chart1.GetFullExtent;
  2. Extent.a.x:= Extent.b.x - 20;
  3. Chart1.Extent.FixTo(Extent);

When adding the next time a data point I need to "unfix" the extent. How can this be done?

Quote
Regarding your second question I refer to my recent answer (https://forum.lazarus.freepascal.org/index.php/topic,55110.msg409620.html#msg409620). I must confess that writing help files is very boring work, and I always put it away from me...

I always remember my teacher at school: "an undocumented feature will be an unused one". And he was right.
Well, I am an active developer of the program FreeCAD and meanwhile I became a Wiki master to document the features I wrote for FreeCAD. And I can see that the feature will first be used by normal users (non-developers) when it is described in our Wiki. Then questions arise, bugs are reported etc.

my trick is to document whenever I add a feature to avoid to collect to much docs works. When documenting other's work (e.g. at work) my trick is the same - every day a small part and after some weeks it is done without a stress feeling.

wp

  • Hero Member
  • *****
  • Posts: 8749
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #3 on: July 03, 2021, 10:02:36 pm »
I always remember my teacher at school: "an undocumented feature will be an unused one". And he was right.
Absolutely. But I think writing this kind of context-help is pretty much frustrating because I think a user who never used the chart tools before will not learn how to use it from that kind of popup help. These texts mostly consist of copy & paste with only a few words replaced, and it does not describe the logical context of the feature for which the popup appeared. I find it more rewarding for me and more instructive for the user to have free-text documentation (https://wiki.lazarus.freepascal.org/TAChart_documentation) or tutorials (e.g. https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Getting_started).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #4 on: July 03, 2021, 11:49:23 pm »
I find it more rewarding for me and more instructive for the user to have free-text documentation

I fully agree. However often just few words would help. For example what does the property "EscapeCancels" of the ZoomDrag tool do? Few words would help here a lot.
Moreover the XML text can and should inform where one can find an example or Wiki page with a proper description of EscapeCancels or an example in which EscapeCancels is used.
« Last Edit: July 03, 2021, 11:54:02 pm by Muso »

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #5 on: July 03, 2021, 11:53:03 pm »
Eventually I found a solution, see attached.

I prepared all series in my chart that they have the same x range (since this is the time, this is doable). Then I look at the max/min values of all series. With these values I set up an extent to which I Fix the chart's extent to.

The problem was now that I have the feature to turn on/off the scrolling. So I must somehow "unfix" the extent - therefore I asked how this can be done.
I could not find another way than to fix the extent to the full extent of all chart series. But OK, that works

wp

  • Hero Member
  • *****
  • Posts: 8749
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #6 on: July 04, 2021, 01:08:16 pm »
Here is a more general version of your code which also does not switch to full extent.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #7 on: July 04, 2021, 01:38:21 pm »
Here is a more general version of your code which also does not switch to full extent.

Thanks. However this does not work for me because then scrolling is stopped the user wants to see the full data range, so x from 0.

A question to your code: You transform the LineSeries to a Custom Series, but when I use the LineSeries directly, it works too. So this code does work for me as well:

Code: Pascal  [Select][+][-]
  1. FViewport := EmptyExtent;
  2.     for i := 0 to Chart1.Series.Count-1 do
  3.     begin
  4.       ext := Chart1.Series[i].GetGraphBounds;
  5.       ExpandRect(FViewport, ext.a);
  6.       ExpandRect(FViewport, ext.b);
  7.       FViewport.a.x := FViewport.b.x - 10;
  8.     end;

wp

  • Hero Member
  • *****
  • Posts: 8749
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #8 on: July 04, 2021, 02:20:51 pm »
You transform the LineSeries to a Custom Series, but when I use the LineSeries directly, it works too. So this code does work for me as well:

Code: Pascal  [Select][+][-]
  1. FViewport := EmptyExtent;
  2.     for i := 0 to Chart1.Series.Count-1 do
  3.     begin
  4.       ext := Chart1.Series[i].GetGraphBounds;
  5.       ExpandRect(FViewport, ext.a);
  6.       ExpandRect(FViewport, ext.b);
  7.       FViewport.a.x := FViewport.b.x - 10;
  8.     end;
You are right: GetGraphBounds is already introduced in TBasicChartSeries, the most elemental series type, and this is what Chart1.Series[ i] returns. So, no type-cast is necessary at all. I had thought that GetGraphBounds is introduced by TCustomChartSeries and therefore applied the type-cast. I did not cast to TLineSeries to keep applicability of the code more general; without it the code works for an AreaSeries or BarSeries without changes.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

wp

  • Hero Member
  • *****
  • Posts: 8749
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #9 on: July 05, 2021, 12:08:21 pm »
Here is a more general version of your code which also does not switch to full extent.
Thanks. However this does not work for me because then scrolling is stopped the user wants to see the full data range, so x from 0.
So, what are your requirements?
- Scrolling viewport showing only the data within the last n seconds.
- Possibility to turn off scrolling (you have the ToggleBox for this purpose). In this case the full data range should be shown.
- Will the users be allowed to zoom? If yes, while scrolling and/or only when scrolling is suspended? If while scrolling then scrolling should be suspended, but unlike in the Togglebox case, the chart should not expand to full range?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #10 on: July 05, 2021, 01:15:56 pm »
So, what are your requirements?

You described it more or less as I needed it and I found the solution I posted.

When the user zoomed in, the scrolling is stopped and then not the full data range is shown of course. Only when not zoomed in and turning off scrolling the full data range is shown.

In my real-life program I implemented everything as I wanted now. So I am happy  :) with the scrolling.

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #11 on: July 05, 2021, 03:01:43 pm »
In my real-life program I implemented everything as I wanted now. So I am happy  :) with the scrolling.

For the records, attached is my final solution.

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #12 on: July 06, 2021, 01:13:30 am »
For the records, attached is my final solution.

Damn, I shot myself into the foot because I have a second axis and your solution with the extent of the LineSeries does then not work.

I played a bit around without success. Attached is an example program. There the red sine should be displayed in the right axis from - 3 to -7, the green since in the left axis from 3 to 5.

Do you see any solution on how to achieve this?

Muso

  • Full Member
  • ***
  • Posts: 228
Re: [ZoomDragTool] how to prevent to zoom out to full extent
« Reply #13 on: July 06, 2021, 03:48:04 pm »
I have to give up. Not only that I have 2 different axes with each an autoscale, I also use the AxisClickTool and when I there change the Min/Max value of the axis, everything goes wrong.

So i will have to live with the minor annoyance that zooming out always shows the full chart content.

 

TinyPortal © 2005-2018