Refactored property names
MODIFY
WalletWasabi.Fluent/Controls/LineChart.cs
WalletWasabi.Fluent/Controls/LineChart.cs
@@ -17,83 +17,40 @@ namespace WalletWasabi.Fluent.Controls
#region Area
- public static readonly StyledProperty<List<double>?> ValuesProperty =
- AvaloniaProperty.Register<LineChart, List<double>?>(nameof(Values));
-
- public static readonly StyledProperty<double> MinValueProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(MinValue));
-
- public static readonly StyledProperty<double> MaxValueProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(MaxValue));
-
- public static readonly StyledProperty<bool> LogarithmicScaleProperty =
- AvaloniaProperty.Register<LineChart, bool>(nameof(LogarithmicScale));
-
public static readonly StyledProperty<Thickness> AreaMarginProperty =
AvaloniaProperty.Register<LineChart, Thickness>(nameof(AreaMargin));
- public static readonly StyledProperty<IBrush?> FillProperty =
- AvaloniaProperty.Register<LineChart, IBrush?>(nameof(Fill));
+ public static readonly StyledProperty<IBrush?> AreaFillProperty =
+ AvaloniaProperty.Register<LineChart, IBrush?>(nameof(AreaFill));
- public static readonly StyledProperty<IBrush?> StrokeProperty =
- AvaloniaProperty.Register<LineChart, IBrush?>(nameof(Stroke));
+ public static readonly StyledProperty<IBrush?> AreaStrokeProperty =
+ AvaloniaProperty.Register<LineChart, IBrush?>(nameof(AreaStroke));
- public static readonly StyledProperty<double> StrokeThicknessProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(StrokeThickness), 1.0);
+ public static readonly StyledProperty<double> AreaStrokeThicknessProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(AreaStrokeThickness), 1.0);
- public static readonly StyledProperty<IDashStyle?> StrokeDashStyleProperty =
- AvaloniaProperty.Register<LineChart, IDashStyle?>(nameof(StrokeDashStyle), null);
+ public static readonly StyledProperty<IDashStyle?> AreaStrokeDashStyleProperty =
+ AvaloniaProperty.Register<LineChart, IDashStyle?>(nameof(AreaStrokeDashStyle), null);
- public static readonly StyledProperty<PenLineCap> StrokeLineCapProperty =
- AvaloniaProperty.Register<LineChart, PenLineCap>(nameof(StrokeLineCap), PenLineCap.Flat);
+ public static readonly StyledProperty<PenLineCap> AreaStrokeLineCapProperty =
+ AvaloniaProperty.Register<LineChart, PenLineCap>(nameof(AreaStrokeLineCap), PenLineCap.Flat);
- public static readonly StyledProperty<PenLineJoin> StrokeLineJoinProperty =
- AvaloniaProperty.Register<LineChart, PenLineJoin>(nameof(StrokeLineJoin), PenLineJoin.Miter);
+ public static readonly StyledProperty<PenLineJoin> AreaStrokeLineJoinProperty =
+ AvaloniaProperty.Register<LineChart, PenLineJoin>(nameof(AreaStrokeLineJoin), PenLineJoin.Miter);
- public static readonly StyledProperty<double> StrokeMiterLimitProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(StrokeMiterLimit), 10.0);
+ public static readonly StyledProperty<double> AreaStrokeMiterLimitProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(AreaStrokeMiterLimit), 10.0);
#endregion
- #region XAxis Labels
+ #region XAxis
+
+ public static readonly StyledProperty<List<double>?> XAxisValuesProperty =
+ AvaloniaProperty.Register<LineChart, List<double>?>(nameof(XAxisValues));
public static readonly StyledProperty<List<string>?> XAxisLabelsProperty =
AvaloniaProperty.Register<LineChart, List<string>?>(nameof(XAxisLabels));
- public static readonly StyledProperty<IBrush?> LabelForegroundProperty =
- AvaloniaProperty.Register<LineChart, IBrush?>(nameof(LabelForeground));
-
- public static readonly StyledProperty<double> LabelOpacityProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(LabelOpacity));
-
- public static readonly StyledProperty<Point> LabelOffsetProperty =
- AvaloniaProperty.Register<LineChart, Point>(nameof(LabelOffset));
-
- public static readonly StyledProperty<Size> LabelSizeProperty =
- AvaloniaProperty.Register<LineChart, Size>(nameof(LabelSize));
-
- public static readonly StyledProperty<TextAlignment> LabelAlignmentProperty =
- AvaloniaProperty.Register<LineChart, TextAlignment>(nameof(LabelAlignment));
-
- public static readonly StyledProperty<double> LabelAngleProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(LabelAngle));
-
- public static readonly StyledProperty<FontFamily> LabelFontFamilyProperty =
- AvaloniaProperty.Register<LineChart, FontFamily>(nameof(LabelFontFamily));
-
- public static readonly StyledProperty<FontStyle> LabelFontStyleProperty =
- AvaloniaProperty.Register<LineChart, FontStyle>(nameof(LabelFontStyle));
-
- public static readonly StyledProperty<FontWeight> LabelFontWeightProperty =
- AvaloniaProperty.Register<LineChart, FontWeight>(nameof(LabelFontWeight));
-
- public static readonly StyledProperty<double> LabelFontSizeProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(LabelFontSize));
-
- #endregion
-
- #region XAxis
-
public static readonly StyledProperty<IBrush?> XAxisStrokeProperty =
AvaloniaProperty.Register<LineChart, IBrush?>(nameof(XAxisStroke));
@@ -105,16 +62,37 @@ namespace WalletWasabi.Fluent.Controls
#endregion
- #region YAxis
+ #region XAxis Label
- public static readonly StyledProperty<IBrush?> YAxisStrokeProperty =
- AvaloniaProperty.Register<LineChart, IBrush?>(nameof(YAxisStroke));
+ public static readonly StyledProperty<IBrush?> XAxisLabelForegroundProperty =
+ AvaloniaProperty.Register<LineChart, IBrush?>(nameof(XAxisLabelForeground));
- public static readonly StyledProperty<double> YAxisStrokeThicknessProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(YAxisStrokeThickness));
+ public static readonly StyledProperty<double> XAxisLabelOpacityProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XAxisLabelOpacity));
- public static readonly StyledProperty<double> YAxisArrowSizeProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(YAxisArrowSize));
+ public static readonly StyledProperty<Point> XAxisLabelOffsetProperty =
+ AvaloniaProperty.Register<LineChart, Point>(nameof(XAxisLabelOffset));
+
+ public static readonly StyledProperty<Size> XAxisLabelSizeProperty =
+ AvaloniaProperty.Register<LineChart, Size>(nameof(XAxisLabelSize));
+
+ public static readonly StyledProperty<TextAlignment> XAxisLabelAlignmentProperty =
+ AvaloniaProperty.Register<LineChart, TextAlignment>(nameof(XAxisLabelAlignment));
+
+ public static readonly StyledProperty<double> XAxisLabelAngleProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XAxisLabelAngle));
+
+ public static readonly StyledProperty<FontFamily> XAxisLabelFontFamilyProperty =
+ AvaloniaProperty.Register<LineChart, FontFamily>(nameof(XAxisLabelFontFamily));
+
+ public static readonly StyledProperty<FontStyle> XAxisLabelFontStyleProperty =
+ AvaloniaProperty.Register<LineChart, FontStyle>(nameof(XAxisLabelFontStyle));
+
+ public static readonly StyledProperty<FontWeight> XAxisLabelFontWeightProperty =
+ AvaloniaProperty.Register<LineChart, FontWeight>(nameof(XAxisLabelFontWeight));
+
+ public static readonly StyledProperty<double> XAxisLabelFontSizeProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XAxisLabelFontSize));
#endregion
@@ -152,6 +130,34 @@ namespace WalletWasabi.Fluent.Controls
#endregion
+ #region YAxis
+
+ public static readonly StyledProperty<List<double>?> YAxisValuesProperty =
+ AvaloniaProperty.Register<LineChart, List<double>?>(nameof(YValues));
+
+ public static readonly StyledProperty<bool> YAxisLogarithmicScaleProperty =
+ AvaloniaProperty.Register<LineChart, bool>(nameof(YAxisLogarithmicScale));
+
+ public static readonly StyledProperty<double> XAxisCurrentValueProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XCurrentValue));
+
+ public static readonly StyledProperty<double> XAxisMinValueProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XMinValue));
+
+ public static readonly StyledProperty<double> XAxisMaxValueProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(XMaxValue));
+
+ public static readonly StyledProperty<IBrush?> YAxisStrokeProperty =
+ AvaloniaProperty.Register<LineChart, IBrush?>(nameof(YAxisStroke));
+
+ public static readonly StyledProperty<double> YAxisStrokeThicknessProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(YAxisStrokeThickness));
+
+ public static readonly StyledProperty<double> YAxisArrowSizeProperty =
+ AvaloniaProperty.Register<LineChart, double>(nameof(YAxisArrowSize));
+
+ #endregion
+
#region YAxis Title
public static readonly StyledProperty<string> YAxisTitleProperty =
@@ -188,9 +194,6 @@ namespace WalletWasabi.Fluent.Controls
#region Cursor
- public static readonly StyledProperty<double> CursorValueProperty =
- AvaloniaProperty.Register<LineChart, double>(nameof(CursorValue));
-
public static readonly StyledProperty<IBrush?> CursorStrokeProperty =
AvaloniaProperty.Register<LineChart, IBrush?>(nameof(CursorStroke));
@@ -241,11 +244,11 @@ namespace WalletWasabi.Fluent.Controls
{
AffectsMeasure<LineChart>(AreaMarginProperty);
AffectsRender<LineChart>(
- ValuesProperty,
+ YAxisValuesProperty,
XAxisLabelsProperty,
- MinValueProperty,
- MaxValueProperty,
- CursorValueProperty);
+ XAxisMinValueProperty,
+ XAxisMaxValueProperty,
+ XAxisCurrentValueProperty);
}
#endregion
@@ -265,190 +268,168 @@ namespace WalletWasabi.Fluent.Controls
#region Area
- public List<double>? Values
+ public Thickness AreaMargin
{
- get => GetValue(ValuesProperty);
- set => SetValue(ValuesProperty, value);
+ get => GetValue(AreaMarginProperty);
+ set => SetValue(AreaMarginProperty, value);
}
- public double MinValue
+ public IBrush? AreaFill
{
- get => GetValue(MinValueProperty);
- set => SetValue(MinValueProperty, value);
+ get => GetValue(AreaFillProperty);
+ set => SetValue(AreaFillProperty, value);
}
- public double MaxValue
+ public IBrush? AreaStroke
{
- get => GetValue(MaxValueProperty);
- set => SetValue(MaxValueProperty, value);
+ get => GetValue(AreaStrokeProperty);
+ set => SetValue(AreaStrokeProperty, value);
}
- public bool LogarithmicScale
+ public double AreaStrokeThickness
{
- get => GetValue(LogarithmicScaleProperty);
- set => SetValue(LogarithmicScaleProperty, value);
+ get => GetValue(AreaStrokeThicknessProperty);
+ set => SetValue(AreaStrokeThicknessProperty, value);
}
- public Thickness AreaMargin
+ public IDashStyle? AreaStrokeDashStyle
{
- get => GetValue(AreaMarginProperty);
- set => SetValue(AreaMarginProperty, value);
+ get => GetValue(AreaStrokeDashStyleProperty);
+ set => SetValue(AreaStrokeDashStyleProperty, value);
}
- public IBrush? Fill
+ public PenLineCap AreaStrokeLineCap
{
- get => GetValue(FillProperty);
- set => SetValue(FillProperty, value);
+ get => GetValue(AreaStrokeLineCapProperty);
+ set => SetValue(AreaStrokeLineCapProperty, value);
}
- public IBrush? Stroke
+ public PenLineJoin AreaStrokeLineJoin
{
- get => GetValue(StrokeProperty);
- set => SetValue(StrokeProperty, value);
+ get => GetValue(AreaStrokeLineJoinProperty);
+ set => SetValue(AreaStrokeLineJoinProperty, value);
}
- public double StrokeThickness
+ public double AreaStrokeMiterLimit
{
- get => GetValue(StrokeThicknessProperty);
- set => SetValue(StrokeThicknessProperty, value);
+ get => GetValue(AreaStrokeMiterLimitProperty);
+ set => SetValue(AreaStrokeMiterLimitProperty, value);
}
- public IDashStyle? StrokeDashStyle
- {
- get => GetValue(StrokeDashStyleProperty);
- set => SetValue(StrokeDashStyleProperty, value);
- }
+ #endregion
+
+ #region XAxis
- public PenLineCap StrokeLineCap
+ public double XCurrentValue
{
- get => GetValue(StrokeLineCapProperty);
- set => SetValue(StrokeLineCapProperty, value);
+ get => GetValue(XAxisCurrentValueProperty);
+ set => SetValue(XAxisCurrentValueProperty, value);
}
- public PenLineJoin StrokeLineJoin
+ public double XMinValue
{
- get => GetValue(StrokeLineJoinProperty);
- set => SetValue(StrokeLineJoinProperty, value);
+ get => GetValue(XAxisMinValueProperty);
+ set => SetValue(XAxisMinValueProperty, value);
}
- public double StrokeMiterLimit
+ public double XMaxValue
{
- get => GetValue(StrokeMiterLimitProperty);
- set => SetValue(StrokeMiterLimitProperty, value);
+ get => GetValue(XAxisMaxValueProperty);
+ set => SetValue(XAxisMaxValueProperty, value);
}
- #endregion
-
- #region Labels
-
public List<string>? XAxisLabels
{
get => GetValue(XAxisLabelsProperty);
set => SetValue(XAxisLabelsProperty, value);
}
- public IBrush? LabelForeground
+ public List<double>? XAxisValues
{
- get => GetValue(LabelForegroundProperty);
- set => SetValue(LabelForegroundProperty, value);
+ get => GetValue(XAxisValuesProperty);
+ set => SetValue(XAxisValuesProperty, value);
}
- public double LabelOpacity
+ public IBrush? XAxisStroke
{
- get => GetValue(LabelOpacityProperty);
- set => SetValue(LabelOpacityProperty, value);
+ get => GetValue(XAxisStrokeProperty);
+ set => SetValue(XAxisStrokeProperty, value);
}
- public double LabelAngle
+ public double XAxisStrokeThickness
{
- get => GetValue(LabelAngleProperty);
- set => SetValue(LabelAngleProperty, value);
+ get => GetValue(XAxisStrokeThicknessProperty);
+ set => SetValue(XAxisStrokeThicknessProperty, value);
}
- public Point LabelOffset
+ public double XAxisArrowSize
{
- get => GetValue(LabelOffsetProperty);
- set => SetValue(LabelOffsetProperty, value);
+ get => GetValue(XAxisArrowSizeProperty);
+ set => SetValue(XAxisArrowSizeProperty, value);
}
- public Size LabelSize
- {
- get => GetValue(LabelSizeProperty);
- set => SetValue(LabelSizeProperty, value);
- }
+ #endregion
- public TextAlignment LabelAlignment
- {
- get => GetValue(LabelAlignmentProperty);
- set => SetValue(LabelAlignmentProperty, value);
- }
+ #region XAxis Label
- public FontFamily LabelFontFamily
+ public IBrush? XAxisLabelForeground
{
- get => GetValue(LabelFontFamilyProperty);
- set => SetValue(LabelFontFamilyProperty, value);
+ get => GetValue(XAxisLabelForegroundProperty);
+ set => SetValue(XAxisLabelForegroundProperty, value);
}
- public FontStyle LabelFontStyle
+ public double XAxisLabelOpacity
{
- get => GetValue(LabelFontStyleProperty);
- set => SetValue(LabelFontStyleProperty, value);
+ get => GetValue(XAxisLabelOpacityProperty);
+ set => SetValue(XAxisLabelOpacityProperty, value);
}
- public FontWeight LabelFontWeight
+ public double XAxisLabelAngle
{
- get => GetValue(LabelFontWeightProperty);
- set => SetValue(LabelFontWeightProperty, value);
+ get => GetValue(XAxisLabelAngleProperty);
+ set => SetValue(XAxisLabelAngleProperty, value);
}
- public double LabelFontSize
+ public Point XAxisLabelOffset
{
- get => GetValue(LabelFontSizeProperty);
- set => SetValue(LabelFontSizeProperty, value);
+ get => GetValue(XAxisLabelOffsetProperty);
+ set => SetValue(XAxisLabelOffsetProperty, value);
}
- #endregion
-
- #region XAxis
-
- public IBrush? XAxisStroke
+ public Size XAxisLabelSize
{
- get => GetValue(XAxisStrokeProperty);
- set => SetValue(XAxisStrokeProperty, value);
+ get => GetValue(XAxisLabelSizeProperty);
+ set => SetValue(XAxisLabelSizeProperty, value);
}
- public double XAxisStrokeThickness
+ public TextAlignment XAxisLabelAlignment
{
- get => GetValue(XAxisStrokeThicknessProperty);
- set => SetValue(XAxisStrokeThicknessProperty, value);
+ get => GetValue(XAxisLabelAlignmentProperty);
+ set => SetValue(XAxisLabelAlignmentProperty, value);
}
- public double XAxisArrowSize
+ public FontFamily XAxisLabelFontFamily
{
- get => GetValue(XAxisArrowSizeProperty);
- set => SetValue(XAxisArrowSizeProperty, value);
+ get => GetValue(XAxisLabelFontFamilyProperty);
+ set => SetValue(XAxisLabelFontFamilyProperty, value);
}
- #endregion
-
- #region YAxis
-
- public IBrush? YAxisStroke
+ public FontStyle XAxisLabelFontStyle
{
- get => GetValue(YAxisStrokeProperty);
- set => SetValue(YAxisStrokeProperty, value);
+ get => GetValue(XAxisLabelFontStyleProperty);
+ set => SetValue(XAxisLabelFontStyleProperty, value);
}
- public double YAxisStrokeThickness
+ public FontWeight XAxisLabelFontWeight
{
- get => GetValue(YAxisStrokeThicknessProperty);
- set => SetValue(YAxisStrokeThicknessProperty, value);
+ get => GetValue(XAxisLabelFontWeightProperty);
+ set => SetValue(XAxisLabelFontWeightProperty, value);
}
- public double YAxisArrowSize
+ public double XAxisLabelFontSize
{
- get => GetValue(YAxisArrowSizeProperty);
- set => SetValue(YAxisArrowSizeProperty, value);
+ get => GetValue(XAxisLabelFontSizeProperty);
+ set => SetValue(XAxisLabelFontSizeProperty, value);
}
#endregion
@@ -517,6 +498,40 @@ namespace WalletWasabi.Fluent.Controls
#endregion
+ #region YAxis
+
+ public List<double>? YValues
+ {
+ get => GetValue(YAxisValuesProperty);
+ set => SetValue(YAxisValuesProperty, value);
+ }
+
+ public bool YAxisLogarithmicScale
+ {
+ get => GetValue(YAxisLogarithmicScaleProperty);
+ set => SetValue(YAxisLogarithmicScaleProperty, value);
+ }
+
+ public IBrush? YAxisStroke
+ {
+ get => GetValue(YAxisStrokeProperty);
+ set => SetValue(YAxisStrokeProperty, value);
+ }
+
+ public double YAxisStrokeThickness
+ {
+ get => GetValue(YAxisStrokeThicknessProperty);
+ set => SetValue(YAxisStrokeThicknessProperty, value);
+ }
+
+ public double YAxisArrowSize
+ {
+ get => GetValue(YAxisArrowSizeProperty);
+ set => SetValue(YAxisArrowSizeProperty, value);
+ }
+
+ #endregion
+
#region YAxisTitle
public string YAxisTitle
@@ -583,12 +598,6 @@ namespace WalletWasabi.Fluent.Controls
#region Cursor
- public double CursorValue
- {
- get => GetValue(CursorValueProperty);
- set => SetValue(CursorValueProperty, value);
- }
-
public IBrush? CursorStroke
{
get => GetValue(CursorStrokeProperty);
@@ -715,10 +724,10 @@ namespace WalletWasabi.Fluent.Controls
private void UpdateCursorPosition(double x)
{
- var rangeValues = MaxValue - MinValue;
+ var rangeValues = XMaxValue - XMinValue;
var rangeArea = Bounds.Width - AreaMargin.Left - AreaMargin.Right;
var value = Clamp(x - AreaMargin.Left, 0, rangeArea);
- CursorValue = MaxValue - rangeValues / rangeArea * value;
+ XCurrentValue = XMaxValue - rangeValues / rangeArea * value;
}
private void PointerMovedHandler(object? sender, PointerEventArgs e)
@@ -751,17 +760,17 @@ namespace WalletWasabi.Fluent.Controls
{
var state = new LineChartState();
- state.Width = width;
- state.Height = height;
+ state.ChartWidth = width;
+ state.ChartHeight = height;
state.AreaMargin = AreaMargin;
state.AreaWidth = width - state.AreaMargin.Left - state.AreaMargin.Right;
state.AreaHeight = height - state.AreaMargin.Top - state.AreaMargin.Bottom;
- var values = Values;
+ var values = YValues;
if (values is not null)
{
- var logarithmicScale = LogarithmicScale;
+ var logarithmicScale = YAxisLogarithmicScale;
var valuesList = logarithmicScale ?
values.Select(y => Math.Log(y)).ToList()
@@ -784,12 +793,12 @@ namespace WalletWasabi.Fluent.Controls
var labels = XAxisLabels;
if (labels is not null)
{
- state.Labels = labels.ToList();
+ state.XLabels = labels.ToList();
}
- var minValue = MinValue;
- var maxValue = MaxValue;
- var cursorValue = CursorValue;
+ var minValue = XMinValue;
+ var maxValue = XMaxValue;
+ var cursorValue = XCurrentValue;
state.CursorPosition = ScaleHorizontal(maxValue - cursorValue, maxValue, state.AreaWidth);
return state;
@@ -801,7 +810,7 @@ namespace WalletWasabi.Fluent.Controls
{
return;
}
- var brush = Fill;
+ var brush = AreaFill;
if (brush is null)
{
return;
@@ -822,16 +831,16 @@ namespace WalletWasabi.Fluent.Controls
{
return;
}
- var brush = Stroke;
+ var brush = AreaStroke;
if (brush is null)
{
return;
}
- var thickness = StrokeThickness;
- var dashStyle = StrokeDashStyle;
- var lineCap = StrokeLineCap;
- var lineJoin = StrokeLineJoin;
- var miterLimit = StrokeMiterLimit;
+ var thickness = AreaStrokeThickness;
+ var dashStyle = AreaStrokeDashStyle;
+ var lineCap = AreaStrokeLineCap;
+ var lineJoin = AreaStrokeLineJoin;
+ var miterLimit = AreaStrokeMiterLimit;
var pen = new Pen(brush, thickness, dashStyle, lineCap, lineJoin, miterLimit);
var deflate = thickness * 0.5;
var geometry = CreateStrokeGeometry(state.Points);
@@ -893,6 +902,55 @@ namespace WalletWasabi.Fluent.Controls
context.DrawLine(pen, p5, p6);
}
+ private void DrawXAxisLabels(DrawingContext context, LineChartState state)
+ {
+ if (state.XLabels is null)
+ {
+ return;
+ }
+ var foreground = XAxisLabelForeground;
+ if (foreground is null)
+ {
+ return;
+ }
+ var opacity = XAxisLabelOpacity;
+ var fontFamily = XAxisLabelFontFamily;
+ var fontStyle = XAxisLabelFontStyle;
+ var fontWeight = XAxisLabelFontWeight;
+ var typeface = new Typeface(fontFamily, fontStyle, fontWeight);
+ var fontSize = XAxisLabelFontSize;
+ var offset = XAxisLabelOffset;
+ var size = XAxisLabelSize;
+ var angleRadians = Math.PI / 180.0 * XAxisLabelAngle;
+ var alignment = XAxisLabelAlignment;
+ var originTop = state.AreaHeight + state.AreaMargin.Top;
+ var offsetTransform = context.PushPreTransform(Matrix.CreateTranslation(offset.X, offset.Y));
+ for (var i = 0; i < state.XLabels.Count; i++)
+ {
+ var origin = new Point(i * state.Step - size.Width / 2 + state.AreaMargin.Left, originTop);
+ var constraint = new Size(size.Width, size.Height);
+ var formattedText = CreateFormattedText(state.XLabels[i], typeface, alignment, fontSize, constraint);
+ var xPosition = origin.X + size.Width / 2;
+ var yPosition = origin.Y + size.Height / 2;
+ var matrix = Matrix.CreateTranslation(-xPosition, -yPosition)
+ * Matrix.CreateRotation(angleRadians)
+ * Matrix.CreateTranslation(xPosition, yPosition);
+ var labelTransform = context.PushPreTransform(matrix);
+ var offsetCenter = new Point(0, size.Height / 2 - formattedText.Bounds.Height / 2);
+ var opacityState = context.PushOpacity(opacity);
+ context.DrawText(foreground, origin + offsetCenter, formattedText);
+#if DEBUG_LABELS
+ context.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.Magenta)), new Rect(origin, constraint));
+#endif
+ opacityState.Dispose();
+ labelTransform.Dispose();
+#if DEBUG_LABELS
+ context.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.Cyan)), new Rect(origin, constraint));
+#endif
+ }
+ offsetTransform.Dispose();
+ }
+
private void DrawYAxis(DrawingContext context, LineChartState state)
{
var brush = YAxisStroke;
@@ -955,63 +1013,18 @@ namespace WalletWasabi.Fluent.Controls
#endif
}
- private void DrawLabels(DrawingContext context, LineChartState state)
- {
- if (state.Labels is null)
+ private void DrawBorder(DrawingContext context, LineChartState state)
{
- return;
- }
- var foreground = LabelForeground;
- if (foreground is null)
+ var brush = BorderBrush;
+ if (brush is null)
{
return;
}
- var opacity = LabelOpacity;
- var fontFamily = LabelFontFamily;
- var fontStyle = LabelFontStyle;
- var fontWeight = LabelFontWeight;
- var typeface = new Typeface(fontFamily, fontStyle, fontWeight);
- var fontSize = LabelFontSize;
- var offset = LabelOffset;
- var size = LabelSize;
- var angleRadians = Math.PI / 180.0 * LabelAngle;
- var alignment = LabelAlignment;
- var originTop = state.AreaHeight + state.AreaMargin.Top;
- var offsetTransform = context.PushPreTransform(Matrix.CreateTranslation(offset.X, offset.Y));
- for (var i = 0; i < state.Labels.Count; i++)
- {
- var origin = new Point(i * state.Step - size.Width / 2 + state.AreaMargin.Left, originTop);
- var constraint = new Size(size.Width, size.Height);
- var formattedText = CreateFormattedText(state.Labels[i], typeface, alignment, fontSize, constraint);
- var xPosition = origin.X + size.Width / 2;
- var yPosition = origin.Y + size.Height / 2;
- var matrix = Matrix.CreateTranslation(-xPosition, -yPosition)
- * Matrix.CreateRotation(angleRadians)
- * Matrix.CreateTranslation(xPosition, yPosition);
- var labelTransform = context.PushPreTransform(matrix);
- var offsetCenter = new Point(0, size.Height / 2 - formattedText.Bounds.Height / 2);
- var opacityState = context.PushOpacity(opacity);
- context.DrawText(foreground, origin + offsetCenter, formattedText);
-#if DEBUG_LABELS
- context.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.Magenta)), new Rect(origin, constraint));
-#endif
- opacityState.Dispose();
- labelTransform.Dispose();
-#if DEBUG_LABELS
- context.DrawRectangle(null, new Pen(new SolidColorBrush(Colors.Cyan)), new Rect(origin, constraint));
-#endif
- }
- offsetTransform.Dispose();
- }
-
- private void DrawBorder(DrawingContext context, LineChartState state)
- {
- var brush = BorderBrush;
var thickness = BorderThickness;
var radiusX = BorderRadiusX;
var radiusY = BorderRadiusY;
var pen = new Pen(brush, thickness, null, PenLineCap.Round, PenLineJoin.Miter, 10.0);
- var rect = new Rect(0, 0, state.Width, state.Height);
+ var rect = new Rect(0, 0, state.ChartWidth, state.ChartHeight);
var rectDeflate = rect.Deflate(thickness * 0.5);
context.DrawRectangle(Brushes.Transparent, pen, rectDeflate, radiusX, radiusY);
}
@@ -1028,19 +1041,19 @@ namespace WalletWasabi.Fluent.Controls
DrawXAxis(context, state);
DrawYAxis(context, state);
DrawYAxisTitle(context, state);
- DrawLabels(context, state);
+ DrawXAxisLabels(context, state);
DrawBorder(context, state);
}
private class LineChartState
{
- public double Width { get; set; }
- public double Height { get; set; }
+ public double ChartWidth { get; set; }
+ public double ChartHeight { get; set; }
public double AreaWidth { get; set; }
public double AreaHeight { get; set; }
public Thickness AreaMargin { get; set; }
public Point[]? Points { get; set; }
- public List<string>? Labels { get; set; }
+ public List<string>? XLabels { get; set; }
public double Step { get; set; }
public double CursorPosition { get; set; }
}

