forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scale independent switch on chart groups.
- Loading branch information
1 parent
58e3f1b
commit 1a86858
Showing
6 changed files
with
160 additions
and
124 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
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; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.