Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0-beta.360 #590

Merged
merged 26 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f7f670c
zoom by section core and wpf view
beto-rodriguez Aug 14, 2022
e8e85be
restore sample zoom
beto-rodriguez Aug 14, 2022
b518907
apply section zoom to all platforms
beto-rodriguez Aug 14, 2022
ad7025c
Merge pull request #581 from beto-rodriguez/zoomBySection
beto-rodriguez Aug 14, 2022
8616f95
a better implementention of ICoordinate
beto-rodriguez Aug 17, 2022
f5f57dd
use empty coordinate
beto-rodriguez Aug 17, 2022
a9bfc43
restore basic line sample
beto-rodriguez Aug 17, 2022
893e875
adds support for null types, datafactory cleanup
beto-rodriguez Aug 17, 2022
55debad
dispose by ref points
beto-rodriguez Aug 17, 2022
103f01c
use dummy rectangle zooming section
beto-rodriguez Aug 17, 2022
bd97e13
simplify ichartentity/icoordinate
beto-rodriguez Aug 17, 2022
6ba50ef
another change to ichartentity
beto-rodriguez Aug 18, 2022
7759282
one visual per chart
beto-rodriguez Aug 18, 2022
b747d14
just cleaning things up
beto-rodriguez Aug 19, 2022
314bac2
fixes #515
beto-rodriguez Aug 19, 2022
f39dbcf
fixes #525
beto-rodriguez Aug 19, 2022
2a0f5f7
fixes #552
beto-rodriguez Aug 19, 2022
259569a
fizes #555
beto-rodriguez Aug 20, 2022
44810ed
fixes #562
beto-rodriguez Aug 20, 2022
bc62f0a
fixes #570
beto-rodriguez Aug 20, 2022
1909c41
fixes #578
beto-rodriguez Aug 20, 2022
d2b2c9b
fixes #575
beto-rodriguez Aug 20, 2022
668c73a
prevents throw for #579
beto-rodriguez Aug 20, 2022
2768e9d
imprive docs, helps #583
beto-rodriguez Aug 20, 2022
043f2f3
restore restart visuals
beto-rodriguez Aug 20, 2022
1521695
2.0.0-beta.360
beto-rodriguez Aug 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.SkiaSharpView;

namespace ViewModelsSamples.VisualTest.TwoChartsOneSeries;
Expand All @@ -10,17 +11,29 @@ public partial class ViewModel
{
public ViewModel()
{
var values = new int[100];
//var values = new int[100];
//var r = new Random();
//var t = 0;

//for (var i = 0; i < 100; i++)
//{
// t += r.Next(-90, 100);
// values[i] = t;
//}

//Series = new ISeries[] { new StepLineSeries<int> { Values = values } };

var values = new ObservableValue[100];
var r = new Random();
var t = 0;

for (var i = 0; i < 100; i++)
{
t += r.Next(-90, 100);
values[i] = t;
values[i] = new(t);
}

Series = new ISeries[] { new StepLineSeries<int> { Values = values } };
Series = new ISeries[] { new StepLineSeries<ObservableValue> { Values = values } };
}

public ISeries[] Series { get; set; }
Expand Down
147 changes: 144 additions & 3 deletions src/LiveChartsCore/CartesianChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class CartesianChart<TDrawingContext> : Chart<TDrawingContext>
internal readonly HashSet<IPlane<TDrawingContext>> _everMeasuredAxes = new();
internal readonly HashSet<Section<TDrawingContext>> _everMeasuredSections = new();
private readonly ICartesianChartView<TDrawingContext> _chartView;
private readonly ISizedGeometry<TDrawingContext> _zoomingSection;
private int _nextSeries = 0;
private double _zoomingSpeed = 0;
private readonly bool _requiresLegendMeasureAlways = false;
Expand All @@ -58,16 +59,23 @@ public class CartesianChart<TDrawingContext> : Chart<TDrawingContext>
/// <param name="view">The view.</param>
/// <param name="defaultPlatformConfig">The default platform configuration.</param>
/// <param name="canvas">The canvas.</param>
/// <param name="zoomingSection">The zooming section.</param>
/// <param name="requiresLegendMeasureAlways">Forces the legends to redraw with every measure request.</param>
public CartesianChart(
ICartesianChartView<TDrawingContext> view,
Action<LiveChartsSettings> defaultPlatformConfig,
MotionCanvas<TDrawingContext> canvas,
ISizedGeometry<TDrawingContext>? zoomingSection,
bool requiresLegendMeasureAlways = false)
: base(canvas, defaultPlatformConfig, view)
{
_chartView = view;
_requiresLegendMeasureAlways = requiresLegendMeasureAlways;
_zoomingSection = zoomingSection ?? throw new Exception($"{nameof(zoomingSection)} is required.");
_zoomingSection.X = -1;
_zoomingSection.Y = -1;
_zoomingSection.Width = 0;
_zoomingSection.Height = 0;
}

/// <summary>
Expand Down Expand Up @@ -227,7 +235,7 @@ public void Zoom(LvcPoint pivot, ZoomDirection direction, double? scaleFactor =
maxt = max + ld * 0.5 * dir;
}

if (maxt - mint < xi.DataBounds.MinDelta * 5) return;
if (direction == ZoomDirection.ZoomIn && maxt - mint < xi.DataBounds.MinDelta * 3) return;

var xm = (max - min) * (isActive ? MaxAxisActiveBound : MaxAxisBound);
if (maxt > xi.DataBounds.Max && direction == ZoomDirection.ZoomOut) maxt = xi.DataBounds.Max + xm;
Expand Down Expand Up @@ -281,7 +289,7 @@ public void Zoom(LvcPoint pivot, ZoomDirection direction, double? scaleFactor =
maxt = max + ld * 0.5 * dir;
}

if (maxt - mint < yi.DataBounds.MinDelta * 5) return;
if (direction == ZoomDirection.ZoomIn && maxt - mint < yi.DataBounds.MinDelta * 3) return;

var ym = (max - min) * (isActive ? MaxAxisActiveBound : MaxAxisBound);
if (maxt > yi.DataBounds.Max && direction == ZoomDirection.ZoomOut) maxt = yi.DataBounds.Max + ym;
Expand Down Expand Up @@ -688,9 +696,9 @@ protected internal override void Measure()
}

