Recent

Author Topic: Zooming  (Read 11330 times)

wp

  • Hero Member
  • *****
  • Posts: 13625
Zooming
« on: August 20, 2012, 09:08:03 am »
For zooming - either using the built-in method of TChart, or using the ZoomDragTool - it is necessary to drag a rectangle from the left-top to the right-bottom corner. Dragging in a different direction does not work. I know Delphi's TeeChart does it this way. But is it really necessary? What is the reason for that restriction? I think it would we nice to draw the zoom rectangle in any direction. In one of my applications, for example, I have to zoom around the maximum of a curve. This would be much easier to do when the zoomrect could be dragged upward.

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Zooming
« Reply #1 on: August 20, 2012, 10:06:43 am »
Not used TChart in Lazarus, but when I've used it in Delphi, I think reverse rectangle dragging triggered a reset zoom feature.

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: Zooming
« Reply #2 on: August 20, 2012, 11:30:20 am »
I know, but in TAChart a single mouse-click is sufficient to unzoom. Therefore, any direction of dragging would be available.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Zooming
« Reply #3 on: August 20, 2012, 02:20:15 pm »
The reason is indeed "done as in Delphi, and nobody requested anything else".
So you want to change the following condition in TZoomDragTool.MouseUp:
Code: [Select]
if (Left >= Right) or (Top >= Bottom) then
That's ok, the question is -- to what?
I think that the user should have an option to revert to current behavior,
but beyond that -- what is your proposal?

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: Zooming
« Reply #4 on: August 20, 2012, 03:20:33 pm »
Out of my head, and untested:

Code: [Select]
type
  TZoomDragDirection = (zddDefault, zddAny);
     // zddDefault = default Delphi behavior left-top to bottom-right
     // zddAny = zoom rect in any direction, unzoom by click

  TZoomDragTool = class(TBasicZoomTool)
  private
    FDragDirection : TZoomDragDirection;
    // ..
  published
    // ...
    property DragDirection: TZoomDragDirection read FDragDirection write FDragDirection default zddDefault;
  end;

procedure TZoomDragToolMouseUp(APoint: TPoint);
// ...
  with FSelectionRect do begin
    case FDragDirection of
      fddDefault:
        // Unzoom by dragging from bottom-right to left-top
        if (Left >= Right) or (Top >= Bottom) then begin
          DoZoom(FChart.GetFullExtent, true);
          exit;
        end; 
      fddAny:
        // Unzoom by simple click
        if (Left = Right) and (Top = Bottom) then begin   // or maybe allow a tolerance of a few pixels...
          DoZoom(FChart.GetFullExtent, true);
          exit;
        end;
      end;
    // ...

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: Zooming
« Reply #5 on: August 21, 2012, 08:58:49 pm »
Now that I found some time I could implement the behavior - see the attached patch. It adds the property ZoomDirection to TZoomDragTool which allows to switch between default (zddDefault) and new (zddAny) behavior.
  • zddDefault means "like Delphi", i.e. zoom in by dragging from left-top to right-bottom, unzoom by dragging in the opposite direction or just clicking (this is TAChart default, not sure about Delphi...).
  • zddAny means zoom in by dragging the zoom rect in any direction, unzoom by just clicking.
BTW, what happened with the other patch that I posted some time ago regarding the distance measurement tool (http://www.lazarus.freepascal.org/index.php/topic,17319.0.html)? Please let me know if you have concerns with it.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Zooming
« Reply #6 on: August 22, 2012, 05:48:00 pm »
Sorry, I was too terse in my previous reply.
The problem, as you have seen yourself, is not to implement the patch,
but to select the feature set.
I can see the following potentially separate controllable features:
1) Unzoom when dragging to top-left
2) Unzoom when dragging to top-right
3) Unzoom when dragging to bottom-left
4) Unzoom when dragging to bottom-right
5) Unzoom with click (perhaps with tolerance)
You suggest essentially a boolean switch between (1,2,3,5) and (5).
Does other combinations make sense? For example, you said the Delphi does NOT unzoom on (5), so maybe (1,2,3) have some value?
Or maybe it is better to allow user to control them separately?
I tend towards the latter -- what do you think?

Quote
regarding the distance measurement tool
I have answered in that topic.

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: Zooming
« Reply #7 on: August 22, 2012, 10:53:45 pm »
That's the way the others do it:
I started Delphi XE2 after a long time (thanks to Lazarus and TAChart...) and tested their zooming behavior:
- zoom in: drag in any direction (in Delphi 7: only drag left-top to right-bottom)
- zoom out: drag in direction that differs from that used for zooming-in, single click does not unzoom.
There are some quite long distances to drag in order to initiate unzooming - this is quite uncomfortable when coming from TAChart's single click...

