Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timing distribution graph sometimes not displaying correctly #24191

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ private partial class Bar : CompositeDrawable
private readonly bool isCentre;
private readonly float totalValue;

private float basalHeight;
private const float minimum_height = 0.02f;

private float offsetAdjustment;

private Circle[] boxOriginals = null!;
Expand Down Expand Up @@ -256,47 +257,42 @@ private void load()
else
{
// A bin with no value draws a grey dot instead.
Circle dot = new Circle
InternalChildren = boxOriginals = new[]
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Colour = isCentre ? Color4.White : Color4.Gray,
Height = 0,
new Circle
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Colour = isCentre ? Color4.White : Color4.Gray,
Height = 0,
}
};
InternalChildren = boxOriginals = new[] { dot };
}
}

protected override void LoadComplete()
{
base.LoadComplete();

if (!values.Any())
return;

updateBasalHeight();
float offsetValue = 0;

foreach (var boxOriginal in boxOriginals)
for (int i = 0; i < boxOriginals.Length; i++)
{
boxOriginal.Y = 0;
boxOriginal.Height = basalHeight;
}
int value = i < values.Count ? values[i].Value : 0;

float offsetValue = 0;
var box = boxOriginals[i];

for (int i = 0; i < values.Count; i++)
{
boxOriginals[i].MoveToY(offsetForValue(offsetValue) * BoundingBox.Height, duration, Easing.OutQuint);
boxOriginals[i].ResizeHeightTo(heightForValue(values[i].Value), duration, Easing.OutQuint);
offsetValue -= values[i].Value;
box.Y = 0;
box.Height = 0;

box.MoveToY(offsetForValue(offsetValue) * BoundingBox.Height, duration, Easing.OutQuint);
box.ResizeHeightTo(heightForValue(value), duration, Easing.OutQuint);
offsetValue -= value;
}
}

protected override void Update()
{
base.Update();
updateBasalHeight();
if (boxAdjustment != null)
drawAdjustmentBar();
}

public void UpdateOffset(float adjustment)
Expand Down Expand Up @@ -324,43 +320,9 @@ public void UpdateOffset(float adjustment)
drawAdjustmentBar();
}

private void updateBasalHeight()
{
float newBasalHeight = DrawHeight > DrawWidth ? DrawWidth / DrawHeight : 1;

if (newBasalHeight == basalHeight)
return;
private float offsetForValue(float value) => (1 - minimum_height) * value / maxValue;

basalHeight = newBasalHeight;
foreach (var dot in boxOriginals)
dot.Height = basalHeight;

draw();
}

private float offsetForValue(float value) => (1 - basalHeight) * value / maxValue;

private float heightForValue(float value) => MathF.Max(basalHeight + offsetForValue(value), 0);

private void draw()
{
resizeBars();

if (boxAdjustment != null)
drawAdjustmentBar();
}

private void resizeBars()
{
float offsetValue = 0;

for (int i = 0; i < values.Count; i++)
{
boxOriginals[i].Y = offsetForValue(offsetValue) * DrawHeight;
boxOriginals[i].Height = heightForValue(values[i].Value);
offsetValue -= values[i].Value;
}
}
bdach marked this conversation as resolved.
Show resolved Hide resolved
private float heightForValue(float value) => minimum_height + offsetForValue(value);

private void drawAdjustmentBar()
{
Expand Down
Loading