Skip to content

Commit

Permalink
Merge pull request #1752 from beto-rodriguez/axis-range
Browse files Browse the repository at this point in the history
Axis range
  • Loading branch information
beto-rodriguez authored Jan 3, 2025
2 parents 4a0275b + 5808322 commit c7383e9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 57 deletions.
8 changes: 0 additions & 8 deletions src/LiveChartsCore/CartesianSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ public virtual SeriesBounds GetBounds(
var ts = tickSecondary.Value * DataPadding.X;
var tp = tickPrimary.Value * DataPadding.Y;

// using different methods for both primary and secondary axis seems to be the best solution
// if this the following 2 lines needs to be changed again, please ensure that the following test passes:
// https://github.com/beto-rodriguez/LiveCharts2/issues/522
// https://github.com/beto-rodriguez/LiveCharts2/issues/642

if (rawBaseBounds.VisibleSecondaryBounds.Delta == 0) ts = secondaryAxis.UnitWidth * DataPadding.X;
if (rawBaseBounds.VisiblePrimaryBounds.Delta == 0) tp = rawBaseBounds.VisiblePrimaryBounds.Max * 0.25f;

var rgs = GetRequestedGeometrySize();
var rso = GetRequestedSecondaryOffset();
var rpo = GetRequestedPrimaryOffset();
Expand Down
8 changes: 0 additions & 8 deletions src/LiveChartsCore/CoreBoxSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,6 @@ public override SeriesBounds GetBounds(
var ts = tickSecondary.Value * DataPadding.X;
var tp = tickPrimary.Value * DataPadding.Y;

// using different methods for both primary and secondary axis seems to be the best solution
// if this the following 2 lines needs to be changed again, please ensure that the following test passes:
// https://github.com/beto-rodriguez/LiveCharts2/issues/522
// https://github.com/beto-rodriguez/LiveCharts2/issues/642

if (rawBaseBounds.VisibleSecondaryBounds.Delta == 0) ts = secondaryAxis.UnitWidth * DataPadding.X;
if (rawBaseBounds.VisiblePrimaryBounds.Delta == 0) tp = rawBaseBounds.VisiblePrimaryBounds.Max * 0.25f;

var rgs = GetRequestedGeometrySize();
var rso = GetRequestedSecondaryOffset();
var rpo = GetRequestedPrimaryOffset();
Expand Down
8 changes: 0 additions & 8 deletions src/LiveChartsCore/CoreFinancialSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,6 @@ public override SeriesBounds GetBounds(
var ts = tickSecondary.Value * DataPadding.X;
var tp = tickPrimary.Value * DataPadding.Y;

// using different methods for both primary and secondary axis seems to be the best solution
// if this the following 2 lines needs to be changed again, please ensure that the following test passes:
// https://github.com/beto-rodriguez/LiveCharts2/issues/522
// https://github.com/beto-rodriguez/LiveCharts2/issues/642

if (rawBaseBounds.VisibleSecondaryBounds.Delta == 0) ts = secondaryAxis.UnitWidth * DataPadding.X;
if (rawBaseBounds.VisiblePrimaryBounds.Delta == 0) tp = rawBaseBounds.VisiblePrimaryBounds.Max * 0.25f;

var rgs = GetRequestedGeometrySize();
var rso = GetRequestedSecondaryOffset();
var rpo = GetRequestedPrimaryOffset();
Expand Down
8 changes: 0 additions & 8 deletions src/LiveChartsCore/CoreRowSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,6 @@ public override SeriesBounds GetBounds(Chart chart, ICartesianAxis secondaryAxis
var ts = tickSecondary.Value * DataPadding.X;
var tp = tickPrimary.Value * DataPadding.Y;

// using different methods for both primary and secondary axis seems to be the best solution
// if this the following 2 lines needs to be changed again, please ensure that the following test passes:
// https://github.com/beto-rodriguez/LiveCharts2/issues/522
// https://github.com/beto-rodriguez/LiveCharts2/issues/642

if (rawBaseBounds.VisibleSecondaryBounds.Delta == 0) tp = secondaryAxis.UnitWidth * DataPadding.X;
if (rawBaseBounds.VisiblePrimaryBounds.Delta == 0) ts = rawBaseBounds.VisiblePrimaryBounds.Max * 0.25f;

var rgs = GetRequestedGeometrySize();
var rso = GetRequestedSecondaryOffset();
var rpo = GetRequestedPrimaryOffset();
Expand Down
40 changes: 23 additions & 17 deletions src/LiveChartsCore/Defaults/FinancialPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace LiveChartsCore.Defaults;
/// </summary>
public class FinancialPoint : IChartEntity, INotifyPropertyChanged
{
private double? _high;
private double? _open;
private double? _close;
private double? _low;
private double _high;
private double _open;
private double _close;
private double _low;
private DateTime _date;

/// <summary>
Expand All @@ -52,13 +52,15 @@ public FinancialPoint()
/// <param name="open">The open.</param>
/// <param name="close">The close.</param>
/// <param name="low">The low.</param>
public FinancialPoint(DateTime date, double? high, double? open, double? close, double? low)
public FinancialPoint(DateTime date, double high, double open, double close, double low)
{
Date = date;
High = high;
Open = open;
Close = close;
Low = low;
_date = date;
_high = high;
_open = open;
_close = close;
_low = low;

OnCoordinateChanged();
}

/// <summary>
Expand All @@ -75,31 +77,31 @@ public FinancialPoint(DateTime date, double? high, double? open, double? close,
/// <value>
/// The high.
/// </value>
public double? High { get => _high; set { _high = value; OnPropertyChanged(); } }
public double High { get => _high; set { _high = value; OnPropertyChanged(); } }

/// <summary>
/// Gets or sets the open.
/// </summary>
/// <value>
/// The open.
/// </value>
public double? Open { get => _open; set { _open = value; OnPropertyChanged(); } }
public double Open { get => _open; set { _open = value; OnPropertyChanged(); } }

/// <summary>
/// Gets or sets the close.
/// </summary>
/// <value>
/// The close.
/// </value>
public double? Close { get => _close; set { _close = value; OnPropertyChanged(); } }
public double Close { get => _close; set { _close = value; OnPropertyChanged(); } }

/// <summary>
/// Gets or sets the low.
/// </summary>
/// <value>
/// The low.
/// </value>
public double? Low { get => _low; set { _low = value; OnPropertyChanged(); } }
public double Low { get => _low; set { _low = value; OnPropertyChanged(); } }

/// <inheritdoc cref="IChartEntity.MetaData"/>
[System.Text.Json.Serialization.JsonIgnore]
Expand All @@ -121,9 +123,13 @@ public FinancialPoint(DateTime date, double? high, double? open, double? close,
/// <param name="propertyName">Name of the property.</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
Coordinate = _open is null || _high is null || _low is null || _close is null
? Coordinate.Empty
: new(_date.Ticks, _high.Value, _open.Value, _close.Value, _low.Value);
OnCoordinateChanged();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

/// <summary>
/// Called when the coordinate changed.
/// </summary>
protected virtual void OnCoordinateChanged() =>
Coordinate = new(_date.Ticks, _high, _open, _close, _low);
}
14 changes: 7 additions & 7 deletions src/LiveChartsCore/Defaults/FinancialPointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public FinancialPointI()
public FinancialPointI(double high, double open, double close, double low)
: this()
{
High = high;
Open = open;
Close = close;
Low = low;
_high = high;
_open = open;
_close = close;
_low = low;

if (MetaData is not null) OnCoordinateChanged(MetaData.EntityIndex);
}

/// <summary>
Expand Down Expand Up @@ -122,8 +124,6 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
/// <summary>
/// Called when the coordinate changed.
/// </summary>
protected virtual void OnCoordinateChanged(int index)
{
protected virtual void OnCoordinateChanged(int index) =>
Coordinate = new(index, _high, _open, _close, _low);
}
}
4 changes: 3 additions & 1 deletion src/LiveChartsCore/Kernel/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public static AxisTick GetTick(this ICartesianAxis axis, LvcSize controlSize, Bo
min /= unit;

var range = max - min;
if (range == 0) range = min;

// when the range is 0, we force the range to be 15% of the max value... just a default value.
if (range == 0) range = 0.15 * max / unit;

var separations = axis.Orientation == AxisOrientation.Y
? Math.Round(controlSize.Height / h, 0)
Expand Down

0 comments on commit c7383e9

Please sign in to comment.