Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions maui/src/Charts/Area/Partial/CartesianChartArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ internal void UpdateSBS()
{
double totalWidth = GetTotalWidth() / SideBySideSeriesPosition.Count;
double startPosition = 0, end = 0;
var seriesGroupValues = SideBySideSeriesPosition.Values.ToList();

var seriesPositionValues = SideBySideSeriesPosition.Values.ToList();
for (int i = 0; i < SideBySideSeriesPosition.Count; i++)
{
var seriesGroup = seriesPositionValues[i];
var seriesGroup = seriesGroupValues[i];
double sbsMaxWidth = GetSBSMaxWidth(seriesGroup);

foreach (ChartSeries chartSeries in seriesGroup)
Expand Down Expand Up @@ -354,15 +355,22 @@ internal void InvalidateMinWidth()

internal void ResetSBSSegments()
{
var sideBySideSeries = VisibleSeries?.Where(series => series.IsSideBySide).ToList();

if (sideBySideSeries != null && sideBySideSeries.Count > 0)
if (VisibleSeries != null)
{
SideBySideSeriesPosition = null;
bool hasSideBySide = false;

foreach (var chartSeries in sideBySideSeries)
foreach (var series in VisibleSeries)
{
chartSeries.SegmentsCreated = false;
if (series.IsSideBySide)
{
if (!hasSideBySide)
{
hasSideBySide = true;
SideBySideSeriesPosition = null;
}

series.SegmentsCreated = false;
}
}
}
}
Expand All @@ -373,11 +381,11 @@ double GetTotalWidth()

if (SideBySideSeriesPosition != null)
{
var positionValues = SideBySideSeriesPosition.Values.ToList();
for (int i = 0; i < SideBySideSeriesPosition.Count; i++)
var seriesGroupValues = SideBySideSeriesPosition.Values.ToList();
for (int i = 0; i < seriesGroupValues.Count; i++)
{
double maxWidth = 0;
foreach (ChartSeries sideBySideSeries in positionValues[i])
foreach (ChartSeries sideBySideSeries in seriesGroupValues[i])
{
CartesianSeries cartesianSeries = (CartesianSeries)sideBySideSeries;
double width = cartesianSeries.GetActualWidth();
Expand Down
54 changes: 48 additions & 6 deletions maui/src/Charts/Segment/AreaSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public partial class AreaSegment : CartesianSegment, IMarkerDependentSegment
internal List<float>? PreviousStrokePoints { get; set; } = null;

PathF? _path;
float[]? _cachedStrokeDashPattern;
DoubleCollection? _previousStrokeDashArray;

#endregion

Expand All @@ -60,7 +62,13 @@ protected internal override void Draw(ICanvas canvas)

if (StrokeDashArray != null)
{
canvas.StrokeDashPattern = StrokeDashArray.ToFloatArray();
if (_cachedStrokeDashPattern == null || _previousStrokeDashArray != StrokeDashArray)
{
_cachedStrokeDashPattern = StrokeDashArray.ToFloatArray();
_previousStrokeDashArray = StrokeDashArray;
}

canvas.StrokeDashPattern = _cachedStrokeDashPattern;
}

DrawPath(canvas, FillPoints, StrokePoints);
Expand Down Expand Up @@ -182,13 +190,47 @@ internal override void SetData(IList xValues, IList yValues)
xValues.CopyTo(XValues, 0);
yValues.CopyTo(YValues, 0);

var yMin = YValues.Min();
yMin = double.IsNaN(yMin) ? YValues.Length > 0 ? YValues.Where(e => !double.IsNaN(e)).DefaultIfEmpty().Min() : 0 : yMin;
double yMin = double.MaxValue;
double yMax = double.MinValue;
double xMin = double.MaxValue;
double xMax = double.MinValue;

for (int i = 0; i < count; i++)
{
double yVal = YValues[i];
if (!double.IsNaN(yVal))
{
if (yVal < yMin) yMin = yVal;
if (yVal > yMax) yMax = yVal;
}

double xVal = XValues[i];
if (!double.IsNaN(xVal))
{
if (xVal < xMin) xMin = xVal;
if (xVal > xMax) xMax = xVal;
}
}

if (yMin == double.MaxValue)
{
Empty = count > 0;
yMin = 0;
yMax = 0;
}
else
{
Empty = false;
}

Empty = double.IsNaN(yMin);
if (xMin == double.MaxValue)
{
xMin = 0;
xMax = 0;
}

series.XRange += new DoubleRange(XValues.Min(), XValues.Max());
series.YRange += new DoubleRange(yMin, YValues.Max());
series.XRange += new DoubleRange(xMin, xMax);
series.YRange += new DoubleRange(yMin, yMax);
}
}

Expand Down
38 changes: 30 additions & 8 deletions maui/src/Charts/Series/CartesianSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,18 +1027,39 @@ internal override void UpdateRange()
return null;
}

double xIndexValues = 0d;
var xValues = ActualXValues as List<double>;

if (IsIndexed || xValues == null)
{
if (ActualXAxis is CategoryAxis categoryAxis && !categoryAxis.ArrangeByIndex || ActualXAxis == null)
{
xValues = GroupedXValuesIndexes.Count > 0 ? GroupedXValuesIndexes : (from val in (ActualXValues as List<string>) select (xIndexValues++)).ToList();
if (GroupedXValuesIndexes.Count > 0)
{
xValues = GroupedXValuesIndexes;
}
else
{
var stringValues = ActualXValues as List<string>;
if (stringValues != null)
{
xValues = new List<double>(stringValues.Count);
for (int i = 0; i < stringValues.Count; i++)
{
xValues.Add(i);
}
}
}
}
else
{
xValues = xValues != null ? (from val in xValues select (xIndexValues++)).ToList() : (from val in (ActualXValues as List<string>) select (xIndexValues++)).ToList();
int count = xValues != null ? xValues.Count : ((ActualXValues as List<string>)?.Count ?? 0);
var indexedValues = new List<double>(count);
for (int i = 0; i < count; i++)
{
indexedValues.Add(i);
}

xValues = indexedValues;
}
}

Expand Down Expand Up @@ -1133,13 +1154,14 @@ internal void UpdateSbsSeries()
{
if (ChartArea != null)
{
var sideBySideSeries = ChartArea.VisibleSeries?.Where(series => series.IsSideBySide).ToList();

if (sideBySideSeries != null && sideBySideSeries.Count > 0)
if (ChartArea.VisibleSeries != null)
{
foreach (var chartSeries in sideBySideSeries)
foreach (var series in ChartArea.VisibleSeries)
{
chartSeries.SegmentsCreated = false;
if (series.IsSideBySide)
{
series.SegmentsCreated = false;
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions maui/src/Charts/Series/ChartSeriesPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,12 @@ internal virtual void GeneratePropertyPoints(string[] yPaths, IList<double>[] yL
{
if (XValues is List<string> xValue)
{
int yPathCount = yPropertyAccessor.Count;
do
{
var xVal = xProperty.GetValue(enumerator.Current);
xValue.Add(xVal.Tostring());
for (int i = 0; i < yPropertyAccessor.Count; i++)
for (int i = 0; i < yPathCount; i++)
{
var yVal = yPropertyAccessor[i].GetValue(enumerator.Current);
yLists[i].Add(Convert.ToDouble(yVal ?? double.NaN));
Expand All @@ -844,6 +845,7 @@ internal virtual void GeneratePropertyPoints(string[] yPaths, IList<double>[] yL
{
if (XValues is List<double> xValue)
{
int yPathCount = yPropertyAccessor.Count;
do
{
var xVal = xProperty.GetValue(enumerator.Current);
Expand All @@ -856,7 +858,7 @@ internal virtual void GeneratePropertyPoints(string[] yPaths, IList<double>[] yL
}

xValue.Add(XData);
for (int i = 0; i < yPropertyAccessor.Count; i++)
for (int i = 0; i < yPathCount; i++)
{
var yVal = yPropertyAccessor[i].GetValue(enumerator.Current);
yLists[i].Add(Convert.ToDouble(yVal ?? double.NaN));
Expand All @@ -872,6 +874,7 @@ internal virtual void GeneratePropertyPoints(string[] yPaths, IList<double>[] yL
{
if (XValues is List<double> xValue)
{
int yPathCount = yPropertyAccessor.Count;
do
{
var xVal = xProperty.GetValue(enumerator.Current);
Expand All @@ -884,7 +887,7 @@ internal virtual void GeneratePropertyPoints(string[] yPaths, IList<double>[] yL
}

xValue.Add(XData);
for (int i = 0; i < yPropertyAccessor.Count; i++)
for (int i = 0; i < yPathCount; i++)
{
var yVal = yPropertyAccessor[i].GetValue(enumerator.Current);
yLists[i].Add(Convert.ToDouble(yVal ?? double.NaN));
Expand Down
4 changes: 2 additions & 2 deletions maui/src/Charts/SfCartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,9 +1551,9 @@ internal void OnTapAction(IChart chart, Point tapPoint, int tapCount)
var visibleSeries = _chartArea.VisibleSeries;
if (visibleSeries != null)
{
foreach (var series in visibleSeries.Reverse())
for (int i = visibleSeries.Count - 1; i >= 0; i--)
{
if (series.SelectionHitTest((float)tapPoint.X, (float)tapPoint.Y))
if (visibleSeries[i].SelectionHitTest((float)tapPoint.X, (float)tapPoint.Y))
{
break;
}
Expand Down