Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes review #1829

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions samples/ViewModelsSamples/Bars/DelayedAnimation/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using LiveChartsCore.Kernel;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;

namespace ViewModelsSamples.Bars.DelayedAnimation;

Expand Down Expand Up @@ -36,9 +38,10 @@ public ViewModel()

private void OnPointMeasured(ChartPoint<float, RoundedRectangleGeometry, LabelGeometry> point)
{
var perPointDelay = 100; // in milliseconds
var baseAnimationsSpeed = 800f; // in milliseconds
var perPointDelay = 100f; // in milliseconds
var delay = point.Context.Entity.MetaData!.EntityIndex * perPointDelay;
var speed = (float)point.Context.Chart.AnimationsSpeed.TotalMilliseconds + delay;
var speed = baseAnimationsSpeed + delay;

// the animation takes a function, that represents the progress of the animation
// the parameter is the progress of the animation, it goes from 0 to 1
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Bars/Race/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ViewModel()
var rowSeries = new RowSeries<PilotInfo>
{
Values = SortData(),
DataLabelsPaint = new SolidColorPaint(new SKColor(245, 245, 245)),
ShowDataLabels = true,
DataLabelsPosition = DataLabelsPosition.End,
DataLabelsTranslate = new(-1, 0),
DataLabelsFormatter = point => $"{point.Model!.Name} {point.Coordinate.PrimaryValue}",
Expand Down
6 changes: 3 additions & 3 deletions samples/ViewModelsSamples/Bars/RowsWithLabels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ public class ViewModel
{
Values = [8, -3, 4],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.End
},
new RowSeries<int>
{
Values = [4, -6, 5],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(250, 250, 250)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.Middle
},
new RowSeries<int>
{
Values = [6, -9, 3],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.Start
}
Expand Down
8 changes: 4 additions & 4 deletions samples/ViewModelsSamples/Error/Basic/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public ViewModel()
new ColumnSeries<ErrorValue>
{
Values = values0,
ErrorPaint = new SolidColorPaint(SKColors.Black),
ShowError = true,
Padding = 0
},
new ColumnSeries<ErrorPoint>
{
Values = values1,
ErrorPaint = new SolidColorPaint(SKColors.Black),
ShowError = true,
Padding = 0
}
];
Expand All @@ -67,7 +67,7 @@ public ViewModel()
new LineSeries<ErrorValue, RectangleGeometry>
{
Values = values0,
ErrorPaint = new SolidColorPaint(SKColors.Black),
ShowError = true,
GeometrySize = 4,
Fill = null
}
Expand All @@ -94,7 +94,7 @@ public ViewModel()
new ScatterSeries<ErrorDateTimePoint>
{
Values = values2,
ErrorPaint = new SolidColorPaint(SKColors.Black),
ShowError = true,
GeometrySize = 10
}
];
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Events/Cartesian/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ViewModel()
Values = data,
YToolTipLabelFormatter = point => $"{point.Model?.Stock} {point.Model?.Name}",
DataLabelsFormatter = point => $"{point.Model?.Stock} {point.Model?.Name}",
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
ShowDataLabels = true,
DataLabelsPosition = DataLabelsPosition.End,
Mapping = (fruit, index) => new(index, fruit.Stock)
};
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/General/MapPoints/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ViewModel()
var series = new ColumnSeries<int>
{
Values = [2, 5, 4, 6, 8, 3, 2, 4, 6],
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
ShowDataLabels = true,
DataLabelsPosition = DataLabelsPosition.Top
}
.OnPointMeasured(point =>
Expand Down
5 changes: 1 addition & 4 deletions samples/ViewModelsSamples/Pies/Custom/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public ViewModel()
series.OuterRadiusOffset = outer;
outer += 50;

series.DataLabelsPaint = new SolidColorPaint(SKColors.White)
{
SKTypeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold)
};
series.ShowDataLabels = true;

