diff --git a/Directory.Build.props b/Directory.Build.props index f6e74488a..059e328b1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 2.0.0-rc5 + 2.0.0-rc5.1 BetoRodriguez 12.0 diff --git a/docs/overview/1.2.install.md b/docs/overview/1.2.install.md index 48918b115..2f400cd65 100644 --- a/docs/overview/1.2.install.md +++ b/docs/overview/1.2.install.md @@ -465,9 +465,9 @@ install a package from NuGet, please follow [this guide](https://docs.microsoft. > LiveChartsCore.SkiaSharpView.Maui -## Register SkiaSharp +## Register SkiaSharp and LiveCharts Handlers -This is a requirement by SkiaSharp, in the solution explorer, browse for the `MauiProgram` class and register SkiaSharp in the application: +You must register SkiaSharp and LiveCharts handlers now, browse for the `MauiProgram` class and add `.UseSkiaSharp()` and `.UseLiveCharts()`:
using Microsoft.Maui.Controls.Hosting;
 using Microsoft.Maui.Hosting;
@@ -482,7 +482,8 @@ namespace MauiApp
             var builder = MauiApp.CreateBuilder();
             builder
                 .UseSkiaSharp() // mark
-                .UseMauiApp()
+                .UseLiveCharts() // mark
+                .UseMauiApp<App>()
                 .ConfigureFonts(fonts =>
                 {
                     fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
diff --git a/docs/samples/events/tutorial/result.gif b/docs/samples/events/tutorial/result.gif
index 72aa55cb3..d7cca624a 100644
Binary files a/docs/samples/events/tutorial/result.gif and b/docs/samples/events/tutorial/result.gif differ
diff --git a/docs/samples/general/visualElements/template.md b/docs/samples/general/visualElements/template.md
index dc5a7db02..ad79de048 100644
--- a/docs/samples/general/visualElements/template.md
+++ b/docs/samples/general/visualElements/template.md
@@ -6,6 +6,12 @@ the creation and destruction of the drawn geometries in the canvas.
 
 In the next example, we create a `CartesianChart`, this chart contains multiple visual elements, each visual element is defined below in this article:
 
+## View Model
+
+```
+{{ full_name | get_vm_from_docs }}
+```
+
 {{~ if xaml ~}}
 ## XAML
 {{~ end ~}}
@@ -59,8 +65,8 @@ Use the `VariableSVGPathGeometry` as the `DrawnElement` to draw svg paths:
 The easiest way is to inherit from `DrawnGeometry`, this class implements `IDrawnElement` and also animates all of its properties;
 In the next example we inherit from `BoundedDrawnGeometry` it only adds the `Width` and `Height` properties to the `DrawnGeometry` class.
 
-
- sample image +
+ sample image
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/General/VisualElements/CustomSkiaShape.cs" ~}} @@ -96,8 +102,8 @@ Used to place children on its own coordinate system, all the children X and Y co the size of the largest element in the children collection. For example in the next case, we place the place the RectangleGeometry` in the 0,0 coordinate [in the layout system] and the `LabelGeometry` in the 10,0 coordinate. -
- sample image +
+ sample image
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/General/VisualElements/AbsoluteVisual.cs" ~}} @@ -106,8 +112,8 @@ coordinate [in the layout system] and the `LabelGeometry` in the 10,0 coordinate Stacks `IDrawnElement` objects in vertical or horizontal order. -
- sample image +
+ sample image
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/General/VisualElements/StackedVisual.cs" ~}} @@ -116,8 +122,8 @@ Stacks `IDrawnElement` objects in vertical or horizontal order. Uses a grid system to place `IDrawnElement` objects. -
- sample image +
+ sample image
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/General/VisualElements/TableVisual.cs" ~}} diff --git a/src/LiveChartsCore/LiveChartsCore.csproj b/src/LiveChartsCore/LiveChartsCore.csproj index b571a2347..3c02e96de 100644 --- a/src/LiveChartsCore/LiveChartsCore.csproj +++ b/src/LiveChartsCore/LiveChartsCore.csproj @@ -11,15 +11,29 @@ $(TargetFrameworks); net462; - net8.0-windows10.0.19041.0;net8.0-windows10.0.20348.0; + + net6.0-windows; + net8.0-windows; + net6.0-windows10.0.19041.0; + net8.0-windows10.0.19041.0; 11.0 13.1 21.0 10.0.17763.0 - 10.0.17763.0 6.5 + 10.0.17763.0 + 7.0 LiveChartsCore LiveChartsCore diff --git a/src/LiveChartsCore/Motion/MotionProperty.cs b/src/LiveChartsCore/Motion/MotionProperty.cs index 13f76790a..5d22d79f4 100644 --- a/src/LiveChartsCore/Motion/MotionProperty.cs +++ b/src/LiveChartsCore/Motion/MotionProperty.cs @@ -95,7 +95,11 @@ public void CopyFrom(IMotionProperty source) /// The instance that is moving. public void SetMovement(T value, Animatable animatable) { - if (value is not null && value.Equals(toValue)) return; + // the next commented line was added from rc4 to rc5, this caused + // https://github.com/beto-rodriguez/LiveCharts2/issues/1768 + // i dont exactly remember why i added it :( + // lets leave things as they were before. + //if (value is not null && value.Equals(toValue)) return; fromValue = GetMovement(animatable); toValue = value; diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj index b26272aac..9bdede4b0 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/LiveChartsCore.SkiaSharpView.WPF.csproj @@ -5,7 +5,23 @@ $(GlobalLangVersion) true - net462;net6.0-windows10.0.19041;net8.0-windows10.0.19041 + + net462; + + net6.0-windows; + net8.0-windows; + net6.0-windows10.0.19041; + net8.0-windows10.0.19041 + LiveChartsCore.SkiaSharpView.WPF LiveChartsCore.SkiaSharpView.WPF $(LiveChartsVersion) @@ -31,8 +47,35 @@ - - + + + + + + + diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/MotionCanvas.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/MotionCanvas.cs index 7c481f434..f5fc2c868 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/MotionCanvas.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WPF/MotionCanvas.cs @@ -40,7 +40,10 @@ namespace LiveChartsCore.SkiaSharpView.WPF; public class MotionCanvas : UserControl { private SKElement? _skiaElement; +#if NET6_0_OR_GREATER + // workaround #250115 private SKGLElement? _skiaGlElement; +#endif private bool _isDrawingLoopRunning = false; /// @@ -90,8 +93,15 @@ private void InitializeElement() { if (LiveCharts.UseGPU) { +#if NET6_0_OR_GREATER + // workaround #250115 Content = _skiaGlElement = new SKGLElement(); _skiaGlElement.PaintSurface += OnPaintGlSurface; +#else + throw new PlatformNotSupportedException( + "GPU rendering is only supported in .NET 6.0 or greater, " + + "because https://github.com/mono/SkiaSharp/issues/3111 needs to be fixed."); +#endif } else { @@ -136,7 +146,10 @@ private async void RunDrawingLoop() while (!CanvasCore.IsValid) { _skiaElement?.InvalidateVisual(); +#if NET6_0_OR_GREATER + // workaround #250115 _skiaGlElement?.InvalidateVisual(); +#endif await Task.Delay(ts); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj index 35a00e417..3fcee6684 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/LiveChartsCore.SkiaSharpView.WinForms.csproj @@ -7,7 +7,24 @@ WinExe true Library - net462;net6.0-windows10.0.19041;net8.0-windows10.0.19041 + + net462; + + net6.0-windows; + net8.0-windows; + net6.0-windows10.0.19041; + net8.0-windows10.0.19041 + + LiveChartsCore.SkiaSharpView.WinForms LiveChartsCore.SkiaSharpView.WinForms $(LiveChartsVersion) @@ -33,8 +50,35 @@ - - + + + + + + + diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.Designer.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.Designer.cs index 71133bb12..8b5a8ddbf 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.Designer.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.Designer.cs @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System; using System.Windows.Forms; using SkiaSharp.Views.Desktop; @@ -55,12 +56,19 @@ private void InitializeComponent() { if (LiveCharts.UseGPU) { +#if NET6_0_OR_GREATER + // workaround #250115 this._skglControl = new SKGLControl(); this._skglControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; this._skglControl.Size = new System.Drawing.Size(1000, 1000); this._skglControl.TabIndex = 1; this._skglControl.PaintSurface += new System.EventHandler(this.SkglControl_PaintSurface); this.Controls.Add(this._skglControl); +#else + throw new PlatformNotSupportedException( + "GPU rendering is only supported in .NET 6.0 or greater, " + + "because https://github.com/mono/SkiaSharp/issues/3111 needs to be fixed."); +#endif } else { @@ -78,9 +86,13 @@ private void InitializeComponent() this.ResumeLayout(false); } - #endregion +#endregion private SKControl _skControl; + +#if NET6_0_OR_GREATER + // workaround #250115 private SKGLControl _skglControl; +#endif } } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs index 327421df3..0b0f33e93 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharp.WinForms/MotionCanvas.cs @@ -26,7 +26,6 @@ using System.Windows.Forms; using LiveChartsCore.Motion; using LiveChartsCore.SkiaSharpView.Drawing; -using SkiaSharp; using SkiaSharp.Views.Desktop; namespace LiveChartsCore.SkiaSharpView.WinForms; @@ -76,12 +75,15 @@ private void SkControl_PaintSurface(object sender, SKPaintSurfaceEventArgs e) => CanvasCore.DrawFrame( new SkiaSharpDrawingContext(CanvasCore, e.Info, e.Surface, e.Surface.Canvas)); +#if NET6_0_OR_GREATER + // workaround #250115 private void SkglControl_PaintSurface(object sender, SKPaintGLSurfaceEventArgs e) => CanvasCore.DrawFrame( new SkiaSharpDrawingContext(CanvasCore, e.Info, e.Surface, e.Surface.Canvas) { - Background = new SKColor(Parent.BackColor.R, Parent.BackColor.G, Parent.BackColor.B) + Background = new SkiaSharp.SKColor(Parent!.BackColor.R, Parent.BackColor.G, Parent.BackColor.B) }); +#endif private void CanvasCore_Invalidated(CoreMotionCanvas sender) => RunDrawingLoop(); @@ -96,7 +98,10 @@ private async void RunDrawingLoop() while (!CanvasCore.IsValid) { _skControl?.Invalidate(); +#if NET6_0_OR_GREATER + // workaround #250115 _skglControl?.Invalidate(); +#endif await Task.Delay(ts); } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj b/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj index d54e6c15b..bc8e66442 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj +++ b/src/skiasharp/LiveChartsCore.SkiaSharp/LiveChartsCore.SkiaSharpView.csproj @@ -11,15 +11,29 @@ $(TargetFrameworks); net462; - net8.0-windows10.0.19041.0;net8.0-windows10.0.20348.0; - + + net6.0-windows; + net8.0-windows; + net8.0-windows10.0.19041.0; + net8.0-windows10.0.20348.0; + 11.0 13.1 21.0 10.0.17763.0 - 10.0.17763.0 6.5 + 10.0.17763.0 + 7.0 LiveChartsCore.SkiaSharpView LiveChartsCore.SkiaSharpView diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/ChartView.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/ChartView.cs index a22535b0d..72cd113da 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/ChartView.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/ChartView.cs @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +using System; using Microsoft.Maui.Controls; namespace LiveChartsCore.SkiaSharpView.Maui; @@ -29,6 +30,17 @@ namespace LiveChartsCore.SkiaSharpView.Maui; /// public abstract class ChartView : ContentView { + static ChartView() + { + if (!LiveChartsCoreMauiAppBuilderExtensions.AreHandlersRegistered) + { + throw new InvalidOperationException( + "Since rc5 version, `.UseLiveCharts()` and `.UseSkiaSharp()` must be " + + "chained to `.UseMauiApp()`, in the MauiProgram.cs file. For more info see:" + + "https://livecharts.dev/docs/Maui/2.0.0-rc5/Overview.Installation"); + } + } + internal virtual void OnPressed(object? sender, Behaviours.Events.PressedEventArgs args) { } internal virtual void OnMoved(object? sender, Behaviours.Events.ScreenEventArgs args) { } internal virtual void OnReleased(object? sender, Behaviours.Events.PressedEventArgs args) { } diff --git a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCoreMauiAppBuilderExtensions.cs b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCoreMauiAppBuilderExtensions.cs index 55c32740c..218d9711b 100644 --- a/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCoreMauiAppBuilderExtensions.cs +++ b/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCoreMauiAppBuilderExtensions.cs @@ -29,11 +29,19 @@ namespace LiveChartsCore.SkiaSharpView.Maui; /// public static class LiveChartsCoreMauiAppBuilderExtensions { + internal static bool AreHandlersRegistered { get; private set; } + /// /// Adds LiveCharts components to the MAUI app. /// /// /// - public static MauiAppBuilder UseLiveCharts(this MauiAppBuilder mauiAppBuilder) => - mauiAppBuilder.ConfigureMauiHandlers(handlers => handlers.AddHandler()); + public static MauiAppBuilder UseLiveCharts(this MauiAppBuilder mauiAppBuilder) + { + AreHandlersRegistered = true; + + return mauiAppBuilder.ConfigureMauiHandlers( + handlers => + handlers.AddHandler()); + } }