Skip to content

Commit d37651c

Browse files
Merge pull request #1959 from beto-rodriguez/render-settings
Render settings
2 parents 77223d7 + 477222e commit d37651c

File tree

183 files changed

+4518
-1051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+4518
-1051
lines changed

LiveCharts.slnx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@
9999
<Deploy Solution="Release|Any CPU" />
100100
</Project>
101101
</Folder>
102+
<Folder Name="/Samples/Vortice/">
103+
<Project Path="samples/VorticeSample/LiveChartsCore.Vortice/LiveChartsCore.Vortice.csproj" Id="bcc252ec-ba03-4111-ba05-bb288cb25227">
104+
<BuildType Solution="Ad-Hoc|*" Project="Release" />
105+
<BuildType Solution="AppStore|*" Project="Release" />
106+
</Project>
107+
<Project Path="samples/VorticeSample/Vortice.SampleFramework/Vortice.SampleFramework.csproj">
108+
<BuildType Solution="Ad-Hoc|*" Project="Release" />
109+
<BuildType Solution="AppStore|*" Project="Release" />
110+
</Project>
111+
<Project Path="samples/VorticeSample/VorticeSample/VorticeSample.csproj" Id="e2407f57-51d0-49fb-8b90-6498ac17730c">
112+
<BuildType Solution="Ad-Hoc|*" Project="Release" />
113+
<BuildType Solution="AppStore|*" Project="Release" />
114+
</Project>
115+
</Folder>
102116
<Folder Name="/Samples/WinForms/">
103117
<Project Path="samples/WinFormsSample/WinFormsSample.csproj">
104118
<BuildType Solution="Ad-Hoc|*" Project="Release" />

docs/overview/1.2.install.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ LiveCharts controls do not have any size constraints, a quick fix is to explicit
552552
[#1581](https://github.com/beto-rodriguez/LiveCharts2/issues/1581).
553553
:::
554554

555-
## Configure themes, fonts, RTL rendering or mappers (Optional)
555+
## Configure themes, fonts, RTL and mappers (Optional)
556556

557557
Optionally you can configure LiveCharts to add a theme, register a global font,
558558
add a mapper for a type or enable `right to left` tooltips and legends; You can configure the library when your app starts:
@@ -629,3 +629,45 @@ pre-defined settings in the library.
629629
```
630630
{{ render this "~/../samples/ViewModelsSamples/LiveChartsAppSettings.cs" }}
631631
```
632+
633+
## Enable hardware acceleration
634+
635+
LiveCharts supports hardware accelerated views via SkiaSharp, by default the library is not
636+
hardware accelerated, this is because as today the GPU views for SkiaSharp are not as stable as the CPU
637+
views.
638+
639+
:::tip
640+
On Avalonia or Uno with the SkiaRenderer enabled, the LiveCharts settings for GPU/CPU control or
641+
VSync are ignored, since this is handled by Avalonia/Uno, LiveCharts just draws as the UI
642+
framework wants. It is normally already using hardware acceleration, but completely handled by the UI
643+
framework.
644+
:::
645+
646+
GPU improves the time it takes to render a frame, which results in smoother and more efficient animations,
647+
but as today, there are some known issues when using the SkiaSharp hardware accelerated views (specially when disposing/re-creating the controls), you can turn on hardware acceleration,
648+
the recommendation is to update SkiaSharp to the latest available version, then test if it works
649+
correctly for your case.
650+
651+
If you face an issue with the hardware accelerated views, ensure to identify if the issue belongs
652+
to SkiaSharp or LiveCharts; If the issue occurs on both CPU and GPU render modes, then the issue
653+
is most likely a LiveCharts issue, if it only happens when GPU is on, then it is most likely an
654+
issue with the hardware accelerated views of SkiaSharp.
655+
656+
```
657+
{{ render this "~/../samples/ViewModelsSamples/LiveChartsRenderSettings.cs" }}
658+
```
659+
660+
## Advanced rendering
661+
662+
SkiaSharp makes it easy to take the library to Android, iOS, Windows, MacOS, Tizen, Linux and the Web,
663+
but on advanced scenarios you can build your own backend, for example in the next example we use DirectX11
664+
via [Vortice.Windows](https://github.com/amerkoleci/Vortice.Windows) to render our chart. This gives us
665+
full control over the rendering pipeline, this has some benefits such as:
666+
667+
- Improved performance.
668+
- Potentially smaller `exe` files since we no longer need the Skia natives.
669+
- Potentially better AOT builds.
670+
671+
You can find the [Vortice sample](https://github.com/beto-rodriguez/LiveCharts2/tree/master/samples/VorticeSample) at the GitHub repo, it does not support all the features in the library, this
672+
example is just to demonstrate that LiveCharts dependency on SkiaSharp is optional; We can connect
673+
the library to any drawing engine.

generators/LiveChartsGenerators/XamlFriendlyObjectsGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ private static string GetConsumerAssemblyType(Compilation compilation, Cancellat
432432
"LiveChartsCore.SkiaSharpView.Uno.WinUI" => "WinUI",
433433
"LiveChartsCore.SkiaSharpView.Avalonia" => "Avalonia",
434434
"LiveChartsCore.SkiaSharpView.WPF" => "WPF",
435+
"LiveChartsCore.SkiaSharpView.Blazor" => "Blazor",
435436
"LiveChartsCore.SkiaSharpView.WinForms" => "WinForms",
436437
"LiveChartsCore.SkiaSharpView.Eto" => "WinForms",
437-
"LiveChartsCore.SkiaSharpView.Blazor" => "Blazor",
438-
_ => null
438+
_ => "WinForms" // as a default, use winforms which is just classic style properties
439439
};
440440
}
441441

global.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"sdk": {
3-
"version": "9.0.101",
4-
"rollForward": "latestFeature"
5-
},
6-
"msbuild-sdks": {
7-
"Uno.Sdk": "6.1.23"
8-
}
9-
}
2+
"sdk": {
3+
"version": "9.0.101",
4+
"rollForward": "latestFeature"
5+
},
6+
"msbuild-sdks": {
7+
"Uno.Sdk": "6.2.29"
8+
}
9+
}
Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using LiveChartsCore.Kernel;
22
using LiveChartsCore.SkiaSharpView;
3-
using SkiaSharp;
43

