plot linechart x axis values to scale.
MODIFY
WalletWasabi.Fluent/Controls/LineChart.Properties.cs
WalletWasabi.Fluent/Controls/LineChart.Properties.cs
@@ -4,6 +4,13 @@ using Avalonia.Media;
namespace WalletWasabi.Fluent.Controls
{
+ public enum AxisPlotMode
+ {
+ Normal,
+ EvenlySpaced,
+ Logarithmic
+ }
+
public partial class LineChart
{
// Area
@@ -70,6 +77,9 @@ namespace WalletWasabi.Fluent.Controls
public static readonly StyledProperty<double> XAxisMinViableWidthProperty =
AvaloniaProperty.Register<LineChart, double>(nameof(XAxisMinViableWidth), double.MinValue);
+ public static readonly StyledProperty<AxisPlotMode> XAxisPlotModeProperty =
+ AvaloniaProperty.Register<LineChart, AxisPlotMode>(nameof(XAxisPlotMode), AxisPlotMode.Normal);
+
// XAxis Label
public static readonly StyledProperty<IList<string>?> XAxisLabelsProperty =
@@ -499,6 +509,12 @@ namespace WalletWasabi.Fluent.Controls
set => SetValue(XAxisMinViableWidthProperty, value);
}
+ public AxisPlotMode XAxisPlotMode
+ {
+ get => GetValue(XAxisPlotModeProperty);
+ set => SetValue(XAxisPlotModeProperty, value);
+ }
+
// XAxis Label
public IList<string>? XAxisLabels

MODIFY
WalletWasabi.Fluent/Controls/LineChart.cs
WalletWasabi.Fluent/Controls/LineChart.cs
@@ -224,17 +224,37 @@ namespace WalletWasabi.Fluent.Controls
state.Points = new Point[yAxisValues.Count];
- var pointStep = state.AreaWidth / (xAxisValues.Count - 1);
+ var xAxisValuesEnumerable = xAxisValues as IEnumerable<double>;
+ switch (XAxisPlotMode)
+ {
+ case AxisPlotMode.Normal:
var min = xAxisValues.Min();
var max = xAxisValues.Max();
var xAxisScaler = new StraightLineFormula();
xAxisScaler.CalculateFrom(min, max, 0, state.AreaWidth);
+ xAxisValuesEnumerable = xAxisValuesEnumerable.Select(x => xAxisScaler.GetYforX(x));
+ break;
+
+ case AxisPlotMode.EvenlySpaced:
+ var pointStep = state.AreaWidth / (xAxisValues.Count - 1);
+
+ xAxisValuesEnumerable = Enumerable.Range(0, xAxisValues.Count).Select(x => pointStep * x);
+ break;
+
+ case AxisPlotMode.Logarithmic:
+ break;
+ }
+
+ using (var enumerator = xAxisValuesEnumerable.GetEnumerator())
+ {
for (var i = 0; i < yAxisValuesScaled.Count; i++)
{
- state.Points[i] = new Point(xAxisScaler.GetYforX(xAxisValues[yAxisValuesScaled.Count -1 - i]), yAxisValuesScaled[i]);
+ state.Points[i] = new Point(enumerator.Current, yAxisValuesScaled[i]);
+ enumerator.MoveNext();
+ }
}
}

plot linechart x axis values to scale.