series.ToolTipLabelFormatter =
point =>
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Pies/Gauge2/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ViewModel
{
series.Fill = new SolidColorPaint(SKColors.YellowGreen);
series.DataLabelsSize = 50;
series.DataLabelsPaint = new SolidColorPaint(SKColors.Red);
series.ShowDataLabels = true;
series.DataLabelsPosition = PolarLabelsPosition.ChartCenter;
series.InnerRadius = 75;
}),
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Pies/Icons/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ViewModel()
(dataItem, series) =>
{
// define the data labels paint.
series.DataLabelsPaint = new SolidColorPaint(SKColors.WhiteSmoke);
series.ShowDataLabels = true;

// now, when the point is measured,
// we will set up the svg label based on the BrowserShare class.
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Pies/OutLabels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ViewModel
series.Name = _names[_index++ % _names.Length];
series.DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer; // mark
series.DataLabelsSize = 15;
series.DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30));
series.ShowDataLabels = true;
series.DataLabelsFormatter =
point =>
$"This slide takes {point.Coordinate.PrimaryValue} " +
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Polar/Basic/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ViewModel
new PolarLineSeries<double>
{
Values = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
ShowDataLabels = true,
GeometrySize = 15,
DataLabelsSize = 8,
DataLabelsPosition = PolarLabelsPosition.Middle,
Expand Down
2 changes: 1 addition & 1 deletion samples/ViewModelsSamples/Polar/Test/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ViewModel : INotifyPropertyChanged
new PolarLineSeries<double>
{
Values = new ObservableCollection<double> { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 },
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
ShowDataLabels = true,
GeometrySize = 30,
DataLabelsSize = 15,
DataLabelsPosition = PolarLabelsPosition.Middle,
Expand Down
6 changes: 3 additions & 3 deletions samples/ViewModelsSamples/StackedBars/Basic/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ViewModel
{
Values = [3, 5, -3, 2, 5, -4, -2],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.Middle,
YToolTipLabelFormatter =
Expand All @@ -24,7 +24,7 @@ public class ViewModel
{
Values = [4, 2, -3, 2, 3, 4, -2],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.Middle,
YToolTipLabelFormatter =
Expand All @@ -34,7 +34,7 @@ public class ViewModel
{
Values = [-2, 6, 6, 5, 4, 3, -2],
Stroke = null,
DataLabelsPaint = new SolidColorPaint(new SKColor(45, 45, 45)),
ShowDataLabels = true,
DataLabelsSize = 14,
DataLabelsPosition = DataLabelsPosition.Middle,
YToolTipLabelFormatter =
Expand Down
2 changes: 1 addition & 1 deletion samples/WinUISample/WinUISample/WinUISample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>
Expand Down
19 changes: 18 additions & 1 deletion src/LiveChartsCore/BarSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public abstract class BarSeries<TModel, TVisual, TLabel>(
private double _rx;
private double _ry;
private Paint? _errorPaint;
private bool _showError;

/// <inheritdoc cref="IBarSeries.Padding"/>
public double Padding { get => _pading; set => SetProperty(ref _pading, value); }
Expand All @@ -75,11 +76,27 @@ public abstract class BarSeries<TModel, TVisual, TLabel>(
/// <inheritdoc cref="IBarSeries.Ry"/>
public double Ry { get => _ry; set => SetProperty(ref _ry, value); }

/// <inheritdoc cref="IErrorSeries.ShowError"/>
public bool ShowError
{
get => _showError;
set
{
SetProperty(ref _showError, value);
if (_errorPaint is not null)
_errorPaint.IsPaused = !value;
}
}

/// <inheritdoc cref="IErrorSeries.ErrorPaint"/>
public Paint? ErrorPaint
{
get => _errorPaint;
set => SetPaintProperty(ref _errorPaint, value, PaintStyle.Stroke);
set
{
SetPaintProperty(ref _errorPaint, value, PaintStyle.Stroke);
_showError = value is not null;
}
}

/// <inheritdoc cref="Series{TModel, TVisual, TLabel}.GetMiniaturesSketch"/>
Expand Down
20 changes: 11 additions & 9 deletions src/LiveChartsCore/CartesianChartEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ protected internal override void Measure()
_preserveFirstDraw = false;
}

MeasureWork = new object();

#region shallow copy the current data in the view

var viewDrawMargin = _chartView.DrawMargin;
Expand All @@ -386,8 +384,8 @@ protected internal override void Measure()
y = [provider.GetDefaultCartesianAxis()];
}

XAxes = x.Cast<ICartesianAxis>().ToArray();
YAxes = y.Cast<ICartesianAxis>().ToArray();
XAxes = [.. x.Cast<ICartesianAxis>()];
YAxes = [.. y.Cast<ICartesianAxis>()];

if (XAxes.Length == 0 || YAxes.Length == 0)
{
Expand All @@ -397,7 +395,7 @@ protected internal override void Measure()
_zoomingSpeed = _chartView.ZoomingSpeed;
_zoomMode = _chartView.ZoomMode;

var theme = LiveCharts.DefaultSettings.GetTheme();
var theme = GetTheme();

LegendPosition = _chartView.LegendPosition;
Legend = _chartView.Legend;
Expand All @@ -406,16 +404,20 @@ protected internal override void Measure()
FindingStrategy = _chartView.FindingStrategy;
Tooltip = _chartView.Tooltip;

AnimationsSpeed = _chartView.AnimationsSpeed;
EasingFunction = _chartView.EasingFunction;

Sections = _chartView.Sections?.Where(static x => x.IsVisible) ?? [];
VisualElements = _chartView.VisualElements ?? [];

ActualAnimationsSpeed = _chartView.AnimationsSpeed == TimeSpan.MaxValue
? theme.AnimationsSpeed
: _chartView.AnimationsSpeed;
ActualEasingFunction = _chartView.EasingFunction == EasingFunctions.Unset
? theme.EasingFunction
: _chartView.EasingFunction;

#endregion

SeriesContext = new SeriesContext(VisibleSeries, this);
var themeId = LiveCharts.DefaultSettings.CurrentThemeId;
var themeId = theme.ThemeId;

// restart axes bounds and meta data
foreach (var axis in XAxes)
Expand Down
39 changes: 25 additions & 14 deletions src/LiveChartsCore/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.Measure;
using LiveChartsCore.Motion;
using LiveChartsCore.Themes;
using LiveChartsCore.VisualElements;

namespace LiveChartsCore;
Expand Down Expand Up @@ -83,7 +84,7 @@ protected Chart(
Kind = kind;
Canvas = canvas;
canvas.Validated += OnCanvasValidated;
EasingFunction = EasingFunctions.QuadraticOut;
ActualEasingFunction = EasingFunctions.QuadraticOut;
LiveCharts.Configure(defaultPlatformConfig);

_updateThrottler = view.DesignerMode
Expand Down Expand Up @@ -122,14 +123,6 @@ protected Chart(
/// </summary>
public AnimatableContainer ActualBounds { get; } = new();

/// <summary>
/// Gets the measure work.
/// </summary>
/// <value>
/// The measure work.
/// </value>
public object MeasureWork { get; protected set; } = new();

/// <summary>
/// Gets the kind of the chart.
/// </summary>
Expand Down Expand Up @@ -247,15 +240,15 @@ protected Chart(
/// <value>
/// The animations speed.
/// </value>
public TimeSpan AnimationsSpeed { get; protected set; }
public TimeSpan ActualAnimationsSpeed { get; protected set; }

/// <summary>
/// Gets the easing function.
/// </summary>
/// <value>
/// The easing function.
/// </value>
public Func<float, float>? EasingFunction { get; protected set; }
public Func<float, float>? ActualEasingFunction { get; protected set; }

/// <summary>
/// Gets the visual elements.
Expand Down Expand Up @@ -309,8 +302,8 @@ public virtual void Load()
{
IsLoaded = true;
_isFirstDraw = true;
View.Tooltip ??= LiveCharts.DefaultSettings.GetTheme().DefaultTooltip();
View.Legend ??= LiveCharts.DefaultSettings.GetTheme().DefaultLegend();
View.Tooltip ??= GetTheme().DefaultTooltip();
View.Legend ??= GetTheme().DefaultLegend();
Update();
}

Expand Down Expand Up @@ -521,7 +514,7 @@ protected void UpdateBounds()

if (_isFirstDraw)
{
ActualBounds.Animate(EasingFunction, AnimationsSpeed);
ActualBounds.Animate(ActualEasingFunction, ActualAnimationsSpeed);
_ = Canvas.Trackers.Add(ActualBounds);
}
}
Expand Down Expand Up @@ -593,6 +586,24 @@ public LvcPoint GetLegendPosition()
/// <returns>A boolean indicating whether the series is drawn.</returns>
public bool IsDrawn(int seriesId) => _drawnSeries.Contains(seriesId);

/// <summary>
/// Gets the active theme.
/// </summary>
/// <returns></returns>
public Theme GetTheme()
{
var theme = LiveCharts.DefaultSettings.GetTheme();
theme.Setup(View);
return theme;
}

/// <summary>
/// Applies the current theme to the chart.
/// </summary>
public virtual void ApplyTheme() =>
// this is not optimal, we should only update the colors instead of re-measuring everything.
Measure();

/// <summary>
/// Collects and deletes from the UI the unused visuals.
/// </summary>
Expand Down
Loading
Loading