Permalink
Browse files

Set height on first added point so it comes in somewhere in the middle

  • Loading branch information...
1 parent a5fffc4 commit 685671e97fa29e34c4b06a7530b2bda69838b733 @jschementi committed Apr 24, 2011
@@ -14,7 +14,7 @@ public partial class MainWindow {
var random = new Random();
timer.Tick += (s, e) => {
foreach (var sparkline in sparklines) {
- var x = random.Next(0, 40);
+ var x = random.Next(0, 20);
Console.WriteLine(x);
sparkline.AddTimeValue(x);
}
@@ -6,10 +6,10 @@
x:Class="Schementi.Controls.Sparkline"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="300">
- <Grid x:Name="Root" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
- <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled" x:Name="ScrollViewer">
+ <Grid x:Name="Root" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="1">
+ <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled" x:Name="ScrollViewer" Padding="0 3">
<Viewbox HorizontalAlignment="Left" VerticalAlignment="Stretch" Stretch="Uniform" StretchDirection="Both">
- <Grid x:Name="Canvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="50" RenderTransformOrigin="0.5,0.5">
+ <Grid x:Name="Canvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<ScaleTransform ScaleY="-1"/>
</Grid.RenderTransform>
@@ -228,6 +228,7 @@ private void OnShowWatermarksPropertyChanged()
Canvas.Children.Add(_polyline);
Canvas.Children.Add(_lowwatermark);
Canvas.Children.Add(_highwatermark);
+ Canvas.Height = double.NaN;
_nextXValue = 0;
foreach (var timeValue in TimeSeries) {
DrawTimeValue(timeValue);
@@ -243,7 +244,7 @@ private void OnShowWatermarksPropertyChanged()
private void AddPoint(Point point) {
_polyline.Points.Add(point);
SetWatermarks(point.Y);
- SetCanvasHeight();
+ SetCanvasHeight(point.Y);
if (PointRadius > 0.0)
Canvas.Children.Add(DrawDot(point));
_nextXValue++;
@@ -271,9 +272,14 @@ private void OnShowWatermarksPropertyChanged()
else if (y < LowWaterMark) LowWaterMark = y;
}
- private void SetCanvasHeight() {
+ private void SetCanvasHeight(double y) {
+ if (double.IsNaN(Canvas.Height)) {
+ Canvas.Height = Math.Max(50, y * 1.5);
+ return;
+ }
if (HighWaterMark != null && HighWaterMark > Canvas.ActualHeight)
Canvas.Height = HighWaterMark.Value;
+ Console.WriteLine("Height: {0}", Canvas.Height);
}
#endregion
}

0 comments on commit 685671e

Please sign in to comment.