5
5
using pax . chess ;
6
6
using pax . uciChessEngine ;
7
7
using Blazored . Toast . Services ;
8
- using Microsoft . AspNetCore . Components . Routing ;
8
+ using pax . BlazorChartJs ;
9
9
10
10
namespace pax . BlazorChess . Pages ;
11
11
public partial class EngineAnalyzesPage : ComponentBase , IDisposable
@@ -31,15 +31,15 @@ public partial class EngineAnalyzesPage : ComponentBase, IDisposable
31
31
List < GameAnalyzes > GameAnalyzis = new List < GameAnalyzes > ( ) ;
32
32
GameAnalyzes ? Analysis ;
33
33
BoardContainer ? boardContainer ;
34
- ChartComponent ? chart ;
34
+ ChartComponent ? chartComponent ;
35
35
LoadModal ? loadModal ;
36
36
SettingsModal ? settingModal ;
37
37
EngineComponent ? engineComponent ;
38
38
MoveStatsComponent ? moveStatsComponent ;
39
39
40
40
CancellationTokenSource cts = new CancellationTokenSource ( ) ;
41
41
42
- private Chart _chart = ChartService . GetRatingChart ( ) ;
42
+ private ChartJsConfig chartConfig = ChartService . GetRatingChart ( ) ;
43
43
private bool Analyzing = false ;
44
44
private bool Loading = false ;
45
45
@@ -75,7 +75,7 @@ private async Task Init()
75
75
76
76
if ( Analysis != null )
77
77
{
78
- _chart . data . labels = Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ;
78
+ chartConfig . SetLabels ( Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ) ;
79
79
if ( Analysis . Game . ReviewVariations . Any ( ) )
80
80
{
81
81
ReviewVariations = new Dictionary < int , List < Variation > > ( Analysis . Game . ReviewVariations ) ;
@@ -131,8 +131,7 @@ private async Task GameImport(Game game)
131
131
_nav . NavigateTo ( _nav . GetUriWithQueryParameter ( "GameId" , GameId ) ) ;
132
132
}
133
133
}
134
- _chart . data . labels = Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ;
135
- chart ? . UpdateLabels ( _chart . data . labels ) ;
134
+ chartConfig . SetLabels ( Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ) ;
136
135
ReviewVariations . Clear ( ) ;
137
136
reviewVariations . Clear ( ) ;
138
137
UpdateChart ( ) ;
@@ -149,8 +148,9 @@ private void SettingsChoosen()
149
148
}
150
149
}
151
150
152
- private void ChartClicked ( string label )
151
+ private void ChartClicked ( KeyValuePair < Guid , string > report )
153
152
{
153
+ string label = report . Value ;
154
154
if ( Analysis != null )
155
155
{
156
156
int i ;
@@ -167,22 +167,23 @@ private void UpdateChart(bool dry = false)
167
167
{
168
168
if ( Analysis != null )
169
169
{
170
- _chart . data . datasets [ 0 ] . data . Clear ( ) ;
170
+ List < object > data = new ( ) ;
171
+
171
172
for ( int i = 0 ; i < Analysis . Game . State . Moves . Count ; i ++ )
172
173
{
173
174
if ( ReviewVariations . ContainsKey ( i ) && ReviewVariations [ i ] . Any ( ) )
174
175
{
175
176
var chartScore = ReviewVariations [ i ] . OrderBy ( o => o . Pv ) . First ( ) . Evaluation ? . ChartScore ( ) ;
176
- _chart . data . datasets [ 0 ] . data . Add ( chartScore == null ? 0 : ( double ) chartScore ) ;
177
+ data . Add ( chartScore == null ? 0 : ( double ) chartScore ) ;
177
178
}
178
179
else
179
180
{
180
- _chart . data . datasets [ 0 ] . data . Add ( 0 ) ;
181
+ data . Add ( 0 ) ;
181
182
}
182
183
}
183
- if ( ! dry )
184
+ if ( ! dry && chartConfig . Data . Datasets . Any ( ) )
184
185
{
185
- chart ? . UpdateDataset ( _chart . data . datasets [ 0 ] ) ;
186
+ chartConfig . SetData ( chartConfig . Data . Datasets . First ( ) , data ) ;
186
187
}
187
188
}
188
189
}
@@ -191,14 +192,23 @@ private void ObserverMoveChanged()
191
192
{
192
193
if ( Analysis != null && Analysis . Game . ObserverState . CurrentMove != null )
193
194
{
195
+ var arConfig = chartConfig . Options ? . Plugins ? . ArbitraryLines ? . FirstOrDefault ( ) ;
194
196
if ( Analysis . Game . ObserverState . CurrentMove . Variation == null )
195
197
{
196
- chart ? . DrawHorizontalLine ( Analysis . Game . ObserverState . CurrentMove . HalfMoveNumber ) ;
198
+ if ( arConfig != null )
199
+ {
200
+ arConfig . XPosition = Analysis . Game . ObserverState . CurrentMove . HalfMoveNumber ;
201
+ chartComponent ? . UpdateChartOptions ( ) ;
202
+ }
197
203
}
198
204
else
199
205
{
200
206
var startMove = Analysis . Game . ObserverState . CurrentMove . Variation ? . StartMove ;
201
- chart ? . DrawHorizontalLine ( startMove ?? 0 ) ;
207
+ if ( arConfig != null )
208
+ {
209
+ arConfig . XPosition = startMove ?? 0 ;
210
+ chartComponent ? . UpdateChartOptions ( ) ;
211
+ }
202
212
}
203
213
boardContainer ? . DrawReviewHints ( ) ;
204
214
reviewVariations = Analysis . Game . GetCurrentReviewVariations ( ) . ToList ( ) ;
@@ -268,8 +278,7 @@ private async Task Analyse()
268
278
int i = 0 ;
269
279
if ( Analysis != null )
270
280
{
271
- _chart . data . labels = Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ;
272
- chart ? . UpdateLabels ( _chart . data . labels ) ;
281
+ chartConfig . SetLabels ( Analysis . Game . State . Moves . Select ( s => s . HalfMoveNumber . ToString ( ) ) . ToList ( ) ) ;
273
282
Analyzing = true ;
274
283
await InvokeAsync ( ( ) => StateHasChanged ( ) ) ;
275
284
cts = new CancellationTokenSource ( ) ;
0 commit comments