Skip to content

Commit

Permalink
extended axis trhow fix to uwp
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Feb 6, 2017
1 parent 91e4769 commit bded6ec
Showing 1 changed file with 47 additions and 25 deletions.
72 changes: 47 additions & 25 deletions UwpView/Charts/Base/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Chart()
Content = Canvas;

DrawMargin = new Canvas();

Canvas.Children.Add(DrawMargin);

TooltipTimeoutTimer = new DispatcherTimer();
Expand Down Expand Up @@ -200,11 +200,13 @@ internal void ChartUpdated()
#endregion

#region Commands

/// <summary>
/// The data click command property
/// </summary>
public static readonly DependencyProperty DataClickCommandProperty = DependencyProperty.Register(
"DataClickCommand", typeof(ICommand), typeof(Chart), new PropertyMetadata(default(ICommand)));

/// <summary>
/// Gets or sets the data click command.
/// </summary>
Expand All @@ -222,6 +224,7 @@ public ICommand DataClickCommand
/// </summary>
public static readonly DependencyProperty DataHoverCommandProperty = DependencyProperty.Register(
"DataHoverCommand", typeof(ICommand), typeof(Chart), new PropertyMetadata(default(ICommand)));

/// <summary>
/// Gets or sets the data hover command.
/// </summary>
Expand All @@ -239,6 +242,7 @@ public ICommand DataHoverCommand
/// </summary>
public static readonly DependencyProperty UpdaterTickCommandProperty = DependencyProperty.Register(
"UpdaterTickCommand", typeof(ICommand), typeof(Chart), new PropertyMetadata(default(ICommand)));

/// <summary>
/// Gets or sets the updater tick command.
/// </summary>
Expand All @@ -247,20 +251,24 @@ public ICommand DataHoverCommand
/// </value>
public ICommand UpdaterTickCommand
{
get { return (ICommand)GetValue(UpdaterTickCommandProperty); }
get { return (ICommand) GetValue(UpdaterTickCommandProperty); }
set { SetValue(UpdaterTickCommandProperty, value); }
}

#endregion

#region Properties

private AxesCollection PreviousXAxis { get; set; }
private AxesCollection PreviousYAxis { get; set; }
private static Random Randomizer { get; }
private SeriesCollection LastKnownSeriesCollection { get; set; }

/// <summary>
/// Gets or sets the chart current canvas
/// </summary>
protected Canvas Canvas { get; set; }

internal Canvas DrawMargin { get; set; }
internal Popup TooltipContainer { get; set; }

Expand All @@ -284,12 +292,13 @@ public ICommand UpdaterTickCommand
/// </summary>
public static readonly DependencyProperty SeriesColorsProperty = DependencyProperty.Register(
"SeriesColors", typeof(ColorsCollection), typeof(Chart), new PropertyMetadata(default(ColorsCollection)));

/// <summary>
/// Gets or sets
/// </summary>
public ColorsCollection SeriesColors
{
get { return (ColorsCollection)GetValue(SeriesColorsProperty); }
get { return (ColorsCollection) GetValue(SeriesColorsProperty); }
set { SetValue(SeriesColorsProperty, value); }
}

Expand All @@ -298,7 +307,8 @@ public ColorsCollection SeriesColors
/// </summary>
public static readonly DependencyProperty AxisYProperty = DependencyProperty.Register(
"AxisY", typeof(AxesCollection), typeof(Chart),
new PropertyMetadata(null, CallChartUpdater()));
new PropertyMetadata(null, AxisInstancechanged(AxisOrientation.Y)));

/// <summary>
/// Gets or sets vertical axis
/// </summary>
Expand All @@ -313,7 +323,7 @@ public AxesCollection AxisY
/// </summary>
public static readonly DependencyProperty AxisXProperty = DependencyProperty.Register(
"AxisX", typeof(AxesCollection), typeof(Chart),
new PropertyMetadata(null, CallChartUpdater()));
new PropertyMetadata(null, AxisInstancechanged(AxisOrientation.X)));

