From a4eec711a6f38fd09b6bfcbdec5f948ffdabdcab Mon Sep 17 00:00:00 2001 From: Beto Rodriguez Date: Thu, 24 Jun 2021 17:03:38 -0500 Subject: [PATCH] fixes #52 --- src/LiveChartsCore/CartesianChart.cs | 2 +- src/LiveChartsCore/CartesianSeries.cs | 3 +- src/LiveChartsCore/ColumnSeries.cs | 60 ++++++----- src/LiveChartsCore/FinancialSeries.cs | 60 ++++++----- src/LiveChartsCore/HeatSeries.cs | 61 ++++++----- .../Kernel/Data/DataProvider.cs | 100 ++++++------------ .../Kernel/Data/SeriesBounds.cs | 57 ++++++++++ .../Kernel/Sketches/ICartesianSeries.cs | 3 +- src/LiveChartsCore/LineSeries.cs | 61 ++++++----- src/LiveChartsCore/PieSeries.cs | 2 +- src/LiveChartsCore/RowSeries.cs | 60 ++++++----- src/LiveChartsCore/ScatterSeries.cs | 62 ++++++----- src/LiveChartsCore/StackedColumnSeries.cs | 61 ++++++----- src/LiveChartsCore/StackedRowSeries.cs | 59 ++++++----- src/LiveChartsCore/StepLineSeries.cs | 59 ++++++----- 15 files changed, 393 insertions(+), 317 deletions(-) create mode 100644 src/LiveChartsCore/Kernel/Data/SeriesBounds.cs diff --git a/src/LiveChartsCore/CartesianChart.cs b/src/LiveChartsCore/CartesianChart.cs index 3ab88281f..76991d4ab 100644 --- a/src/LiveChartsCore/CartesianChart.cs +++ b/src/LiveChartsCore/CartesianChart.cs @@ -419,7 +419,7 @@ protected override void Measure() var secondaryAxis = XAxes[series.ScalesXAt]; var primaryAxis = YAxes[series.ScalesYAt]; - var seriesBounds = series.GetBounds(this, secondaryAxis, primaryAxis); + var seriesBounds = series.GetBounds(this, secondaryAxis, primaryAxis).Bounds; secondaryAxis.DataBounds.AppendValue(seriesBounds.SecondaryBounds.Max); secondaryAxis.DataBounds.AppendValue(seriesBounds.SecondaryBounds.Min); diff --git a/src/LiveChartsCore/CartesianSeries.cs b/src/LiveChartsCore/CartesianSeries.cs index 9e377e438..d914379ab 100644 --- a/src/LiveChartsCore/CartesianSeries.cs +++ b/src/LiveChartsCore/CartesianSeries.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using System.Drawing; using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -66,7 +67,7 @@ public CartesianSeries(SeriesProperties properties) : base(properties) { } public DataLabelsPosition DataLabelsPosition { get => _labelsPosition; set { _labelsPosition = value; OnPropertyChanged(); } } /// - public virtual DimensionalBounds GetBounds( + public virtual SeriesBounds GetBounds( CartesianChart chart, IAxis x, IAxis y) { return dataProvider == null diff --git a/src/LiveChartsCore/ColumnSeries.cs b/src/LiveChartsCore/ColumnSeries.cs index 7145ed679..83a4f0730 100644 --- a/src/LiveChartsCore/ColumnSeries.cs +++ b/src/LiveChartsCore/ColumnSeries.cs @@ -22,6 +22,7 @@ using LiveChartsCore.Drawing; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Data; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; @@ -256,10 +257,12 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -279,31 +282,34 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/FinancialSeries.cs b/src/LiveChartsCore/FinancialSeries.cs index 5b06d072e..a6c1030b5 100644 --- a/src/LiveChartsCore/FinancialSeries.cs +++ b/src/LiveChartsCore/FinancialSeries.cs @@ -25,6 +25,7 @@ using System.Drawing; using LiveChartsCore.Drawing; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Data; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; @@ -292,12 +293,14 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { if (dataProvider == null) throw new Exception("A data provider is required"); - var baseBounds = dataProvider.GetFinancialBounds(chart, this, secondaryAxis, primaryAxis); + var baseSeriesBounds = dataProvider.GetFinancialBounds(chart, this, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -317,31 +320,34 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/HeatSeries.cs b/src/LiveChartsCore/HeatSeries.cs index 20b1fea6a..98fc09cf9 100644 --- a/src/LiveChartsCore/HeatSeries.cs +++ b/src/LiveChartsCore/HeatSeries.cs @@ -23,6 +23,7 @@ using LiveChartsCore.Drawing; using LiveChartsCore.Drawing.Common; using LiveChartsCore.Kernel; +using LiveChartsCore.Kernel.Data; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Measure; @@ -229,10 +230,13 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; + _weightBounds = baseBounds.TertiaryBounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); @@ -253,31 +257,34 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + 0.5 * primaryAxis.UnitWidth + tp, - Min = baseBounds.PrimaryBounds.Min - 0.5 * primaryAxis.UnitWidth - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + 0.5 * primaryAxis.UnitWidth + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - 0.5 * primaryAxis.UnitWidth - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + 0.5 * primaryAxis.UnitWidth + tp, + Min = baseBounds.PrimaryBounds.Min - 0.5 * primaryAxis.UnitWidth - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + 0.5 * primaryAxis.UnitWidth + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - 0.5 * primaryAxis.UnitWidth - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/Kernel/Data/DataProvider.cs b/src/LiveChartsCore/Kernel/Data/DataProvider.cs index 8e1ad7e03..90e598b91 100644 --- a/src/LiveChartsCore/Kernel/Data/DataProvider.cs +++ b/src/LiveChartsCore/Kernel/Data/DataProvider.cs @@ -38,6 +38,7 @@ public class DataProvider private readonly Dictionary> _byChartbyValueVisualMap = new(); private readonly Dictionary> _byChartByReferenceVisualMap = new(); private readonly bool _isValueType = false; + private DimensionalBounds _previousKnownBounds; /// /// Initializes a new instance of the class. @@ -46,6 +47,23 @@ public DataProvider() { var t = typeof(TModel); _isValueType = t.IsValueType; + + var bounds = new DimensionalBounds(); + + bounds.VisiblePrimaryBounds.AppendValue(0); + bounds.VisiblePrimaryBounds.AppendValue(10); + bounds.PrimaryBounds.AppendValue(0); + bounds.PrimaryBounds.AppendValue(10); + + bounds.VisibleSecondaryBounds.AppendValue(0); + bounds.VisibleSecondaryBounds.AppendValue(10); + bounds.SecondaryBounds.AppendValue(0); + bounds.SecondaryBounds.AppendValue(10); + + bounds.VisibleTertiaryBounds.AppendValue(1); + bounds.TertiaryBounds.AppendValue(1); + + _previousKnownBounds = bounds; } /// @@ -142,7 +160,7 @@ public void DisposePoint(ChartPoint point) /// The x. /// The y. /// - public virtual DimensionalBounds GetCartesianBounds( + public virtual SeriesBounds GetCartesianBounds( CartesianChart chart, IChartSeries series, IAxis x, @@ -158,7 +176,9 @@ public virtual DimensionalBounds GetCartesianBounds( var hasData = false; var bounds = new DimensionalBounds(); + ChartPoint? previous = null; + foreach (var point in series.Fetch(chart)) { var primary = point.PrimaryValue; @@ -190,39 +210,9 @@ public virtual DimensionalBounds GetCartesianBounds( hasData = true; } - if (!hasData) - if (x.PreviousDataBounds == null || y.PreviousDataBounds == null) - { - bounds.VisiblePrimaryBounds.AppendValue(0); - bounds.VisiblePrimaryBounds.AppendValue(10); - bounds.PrimaryBounds.AppendValue(0); - bounds.PrimaryBounds.AppendValue(10); - - bounds.VisibleSecondaryBounds.AppendValue(0); - bounds.VisibleSecondaryBounds.AppendValue(10); - bounds.SecondaryBounds.AppendValue(0); - bounds.SecondaryBounds.AppendValue(10); - - bounds.VisibleTertiaryBounds.AppendValue(1); - bounds.TertiaryBounds.AppendValue(1); - } - else - { - bounds.VisiblePrimaryBounds.AppendValue(x.PreviousDataBounds.Max); - bounds.VisiblePrimaryBounds.AppendValue(x.PreviousDataBounds.Min); - bounds.PrimaryBounds.AppendValue(x.PreviousDataBounds.Max); - bounds.PrimaryBounds.AppendValue(x.PreviousDataBounds.Min); - - bounds.VisibleSecondaryBounds.AppendValue(y.PreviousDataBounds.Max); - bounds.VisibleSecondaryBounds.AppendValue(y.PreviousDataBounds.Min); - bounds.SecondaryBounds.AppendValue(y.PreviousDataBounds.Max); - bounds.SecondaryBounds.AppendValue(y.PreviousDataBounds.Min); - - bounds.VisibleTertiaryBounds.AppendValue(1); - bounds.TertiaryBounds.AppendValue(1); - } - - return bounds; + return !hasData + ? new SeriesBounds(_previousKnownBounds, true) + : new SeriesBounds(_previousKnownBounds = bounds, false); } /// @@ -233,7 +223,7 @@ public virtual DimensionalBounds GetCartesianBounds( /// The x. /// The y. /// - public virtual DimensionalBounds GetFinancialBounds( + public virtual SeriesBounds GetFinancialBounds( CartesianChart chart, IChartSeries series, IAxis x, @@ -280,39 +270,9 @@ public virtual DimensionalBounds GetFinancialBounds( hasData = true; } - if (!hasData) - if (x.PreviousDataBounds == null || y.PreviousDataBounds == null) - { - bounds.VisiblePrimaryBounds.AppendValue(0); - bounds.VisiblePrimaryBounds.AppendValue(10); - bounds.PrimaryBounds.AppendValue(0); - bounds.PrimaryBounds.AppendValue(10); - - bounds.VisibleSecondaryBounds.AppendValue(0); - bounds.VisibleSecondaryBounds.AppendValue(10); - bounds.SecondaryBounds.AppendValue(0); - bounds.SecondaryBounds.AppendValue(10); - - bounds.VisibleTertiaryBounds.AppendValue(1); - bounds.TertiaryBounds.AppendValue(1); - } - else - { - bounds.VisiblePrimaryBounds.AppendValue(x.PreviousDataBounds.Max); - bounds.VisiblePrimaryBounds.AppendValue(x.PreviousDataBounds.Min); - bounds.PrimaryBounds.AppendValue(x.PreviousDataBounds.Max); - bounds.PrimaryBounds.AppendValue(x.PreviousDataBounds.Min); - - bounds.VisibleSecondaryBounds.AppendValue(y.PreviousDataBounds.Max); - bounds.VisibleSecondaryBounds.AppendValue(y.PreviousDataBounds.Min); - bounds.SecondaryBounds.AppendValue(y.PreviousDataBounds.Max); - bounds.SecondaryBounds.AppendValue(y.PreviousDataBounds.Min); - - bounds.VisibleTertiaryBounds.AppendValue(1); - bounds.TertiaryBounds.AppendValue(1); - } - - return bounds; + return !hasData + ? new SeriesBounds(_previousKnownBounds, true) + : new SeriesBounds(_previousKnownBounds = bounds, false); } /// @@ -322,7 +282,7 @@ public virtual DimensionalBounds GetFinancialBounds( /// The series. /// /// Unexpected null stacker - public virtual DimensionalBounds GetPieBounds( + public virtual SeriesBounds GetPieBounds( PieChart chart, IPieSeries series) { var stack = chart.SeriesContext.GetStackPosition(series, series.GetStackGroup()); @@ -347,7 +307,7 @@ public virtual DimensionalBounds GetPieBounds( bounds.TertiaryBounds.AppendValue(0); } - return bounds; + return new SeriesBounds(bounds, false); } /// diff --git a/src/LiveChartsCore/Kernel/Data/SeriesBounds.cs b/src/LiveChartsCore/Kernel/Data/SeriesBounds.cs new file mode 100644 index 000000000..d233dc26d --- /dev/null +++ b/src/LiveChartsCore/Kernel/Data/SeriesBounds.cs @@ -0,0 +1,57 @@ +// The MIT License(MIT) +// +// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace LiveChartsCore.Kernel.Data +{ + /// + /// Defines the series bounds class, it contains the data bounds in a series. + /// + public class SeriesBounds + { + /// + /// Initializes a new instance of the class. + /// + /// The bounds. + /// if set to true [is previous]. + public SeriesBounds(DimensionalBounds bounds, bool isPrevious) + { + Bounds = bounds; + IsPrevious = IsPrevious; + } + + /// + /// Gets the bounds. + /// + /// + /// The bounds. + /// + public DimensionalBounds Bounds { get; } + + /// + /// Gets a value indicating whether this instance is previous. + /// + /// + /// true if this instance is previous; otherwise, false. + /// + public bool IsPrevious { get; } + } +} diff --git a/src/LiveChartsCore/Kernel/Sketches/ICartesianSeries.cs b/src/LiveChartsCore/Kernel/Sketches/ICartesianSeries.cs index 713697879..f7b5e5c83 100644 --- a/src/LiveChartsCore/Kernel/Sketches/ICartesianSeries.cs +++ b/src/LiveChartsCore/Kernel/Sketches/ICartesianSeries.cs @@ -21,6 +21,7 @@ // SOFTWARE. using LiveChartsCore.Drawing; +using LiveChartsCore.Kernel.Data; using LiveChartsCore.Measure; namespace LiveChartsCore.Kernel.Sketches @@ -66,6 +67,6 @@ public interface ICartesianSeries : IChartSeriesThe x. /// The y. /// the series bounds - DimensionalBounds GetBounds(CartesianChart chart, IAxis x, IAxis y); + SeriesBounds GetBounds(CartesianChart chart, IAxis x, IAxis y); } } diff --git a/src/LiveChartsCore/LineSeries.cs b/src/LiveChartsCore/LineSeries.cs index aba2631cd..fe2fe0926 100644 --- a/src/LiveChartsCore/LineSeries.cs +++ b/src/LiveChartsCore/LineSeries.cs @@ -29,6 +29,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -438,10 +439,13 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -461,31 +465,34 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + ts, - Min = baseBounds.SecondaryBounds.Min - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + ts, + Min = baseBounds.SecondaryBounds.Min - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/PieSeries.cs b/src/LiveChartsCore/PieSeries.cs index 49666f3ac..235a21587 100644 --- a/src/LiveChartsCore/PieSeries.cs +++ b/src/LiveChartsCore/PieSeries.cs @@ -397,7 +397,7 @@ public DimensionalBounds GetBounds(PieChart chart) { return dataProvider == null ? throw new Exception("Data provider not found") - : dataProvider.GetPieBounds(chart, this); + : dataProvider.GetPieBounds(chart, this).Bounds; } /// diff --git a/src/LiveChartsCore/RowSeries.cs b/src/LiveChartsCore/RowSeries.cs index 50e013582..957fc80a9 100644 --- a/src/LiveChartsCore/RowSeries.cs +++ b/src/LiveChartsCore/RowSeries.cs @@ -28,6 +28,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Kernel.Drawing; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -236,10 +237,12 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -259,31 +262,34 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - PrimaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - SecondaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + PrimaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + SecondaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/ScatterSeries.cs b/src/LiveChartsCore/ScatterSeries.cs index 84334e997..ac1c7fea3 100644 --- a/src/LiveChartsCore/ScatterSeries.cs +++ b/src/LiveChartsCore/ScatterSeries.cs @@ -28,6 +28,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Kernel.Drawing; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -216,10 +217,14 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; + _weightBounds = baseBounds.TertiaryBounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); @@ -228,31 +233,34 @@ public override DimensionalBounds GetBounds( var ts = tickSecondary.Value * DataPadding.X; var tp = tickPrimary.Value * DataPadding.Y; - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + ts, - Min = baseBounds.SecondaryBounds.Min - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + ts, + Min = baseBounds.SecondaryBounds.Min - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/StackedColumnSeries.cs b/src/LiveChartsCore/StackedColumnSeries.cs index 49a43b6ee..e4d679558 100644 --- a/src/LiveChartsCore/StackedColumnSeries.cs +++ b/src/LiveChartsCore/StackedColumnSeries.cs @@ -28,6 +28,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Kernel.Drawing; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -231,10 +232,13 @@ public override void Measure(Chart chart) /// The secondary axis. /// The primary axis. /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -242,31 +246,34 @@ public override DimensionalBounds GetBounds( var ts = tickSecondary.Value * DataPadding.X; var tp = tickPrimary.Value * DataPadding.Y; - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, + false); } /// diff --git a/src/LiveChartsCore/StackedRowSeries.cs b/src/LiveChartsCore/StackedRowSeries.cs index c8d73bb91..441621238 100644 --- a/src/LiveChartsCore/StackedRowSeries.cs +++ b/src/LiveChartsCore/StackedRowSeries.cs @@ -28,6 +28,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Sketches; using LiveChartsCore.Kernel.Drawing; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -229,10 +230,12 @@ public override void Measure(Chart chart) /// The secondary axis. /// The primary axis. /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -252,31 +255,33 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - PrimaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - SecondaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + PrimaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.SecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + SecondaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + 0.5 * secondaryAxis.UnitWidth + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - 0.5 * secondaryAxis.UnitWidth - ts + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min < 0 ? baseBounds.PrimaryBounds.Min - tp : 0 + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, false); } /// diff --git a/src/LiveChartsCore/StepLineSeries.cs b/src/LiveChartsCore/StepLineSeries.cs index 5c3721352..789640d21 100644 --- a/src/LiveChartsCore/StepLineSeries.cs +++ b/src/LiveChartsCore/StepLineSeries.cs @@ -29,6 +29,7 @@ using System.Drawing; using LiveChartsCore.Kernel.Drawing; using LiveChartsCore.Kernel.Sketches; +using LiveChartsCore.Kernel.Data; namespace LiveChartsCore { @@ -427,10 +428,12 @@ public override void Measure(Chart chart) } /// - public override DimensionalBounds GetBounds( + public override SeriesBounds GetBounds( CartesianChart chart, IAxis secondaryAxis, IAxis primaryAxis) { - var baseBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + var baseSeriesBounds = base.GetBounds(chart, secondaryAxis, primaryAxis); + if (baseSeriesBounds.IsPrevious) return baseSeriesBounds; + var baseBounds = baseSeriesBounds.Bounds; var tickPrimary = primaryAxis.GetTick(chart.ControlSize, baseBounds.VisiblePrimaryBounds); var tickSecondary = secondaryAxis.GetTick(chart.ControlSize, baseBounds.VisibleSecondaryBounds); @@ -450,31 +453,33 @@ public override DimensionalBounds GetBounds( tp = 0.1 * mp * DataPadding.Y; } - return new DimensionalBounds - { - SecondaryBounds = new Bounds - { - Max = baseBounds.SecondaryBounds.Max + ts, - Min = baseBounds.SecondaryBounds.Min - ts - }, - PrimaryBounds = new Bounds - { - Max = baseBounds.PrimaryBounds.Max + tp, - Min = baseBounds.PrimaryBounds.Min - tp - }, - VisibleSecondaryBounds = new Bounds - { - Max = baseBounds.VisibleSecondaryBounds.Max + ts, - Min = baseBounds.VisibleSecondaryBounds.Min - ts - }, - VisiblePrimaryBounds = new Bounds - { - Max = baseBounds.VisiblePrimaryBounds.Max + tp, - Min = baseBounds.VisiblePrimaryBounds.Min - tp - }, - MinDeltaPrimary = baseBounds.MinDeltaPrimary, - MinDeltaSecondary = baseBounds.MinDeltaSecondary - }; + return + new SeriesBounds( + new DimensionalBounds + { + SecondaryBounds = new Bounds + { + Max = baseBounds.SecondaryBounds.Max + ts, + Min = baseBounds.SecondaryBounds.Min - ts + }, + PrimaryBounds = new Bounds + { + Max = baseBounds.PrimaryBounds.Max + tp, + Min = baseBounds.PrimaryBounds.Min - tp + }, + VisibleSecondaryBounds = new Bounds + { + Max = baseBounds.VisibleSecondaryBounds.Max + ts, + Min = baseBounds.VisibleSecondaryBounds.Min - ts + }, + VisiblePrimaryBounds = new Bounds + { + Max = baseBounds.VisiblePrimaryBounds.Max + tp, + Min = baseBounds.VisiblePrimaryBounds.Min - tp + }, + MinDeltaPrimary = baseBounds.MinDeltaPrimary, + MinDeltaSecondary = baseBounds.MinDeltaSecondary + }, false); } ///