AutoXFit without scaling when zooming or panning

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Salto
Posts: 27
Joined: Mon Jan 13, 2014 5:43 pm

AutoXFit without scaling when zooming or panning

Post by Salto » Tue Jan 14, 2014 7:45 am

Hello

I need a diagram with automatic scaling of the x-axis and the y-axis.

For the y-Axis, i can use AutoYFit:

Code: Select all

_lightningChart.ViewXY.ZoomPanOptions.AutoYFit.Enabled = true;
For the x-Axis (and also y-Axis), i can use:

Code: Select all

_xAxis.SetRange(0, xMax);
if i add one or more points.

My problem is, when i zoom into the chart and new points are added to the chart, the selected zoom range changed. Is there a solution(an event) to find out when you zoom into the chart and when the zoom is reset (revertToRange with the rectangle with the mouse). I also need to know if the diagram is panning or reset.
The code should look like this:

Code: Select all

if (!zooming && ! panning)
{
    _xAxis.SetRange(0, xMax); //or yAxis
}
I hope you can help me, thank you
Raphael

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

Re: AutoXFit without scaling when zooming or panning

Post by ArctionPasi » Tue Jan 14, 2014 8:20 am

Hello Raphael,

_lightningChart.ViewXY.FitView() also makes auto-fit of both X and Y axes, to the whole data contents.

Axes have RangeChanged event. You can use that to store the range in your
private double _xMin, _xMax, _yMin, _yMax variables.

Then in the RangeChanged event, you can use a logic like the following
bool zoomed = false;
bool panned = false;

if( (newXMax-newXMIn) != (_xMax-_xMin))
{
zoomed = true;
}
else if(newXMin != _xMin)
{
panned = true;
}

something like this?
LightningChart Support Team, PT

Salto
Posts: 27
Joined: Mon Jan 13, 2014 5:43 pm

Re: AutoXFit without scaling when zooming or panning

Post by Salto » Wed Jan 15, 2014 10:37 am

Hello Pasi

Thank you for your fast answer. Your idea is good, but I've a problem with the reset from the zoom. I've the following methods for each axis:

Code: Select all

        /// <summary>
        /// Update the min and the max value if they are larger than the current one.
        /// </summary>
        /// <param name="min">
        /// The min value from the new points.
        /// </param>
        /// <param name="max">
        /// The max value from the new points.
        /// </param>
        public void UpdateMinMax(double min, double max)
        {
            bool updateMax = false;
            bool updateMin = false;
            if (max > _max)
            {
                _max = max;
                _lightningChartAxisXYBase.RangeRevertMaximum = _max;
                updateMax = _autoScale && !_zoomed && !_panned;
            }

            if (min < _min || (!_includeZero && _min == 0))
            {
                _min = min;
                _lightningChartAxisXYBase.RangeRevertMinimum = _min;
                updateMin = _autoScale && !_zoomed && !_panned;
            }

            if (updateMin && updateMax)
            {
                _lightningChartAxisXYBase.SetRange(_min, _max);
            } 
            else if (updateMax)
            {
                _lightningChartAxisXYBase.Maximum = _max;
            }
            else if (updateMin)
            {
                _lightningChartAxisXYBase.Minimum = _min;
            }
        }

        private void LightningChartAxisBaseOnRangeChanged(double newMin, double newMax, Arction.WPF.LightningChartUltimate.Axes.AxisBase axis, ref bool cancelRendering)
        {
            _zoomed = false;
            _panned = false;

            if ((newMax - newMin) != (_max - _min))
            {
                _zoomed = true;
            }
            else if (newMin != _min)
            {
                _panned = true;
            }
        }
When I reset the zoom (rectangle with the mouse), I've the following values (y-axis):
(this._lightningChartAxisXYBase).RangeRevertMaximum 1.014568843
(this._lightningChartAxisXYBase).RangeRevertMinimum 0.900584273
_max 1.014568843
_min 0.900584273
newMax 1.0173329030115472
newMin 0.8980834567990762
newMax-_max 0.0027640600115472758
_min-newMin 0.0025008162009237944

There is a margin or something else. With a delta, it works, but that's not the correct solution.

Code: Select all

private void LightningChartAxisBaseOnRangeChanged(double newMin, double newMax, Arction.WPF.LightningChartUltimate.Axes.AxisBase axis, ref bool cancelRendering)
        {
            _zoomed = false;
            _panned = false;

            if (Math.Abs((newMax - newMin) - (_max - _min)) > 0.008)
            {
                _zoomed = true;
            }
            else if (Math.Abs(newMin - _min) > 0.008)
            {
                _panned = true;
            }
        }
I've disabled the AutoYFit and MarginPixels, but nothing works.

Code: Select all

            _lightningChart.ViewXY.ZoomPanOptions.AutoYFit.Enabled = false;
            _lightningChart.ViewXY.ZoomPanOptions.AutoYFit.MarginPercents = 0;
            _lightningChart.ViewXY.ZoomPanOptions.ViewFitYMarginPixels = 0;
Do you have an idea for my problem?

Salto
Posts: 27
Joined: Mon Jan 13, 2014 5:43 pm

Re: AutoXFit without scaling when zooming or panning

Post by Salto » Thu Jan 16, 2014 8:14 am

Hello again

I've found the problem. I've in a chartstyle set the ZoomPanViewFitYMarginPixels to 10 pixels :oops:
Thank you for your help!

Post Reply