Permalink
Browse files

Redo scaling to center initial point and push high/low water marks as…

… needed
  • Loading branch information...
jschementi committed May 1, 2011
1 parent 6f11545 commit b1edcc6dfd1d2b68e7737108be838c31916a48c8
@@ -12,9 +12,10 @@ public partial class MainWindow {
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) };
var random = new Random();
var x = 20.0;
var x = 100.0;
timer.Tick += (s, e) => {
foreach (var sparkline in sparklines) {
//x = random.Next(100, 200);
x = x + (random.NextDouble() * 10 * random.NextDouble() * (random.NextDouble() < 0.5 ? -1 : 1));
if (x < 1) x = Math.Abs(x) + 1;
Console.WriteLine(x);
@@ -240,6 +240,7 @@ private void OnShowWatermarksPropertyChanged()
}
private void ResetTimeSeries() {
_both = _lower = _higher = false;
Canvas.Children.Clear();
Canvas.Children.Add(_polyline);
Canvas.Children.Add(_lowwatermark);
@@ -301,14 +302,33 @@ private void OnShowWatermarksPropertyChanged()
else if (y < LowWaterMark) LowWaterMark = y;
}
private double _lowMargin;
private double _height;
private bool _lower;
private bool _higher;
private bool _both;
private void SetCanvasHeight(double y) {
var range = HighWaterMark - LowWaterMark;
if (range < MinYRange) {
Canvas.Height = (LowWaterMark ?? 0) + MinYRange;
} else {
Canvas.Height = double.NaN;
Canvas.Margin = new Thickness(0, 0, 0, -(LowWaterMark ?? 0));
if (TimeSeries.Count < 2) {
Canvas.Height = _height = y + MinYRange;
_lowMargin = -y + MinYRange;
Canvas.Margin = new Thickness(0, 0, 0, _lowMargin);
return;
}
if (!_both && LowWaterMark != null && LowWaterMark < _lowMargin * -1) {
_lower = true;
_lowMargin = -LowWaterMark.Value;
Canvas.Margin = new Thickness(0, 0, 0, _lowMargin);
_both = _lower && _higher;
}
if (!_both && HighWaterMark != null && HighWaterMark > _height) {
_higher = true;
Canvas.Height = HighWaterMark.Value;
_both = _lower && _higher;
}
if (!_both) return;
Canvas.Height = double.NaN;
Canvas.Margin = new Thickness(0, 0, 0, -(LowWaterMark ?? 0));
}
#endregion
}

0 comments on commit b1edcc6

Please sign in to comment.