Skip to content

Commit

Permalink
Add scale independent switch on chart groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Mar 16, 2017
1 parent 58e3f1b commit 1a86858
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 124 deletions.
101 changes: 101 additions & 0 deletions LogViewer/LogViewer/Controls/ChartGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace LogViewer.Controls
{
/// <summary>
/// Represents a group of chats located on top of each other.
/// </summary>
public class ChartGroup : Grid
{
private bool scaleIndependently;
private int scaleIndex;

public bool ScaleIndependently
{
get { return scaleIndependently; }
set
{
if (scaleIndependently != value)
{
scaleIndependently = value;
InvalidateCharts();
}
}
}

public void InvalidateCharts()
{
foreach (var chart in FindCharts())
{
chart.ScaleIndependently = this.scaleIndependently;
chart.InvalidateArrange();
chart.DelayedUpdate();
}
}


internal void AddChart(SimpleLineChart chart)
{
this.Children.Add(chart);
chart.Group = this;
InvalidateCharts();
}



public IEnumerable<SimpleLineChart> FindCharts()
{
List<SimpleLineChart> result = new List<SimpleLineChart>();
foreach (UIElement f in this.Children)
{
SimpleLineChart chart = f as SimpleLineChart;
if (chart != null)
{
result.Add(chart);
}
}
return result;
}

internal bool ComputeScale(SimpleLineChart trigger)
{
bool changed = false;
ChartScaleInfo combined = null;

int index = this.scaleIndex;

// make sure they are all up to date.
foreach (var ptr in FindCharts())
{
ChartScaleInfo info = ptr.ComputeScaleSelf(index);
if (combined == null)
{
combined = info;
}
else
{
combined.Combine(info);
}
}

foreach (var ptr in FindCharts())
{
if (ptr.ApplyScale(combined))
{
if (ptr != trigger)
{
ptr.DelayedUpdate();
}
changed = true;
}
}
return changed;
}
}
}
71 changes: 9 additions & 62 deletions LogViewer/LogViewer/Controls/ChartStack.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace LogViewer.Controls
{
/// <summary>
/// Interaction logic for SelectionOverlay.xaml
/// Represents a vertical stack of charts or chartgroups
/// </summary>
public partial class ChartStack : Grid
{
Expand All @@ -28,7 +28,7 @@ public ChartStack()
private Point mouseDownPos;
private int mouseDownTime;

internal void AddChartGroup(Grid chartGroup)
internal void AddChartGroup(ChartGroup chartGroup)
{
theStack.Children.Add(chartGroup);
}
Expand All @@ -38,76 +38,27 @@ public void AddChart(SimpleLineChart chart)
theStack.Children.Add(chart);
}

internal void AddToGroup(Grid chartGroup, FrameworkElement chart)
{
chartGroup.Children.Add(chart);

if (chartGroup.Parent == null)
{
this.AddChartGroup(chartGroup);
}

FixNextPointers(chartGroup);
}


public void RemoveChart(SimpleLineChart e)
{
if (e.Parent == theStack)
{
theStack.Children.Remove(e);
}
else if (e.Parent is Grid)
else if (e.Parent is ChartGroup)
{
// it's a chart group then.
Grid group = (Grid)e.Parent;
ChartGroup group = (ChartGroup)e.Parent;
group.Children.Remove(e);
SimpleLineChart chart = e as SimpleLineChart;
if (chart != null)
{
chart.Next = null;
chart.Group = null;
}
if (group.Children.Count == 0)
{
theStack.Children.Remove(group);
}
else
{
FixNextPointers(group);
}
}
}

private static void FixNextPointers(Grid group)
{
// fix up the "next" pointers for removed chart.
SimpleLineChart first = null;
SimpleLineChart previous = null;
foreach (UIElement f in group.Children)
{
SimpleLineChart chart = f as SimpleLineChart;
if (chart != null)
{
if (first == null)
{
first = chart;
chart.Next = null;
}
else
{
previous.Next = chart;
chart.Next = first;
}
previous = chart;
}
}
foreach (UIElement f in group.Children)
{
SimpleLineChart chart = f as SimpleLineChart;
if (chart != null)
{
chart.InvalidateArrange();
}
group.InvalidateCharts();
}
}

Expand Down Expand Up @@ -182,16 +133,12 @@ public IEnumerable<SimpleLineChart> FindCharts()
{
yield return chart;
}
Grid group = e as Grid;
ChartGroup group = e as ChartGroup;
if (group != null)
{
foreach (UIElement f in Snapshot(group.Children))
foreach (SimpleLineChart child in group.FindCharts())
{
chart = f as SimpleLineChart;
if (chart != null)
{
yield return chart;
}
yield return child;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions LogViewer/LogViewer/Controls/SimpleLineChart.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Grid x:Name="RootContent" ClipToBounds="True" Background="Transparent">
<Grid.ContextMenu>
<ContextMenu x:Name="ContextMenu">
<MenuItem x:Name="ScaleIndependentMenuItem" Header="Scale independendently" Click="OnScaleIndependently"/>
<MenuItem x:Name="LockTooltipMenuItem" Header="Lock Tooltip" Click="OnLockTooltip" IsEnabled="False"/>
<MenuItem x:Name="AddTrendLineMenuItem" Header="Add Trend Line" Click="OnAddTrendLine" IsEnabled="False"/>
<Separator/>
Expand Down
Loading

0 comments on commit 1a86858

Please sign in to comment.