MODIFY
WalletWasabi.Fluent/ViewModels/TestLineChartViewModel.cs
WalletWasabi.Fluent/ViewModels/TestLineChartViewModel.cs
@@ -23,25 +23,6 @@ namespace WalletWasabi.Fluent.ViewModels
600
};
- public List<string> Labels => new List<string>()
- {
- "6d",
- "4d",
- "3d",
- "1d",
- "22h",
- "20h",
- "18h",
- "10h",
- "6h",
- "4h",
- "2h",
- "1h",
- "50m",
- "30m",
- "20m"
- };
-
// public List<string> Labels => new List<string>()
// {
// "6 days",
@@ -60,5 +41,49 @@ namespace WalletWasabi.Fluent.ViewModels
// "30 min",
// "20 min"
// };
+
+ public List<string> XAxisLabels => new List<string>()
+ {
+ "6d",
+ "4d",
+ "3d",
+ "1d",
+ "22h",
+ "20h",
+ "18h",
+ "10h",
+ "6h",
+ "4h",
+ "2h",
+ "1h",
+ "50m",
+ "30m",
+ "20m"
+ };
+
+ public List<double> XAxisLabelsPosition => new List<double>()
+ {
+ 864,
+ 576,
+ 432,
+ 144,
+ 132,
+ 120,
+ 108,
+ 60,
+ 36,
+ 24,
+ 12,
+ 6,
+ 5,
+ 3,
+ 2,
+ };
+
+ public double XCurrentValue { get; set; } = 36;
+
+ public double XMinValue { get; set; } = 2;
+
+ public double XMaxValue { get; set; } = 864;
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/TestLineChartView.axaml
WalletWasabi.Fluent/Views/TestLineChartView.axaml
</Style>
<!-- LineChart Labels -->
<Style Selector="c|LineChart.labels">
- <Setter Property="LabelForeground" Value="{DynamicResource TextForegroundColor}" />
- <Setter Property="LabelOpacity" Value="0.5" />
- <Setter Property="LabelAngle" Value="0" />
- <Setter Property="LabelOffset" Value="0,10" />
- <Setter Property="LabelSize" Value="50,30" />
- <Setter Property="LabelAlignment" Value="Center" />
- <Setter Property="LabelFontFamily" Value="Arial" />
- <Setter Property="LabelFontStyle" Value="Normal" />
- <Setter Property="LabelFontWeight" Value="Normal" />
- <Setter Property="LabelFontSize" Value="10" />
+ <Setter Property="XAxisLabelForeground" Value="{DynamicResource TextForegroundColor}" />
+ <Setter Property="XAxisLabelOpacity" Value="0.5" />
+ <Setter Property="XAxisLabelAngle" Value="0" />
+ <Setter Property="XAxisLabelOffset" Value="0,10" />
+ <Setter Property="XAxisLabelSize" Value="50,30" />
+ <Setter Property="XAxisLabelAlignment" Value="Center" />
+ <Setter Property="XAxisLabelFontFamily" Value="Arial" />
+ <Setter Property="XAxisLabelFontStyle" Value="Normal" />
+ <Setter Property="XAxisLabelFontWeight" Value="Normal" />
+ <Setter Property="XAxisLabelFontSize" Value="10" />
</Style>
<!-- LineChart Cursor -->
<Style Selector="c|LineChart.cursor">
<Slider x:Name="CursorValue2"
DockPanel.Dock="Bottom"
Classes="cursor"
- Minimum="{Binding #GradientLineChart.MinValue}"
- Maximum="{Binding #GradientLineChart.MaxValue}"
- Value="{Binding #GradientLineChart.CursorValue}"
+ Minimum="{Binding #GradientLineChart.XMinValue}"
+ Maximum="{Binding #GradientLineChart.XMaxValue}"
+ Value="{Binding #GradientLineChart.XCurrentValue}"
Margin="60,0,30,0"/>
<c:LineChart x:Name="GradientLineChart"
- Classes="labels cursor border yAxis yAxisTitle"
- Values="{Binding Values}"
- XAxisLabels="{Binding Labels}"
- CursorValue="36"
- MinValue="2"
- MaxValue="1008"
- LogarithmicScale="False"
+ YValues="{Binding Values}"
+ XAxisLabels="{Binding XAxisLabels}"
+ XCurrentValue="{Binding XCurrentValue}"
+ XMinValue="{Binding XMinValue}"
+ XMaxValue="{Binding XMaxValue}"
+ YAxisLogarithmicScale="False"
AreaMargin="60,40,30,30"
- StrokeThickness="2"
- StrokeLineCap="Round"
+ AreaStrokeThickness="2"
+ AreaStrokeLineCap="Round"
YAxisTitle="More Expensive">
- <c:LineChart.Fill>
+ <c:LineChart.AreaFill>
<LinearGradientBrush StartPoint="50%,0%" EndPoint="50%,100%" Opacity="0.2">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0" Color="#FF72BD81"/>
<GradientStop Offset="1.0" Color="#0072BD81"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
- </c:LineChart.Fill>
- <c:LineChart.Stroke>
+ </c:LineChart.AreaFill>
+ <c:LineChart.AreaStroke>
<LinearGradientBrush StartPoint="0%,50%" EndPoint="100%,50%">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0" Color="#72BD81"/>
<GradientStop Offset="1.0" Color="#72BD81"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
- </c:LineChart.Stroke>
+ </c:LineChart.AreaStroke>
</c:LineChart>
</DockPanel>
</TabItem>
<Slider x:Name="CursorValue1"
DockPanel.Dock="Bottom"
Classes="cursor"
- Minimum="{Binding #SolidLineChart.MinValue}"
- Maximum="{Binding #SolidLineChart.MaxValue}"
- Value="{Binding #SolidLineChart.CursorValue}"
+ Minimum="{Binding #SolidLineChart.XMinValue}"
+ Maximum="{Binding #SolidLineChart.XMaxValue}"
+ Value="{Binding #SolidLineChart.XCurrentValue}"
Margin="60,0,30,0"/>
<c:LineChart x:Name="SolidLineChart"
Classes="labels cursor border yAxis yAxisTitle"
- Values="{Binding Values}"
- CursorValue="36"
- XAxisLabels="{Binding Labels}"
- MinValue="2"
- MaxValue="1008"
- LogarithmicScale="False"
+ YValues="{Binding Values}"
+ XCurrentValue="{Binding XCurrentValue}"
+ XMinValue="{Binding XMinValue}"
+ XMaxValue="{Binding XMaxValue}"
+ XAxisLabels="{Binding XAxisLabels}"
+ YAxisLogarithmicScale="False"
AreaMargin="60,40,30,30"
- Fill="#2872BD81"
- Stroke="#FF72BD81"
- StrokeThickness="2"
+ AreaFill="#2872BD81"
+ AreaStroke="#FF72BD81"
+ AreaStrokeThickness="2"
YAxisTitle="More Expensive">
</c:LineChart>
</DockPanel>

Refactored property names