Skip to content

Commit

Permalink
fixes #52
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Jun 24, 2021
1 parent dc553ca commit a4eec71
Show file tree
Hide file tree
Showing 15 changed files with 393 additions and 317 deletions.
2 changes: 1 addition & 1 deletion src/LiveChartsCore/CartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/LiveChartsCore/CartesianSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using System.Collections.Generic;
using System.Drawing;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.Kernel.Data;

namespace LiveChartsCore
{
Expand Down Expand Up @@ -66,7 +67,7 @@ public CartesianSeries(SeriesProperties properties) : base(properties) { }
public DataLabelsPosition DataLabelsPosition { get => _labelsPosition; set { _labelsPosition = value; OnPropertyChanged(); } }

/// <inheritdoc cref="ICartesianSeries{TDrawingContext}.GetBounds(CartesianChart{TDrawingContext}, IAxis{TDrawingContext}, IAxis{TDrawingContext})"/>
public virtual DimensionalBounds GetBounds(
public virtual SeriesBounds GetBounds(
CartesianChart<TDrawingContext> chart, IAxis<TDrawingContext> x, IAxis<TDrawingContext> y)
{
return dataProvider == null
Expand Down
60 changes: 33 additions & 27 deletions src/LiveChartsCore/ColumnSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -256,10 +257,12 @@ public override void Measure(Chart<TDrawingContext> chart)
}

/// <inheritdoc cref="ICartesianSeries{TDrawingContext}.GetBounds(CartesianChart{TDrawingContext}, IAxis{TDrawingContext}, IAxis{TDrawingContext})"/>
public override DimensionalBounds GetBounds(
public override SeriesBounds GetBounds(
CartesianChart<TDrawingContext> chart, IAxis<TDrawingContext> secondaryAxis, IAxis<TDrawingContext> 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);
Expand All @@ -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);
}

/// <inheritdoc cref="Series{TModel, TVisual, TLabel, TDrawingContext}.SetDefaultPointTransitions(ChartPoint)"/>
Expand Down
60 changes: 33 additions & 27 deletions src/LiveChartsCore/FinancialSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -292,12 +293,14 @@ public override void Measure(Chart<TDrawingContext> chart)
}

/// <inheritdoc cref="ICartesianSeries{TDrawingContext}.GetBounds(CartesianChart{TDrawingContext}, IAxis{TDrawingContext}, IAxis{TDrawingContext})"/>
public override DimensionalBounds GetBounds(
public override SeriesBounds GetBounds(
CartesianChart<TDrawingContext> chart, IAxis<TDrawingContext> secondaryAxis, IAxis<TDrawingContext> 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);
Expand All @@ -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);
}

/// <inheritdoc cref="Series{TModel, TVisual, TLabel, TDrawingContext}.SetDefaultPointTransitions(ChartPoint)"/>
Expand Down
61 changes: 34 additions & 27 deletions src/LiveChartsCore/HeatSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -229,10 +230,13 @@ public override void Measure(Chart<TDrawingContext> chart)
}

/// <inheritdoc cref="ICartesianSeries{TDrawingContext}.GetBounds(CartesianChart{TDrawingContext}, IAxis{TDrawingContext}, IAxis{TDrawingContext})"/>
public override DimensionalBounds GetBounds(
public override SeriesBounds GetBounds(
CartesianChart<TDrawingContext> chart, IAxis<TDrawingContext> secondaryAxis, IAxis<TDrawingContext> 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);
Expand All @@ -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);
}

/// <inheritdoc cref="Series{TModel, TVisual, TLabel, TDrawingContext}.SetDefaultPointTransitions(ChartPoint)"/>
Expand Down
Loading

0 comments on commit a4eec71

Please sign in to comment.