Example #1
0
        /// <summary>
        /// Adjusts the Y extent.
        /// </summary>
        /// <param name="series">Series.</param>
        /// <param name="xaxis">Xaxis.</param>
        /// <param name="yaxis">Yaxis.</param>
        private static void AdjustYExtent(CandleStickSeries series, DateTimeAxis xaxis, LinearAxis yaxis)
        {
            var xmin = xaxis.ActualMinimum;
            var xmax = xaxis.ActualMaximum;

            var istart = series.FindByX(xmin);
            var iend   = series.FindByX(xmax, istart);

            var ymin = double.MaxValue;
            var ymax = double.MinValue;

            for (int i = istart; i <= iend; i++)
            {
                var bar = series.Items[i];
                ymin = Math.Min(ymin, bar.Low);
                ymax = Math.Max(ymax, bar.High);
            }

            var extent = ymax - ymin;
            var margin = extent * 0.10;

            yaxis.Zoom(ymin - margin, ymax + margin);
        }
        private void AdjustYAxisZoom()
        {
            var xmin = XAxis.ActualMinimum;
            var xmax = XAxis.ActualMaximum;
            Dictionary <string, (double min, double max)> zooms = new Dictionary <string, (double min, double max)>();

            //adcjust candles and volume
            if (Candles.Items.Count > 0)
            {
                var istart = Candles.FindByX(xmin);
                var iend   = Candles.FindByX(xmax, istart);

                var ymin = double.MaxValue;
                var ymax = double.MinValue;

                var volMin = double.MaxValue;
                var volMax = double.MinValue;
                for (int i = istart; i <= iend; i++)
                {
                    var bar = Candles.Items[i];
                    ymin = Math.Min(ymin, bar.Low);
                    ymax = Math.Max(ymax, bar.High);

                    var vol = Volumes.Items[i].BuyVolume + Volumes.Items[i].SellVolume;
                    volMin = Math.Min(volMin, vol);
                    volMax = Math.Max(volMax, vol);
                }

                var extent = ymax - ymin;
                var margin = extent * 0.10;
                zooms[this.Candles_Yaxis.Key] = (ymin - margin, ymax + margin);
                this.Candles_Yaxis.Zoom(ymin - margin, ymax + margin);
                this.Volume_Yaxis.Zoom(0, volMax);
            }


            //adjust other lines
            //reset zoom of all exes
            foreach (var line in this.Lines)
            {
                if (!line.IgnoreForZoom)
                {
                    (double min, double max)zoom = (double.MaxValue, double.MinValue);
                    if (zooms.ContainsKey(line.YAxisKey))
                    {
                        zoom = zooms[line.YAxisKey];
                    }

                    foreach (var p in line.Points)
                    {
                        if (p.X > XAxis.ActualMinimum)
                        {
                            zoom.min = p.Y < zoom.min ? p.Y : zoom.min;
                            zoom.max = p.Y > zoom.max ? p.Y : zoom.max;
                        }
                        if (p.X > XAxis.ActualMaximum)
                        {
                            break;
                        }
                    }
                    zooms[line.YAxisKey] = zoom;
                }
            }
            foreach (var axis in PlotViewModel.Axes)
            {
                if (zooms.ContainsKey(axis.Key))
                {
                    var zoom = zooms[axis.Key];
                    axis.Zoom(zoom.min, zoom.max);
                }
            }
        }