Refactor SetStateXAxisLabels and SetStateYAxisLabels method
MODIFY
WalletWasabi.Fluent/Controls/LineChart.cs
WalletWasabi.Fluent/Controls/LineChart.cs
@@ -217,36 +217,41 @@ namespace WalletWasabi.Fluent.Controls
{
var xAxisLabels = XAxisLabels;
- if (xAxisLabels is null)
+ if (xAxisLabels is not null)
{
- var xAxisValues = XAxisValues;
-
- if (xAxisValues is null || xAxisValues.Count <= 1)
+ if (xAxisLabels.Count <= 1)
{
state.XAxisLabelStep = double.NaN;
}
else
{
- state.XAxisLabelStep = state.AreaWidth / (xAxisValues.Count - 1);
+ state.XAxisLabelStep = state.AreaWidth / (xAxisLabels.Count - 1);
}
- if (XAxisStroke is not null && XAxisValues is not null)
+ state.XAxisLabels = xAxisLabels.ToList();
+ }
+ else
{
- state.XAxisLabels = XAxisValues.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList();
+ AutoGenerateXAxisLabels(state);
}
}
- else
+
+ private void AutoGenerateXAxisLabels(LineChartState state)
{
- if (xAxisLabels.Count <= 1)
+ var xAxisValues = XAxisValues;
+
+ if (xAxisValues is null || xAxisValues.Count <= 1)
{
state.XAxisLabelStep = double.NaN;
}
else
{
- state.XAxisLabelStep = state.AreaWidth / (xAxisLabels.Count - 1);
+ state.XAxisLabelStep = state.AreaWidth / (xAxisValues.Count - 1);
}
- state.XAxisLabels = xAxisLabels.ToList();
+ if (XAxisStroke is not null && XAxisValues is not null)
+ {
+ state.XAxisLabels = XAxisValues.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList();
}
}
@@ -254,36 +259,41 @@ namespace WalletWasabi.Fluent.Controls
{
var yAxisLabels = YAxisLabels;
- if (yAxisLabels is null)
+ if (yAxisLabels is not null)
{
- var yAxisValues = YAxisValues;
-
- if (yAxisValues is null || yAxisValues.Count <= 1)
+ if (yAxisLabels.Count <= 1)
{
state.YAxisLabelStep = double.NaN;
}
else
{
- state.YAxisLabelStep = state.AreaHeight / (yAxisValues.Count - 1);
+ state.YAxisLabelStep = state.AreaHeight / (yAxisLabels.Count - 1);
}
- if (YAxisStroke is not null && YAxisValues is not null)
+ state.YAxisLabels = yAxisLabels.ToList();
+ }
+ else
{
- state.YAxisLabels = YAxisValues.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList();
+ AutoGenerateYAxisLabels(state);
}
}
- else
+
+ private void AutoGenerateYAxisLabels(LineChartState state)
{
- if (yAxisLabels.Count <= 1)
+ var yAxisValues = YAxisValues;
+
+ if (yAxisValues is null || yAxisValues.Count <= 1)
{
state.YAxisLabelStep = double.NaN;
}
else
{
- state.YAxisLabelStep = state.AreaHeight / (yAxisLabels.Count - 1);
+ state.YAxisLabelStep = state.AreaHeight / (yAxisValues.Count - 1);
}
- state.YAxisLabels = yAxisLabels.ToList();
+ if (YAxisStroke is not null && YAxisValues is not null)
+ {
+ state.YAxisLabels = YAxisValues.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToList();
}
}

Refactor SetStateXAxisLabels and SetStateYAxisLabels method