Permalink
Browse files

Scaling

  • Loading branch information...
1 parent 8fd5128 commit 6f11545f5a19dda3f3ef765a62f3a53fdfbda29a @jschementi committed May 1, 2011
@@ -2,24 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:schementi="clr-namespace:Schementi.Controls;assembly=Schementi.Controls.Sparkline"
- Title="Sparkline Demo (Jimmy Schementi)" Height="450" Width="600">
+ Title="Sparkline Demo (Jimmy Schementi)" Height="300" Width="600">
<Grid Background="Black" x:Name="Grid">
- <Grid.RowDefinitions>
- <RowDefinition/>
- <RowDefinition/>
- <RowDefinition/>
- </Grid.RowDefinitions>
- <schementi:Sparkline Foreground="#FFEEEEEE"
- StrokeThickness="0.5"
- PointFill="White"
- PointRadius="0.5"/>
- <schementi:Sparkline Grid.Row="1"
- ShowWatermarks="True"
- Foreground="#FFEEEEEE"
- StrokeThickness="0.5"
- PointFill="White"
- PointRadius="0.5"/>
- <schementi:Sparkline Grid.Row="2"
+ <schementi:Sparkline ShowWatermarks="True"
Foreground="#FFEEEEEE"
StrokeThickness="0.5"
PointFill="White"
@@ -12,9 +12,11 @@ public partial class MainWindow {
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(0.5) };
var random = new Random();
+ var x = 20.0;
timer.Tick += (s, e) => {
foreach (var sparkline in sparklines) {
- var x = random.Next(10, 61);
+ x = x + (random.NextDouble() * 10 * random.NextDouble() * (random.NextDouble() < 0.5 ? -1 : 1));
+ if (x < 1) x = Math.Abs(x) + 1;
Console.WriteLine(x);
sparkline.AddTimeValue(x);
}
@@ -158,24 +158,26 @@ private void OnShowWatermarksPropertyChanged()
}
#endregion
- //#region MinYRange
- //public static DependencyProperty MinYRangeProperty = DependencyProperty.Register(
- // "MinYRange",
- // typeof(double),
- // typeof(Sparkline),
- // new PropertyMetadata(25.0));
-
- //public double MinYRange {
- // get { return (double)GetValue(MinYRangeProperty); }
- // set { SetValue(MinYRangeProperty, value); }
- //}
- //#endregion
+ #region MinYRange
+ public static DependencyProperty MinYRangeProperty = DependencyProperty.Register(
+ "MinYRange",
+ typeof(double),
+ typeof(Sparkline),
+ new PropertyMetadata(25.0));
+
+ public double MinYRange {
+ get { return (double)GetValue(MinYRangeProperty); }
+ set { SetValue(MinYRangeProperty, value); }
+ }
+ #endregion
#endregion
#region Fields
private int _nextXValue;
private const int XWidth = 10;
+ private const int MinValue = 0;
+ private const int MaxValue = 100;
private Polyline _polyline;
@@ -196,7 +198,6 @@ private void OnShowWatermarksPropertyChanged()
new Binding("Foreground") { Mode = BindingMode.TwoWay, Source = this });
BindingOperations.SetBinding(_polyline, Shape.StrokeThicknessProperty,
new Binding("StrokeThickness") { Mode = BindingMode.TwoWay, Source = this });
- //Canvas.MinHeight = this.MinYRange;
Canvas.Children.Add(_polyline);
}
@@ -264,15 +265,15 @@ private void OnShowWatermarksPropertyChanged()
Canvas.Children.Add(DrawDot(point));
//#if DEBUG
// var textbox = new TextBlock {
-// Text = Convert.ToString(point.Y),
-// FontSize = 3,
-// Foreground = this.Foreground,
-// Opacity = 0.25,
-// Padding = new Thickness(2.0, 0, 0, 0),
-// Margin = new Thickness(point.X, point.Y + 1, 0, 0),
-// RenderTransform = new ScaleTransform { ScaleY = -1.0 },
-// RenderTransformOrigin = new Point(0.0,0.0),
-// };
+// Text = Convert.ToString(Math.Round(point.Y, 2)),
+// FontSize = 3,
+// Foreground = this.Foreground,
+// Opacity = 0.25,
+// Padding = new Thickness(2.0, 0, 0, 0),
+// Margin = new Thickness(point.X, point.Y + 1, 0, 0),
+// RenderTransform = new ScaleTransform { ScaleY = -1.0 },
+// RenderTransformOrigin = new Point(0.0, 0.0),
+// };
// Canvas.Children.Add(textbox);
//#endif
_nextXValue++;
@@ -301,12 +302,13 @@ private void OnShowWatermarksPropertyChanged()
}
private void SetCanvasHeight(double y) {
- //if (TimeSeries.Count < 2) {
- // Canvas.Height = y*2;
- // return;
- //}
- var highwater = HighWaterMark.HasValue ? HighWaterMark.Value + 2 : 0;
- if (highwater > Canvas.ActualHeight || highwater > Canvas.Height) Canvas.Height = highwater;
+ 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));
+ }
}
#endregion
}

0 comments on commit 6f11545

Please sign in to comment.