Skip to content

Commit

Permalink
Merge pull request #1352 from beto-rodriguez/dev
Browse files Browse the repository at this point in the history
rc2
  • Loading branch information
beto-rodriguez authored Nov 11, 2023
2 parents b0e32c2 + cda1e0a commit 5836c7f
Show file tree
Hide file tree
Showing 491 changed files with 4,173 additions and 3,578 deletions.
388 changes: 3 additions & 385 deletions LiveCharts.sln

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build/pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ param([string]$configuration = "Debug", [string]$nupkgOutputPath = "./nupkg")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharp.Xamarin.Forms/LiveChartsCore.SkiaSharpView.Xamarin.Forms.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Blazor/LiveChartsCore.SkiaSharpView.Blazor.csproj")
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Eto/LiveChartsCore.SkiaSharpView.Eto.csproj")
[Project]::new("./src/LiveChartsCore.Behaviours/LiveChartsCore.Behaviours.csproj", $true)
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Maui/LiveChartsCore.SkiaSharpView.Maui.csproj", $true)
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno/LiveChartsCore.SkiaSharpView.Uno.csproj", $true)
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj", $true)
[Project]::new("./src/skiasharp/LiveChartsCore.SkiaSharpView.Uno.WinUI/LiveChartsCore.SkiaSharpView.Uno.WinUI.csproj", $true),
[Project]::new(
"./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.csproj",
$true,
"nuget",
"./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.nuspec"
"./src/LiveChartsCore.Behaviours/LiveChartsCore.Behaviours.csproj", $true,
"nuget", "./src/LiveChartsCore.Behaviours/LiveChartsCore.Behaviours.nuspec")
[Project]::new(
"./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.csproj", $true,
"nuget", "./src/skiasharp/LiveChartsCore.SkiaSharpView.WinUI/LiveChartsCore.SkiaSharpView.WinUI.nuspec"
)
)

Expand Down
36 changes: 13 additions & 23 deletions docs/overview/1.5.mappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ the `TempSample` class by setting a Mapper or implementing `IChartEntity` in our

## Mappers

Mappers are the easiest way but has a performance cost, a mapper is a method that takes both the `instance`
(each `TempSample` in our data collection) and the `point` (that LiveCharts assigned) as parameters, inside this function we must
specify the X and Y coordinates in our chart.
Mappers are the easiest way but has a performance cost, a mapper is a function that takes both: the `instance`
(each `TempSample` in our data collection) and the `index` of the instance in the collection as parameters,
and returns a `Coordinate` in the chart.

