-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1811 from beto-rodriguez/dev
RC 5.2
- Loading branch information
Showing
73 changed files
with
874 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,98 @@ | ||
{{ render this "~/shared/genericSampleJustGif.md" }} | ||
{{ render this "~/shared/genericSampleJustGifHeader.md" }} | ||
|
||
#### View model | ||
|
||
``` | ||
{{ full_name | get_vm_from_docs }} | ||
``` | ||
|
||
{{~ if xaml ~}} | ||
#### XAML | ||
{{~ end ~}} | ||
|
||
{{~ if winforms ~}} | ||
#### Form code behind | ||
{{~ end ~}} | ||
|
||
{{~ if blazor~}} | ||
#### HTML | ||
{{~ end~}} | ||
|
||
``` | ||
{{ full_name | get_view_from_docs }} | ||
``` | ||
|
||
# Custom needle | ||
|
||
You can inherit from `NeedleGeometry` to change the aspect of the needle, for example in the next code snippet, | ||
the `SmallNeedle` class inherits from `NeedleGeometry`, then in the constructor it sets the `ScaleTransform` | ||
property to `0.6` in the `X` and `Y` axis, this will make the needle 40% smaller. | ||
|
||
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/Pies/AngularGauge/SmallNeedle.cs" ~}} | ||
|
||
Finally we need to use this new needle in our gauge, in the example above change the type `NeedleVisual` | ||
to `NeedleVisual<SmallNeedle>`. | ||
|
||
```c# | ||
public partial class ViewModel | ||
{ | ||
// ... | ||
public NeedleVisual<SmallNeedle> Needle { get; set; } | ||
|
||
public ViewModel() | ||
{ | ||
Needle = new NeedleVisual<SmallNeedle> | ||
{ | ||
Value = 45 | ||
}; | ||
|
||
// ... | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
Run the app again, now the needle is 40% smaller. | ||
|
||
You can also override the `Draw()` method and use SkiaSharp to create your own needle, in the next snippet, | ||
we are drawing a rectangle using SkiaSharp to represent the needle: | ||
|
||
{{~ render_params_file_as_code this "~/../samples/ViewModelsSamples/Pies/AngularGauge/CustomNeedle.cs" ~}} | ||
|
||
Finally we need to use this new needle in our gauge:" | ||
|
||
```c# | ||
public partial class ViewModel | ||
{ | ||
// ... | ||
public NeedleVisual<CustomNeedle> Needle { get; set; } | ||
|
||
public ViewModel() | ||
{ | ||
Needle = new NeedleVisual<CustomNeedle> | ||
{ | ||
Value = 45 | ||
}; | ||
|
||
// ... | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
Run the app again, now there is a rectangle as our needle: | ||
|
||
<div class="text-center"> | ||
<img src="{{ assets_url }}/docs/{{ unique_name }}/needle-rect.png" alt="sample image" /> | ||
</div> | ||
|
||
:::tip | ||
You can draw anything with SkiaSharp, this article does not explain how to do it. | ||
If you need help, you can see the default [NeedleGeometry source code](https://github.com/beto-rodriguez/LiveCharts2/blob/master/src/skiasharp/LiveChartsCore.SkiaSharp/Drawing/Geometries/NeedleGeometry.cs), or you can follow any SkiaSharp guide. | ||
::: | ||
|
||
{{ render this "~/shared/relatedTo.md" }} |
63 changes: 63 additions & 0 deletions
63
samples/ViewModelsSamples/Axes/MatchScale/InchScaleExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using LiveChartsCore; | ||
using LiveChartsCore.Drawing; | ||
using LiveChartsCore.Kernel.Sketches; | ||
|
||
namespace ViewModelsSamples.Axes.MatchScale; | ||
|
||
public static class InchScaleExtensions | ||
{ | ||
// the DrawMarginDefined event is called once the chart // mark | ||
// has defined the area where the series will be drawn // mark | ||
// ignoring the axes, titles, and legends // mark | ||
// this is where we modify the axes limits to define our custom scale // mark | ||
public static void InchSeparator(this ICartesianChartView chart) => | ||
((CartesianChartEngine)chart.CoreChart).DrawMarginDefined += OnDrawMarginDefined; | ||
|
||
// we will force the axis step to be 1 inch long // mark | ||
private static void OnDrawMarginDefined(CartesianChartEngine chart) | ||
{ | ||
var dataPerInch = GetDataPerInch((ICartesianChartView)chart.View); | ||
|
||
// knowing the data per inch, we can set an step that will, in this case 1 inch | ||
var inches = 1d; | ||
|
||
var x = chart.XAxes[0]; | ||
var xMin = x.MinLimit ?? x.DataBounds.Min; | ||
var xMax = x.MaxLimit ?? x.DataBounds.Max; | ||
var xStep = inches * dataPerInch.X; | ||
|
||
x.SetLimits(xMin, xMax, xStep, notify: false); | ||
|
||
var y = chart.YAxes[0]; | ||
var yMin = y.MinLimit ?? y.DataBounds.Min; | ||
var yMax = y.MaxLimit ?? y.DataBounds.Max; | ||
var yStep = inches * dataPerInch.Y; | ||
|
||
y.SetLimits(yMin, yMax, yStep, notify: false); | ||
|
||
// it is important to use notify: false // mark | ||
// to avoid the chart to update once we set the limits. // mark | ||
} | ||
|
||
private static LvcPointD GetDataPerInch(ICartesianChartView chart) | ||
{ | ||
var p0 = chart.ScaleDataToPixels(new(0, 0)); | ||
var p1 = chart.ScaleDataToPixels(new(1, 1)); | ||
|
||
// calculate the distance between 0,0 and 1,1 in pixels | ||
var pux = Math.Abs(p0.X - p1.X); | ||
var puy = Math.Abs(p0.Y - p1.Y); | ||
|
||
var ppi = GetPixelsPerInch(); | ||
|
||
// calculate the data per inch | ||
var dpix = ppi / pux; | ||
var dpiy = ppi / puy; | ||
|
||
return new LvcPointD(dpix, dpiy); | ||
} | ||
|
||
// this is an example, in a real scenario you should get the screen PPI | ||
private static double GetPixelsPerInch() => 96.0; | ||
} |
Oops, something went wrong.