Refactor X axis label state setter methods
MODIFY
WalletWasabi.Fluent/Controls/LineChart.cs
WalletWasabi.Fluent/Controls/LineChart.cs
@@ -170,8 +170,8 @@ namespace WalletWasabi.Fluent.Controls
SetStateAreaPoints(state);
- SetStateXAxisLabels(state, XAxisLabels);
- SetStateYAxisLabels(state, YAxisLabels);
+ SetStateXAxisLabels(state);
+ SetStateYAxisLabels(state);
SetStateXAxisCursor(state);
@@ -213,11 +213,17 @@ namespace WalletWasabi.Fluent.Controls
}
}
- private void SetStateXAxisLabels(LineChartState state, IList<string>? xAxisLabels)
+ private void SetStateXAxisLabels(LineChartState state)
{
+ var xAxisLabels = XAxisLabels;
+
if (xAxisLabels is not null)
{
- GenerateXAxisLabels(state, xAxisLabels);
+ state.XAxisLabelStep = xAxisLabels.Count <= 1
+ ? double.NaN
+ : state.AreaWidth / (xAxisLabels.Count - 1);
+
+ state.XAxisLabels = xAxisLabels.ToList();
}
else
{
@@ -225,58 +231,31 @@ namespace WalletWasabi.Fluent.Controls
}
}
- private void SetStateYAxisLabels(LineChartState state, IList<string>? yAxisLabels)
- {
- if (yAxisLabels is not null)
+ private void SetStateYAxisLabels(LineChartState state)
{
- GenerateYAxisLabels(state, yAxisLabels);
- }
- else
- {
- AutoGenerateYAxisLabels(state);
- }
- }
+ var yAxisLabels = YAxisLabels;
- private void GenerateXAxisLabels(LineChartState state, IList<string> xAxisLabels)
- {
- if (xAxisLabels.Count <= 1)
- {
- state.XAxisLabelStep = double.NaN;
- }
- else
+ if (yAxisLabels is not null)
{
- state.XAxisLabelStep = state.AreaWidth / (xAxisLabels.Count - 1);
- }
-
- state.XAxisLabels = xAxisLabels.ToList();
- }
+ state.YAxisLabelStep = yAxisLabels.Count <= 1
+ ? double.NaN
+ : state.AreaHeight / (yAxisLabels.Count - 1);
- private void GenerateYAxisLabels(LineChartState state, IList<string> yAxisLabels)
- {
- if (yAxisLabels.Count <= 1)
- {
- state.YAxisLabelStep = double.NaN;
+ state.YAxisLabels = yAxisLabels.ToList();
}
else
{
- state.YAxisLabelStep = state.AreaHeight / (yAxisLabels.Count - 1);
+ AutoGenerateYAxisLabels(state);
}
-
- state.YAxisLabels = yAxisLabels.ToList();
}
private void AutoGenerateXAxisLabels(LineChartState state)
{
var xAxisValues = XAxisValues;
- if (xAxisValues is null || xAxisValues.Count <= 1)
- {
- state.XAxisLabelStep = double.NaN;
- }
- else
- {
- state.XAxisLabelStep = state.AreaWidth / (xAxisValues.Count - 1);
- }
+ state.XAxisLabelStep = xAxisValues is null || xAxisValues.Count <= 1
+ ? double.NaN
+ : state.AreaWidth / (xAxisValues.Count - 1);
if (XAxisStroke is not null && XAxisValues is not null)
{
@@ -288,14 +267,9 @@ namespace WalletWasabi.Fluent.Controls
{
var yAxisValues = YAxisValues;
- if (yAxisValues is null || yAxisValues.Count <= 1)
- {
- state.YAxisLabelStep = double.NaN;
- }
- else
- {
- state.YAxisLabelStep = state.AreaHeight / (yAxisValues.Count - 1);
- }
+ state.YAxisLabelStep = yAxisValues is null || yAxisValues.Count <= 1
+ ? double.NaN
+ : state.AreaHeight / (yAxisValues.Count - 1);
if (YAxisStroke is not null && YAxisValues is not null)
{

Refactor X axis label state setter methods