As I implemented in the patch, my favorite behavior would be to zoom in by dragging in any direction and to unzoom by clicking. But I see that this may not be general enough, and "eating" the click is not good anyway, it might be needed for other purposes.

Maybe there woud be a greater flexibility if there were an additional TUnzoomDragTool and TUnzoomClickTool which unzoom to the chart's full extent (*) in a single step. Both Zoom- and Unzoom DragTools should have a set property Directions = (SouthEast, NorthWest, etc).

To get my desired behavior, I would combine a ZoomDragTool having all directions activated with an UnzoomClickTool.

For the Delphi 7 behavior, we would need a ZoomDragTool with Direction=SouthEast and a UnzoomDragTool having all directions active. The ZoomDragTool should be handled before the UnzoomDragTool to avoid unzooming by the zoom-direction.

Delphi XE2 would need a ZoomDragTool and an UnzoomDragTool, both with all directions enabled. The ZoomDragTool should "somehow" tell UnzoomDragTool which direction had been used for the zoom-in. Well, this case sounds a bit complicated, I admit...

For compatibility with existing code, TZoomDragTool should keep its present unzooming behavior, but it should disable it when it finds an UnZoomTool in the tools collection.

-----------------
(*) There may be one exception from unzooming to the full extent. In one of my project I am plotting a long data series which is very compressed. To avoid this I added a TChartScrollbar which shows me only a reasonable section, but still allows to see other data by scrolling. Now when I zoom into the chart and unzoom the data are compressed again, the window defined by the scrollbar is destroyed. Maybe this is already possible now without excessive programming, but unzooming should take care of such a case.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Zooming
« Reply #8 on: August 23, 2012, 06:18:23 am »
Ok, see my attempt at the solution in r38342.
I think I've managed to represent all the variants discussed with a single
"set of options" property, with every option independent of the others.

You can get the following behaviors:
* backwards-compatible (default) by setting [zreDragTopLeft, zreDragTopRight, zreDragBottomLeft, zreClick]
* your preferred by setting [zreClick]
* Delphi 7 by setting [zreDragTopLeft, zreDragTopRight, zreDragBottomLeft]
* Delphi XE2 by setting [zreDifferentDrag]

Please test.

Quote
when I zoom into the chart and unzoom the data are compressed again, the window defined by the scrollbar is destroyed
Try http://wiki.lazarus.freepascal.org/TAChart_documentation#Extent_limits.

wp

  • Hero Member
  • *****
  • Posts: 13625
Re: Zooming
« Reply #9 on: August 23, 2012, 11:30:21 pm »
Thank you - perfect.

CM630

  • Hero Member
  • *****
  • Posts: 1737
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Zooming
« Reply #10 on: September 14, 2012, 07:57:53 am »
In my opinion, it would be better if there were some more options- currently regarding the mouse buttons, there is only zreClick. It would be nicer if there were also zreLeftClick, zreRightClick and zreMiddleClick. In fact, currently zreClick is zreRightClick indeed, since a left click does not zoom out.
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Zooming
« Reply #11 on: September 14, 2012, 09:18:35 am »
Quote
left click does not zoom out.

It works for me, of course if the left mouse button is selected for this tool.

If you can reproduce this problem, please state the platform/widgetset you use
and provide a small test program.

CM630

  • Hero Member
  • *****
  • Posts: 1737
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Zooming
« Reply #12 on: September 14, 2012, 10:02:16 am »
of course if the left mouse button is selected for this tool.
Well, I did not think that it was supposed to work this way, that is why I asked for left/right/middle click.
So if I want to zoom out with left+right click, I just have to capture the clicks and do logicalextend:= fullextend;

If you can reproduce this problem, please state the platform/widgetset you use
and provide a small test program.
Generally, do you prefer zip or 7zip?
Лазар 4,8 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Zooming
« Reply #13 on: September 14, 2012, 10:14:38 am »
Quote
Well, I did not think that it was supposed to work this way, that is why I asked for left/right/middle click.
So if I want to zoom out with left+right click,
I do not quite understand -- do you want to drag-zoom in with one button, but to drag-unzoom with another?
If so, this is quite exotic request, I do not think it useful to implement in TAChart itself.
You correctly noted that you can
Quote
just have to capture the clicks and do logicalextend:= fullextent;

Note that it is slightly better to call ZoomFull procedure,
although the difference may be insignificant for your case.

Quote
do you prefer zip or 7zip?
I have no problem with either of them.
Please, archive only the source, not the executable or object files.

 

TinyPortal © 2005-2018