Skip to content

Commit

Permalink
fixes #1076
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Sep 15, 2023
1 parent 298983d commit 659ba0a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/LiveChartsCore/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,8 @@ NamePadding is not null || SeparatorsPaint is not null || LabelsPaint is not nul
if (_forceStepToMin) s = _minStep;

var start = Math.Truncate(min / s) * s;
var separatorsSource = CustomSeparators ?? Axis<TDrawingContext, TTextGeometry, TLineGeometry>.EnumerateSeparators(start, s, max);

foreach (var i in separatorsSource)
foreach (var i in EnumerateSeparators(start, max, s))
{
var separatorKey = Labelers.SixRepresentativeDigits(i - 1d + 1d);
var labelContent = i < min || i > max ? string.Empty : TryGetLabelOrLogError(labeler, i - 1d + 1d);
Expand Down Expand Up @@ -781,9 +780,16 @@ public void InvalidateCrosshair(Chart<TDrawingContext> chart, LvcPoint pointerPo
chart.Canvas.Invalidate();
}

private static IEnumerable<double> EnumerateSeparators(double start, double s, double max)
private IEnumerable<double> EnumerateSeparators(double start, double end, double step)
{
for (var i = start - s; i <= max + s; i += s) yield return i;
if (CustomSeparators is not null)
{
foreach (var s in CustomSeparators) yield return s;
yield break;
}

var relativeEnd = end - start;
for (var i = 0d; i <= relativeEnd; i += step) yield return start + i;
}

private static ChartPoint? FindClosestPoint(
Expand Down Expand Up @@ -852,7 +858,7 @@ public virtual LvcSize GetPossibleSize(Chart<TDrawingContext> chart)
var h = 0f;
var r = (float)LabelsRotation;

for (var i = start; i <= max; i += s)
foreach (var i in EnumerateSeparators(start, max, s))
{
var textGeometry = new TTextGeometry
{
Expand Down Expand Up @@ -1004,7 +1010,7 @@ private LvcSize GetPossibleMaxLabelSize(Chart<TDrawingContext> chart)

if (max - min == 0) return maxLabelSize;

for (var i = min; i <= max; i += s)
foreach (var i in EnumerateSeparators(min, max, s))
{
var textGeometry = new TTextGeometry
{
Expand Down

0 comments on commit 659ba0a

Please sign in to comment.