forked from gbtami/pychess-variants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysisChart.ts
117 lines (115 loc) · 3.89 KB
/
analysisChart.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import Highcharts from "highcharts";
import { _ } from './i18n';
import { selectMove } from './movelist';
import { povChances } from './winningChances';
import { AnalysisController } from './analysisCtrl';
import { Step } from "./messages";
export function analysisChart(ctrl: AnalysisController) {
const scores = ctrl.steps.map(
(step: Step, ply: number) => {
if (step.ceval !== undefined) {
const score = step.ceval.s;
const color = (ctrl.variant.colors.first === "Black") ? step.turnColor === 'black' ? 'white' : 'black' : step.turnColor;
if (score !== undefined) {
const turn = Math.floor((ply - 1) / 2) + 1;
const dots = step.turnColor === 'black' ? '.' : '...';
const point = {
name: turn + dots + ' ' + step.san,
y: povChances(color, score)
};
if (ply === 0) point.name = _('Initial position');
return point;
}
else {
return null;
}
}
else {
return null;
}
}
);
ctrl.analysisChart = Highcharts.chart('chart-analysis', {
chart: { type: 'area',
spacing: [3, 0, 3, 0],
animation: false,
backgroundColor: undefined,
},
credits: { enabled: false },
legend: { enabled: false },
title: { text: undefined },
plotOptions: {
series: {
animation: false
},
area: {
fillColor: 'rgba(255,255,255,0.7)',
negativeFillColor: 'rgba(0,0,0,0.2)',
threshold: 0,
lineWidth: 1,
color: '#d85000',
allowPointSelect: true,
cursor: 'pointer',
states: {
hover: {
lineWidth: 1
}
},
events: {
click: function(event) {
if (event.point) {
event.point.select();
selectMove (ctrl, event.point.x)
}
}
},
marker: {
radius: 1,
states: {
hover: {
radius: 4,
lineColor: '#d85000'
},
select: {
radius: 4,
lineColor: '#d85000'
}
}
}
}
},
tooltip: {
pointFormatter: function(format: string) {
format = format.replace('{series.name}', _('Advantage'));
const self: Highcharts.Point = this;
const step = ctrl.steps[self.x];
const ceval = step?.ceval?.s;
if (!ceval) return '';
else return format.replace('{point.y}', step.scoreStr || '');
} as Highcharts.FormatterCallbackFunction<Highcharts.Point>
},
xAxis: {
title: { text: undefined },
labels: { enabled: false },
gridLineWidth: 0,
lineWidth: 0,
tickWidth: 0
},
yAxis: {
title: { text: undefined },
labels: { enabled: false },
min: -1.1,
max: 1.1,
startOnTick: false,
endOnTick: false,
lineWidth: 1,
gridLineWidth: 0,
plotLines: [{
color: '#a0a0a0',
width: 1,
value: 0,
}]
},
series: [{ data: scores } as Highcharts.SeriesColumnOptions]
});
}