Skip to content

Commit 02defc9

Browse files
authored
Merge pull request #537 from ipax77/dev
cleanup Builds UnitsChart
2 parents 7f5bddc + a3e0b5c commit 02defc9

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/dsstats.razorlib/Builds/UnitsChartComponent.razor

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
private UnitChartData unitChartData = new();
1818
private bool isInit;
19+
private int requestHash;
1920

2021
protected override void OnInitialized()
2122
{
@@ -30,30 +31,6 @@
3031
},
3132
Datasets = new List<ChartJsDataset>()
3233
{
33-
new BarDataset()
34-
{
35-
Label = "Roach",
36-
Data = new List<object>() { 12, 19, 3 },
37-
BackgroundColor = "rgba(255, 99, 132, 0.2)",
38-
BorderColor = "rgba(255, 99, 132, 1)",
39-
BorderWidth = 1
40-
},
41-
new BarDataset()
42-
{
43-
Label = "Mutalisk",
44-
Data = new List<object>() { 30, 20, 10 },
45-
BackgroundColor = "rgba(54, 162, 235, 0.2)",
46-
BorderColor = "rgba(54, 162, 235, 1)",
47-
BorderWidth = 1
48-
},
49-
new BarDataset()
50-
{
51-
Label = "Swarmhost",
52-
Data = new List<object>() { 22, 19, 30 },
53-
BackgroundColor = "rgba(255, 206, 86, 0.2)",
54-
BorderColor = "rgba(255, 206, 86, 1)",
55-
BorderWidth = 1
56-
},
5734
}
5835
},
5936
Options = new ChartJsOptions()
@@ -151,8 +128,30 @@
151128

152129
public void Update(BuildRequest request)
153130
{
131+
var hash = GetHashExcludingBreakpoint(request);
154132
Request = request;
155-
_ = LoadData();
133+
if (hash != requestHash)
134+
{
135+
_ = LoadData();
136+
}
137+
requestHash = hash;
138+
}
139+
140+
public static int GetHashExcludingBreakpoint(BuildRequest request)
141+
{
142+
var hash = new HashCode();
143+
hash.Add(request.RatingType);
144+
hash.Add(request.TimePeriod);
145+
hash.Add(request.Interest);
146+
hash.Add(request.Versus);
147+
hash.Add(request.FromRating);
148+
hash.Add(request.ToRating);
149+
hash.Add(request.WithLeavers);
150+
151+
foreach (var name in request.PlayerNames)
152+
hash.Add(name);
153+
154+
return hash.ToHashCode();
156155
}
157156

158157
private async Task LoadData()
@@ -196,8 +195,8 @@
196195
{
197196
Label = unitName,
198197
Data = data.Cast
199-
<object>
200-
().ToList(),
198+
<object>
199+
().ToList(),
201200
BackgroundColor = hexColor + "80",
202201
BorderColor = hexColor,
203202
BorderWidth = 1,

0 commit comments

Comments
 (0)