ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Arbitrary Zoom Question
Posted by TN on Nov-16-2022 04:39
In all the zoom examples, seems like we need to filter for viewable data and there must be at least one point within the viewport to see anything. Is possible to zoom without filtering data and just set the viewing box. For example I would like to zoom in on the line between 2 points without including the 2 points in the viewing box.

  Re: Arbitrary Zoom Question
Posted by TN on Nov-16-2022 07:13
Looks like I can get it to work if I manually set the axis scale range. Tangent question.. Once you call packPlotArea, no more modifications can occur to the chart?

  Re: Arbitrary Zoom Question
Posted by Peter Kwan on Nov-16-2022 14:11
Hi TN,

You do not need to filter the data. However, it may be more efficient for your code to filter the data because you may have some knowledge about the data that ChartDirector does not have.

For example, suppose you have 10 million data points, and you zoom in to display only 5 data points. If you know the data are sorted, it is trivial and very fast to pick the 5 points (just use binary search to pick the points) and pass only the 5 points to ChartDirector. You can also pass all 10 million data points unfiltered to ChartDirector, but ChartDirector does not know if the data are sorted, so it needs to process all 10 million data points to determine which points should be plotted.

Most of our zooming and scrolling examples use sorted data and it includes code to filter the data to the visible region. The "XY Zooming and Scrolling" is an example that does not use sorted data, and it does not filter the data.

In our sample code that filters the data, it will also include the points that are immediately outside the viewport. So even if you zoom in to a region between two points, it will still point a line because it will include the two points in the filtered data.

For example, consider the "Simple Zooming and Scrolling" sample code:

https://www.advsofteng.com/doc/cdnet.htm#simplezoomscroll.htm

The code that picks the range is:

int startIndex = (int)Math.Floor(Chart.bSearch(timeStamps, viewPortStartDate));
int endIndex = (int)Math.Ceiling(Chart.bSearch(timeStamps, viewPortEndDate));

The Math.Floor and Math.Ceiling rounds towards the outside direction. It ensures the points that are immediately outside the viewport are included.

To test the code, you can set the maximum zoom in to 0.1 points. (The original sample code it is set to 10 points.)

// Set the maximum zoom to 0.1 points
viewer.ZoomInWidthLimit = 0.1 / timeStamps.Length;

Now you can zoom in to the line segment in between two points, and it should still work.

For packPlotArea, you cannot add any more "layers" or "data points" to the chart after layout out the axis (BaseChart.layoutAxes)., packPlotArea automatically layout the axis because its purpose is to adjust the plot area based on the axis layout. After packPlotArea, you can only add custom drawings (BaseChart.addText, BaseChart.addLine, or use the DrawArea object to draw lines and shapes), adjust the position of the legend box, resize the chart border, or call packPlotArea again ...

Best Regards
Peter Kwan

  Re: Arbitrary Zoom Question
Posted by TN on Nov-18-2022 00:33
Thanks for the reply. The functionality ultimately ended being much simpler to implement than first imagined.

  Re: Arbitrary Zoom Question
Posted by TN on Nov-30-2022 03:27
Follow up issue. The zooming ended up being simple with simply syncing axis
when the viewport is updated.

When I try to add the scroll on drag feature by the included code shown below, the viewport does not change when mouseusage is scrollondrag, but does change when mouseusage is zoomin.

By not changing I mean:
   Console.WriteLine($"Viewport {WinViewer.ViewPortLeft} {WinViewer.ViewPortTop} {WinViewer.Width}");

the printouts remain the same.

Any obvious errors with the code?



//on init
WinViewer.ScrollDirection = WinChartDirection.HorizontalVertical;

  private void WinViewer_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) {
                WinViewer.MouseUsage = WinChartMouseUsage.ZoomIn;
            }

            if (e.Button == MouseButtons.Middle) {
                WinViewer.MouseUsage = WinChartMouseUsage.ScrollOnDrag;
                Drag = true;
            }

        }

private void WinViewer_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left) {
                WinViewer.MouseUsage = WinChartMouseUsage.Default;
                WinViewer.Cursor = Cursors.Default;
            }

            if (e.Button == MouseButtons.Middle) {
                Drag = false;

                WinViewer.MouseUsage = WinChartMouseUsage.Default;
            }
        }

   private void WinViewer_MouseMoveChart(object sender, MouseEventArgs e)
        {
            if(Drag)
                WinViewer.updateViewPort(true, false);
        }

  private void WinViewer_ViewPortChanged(object sender, ChartDirector.WinViewPortEventArgs e)
        {
            if (e.NeedUpdateChart) {
                WinTSChart.Update();
            }
        }

  Re: Arbitrary Zoom Question
Posted by Peter Kwan on Dec-01-2022 00:21
Hi TN,

It is because all zoom/scroll mouse actions in ChartDirector use only the left mouse button. The right mouse button is not used. (It is intended to allow the programmer to implement other features with this button.) The middle button is not used as well as some mice may not have this button.

If you do not like to use extra buttons to select "Drag To Scroll" and "Drag to Zoom" modes, you may consider to use the mouse left button for "Drag to Scroll", and use the mouse wheel for zooming.

Best Regards
Peter Kwan