Zoom bug

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Queue Moderators

Post Reply
ehdrnsep
Posts: 48
Joined: Mon Jan 12, 2015 6:52 am

Zoom bug

Post by ehdrnsep » Tue Oct 06, 2015 5:10 am

In the code it was created three series.

When using the mouse wheel to zoom a problem arises.

English not well written.
The blog to view the video was attached.

http://ehdrn.tistory.com/450

If you check the questions, url will delete.
Thank you.

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Arction.LightningChartUltimate;
using Arction.LightningChartUltimate.Axes;
using Arction.LightningChartUltimate.SeriesXY;
using Arction.LightningChartUltimate.Views.ViewXY;

namespace ZoomBug
{
    public partial class Form1 : Form
    {
        LightningChartUltimate chart;

        public Form1()
        {
            InitializeComponent();
            CreateChart();
        }

        private SeriesPoint[] CreateSamplePoints(int index)
        {
            SeriesPoint []points = new SeriesPoint[100000];
            Random rand = new Random();

            #region Bug
            int x = 80000;
            const int MaxX = 92000;
            for (int i = 0; i < points.Length; i++)
            {
                if (index == 0)
                {
                    points[i] = new SeriesPoint(i, x++);
                }
                else if (index == 1)
                {
                    points[i] = new SeriesPoint(i, x++);
                }
                else
                {
                    points[i] = new SeriesPoint(i, 0);
                }
                if (x == MaxX)
                    x = 80000;
            }
            #endregion

            #region  Good
            //for (int i = 0; i < points.Length; i++)
            //{
            //    points[i] = new SeriesPoint(i, rand.Next(0,10000));
            //}
            #endregion
            return points;
        }

        private void CreateChart()
        {
            chart = new LightningChartUltimate();
            chart.BeginUpdate();
            chart.Parent = this;
            chart.Dock = DockStyle.Fill;
            chart.ViewXY.AxisLayout.YAxesLayout = YAxesLayout.Segmented;
            chart.ViewXY.LegendBox.Visible = false;

            ViewXY chartView = chart.ViewXY;
            
            chart.ViewXY.AxisLayout.Segments.Clear();
            chart.ViewXY.YAxes.Clear();
            for (int i = 0; i < 3; i++)
            {
                chart.ViewXY.AxisLayout.Segments.Add(new YAxisSegment() {  Height = 1});

                AxisY yAxis = new AxisY();
                yAxis.SegmentIndex = i;
                chart.ViewXY.YAxes.Add(yAxis);

                PointLineSeries series = new PointLineSeries(chartView, chartView.XAxes[0], chartView.YAxes[i]);
                series.Points = CreateSamplePoints(i);
                series.LimitYToStackSegment = true;

                series.LineStyle.Pattern = LinePattern.Solid;
                series.LineStyle.Width = 1f;
                series.LineStyle.AntiAliasing = LineAntialias.None;
                series.LimitYToStackSegment = true;
                series.PointsOptimization = PointsRenderOptimization.Pixels;
                series.PointsVisible = false;
                series.ScrollingStabilizing = true;
                series.ScrollModePointsKeepLevel = 100;
                series.MouseInteraction = false;
                series.MouseHighlight = MouseOverHighlight.None;
                
                chart.ViewXY.PointLineSeries.Add(series);
            }

            chart.EndUpdate();
            chart.ViewXY.FitView();
        }
    }
}

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Zoom bug

Post by ArctionPasi » Wed Oct 07, 2015 12:54 pm

It's actually not a bug, but may seem such.

In stacked or segmented mode, vertical zooming currently works as follows:
axis.Maximum and Minimum are multiplied or divided (depending on in/out zoom) by ViewXY.ZoomPanOptions.ZoomFactor value. That happens when zooming with Ctrl + left or right mouse button click. Wheel is related to factor this as well.

As your Y range is not symmetrical to 0 level, the new zoomed scale is not suitable for your data. And in your code you have enabled series.LimitYToStackSegment, so it shows up very clearly and ugly.

There's a way to override zooming with custom logic like this, by using BeforeZooming event handler:

m_chart.ViewXY.BeforeZooming += ViewXY_BeforeZooming;


//Make symmetrical zooming around old Y range center point.
void ViewXY_BeforeZooming(System.Collections.Generic.List<RangeChangeInfo> xRanges,
System.Collections.Generic.List<RangeChangeInfo> yRanges, bool byWheel, ref bool cancel)
{
m_chart.BeginUpdate();
cancel = true;
foreach(RangeChangeInfo rci in yRanges)
{
double yMid = (rci.OldMin + rci.OldMax) / 2.0;
double newYRange = rci.NewMax - rci.NewMin;

rci.Axis.SetRange(yMid-newYRange/2.0, yMid + newYRange/2.0);
}
m_chart.EndUpdate();
}


Maybe we should change the built-in zooming to use this kind of "symmetrical-to-Y-range-mid-point" instead of the current approach?
LightningChart Support Team, PT

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Zoom bug

Post by ArctionPasi » Fri Apr 22, 2016 5:28 am

Symmetrical zooming was implemented in v.7.0
LightningChart Support Team, PT

Post Reply