Skip to content

Commit

Permalink
designer improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Aug 21, 2021
1 parent 976ff1d commit 84378fc
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 70 deletions.
11 changes: 6 additions & 5 deletions src/LiveChartsCore/CartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using LiveChartsCore.Measure;
using LiveChartsCore.Kernel.Sketches;
using System.Threading;
using System.Threading.Tasks;
#if DEBUG
using System.Diagnostics;
#endif
Expand All @@ -52,6 +51,7 @@ public class CartesianChart<TDrawingContext> : Chart<TDrawingContext>
private double _zoomingSpeed = 0;
private ZoomAndPanMode _zoomMode;
private DrawMarginFrame<TDrawingContext>? _previousDrawMarginFrame;
private IEnumerable<ISeries>? _designerSeries = null;

/// <summary>
/// Initializes a new instance of the <see cref="CartesianChart{TDrawingContext}"/> class.
Expand Down Expand Up @@ -144,8 +144,6 @@ public CartesianChart(
/// <inheritdoc cref="IChart.Update(ChartUpdateParams?)" />
public override void Update(ChartUpdateParams? chartUpdateParams = null)
{
if (View.DesignerMode) return;

chartUpdateParams ??= new ChartUpdateParams();
if (chartUpdateParams.IsAutomaticUpdate && !View.AutoUpdateEnabled) return;
if (!chartUpdateParams.Throttling)
Expand Down Expand Up @@ -420,8 +418,11 @@ protected override void Measure()
animationsSpeed = _chartView.AnimationsSpeed;
easingFunction = _chartView.EasingFunction;

Series = _chartView.Series
.Where(x => x.IsVisible)
var actualSeries = View.DesignerMode
? _designerSeries ??= LiveCharts.CurrentSettings.DesignerSeriesGenerator(DesignerKind.Cartesian)
: _chartView.Series.Where(x => x.IsVisible);

Series = actualSeries
.Cast<ICartesianSeries<TDrawingContext>>()
.ToArray();

Expand Down
16 changes: 9 additions & 7 deletions src/LiveChartsCore/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,18 @@ protected bool SeriesMiniatureChanged(IReadOnlyList<IChartSeries<TDrawingContext
/// <returns></returns>
protected virtual Task UpdateThrottlerUnlocked()
{
return Task.Run(() =>
{
View.InvokeOnUIThread(() =>
return View.DesignerMode
? Task.CompletedTask
: Task.Run(() =>
{
lock (Canvas.Sync)
View.InvokeOnUIThread(() =>
{
Measure();
}
lock (Canvas.Sync)
{
Measure();
}
});
});
});
}

private Task TooltipThrottlerUnlocked()
Expand Down
39 changes: 39 additions & 0 deletions src/LiveChartsCore/Kernel/DesignerKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// The MIT License(MIT)
//
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

namespace LiveChartsCore.Kernel
{
/// <summary>
/// Designer series kind.
/// </summary>
public enum DesignerKind
{
/// <summary>
/// The Cartesian kind.
/// </summary>
Cartesian,
/// <summary>
/// The pie kind.
/// </summary>
Pie
}
}
12 changes: 12 additions & 0 deletions src/LiveChartsCore/Kernel/LiveChartsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public class LiveChartsSettings
internal Func<IAxis> AxisProvider { get; set; } =
() => throw new NotImplementedException($"{nameof(AxisProvider)} is not defined yet.");

/// <summary>
/// Gets the designer series.
/// </summary>
internal Func<DesignerKind, IEnumerable<ISeries>> DesignerSeriesGenerator { get; set; } =
x => throw new NotImplementedException($"{nameof(DefaultAnimationsSpeed)} is not defined yet.");

/// <summary>
/// Adds or replaces a mapping for a given type, the mapper defines how a type is mapped to a<see cref="ChartPoint"/> instance,
/// then the <see cref="ChartPoint"/> will be drawn as a point in our chart.
Expand Down Expand Up @@ -157,6 +163,12 @@ internal LiveChartsSettings HasAxisProvider(Func<IAxis> provider)
return this;
}

internal LiveChartsSettings HasDesigerSeriesProvider(Func<DesignerKind, IEnumerable<ISeries>> provider)
{
DesignerSeriesGenerator = provider;
return this;
}

internal IDataFactoryProvider<TDrawingContext> GetFactory<TDrawingContext>()
where TDrawingContext : DrawingContext
{
Expand Down
2 changes: 1 addition & 1 deletion src/LiveChartsCore/LiveChartsCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFrameworks>net462;netstandard2.0;netcoreapp2.0;</TargetFrameworks>
<AssemblyName>LiveChartsCore</AssemblyName>
<RootNamespace>LiveChartsCore</RootNamespace>
<Version>2.0.0-beta.50</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for .Net, this is the core package probably you need another package also unless you are building your own backed.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
10 changes: 6 additions & 4 deletions src/LiveChartsCore/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PieChart<TDrawingContext> : Chart<TDrawingContext>
private readonly HashSet<ISeries> _everMeasuredSeries = new();
private readonly IPieChartView<TDrawingContext> _chartView;
private int _nextSeries = 0;
private IEnumerable<ISeries>? _designerSeries = null;

/// <summary>
/// Initializes a new instance of the <see cref="PieChart{TDrawingContext}"/> class.
Expand Down Expand Up @@ -139,8 +140,6 @@ public override TooltipPoint[] FindPointsNearTo(PointF pointerPosition)
/// <inheritdoc cref="IChart.Update(ChartUpdateParams?)" />
public override void Update(ChartUpdateParams? chartUpdateParams = null)
{
if (View.DesignerMode) return;

chartUpdateParams ??= new ChartUpdateParams();

if (chartUpdateParams.IsAutomaticUpdate && !View.AutoUpdateEnabled) return;
Expand Down Expand Up @@ -182,8 +181,11 @@ protected override void Measure()
viewDrawMargin = _chartView.DrawMargin;
controlSize = _chartView.ControlSize;

Series = _chartView.Series
.Where(x => x.IsVisible)
var actualSeries = View.DesignerMode
? _designerSeries ??= LiveCharts.CurrentSettings.DesignerSeriesGenerator(DesignerKind.Cartesian)
: _chartView.Series.Where(x => x.IsVisible);

Series = actualSeries
.Cast<IPieSeries<TDrawingContext>>()
.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFrameworks>netcoreapp2.0;netstandard2.0;net462;</TargetFrameworks>
<AssemblyName>LiveChartsCore.SkiaSharpView.Avalonia</AssemblyName>
<RootNamespace>LiveChartsCore.SkiaSharpView.Avalonia</RootNamespace>
<Version>2.0.0-beta.50</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for AvaloniaUI.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<Nullable>enable</Nullable>
Expand All @@ -7,7 +7,7 @@
<TargetFrameworks>net462;netcoreapp3.0</TargetFrameworks>
<AssemblyName>LiveChartsCore.SkiaSharpView.WPF</AssemblyName>
<RootNamespace>LiveChartsCore.SkiaSharpView.WPF</RootNamespace>
<Version>2.0.0-beta.50</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for WPF.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
26 changes: 12 additions & 14 deletions src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/CartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace LiveChartsCore.SkiaSharpView.WinForms
{
Expand Down Expand Up @@ -61,8 +62,6 @@ public CartesianChart() : this(null, null) { }
public CartesianChart(IChartTooltip<SkiaSharpDrawingContext>? tooltip = null, IChartLegend<SkiaSharpDrawingContext>? legend = null)
: base(tooltip, legend)
{
var s = PointStates;

_seriesObserver = new CollectionDeepObserver<ISeries>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
_xObserver = new CollectionDeepObserver<IAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
_yObserver = new CollectionDeepObserver<IAxis>(OnDeepCollectionChanged, OnDeepCollectionPropertyChanged, true);
Expand Down Expand Up @@ -93,7 +92,7 @@ public IEnumerable<ISeries> Series
_seriesObserver.Dispose(_series);
_seriesObserver.Initialize(value);
_series = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -107,7 +106,7 @@ public IEnumerable<IAxis> XAxes
_xObserver.Dispose(_xAxes);
_xObserver.Initialize(value);
_xAxes = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -121,7 +120,7 @@ public IEnumerable<IAxis> YAxes
_yObserver.Dispose(_yAxes);
_yObserver.Initialize(value);
_yAxes = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -135,7 +134,7 @@ public IEnumerable<Section<SkiaSharpDrawingContext>> Sections
_sectionsObserverer.Dispose(_sections);
_sectionsObserverer.Initialize(value);
_sections = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -147,7 +146,7 @@ public DrawMarginFrame<SkiaSharpDrawingContext>? DrawMarginFrame
set
{
_drawMarginFrame = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -169,6 +168,7 @@ public DrawMarginFrame<SkiaSharpDrawingContext>? DrawMarginFrame
protected override void InitializeCore()
{
core = new CartesianChart<SkiaSharpDrawingContext>(this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore);
if (DesignerMode) return;
core.Update();
}

Expand All @@ -182,17 +182,15 @@ public double[] ScaleUIPoint(PointF point, int xAxisIndex = 0, int yAxisIndex =

private void OnDeepCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (core is null) return;
core.Update();
OnPropertyChanged();
}

private void OnDeepCollectionPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (core is null) return;
core.Update();
OnPropertyChanged();
}

private void OnMouseWheel(object? sender, System.Windows.Forms.MouseEventArgs e)
private void OnMouseWheel(object? sender, MouseEventArgs e)
{
if (core is null) throw new Exception("core not found");
var c = (CartesianChart<SkiaSharpDrawingContext>)core;
Expand All @@ -201,12 +199,12 @@ private void OnMouseWheel(object? sender, System.Windows.Forms.MouseEventArgs e)
Capture = true;
}

private void OnMouseDown(object? sender, System.Windows.Forms.MouseEventArgs e)
private void OnMouseDown(object? sender, MouseEventArgs e)
{
core?.InvokePointerDown(new PointF(e.Location.X, e.Location.Y));
}

private void OnMouseUp(object? sender, System.Windows.Forms.MouseEventArgs e)
private void OnMouseUp(object? sender, MouseEventArgs e)
{
core?.InvokePointerUp(new PointF(e.Location.X, e.Location.Y));
}
Expand Down
2 changes: 1 addition & 1 deletion src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void SyncAction(Action action)
/// <returns></returns>
protected void OnPropertyChanged()
{
if (core is null) return;
if (core is null || DesignerMode) return;
core.Update();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<TargetFrameworks>net462;netcoreapp3.0</TargetFrameworks>
<AssemblyName>LiveChartsCore.SkiaSharpView.WinForms</AssemblyName>
<RootNamespace>LiveChartsCore.SkiaSharpView.WinForms</RootNamespace>
<Version>2.0.0-beta.55</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for WindowsForms.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
9 changes: 4 additions & 5 deletions src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/PieChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ public PieChart(IChartTooltip<SkiaSharpDrawingContext>? tooltip = null, IChartLe
_seriesObserver = new CollectionDeepObserver<ISeries>(
(object? sender, NotifyCollectionChangedEventArgs e) =>
{
if (core is null) return;
core.Update();
OnPropertyChanged();
},
(object? sender, PropertyChangedEventArgs e) =>
{
if (core is null) return;
core.Update();
OnPropertyChanged();
},
true);
}
Expand All @@ -79,7 +77,7 @@ public IEnumerable<ISeries> Series
_seriesObserver.Dispose(_series);
_seriesObserver.Initialize(value);
_series = value;
core?.Update();
OnPropertyChanged();
}
}

Expand All @@ -98,6 +96,7 @@ public IEnumerable<ISeries> Series
protected override void InitializeCore()
{
core = new PieChart<SkiaSharpDrawingContext>(this, LiveChartsSkiaSharp.DefaultPlatformBuilder, motionCanvas.CanvasCore);
if (DesignerMode) return;
core.Update();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
<AssemblyName>LiveChartsCore.SkiaSharpView.XamarinForms</AssemblyName>
<RootNamespace>LiveChartsCore.SkiaSharpView.XamarinForms</RootNamespace>
<Version>2.0.0-beta.50</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for XamarinForms.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net462;netstandard2.0;netcoreapp2.0;</TargetFrameworks>
<AssemblyName>LiveChartsCore.SkiaSharpView</AssemblyName>
<RootNamespace>LiveChartsCore.SkiaSharpView</RootNamespace>
<Version>2.0.0-beta.50</Version>
<Version>2.0.0-beta.60</Version>
<PackageIcon>icon.png</PackageIcon>
<Description>Simple, flexible, interactive and powerful data visualization for .Net, this package contains the SkiaSharp backend.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Loading

0 comments on commit 84378fc

Please sign in to comment.