Skip to content

Commit

Permalink
update trend graph to use boxView
Browse files Browse the repository at this point in the history
  • Loading branch information
rizanzaky committed Jun 18, 2021
1 parent 75abb2c commit 451c056
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions src/DIPS.Xamarin.UI/Controls/TrendGraph/TrendGraph.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,42 @@ private void DrawGraph(double x, object item, double widthPerItem)
color = OutOfBoundsColor;
}

var itemHeight = value.CalculateRelativePosition(MinValue, MaxValue);
var backFrame = CreateFrame(GraphBackgroundColor);

graphContainer.Children.Add(backFrame,
Constraint.RelativeToParent(r => x),
Constraint.RelativeToParent(r => 0),
Constraint.RelativeToParent(r => widthPerItem),
Constraint.RelativeToParent(r => r.Height));

graphContainer.Children.Add(CreateFrame(color),
Constraint.RelativeToParent(r => backFrame.X),
Constraint.RelativeToParent(r => (backFrame.Y + backFrame.Height) - (itemHeight * backFrame.Height)),
Constraint.RelativeToParent(r => backFrame.Width),
Constraint.RelativeToParent(r => itemHeight * backFrame.Height));
var backBar = CreateGraphBar(GraphBackgroundColor);
var barHeight = value.CalculateRelativePosition(MinValue, MaxValue);
var graphBar = CreateGraphBar(color);

if (Device.RuntimePlatform == Device.iOS)
{
Device.BeginInvokeOnMainThread(() =>
{
graphContainer.Children.Add(backBar,
Constraint.RelativeToParent(r => x),
Constraint.RelativeToParent(r => 0),
Constraint.RelativeToParent(r => widthPerItem),
Constraint.RelativeToParent(r => r.Height));
graphContainer.Children.Add(graphBar,
Constraint.RelativeToParent(r => backBar.X),
Constraint.RelativeToParent(r =>
backBar.Y + backBar.Height - (barHeight * backBar.Height)),
Constraint.RelativeToParent(r => backBar.Width),
Constraint.RelativeToParent(r => barHeight * backBar.Height));
});
}
else
{
graphContainer.Children.Add(backBar,
Constraint.RelativeToParent(r => x),
Constraint.RelativeToParent(r => 0),
Constraint.RelativeToParent(r => widthPerItem),
Constraint.RelativeToParent(r => r.Height));

graphContainer.Children.Add(graphBar,
Constraint.RelativeToParent(r => backBar.X),
Constraint.RelativeToParent(r => backBar.Y + backBar.Height - (barHeight * backBar.Height)),
Constraint.RelativeToParent(r => backBar.Width),
Constraint.RelativeToParent(r => barHeight * backBar.Height));
}
}

private void AnimateTrendBarsIfNeeded()
Expand Down Expand Up @@ -294,9 +316,9 @@ private void AnimateWithGrowAll()
}
}

private static Frame CreateFrame(Color background)
private static BoxView CreateGraphBar(Color background)
{
return new Frame {BackgroundColor = background, CornerRadius = 0, Padding = 0, HasShadow = false};
return new BoxView {BackgroundColor = background, CornerRadius = 0};
}

private void CollectionChanged_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down

0 comments on commit 451c056

Please sign in to comment.