54
namespace ViewModelsSamples;
65

7-
public static class CustomLiveChartsExtensions
6+
public static partial class CustomLiveChartsExtensions
87
{
98
public static LiveChartsSettings AddLiveChartsAppSettings(this LiveChartsSettings settings) =>
109
settings
@@ -16,6 +15,9 @@ public static LiveChartsSettings AddLiveChartsAppSettings(this LiveChartsSetting
1615

1716
// adds a theme that is light or dark depending on the OS theme;
1817
// OS theme awareness is not supported in WPF, WinForms and ETO.
18+
// themes registered here are handled by livecharts and can be used
19+
// across all the supported UI frameworks, but you could also
20+
// use XAML based themes if your platform supports them.
1921
.AddDefaultTheme(
2022
// if neccessary, override the default theme, for more info see:
2123
// https://github.com/beto-rodriguez/LiveCharts2/blob/dev/samples/ViewModelsSamples/LiveChartsThemeExtensions.cs
@@ -46,44 +48,12 @@ public static LiveChartsSettings AddLiveChartsAppSettings(this LiveChartsSetting
4648
// City.Population as Y and the index as the X.
4749
(city, index) => new(index, city.Population)) // mark
4850

49-
// LiveCharts uses some defaults for text rendering, but you can
50-
// improve the configuration to fit your app needs.
51-
.HasTextSettings(new TextSettings
52-
{
53-
// A typeface to use as a default when a paint does not
54-
// explicitly set a typeface, this could improve the
55-
// text quality but requires the font to be installed.
56-
// example: SKTypeface.FromFamilyName("Arial")
57-
DefaultTypeface = SKTypeface.Default,
58-
59-
// This function is called every time text is drawn,
60-
// it allows you to configure the paint and font before
61-
// drawing, you could improve the text quality by changing
62-
// Edging, Hinting, etc.
63-
FontBuilder = (paint, typeface, size) =>
64-
{
65-
// This is the default used by LiveCharts:
66-
// you can improve this function to suit your needs.
67-
68-
paint.TextSize = size;
69-
paint.Typeface = typeface;
70-
paint.IsAntialias = true;
71-
paint.LcdRenderText = true;
72-
73-
return new SKFont(typeface, size)
74-
{
75-
Edging = SKFontEdging.SubpixelAntialias,
76-
Hinting = SKFontHinting.Normal
77-
};
78-
}
79-
})
80-
8151
// RTL (right-to-left) shaping is handled already in the library by Harfbuzz,
8252
// but we can enable RTL to force RTL tooltips and legends.
8353
// RTL settings are enabled when the system culture is RTL,
8454
// but you can also force the use of RTL settings by calling:
8555
//.UseRightToLeftSettings()
86-
;
56+
;
8757

8858
public record City(string Name, double Population);
8959
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using LiveChartsCore.Kernel;
2+
using LiveChartsCore.SkiaSharpView;
3+
using SkiaSharp;
4+
5+
namespace ViewModelsSamples;
6+
7+
public static partial class CustomLiveChartsExtensions
8+
{
9+
public static LiveChartsSettings AddLiveChartsRenderSettings(this LiveChartsSettings settings) =>
10+
settings
11+
// Configure the global rendering settings
12+
// this is the default configuration used by LiveCharts,
13+
// uncomment the lines below to override the defaults.
14+
// this has no effect in Avalonia or Uno with skia rendering.
15+
.HasRenderingSettings(settings =>
16+
{
17+
// enabling GPU may improve performance but could not be as stable as CPU rendering.
18+
// settings.UseGPU = false;
19+
20+
// when Vsync is enabled the charts will render in sync with the screen refresh rate,
21+
// this improves animations quiality and lets the system handle the refresh rate.
22+
// settings.TryUseVSync = true;
23+
24+
// if Vsync is disabled, then the charts will try to render at the specified FPS.
25+
// settings.LiveChartsRenderLoopFPS = 60;
26+
27+
// shows the current FPS in the top-left corner of the chart,
28+
// settings.ShowFPS = false;
29+
})
30+
31+
// LiveCharts uses some defaults for text rendering, but you can
32+
// improve the configuration to fit your app needs.
33+
.HasTextSettings(new TextSettings
34+
{
35+
// A typeface to use as a default when a paint does not
36+
// explicitly set a typeface, this could improve the
37+
// text quality but requires the font to be installed.
38+
// example: SKTypeface.FromFamilyName("Arial")
39+
DefaultTypeface = SKTypeface.Default,
40+
41+
// This function is called every time text is drawn,
42+
// it allows you to configure the paint and font before
43+
// drawing, you could improve the text quality by changing
44+
// Edging, Hinting, etc.
45+
FontBuilder = (paint, typeface, size) =>
46+
{
47+
// This is the default used by LiveCharts:
48+
// you can improve this function to suit your needs.
49+
50+
paint.TextSize = size;
51+
paint.Typeface = typeface;
52+
paint.IsAntialias = true;
53+
paint.LcdRenderText = true;
54+
55+
return new SKFont(typeface, size)
56+
{
57+
Edging = SKFontEdging.SubpixelAntialias,
58+
Hinting = SKFontHinting.Normal
59+
};
60+
}
61+
})
62+
63+
// advanced settings, register your own rendering factory, for example:
64+
// https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/MotionCanvas.cs#L43
65+
// in that link we use the CPU or GPU render mode depending on the user settings, the GPU uses
66+
// the SkiaSharp hardware accelerated views.
67+
//.HasRenderingFactory(
68+
// (settings, forceGPU) =>
69+
// {
70+
// // return your renderer here.
71+
// })
72+
;
73+
}

src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/IBlazorChart.cs renamed to samples/VorticeSample/LiveChartsCore.Vortice/Axis.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,13 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
using Microsoft.AspNetCore.Components;
23+
using LiveChartsCore.Kernel.Sketches;
24+
using LiveChartsCore.Vortice.Drawing.Geometries;
2425

25-
namespace LiveChartsCore.SkiaSharpView.Blazor;
26+
namespace LiveChartsCore.Vortice;
2627

27-
/// <summary>
28-
/// Defines a blazor chart.
29-
/// </summary>
30-
public interface IBlazorChart
28+
/// <inheritdoc cref="ICartesianAxis" />
29+
public class Axis : CoreAxis<LabelGeometry, LineGeometry>
3130
{
32-
/// <summary>
33-
/// Gets the canvas element.
34-
/// </summary>
35-
ElementReference CanvasContainerElement { get; }
3631

37-
/// <summary>
38-
/// Gets or sets the container css class.
39-
/// </summary>
40-
string ContainerClass { get; set; }
4132
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The MIT License(MIT)
2+
//
3+
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
namespace LiveChartsCore.Vortice;
24+
25+
public class CartesianChart : LiveChartsGeneratedCode.CartesianChart
26+
{
27+
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// The MIT License(MIT)
2+
//
3+
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
using LiveChartsCore.Vortice.Drawing.Geometries;
24+
25+
namespace LiveChartsCore.Vortice;
26+
27+
public class ColumnSeries<TModel>
28+
: CoreColumnSeries<TModel, RoundedRectangleGeometry, LabelGeometry, LineGeometry>
29+
{
30+
public ColumnSeries()
31+
: base(null)
32+
{ }
33+
34+
public ColumnSeries(IReadOnlyCollection<TModel>? values)
35+
: base(values)
36+
{ }
37+
38+
public ColumnSeries(params TModel[] values)
39+
: base(values)
40+
{ }
41+
}

0 commit comments

Comments
 (0)