1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

Simplify column ticks creation

This commit is contained in:
Andrei Zavatski 2020-11-22 03:11:38 +03:00
parent 453f0ba675
commit 6e581902cd

View File

@ -123,14 +123,42 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
while (rollingRow <= max)
{
var y = -Interpolation.ValueAt(rollingRow, 0, 1f, min, max);
addRowTick(y, (long)rollingRow);
rollingRow += niceTick;
}
}
private void createColumnTicks()
{
columnTicksContainer.Clear();
columnLinesContainer.Clear();
var totalMonths = values.Length - 1;
int monthsPerTick = 1;
if (totalMonths >= 45)
monthsPerTick = 3;
else if (totalMonths >= 20)
monthsPerTick = 2;
for (int i = 0; i < totalMonths; i += monthsPerTick)
{
var x = (float)i / totalMonths;
addColumnTick(x, values[i].Date);
}
}
private void addRowTick(float y, long value)
{
rowTicksContainer.Add(new TickText
{
Anchor = Anchor.BottomRight,
Origin = Anchor.CentreRight,
RelativePositionAxes = Axes.Y,
Margin = new MarginPadding { Right = 3 },
Text = rollingRow.ToString("N0"),
Text = value.ToString("N0"),
Font = OsuFont.GetFont(size: 12),
Y = y
});
@ -145,33 +173,15 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
EdgeSmoothness = Vector2.One,
Y = y
});
rollingRow += niceTick;
}
}
private void createColumnTicks()
private void addColumnTick(float x, DateTime value)
{
columnTicksContainer.Clear();
columnLinesContainer.Clear();
var min = values.Select(v => v.Date).Min().ToOADate();
var max = values.Select(v => v.Date).Max().ToOADate();
var niceRange = niceNumber(max - min, false);
var niceTick = niceNumber(niceRange / (Math.Min(values.Length, 15) - 1), true);
double rollingRow = min;
while (rollingRow <= max)
{
var x = Interpolation.ValueAt(rollingRow, 0, 1f, min, max);
columnTicksContainer.Add(new TickText
{
Origin = Anchor.CentreLeft,
RelativePositionAxes = Axes.X,
Text = DateTime.FromOADate(rollingRow).ToString("MMM yyyy"),
Text = value.ToString("MMM yyyy"),
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Rotation = 45,
X = x
@ -186,9 +196,6 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
EdgeSmoothness = Vector2.One,
X = x
});
rollingRow += niceTick;
}
}
private double niceNumber(double value, bool round)