var drawablePlane = (IPlane<TDrawingContext>)axis;
_ = _everMeasuredAxes.Add(drawablePlane);
if (drawablePlane.IsVisible)
{
_everMeasuredAxes.Add(drawablePlane);
drawablePlane.Measure(this);
_ = toDeleteAxes.Remove(drawablePlane);
}
Expand Down Expand Up @@ -782,4 +790,137 @@ public override void Unload()

IsFirstDraw = true;
}

private LvcPoint? _sectionZoomingStart = null;

internal override void InvokePointerDown(LvcPoint point, bool isSecondaryAction)
{
if (isSecondaryAction)
{
_sectionZoomingStart = point;

_zoomingSection.X = point.X;
_zoomingSection.Y = point.Y;

var xMode = (_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X;
var yMode = (_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y;

if (!xMode)
{
_zoomingSection.X = DrawMarginLocation.X;
_zoomingSection.Width = DrawMarginSize.Width;
}

if (!yMode)
{
_zoomingSection.Y = DrawMarginLocation.Y;
_zoomingSection.Height = DrawMarginSize.Height;
}

Update();
return;
}

base.InvokePointerDown(point, isSecondaryAction);
}

internal override void InvokePointerMove(LvcPoint point)
{
if (_sectionZoomingStart is not null)
{
var xMode = (_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X;
var yMode = (_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y;

if (xMode) _zoomingSection.Width = point.X - _sectionZoomingStart.Value.X;
if (yMode) _zoomingSection.Height = point.Y - _sectionZoomingStart.Value.Y;

Update();
return;
}

base.InvokePointerMove(point);
}

internal override void InvokePointerUp(LvcPoint point, bool isSecondaryAction)
{
if (_sectionZoomingStart is not null)
{
if ((_zoomMode & ZoomAndPanMode.X) == ZoomAndPanMode.X)
{
for (var i = 0; i < XAxes.Length; i++)
{
var x = XAxes[i];

var xi = ScaleUIPoint(_sectionZoomingStart.Value, i, 0)[0];
var xj = ScaleUIPoint(point, i, 0)[0];

double xMax, xMin;

if (xi > xj)
{
xMax = xi;
xMin = xj;
}
else
{
xMax = xj;
xMin = xi;
}

if (xMax > (x.MaxLimit ?? double.MaxValue)) xMax = x.MaxLimit ?? double.MaxValue;
if (xMin < (x.MinLimit ?? double.MinValue)) xMin = x.MinLimit ?? double.MinValue;

if (xMax - xMin > x.DataBounds.MinDelta * 3)
{
x.MinLimit = xMin;
x.MaxLimit = xMax;
}
}
}

if ((_zoomMode & ZoomAndPanMode.Y) == ZoomAndPanMode.Y)
{
for (var i = 0; i < YAxes.Length; i++)
{
var y = YAxes[i];

var yi = ScaleUIPoint(_sectionZoomingStart.Value, 0, i)[1];
var yj = ScaleUIPoint(point, 0, i)[1];

double yMax, yMin;

if (yi > yj)
{
yMax = yi;
yMin = yj;
}
else
{
yMax = yj;
yMin = yi;
}

if (yMax > (y.MaxLimit ?? double.MaxValue)) yMax = y.MaxLimit ?? double.MaxValue;
if (yMin < (y.MinLimit ?? double.MinValue)) yMin = y.MinLimit ?? double.MinValue;

if (yMax - yMin > y.DataBounds.MinDelta * 3)
{
y.MinLimit = yMin;
y.MaxLimit = yMax;
}
}
}

_zoomingSection.X = -1;
_zoomingSection.Y = -1;
_zoomingSection.Width = 0;
_zoomingSection.Height = 0;
Update();

_sectionZoomingStart = null;
return;
}

base.InvokePointerUp(point, isSecondaryAction);
}
}
7 changes: 3 additions & 4 deletions src/LiveChartsCore/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ internal void ClearTooltipData()

Canvas.Invalidate();
}

internal void InvokePointerDown(LvcPoint point)
internal virtual void InvokePointerDown(LvcPoint point, bool isSecondaryAction)
{
PointerDown?.Invoke(point);

Expand All @@ -366,12 +365,12 @@ internal void InvokePointerDown(LvcPoint point)
View.OnDataPointerDown(iterable, point);
}

internal void InvokePointerMove(LvcPoint point)
internal virtual void InvokePointerMove(LvcPoint point)
{
PointerMove?.Invoke(point);
}

internal void InvokePointerUp(LvcPoint point)
internal virtual void InvokePointerUp(LvcPoint point, bool isSecondaryAction)
{
PointerUp?.Invoke(point);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LiveChartsCore/ColumnSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override void Measure(Chart<TDrawingContext> chart)
var secondary = secondaryScale.ToPixels(point.SecondaryValue);
var b = Math.Abs(primary - helper.p);

if (point.IsNull)
if (point.IsEmpty)
{
if (visual is not null)
{
Expand Down
20 changes: 12 additions & 8 deletions src/LiveChartsCore/Defaults/DateTimePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using LiveChartsCore.Kernel;
using LiveChartsCore.Kernel.Sketches;

namespace LiveChartsCore.Defaults;

Expand All @@ -48,8 +50,9 @@ public DateTimePoint()
/// <param name="value">The value.</param>
public DateTimePoint(DateTime dateTime, double? value)
{
_dateTime = dateTime;
_value = value;
DateTime = dateTime;
Value = value;
Coordinate = value is null ? Coordinate.Empty : new(dateTime.Ticks, value.Value);
}

/// <summary>
Expand All @@ -68,14 +71,14 @@ public DateTimePoint(DateTime dateTime, double? value)
/// </value>
public double? Value { get => _value; set { _value = value; OnPropertyChanged(); } }

/// <inheritdoc cref="IChartEntity.ChartPoint"/>
public ChartPoint? ChartPoint { get; set; }
/// <inheritdoc cref="IChartEntity.EntityIndex"/>
public int EntityIndex { get; set; }

/// <inheritdoc cref="IChartEntity.EntityId"/>
public int EntityId { get; set; }
/// <inheritdoc cref="IChartEntity.ChartPoints"/>
public Dictionary<IChartView, ChartPoint>? ChartPoints { get; set; }

/// <inheritdoc cref="ICoordinate.Coordinate"/>
public Coordinate Coordinate => new(_dateTime.Ticks, _value ?? 0d);
/// <inheritdoc cref="IChartEntity.Coordinate"/>
public Coordinate Coordinate { get; private set; } = Coordinate.Empty;

/// <summary>
/// Occurs when a property value changes.
Expand All @@ -89,6 +92,7 @@ public DateTimePoint(DateTime dateTime, double? value)
/// <param name="propertyName">Name of the property.</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
Coordinate = _value is null ? Coordinate.Empty : new(_dateTime.Ticks, _value.Value);
PropertyChanged?.Invoke(propertyName, new PropertyChangedEventArgs(propertyName));
}
}