mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Handle empty values as a separate case
This commit is contained in:
parent
0239103b6b
commit
6f449a583e
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
@ -32,6 +33,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
AddStep("values from 1-10", () => graph.Values = Enumerable.Range(1, 10).Select(i => (float)i));
|
||||
AddStep("values from 1-100", () => graph.Values = Enumerable.Range(1, 100).Select(i => (float)i));
|
||||
AddStep("reversed values from 1-10", () => graph.Values = Enumerable.Range(1, 10).Reverse().Select(i => (float)i));
|
||||
AddStep("empty values", () => graph.Values = Array.Empty<float>());
|
||||
AddStep("Bottom to top", () => graph.Direction = BarDirection.BottomToTop);
|
||||
AddStep("Top to bottom", () => graph.Direction = BarDirection.TopToBottom);
|
||||
AddStep("Left to right", () => graph.Direction = BarDirection.LeftToRight);
|
||||
|
@ -51,13 +51,18 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
set
|
||||
{
|
||||
if (!value.Any())
|
||||
{
|
||||
bars.Clear();
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
return;
|
||||
}
|
||||
|
||||
int newCount = value.Count();
|
||||
|
||||
float size = newCount;
|
||||
if (size != 0)
|
||||
size = 1.0f / size;
|
||||
float size = 1.0f / newCount;
|
||||
|
||||
float maxLength = MaxValue ?? (newCount == 0 ? 0 : value.Max());
|
||||
float maxLength = MaxValue ?? value.Max();
|
||||
|
||||
foreach (var bar in value.Select((length, index) => new { Value = length, Index = index }))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user