```c#
using var streamReader = new StreamReader("data.json");
Expand All @@ -86,15 +86,9 @@ var chart = new SKCartesianChart
new LineSeries<TempSample>
{
Values = samples,
Mapping = (sample, chartPoint) => // mark
{ // mark
// use the Temperature property in the Y axis // mark
// and the Time property in the X axis // mark
chartPoint.Coordinate = new(sample.Time, sample.Temperature);

// sometimes it is useful to use the index of the instance in the array as the X coordinate: // mark
// chartPoint.SecondaryValue = chartPoint.Index; // mark
} // mark
// use the Temperature property in the Y axis // mark
// and the Time property in the X axis // mark
Mapping = (sample, index) => new(sample.Time, sample.Temperature) // mark
}
},
XAxes = new[] { new Axis { Labeler = value => $"{value} seconds" } },
Expand All @@ -108,19 +102,14 @@ Now it works! You can also register the mapper globally, this means that every t
chart all over our application, the library will use the mapper we indicated.

``` c#
// ideally this code must be placed where your application or view starts
// ideally this code must be placed where your application starts
LiveCharts.Configure(config =>
config
.HasMap<TempSample>(
(sample, chartPoint) =>
{
chartPoint.PrimaryValue = sample.Temperature;
chartPoint.SecondaryValue = sample.Time;
}));
config.HasMap<TempSample>(
(sample, index) => new(sample.Time, sample.Temperature));
```

Global mappers are unique for a type, this means that every time a `TempSample` instance is in a chart, LiveCharts will use this mapper,
if You register again a global mapper for the `TempSample` class, then the previous will be replaced by the new one.
if you register again a global mapper for the `TempSample` class, then the previous will be replaced by the new one.
If the series specifies the `Mapping` property, then the global mapper will be ignored and instead it will use the series instance mapper.

<a href="https://github.com/beto-rodriguez/LiveCharts2/blob/master/samples/MappersSamples/Program.cs" class="btn btn-light btn-lg text-primary shadow-sm mb-3">
Expand All @@ -129,8 +118,9 @@ If the series specifies the `Mapping` property, then the global mapper will be i

## IChartEntity

The `IChartEntity` interface force our points to have a [Coordinate](https://lvcharts.com/api/2.0.0-beta.710/LiveChartsCore.Kernel.Coordinate), LiveCharts will use this property to build the plot, when the interface is implemented correctly, you will notice a considerable
performance improvement, specially in large data sets.
The `IChartEntity` interface forces our points to have a [Coordinate](https://lvcharts.com/api/2.0.0-beta.710/LiveChartsCore.Kernel.Coordinate),
LiveCharts will use this property to build the plot, when the interface is implemented correctly, you will notice a considerable
performance improvement, specially on large data sets.

Imagine the same case we used in the previous sample where we have a json file that contains the temperature of a CPU at a given time,
we want to build a chart with that data.
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For Uno, open ./samples/UnoPlatform_v5/UnoPlatform_v5.sln
8 changes: 3 additions & 5 deletions samples/AvaloniaSample/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public override void Initialize()
// finally register your own mappers
// you can learn more about mappers at:
// https://livecharts.dev/docs/{{ platform }}/{{ version }}/Overview.Mappers
.HasMap<City>((city, point) => // mark
{ // mark
// here we use the index as X, and the population as Y // mark
point.Coordinate = new(point.Index, city.Population); // mark
}) // mark

// here we use the index as X, and the population as Y // mark
.HasMap<City>((city, index) => new(index, city.Population)) // mark
// .HasMap<Foo>( .... ) // mark
// .HasMap<Bar>( .... ) // mark
); // mark
Expand Down
13 changes: 13 additions & 0 deletions samples/AvaloniaSample/General/DrawOnCanvas/View.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<UserControl x:Class="AvaloniaSample.General.DrawOnCanvas.View"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
xmlns:vms="using:ViewModelsSamples.General.DrawOnCanvas">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>

<Grid>
<lvc:CartesianChart UpdateStartedCommand="{Binding ChartUpdatedCommand}"/>
</Grid>
</UserControl>
17 changes: 17 additions & 0 deletions samples/AvaloniaSample/General/DrawOnCanvas/View.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace AvaloniaSample.General.DrawOnCanvas;

public partial class View : UserControl
{
public View()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
8 changes: 3 additions & 5 deletions samples/BlazorSample/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
// finally register your own mappers
// you can learn more about mappers at:
// https://livecharts.dev/docs/{{ platform }}/{{ version }}/Overview.Mappers
.HasMap<City>((city, point) => // mark
{ // mark
// here we use the index as X, and the population as Y // mark
point.Coordinate = new(point.Index, city.Population); // mark
}) // mark
// here we use the index as X, and the population as Y // mark
.HasMap<City>((city, index) => new(index, city.Population)) // mark
// .HasMap<Foo>( .... ) // mark
// .HasMap<Bar>( .... ) // mark
); // mark
Expand Down
22 changes: 22 additions & 0 deletions samples/BlazorSample/Pages/General/DrawOnCanvas.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@page "/General/DrawOnCanvas"
@using LiveChartsCore.SkiaSharpView.Blazor
@using ViewModelsSamples.General.DrawOnCanvas

<CartesianChart
@ref="chart">
</CartesianChart>

@code {
public CartesianChart chart = null!;
public ViewModel ViewModel { get; set; } = new();

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);

chart.UpdateStarted += chart =>
{
ViewModel.ChartUpdated(new(chart));
};
}
}
3 changes: 1 addition & 2 deletions samples/BlazorSample/Pages/Hello.razor
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
<p class="text-center text-muted">
LiveCharts provides controls for any UI framework (console and server-side is also supported). <br />
<small class="text-center text-muted">
The minimum requirement for .Net framework is .Net 4.6.2 and is compatible with is compatible
with .NET standard 2.0.
The minimum requirement for .Net framework is .Net 4.6.2 and is compatible with .NET standard 2.0.
</small>
</p>

Expand Down
23 changes: 23 additions & 0 deletions samples/EtoFormsSample/General/DrawOnCanvas/View.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Eto.Forms;
using LiveChartsCore.SkiaSharpView.Eto;
using ViewModelsSamples.General.DrawOnCanvas;

namespace EtoFormsSample.General.DrawOnCanvas;

public class View : Panel
{
private readonly CartesianChart cartesianChart;

public View()
{
var viewModel = new ViewModel();

cartesianChart = new CartesianChart();
cartesianChart.UpdateStarted += chart =>
{
viewModel.ChartUpdated(new(chart));
};

Content = cartesianChart;
}
}
12 changes: 5 additions & 7 deletions samples/EtoFormsSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ static void Main()
// finally register your own mappers
// you can learn more about mappers at:
// https://livecharts.dev/docs/{{ platform }}/{{ version }}/Overview.Mappers
.HasMap<City>((city, point) => // mark
{ // mark
// here we use the index as X, and the population as Y // mark
point.Coordinate = new(point.Index, city.Population); // mark
}) // mark
// .HasMap<Foo>( .... ) // mark
// .HasMap<Bar>( .... ) // mark

// here we use the index as X, and the population as Y // mark
.HasMap<City>((city, index) => new(index, city.Population)) // mark
// .HasMap<Foo>( .... ) // mark
// .HasMap<Bar>( .... ) // mark
); // mark

new Application(Eto.Platform.Detect).Run(new Form1());
Expand Down
28 changes: 8 additions & 20 deletions samples/MappersSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@
{
new LineSeries<TempSample>
{
Mapping = (tempSample, chartPoint) =>
{
// we set the X coordinate to the Time property
// and the Y coordinate to the Temperature property
chartPoint.Coordinate = new(tempSample.Time, tempSample.Temperature);
},
// we set the X coordinate to the Time property
// and the Y coordinate to the Temperature property
Mapping = (tempSample, index) => new(tempSample.Time, tempSample.Temperature),
Values = samples
}
},
Expand Down Expand Up @@ -68,12 +65,9 @@
{
new ColumnSeries<City>
{
Mapping = (city, chartPoint) =>
{
// we set the X coordinate to the index of the item in the array
// and the Y coordinate to the Population property
chartPoint.Coordinate = new(chartPoint.Index, city.Population);
},
// we set the X coordinate to the index of the item in the array
// and the Y coordinate to the Population property
Mapping = (city, index) => new(index, city.Population),
Values = cities
}
},
Expand All @@ -100,14 +94,8 @@
// this is useful when you have a lot of series and you don't want to repeat the mapping for each series.
LiveCharts.Configure(config =>
config
.HasMap<TempSample>((tempSample, chartPoint) =>
{
chartPoint.Coordinate = new(tempSample.Time, tempSample.Temperature);
})
.HasMap<City>((city, chartPoint) =>
{
chartPoint.Coordinate = new(chartPoint.Index, city.Population);
}));
.HasMap<TempSample>((tempSample, index) => new(tempSample.Time, tempSample.Temperature))
.HasMap<City>((city, index) => new(index, city.Population)));

Console.WriteLine("chart saved");

Expand Down
12 changes: 5 additions & 7 deletions samples/MauiSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ protected override void OnStart()

LiveCharts.Configure(config => // mark
config // mark
// you can override the theme
//.AddDarkTheme() // mark
// you can override the theme
//.AddDarkTheme() // mark

// In case you need a non-Latin based font, you must register a typeface for SkiaSharp
//.HasGlobalSKTypeface(SKFontManager.Default.MatchCharacter('汉')) // <- Chinese // mark
Expand All @@ -35,11 +35,9 @@ protected override void OnStart()
// finally register your own mappers
// you can learn more about mappers at:
// https://livecharts.dev/docs/{{ platform }}/{{ version }}/Overview.Mappers
.HasMap<City>((city, point) => // mark
{ // mark
// here we use the index as X, and the population as Y // mark
point.Coordinate = new(point.Index, city.Population); // mark
}) // mark

// here we use the index as X, and the population as Y // mark
.HasMap<City>((city, index) => new(index, city.Population)) // mark
// .HasMap<Foo>( .... ) // mark
// .HasMap<Bar>( .... ) // mark
); // mark
Expand Down
4 changes: 3 additions & 1 deletion samples/MauiSample/Axes/Crosshairs/View.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
</Grid.RowDefinitions>

<lvc:CartesianChart
Series="{Binding Series}">
Series="{Binding Series}"
XAxes="{Binding XAxes}"
YAxes="{Binding YAxes}">
</lvc:CartesianChart>
</Grid>
</ContentPage.Content>
Expand Down
16 changes: 16 additions & 0 deletions samples/MauiSample/General/DrawOnCanvas/View.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiSample.General.DrawOnCanvas.View"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Maui;assembly=LiveChartsCore.SkiaSharpView.Maui"
xmlns:vms="clr-namespace:ViewModelsSamples.General.DrawOnCanvas;assembly=ViewModelsSamples"
>
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<ContentPage.Content>
<Grid>
<lvc:CartesianChart UpdateStartedCommand="{Binding ChartUpdatedCommand}"/>
</Grid>
</ContentPage.Content>
</ContentPage>
10 changes: 10 additions & 0 deletions samples/MauiSample/General/DrawOnCanvas/View.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MauiSample.General.DrawOnCanvas;

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class View : ContentPage
{
public View()
{
InitializeComponent();
}
}
19 changes: 19 additions & 0 deletions samples/UWPSample/General/DrawOnCanvas/View.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<UserControl
x:Class="UWPSample.General.DrawOnCanvas.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Uno"
xmlns:vms="using:ViewModelsSamples.General.DrawOnCanvas"
mc:Ignorable="d">

<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>

<Grid>
<lvc:CartesianChart UpdateStartedCommand="{Binding ChartUpdatedCommand}"/>
</Grid>

</UserControl>
12 changes: 12 additions & 0 deletions samples/UWPSample/General/DrawOnCanvas/View.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Windows.UI.Xaml.Controls;

namespace UWPSample.General.DrawOnCanvas
{
public sealed partial class View : UserControl
{
public View()
{
InitializeComponent();
}
}
}
7 changes: 7 additions & 0 deletions samples/UWPSample/UWPSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@
<Compile Include="General\Legends\View.xaml.cs">
<DependentUpon>View.xaml</DependentUpon>
</Compile>
<Compile Include="General\DrawOnCanvas\View.xaml.cs">
<DependentUpon>View.xaml</DependentUpon>
</Compile>
<Compile Include="General\RealTime\View.xaml.cs">
<DependentUpon>View.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -577,6 +580,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="General\DrawOnCanvas\View.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="General\RealTime\View.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Loading

0 comments on commit 5836c7f

Please sign in to comment.