/// <summary>
/// Gets or sets horizontal axis
Expand Down Expand Up @@ -361,6 +371,7 @@ public ZoomingOptions Zoom
/// </summary>
public static readonly DependencyProperty PanProperty = DependencyProperty.Register(
"Pan", typeof(PanningOptions), typeof(Chart), new PropertyMetadata(PanningOptions.Unset));

/// <summary>
/// Gets or sets the chart pan, default is Unset, which bases the behavior according to Zoom property
/// </summary>
Expand All @@ -369,7 +380,7 @@ public ZoomingOptions Zoom
/// </value>
public PanningOptions Pan
{
get { return (PanningOptions)GetValue(PanProperty); }
get { return (PanningOptions) GetValue(PanProperty); }
set { SetValue(PanProperty, value); }
}

Expand Down Expand Up @@ -764,7 +775,7 @@ public void EnsureElementBelongsToCurrentDrawMargin(object element)
/// <returns></returns>
public bool ContainsElement(object element)
{
var wpfElement = (FrameworkElement)element;
var wpfElement = (FrameworkElement) element;
return wpfElement != null && Canvas.Children.Contains(wpfElement);
}

Expand Down Expand Up @@ -827,7 +838,6 @@ public List<AxisCore> MapXAxes(ChartCore chart)
{
if (x.Parent == null)
{
CleanAxes(chart.AxisX);
x.AxisOrientation = AxisOrientation.X;
if (x.Separator != null) chart.View.AddToView(x.Separator);
chart.View.AddToView(x);
Expand Down Expand Up @@ -856,7 +866,6 @@ public List<AxisCore> MapYAxes(ChartCore chart)
{
if (y.Parent == null)
{
CleanAxes(chart.AxisY);
y.AxisOrientation = AxisOrientation.Y;
if (y.Separator != null) chart.View.AddToView(y.Separator);
chart.View.AddToView(y);
Expand All @@ -879,9 +888,9 @@ public Color GetNextDefaultColor()
if (SeriesColors != null)
{
var rsc = RandomizeStartingColor
? Randomizer.Next(0, SeriesColors.Count)
: 0;
return SeriesColors[(i + rsc) % SeriesColors.Count];
? Randomizer.Next(0, SeriesColors.Count)
: 0;
return SeriesColors[(i + rsc)%SeriesColors.Count];
}

var r = RandomizeStartingColor
Expand Down Expand Up @@ -1256,7 +1265,7 @@ internal SeriesCollection GetDesignerModeCollection()
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (Zoom == ZoomingOptions.None) return;

var p = e.GetCurrentPoint(this);

var corePoint = new CorePoint(p.Position.X, p.Position.Y);
Expand All @@ -1272,7 +1281,7 @@ private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
private void OnDraggingStart(object sender, PointerRoutedEventArgs e)
{
if (Model?.AxisX == null || Model.AxisY == null) return;

DragOrigin = e.GetCurrentPoint(this).Position;
DragOrigin = new Point(
ChartFunctions.FromPlotArea(DragOrigin.X, AxisOrientation.X, Model),
Expand Down Expand Up @@ -1447,17 +1456,6 @@ private static void ScrollLimitOnChanged(DependencyObject o, DependencyPropertyC
// }
// #endregion

private static void CleanAxes(List<AxisCore> axes)
{
if (axes != null && axes.Any())
{
foreach (var axisCore in axes)
{
axisCore.View.Clean();
}
}
}

#region Property Changed

/// <summary>
Expand Down Expand Up @@ -1489,6 +1487,30 @@ private static void UpdateChartFrequency(DependencyObject o, DependencyPropertyC
CallChartUpdater(true)(o, e);
}

private static PropertyChangedCallback AxisInstancechanged(AxisOrientation orientation)
{
return (o, a) =>
{
var chart = (Chart) o;
var ax = orientation == AxisOrientation.X ? chart.PreviousXAxis : chart.PreviousYAxis;

if (ax != null)
foreach (var axis in ax)
{
axis.Clean();
}
if (orientation == AxisOrientation.X)
{
chart.PreviousXAxis = chart.AxisX;
}
else
{
chart.PreviousYAxis = chart.AxisY;
}
CallChartUpdater()(o, a);
};
}

#endregion
}
}

0 comments on commit bded6ec

Please sign in to comment.