From 111cc93e610e7866f7f9ca63ebd0e3c948b0bf81 Mon Sep 17 00:00:00 2001
From: Benedikt Werner <1benediktwerner@gmail.com>
Date: Sat, 12 Jun 2021 13:14:11 +0200
Subject: [PATCH] Movetime chart: Only set last total time to 0 if it actually
was a timeout
---
public/javascripts/chart/movetime.js | 30 +++++++++++++++++-----------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/public/javascripts/chart/movetime.js b/public/javascripts/chart/movetime.js
index df08122d22..d4a4c3dde3 100644
--- a/public/javascripts/chart/movetime.js
+++ b/public/javascripts/chart/movetime.js
@@ -52,7 +52,7 @@ lichess.movetimeChart = function (data, trans, hunter) {
const blurs = [toBlurArray(data.player), toBlurArray(data.opponent)];
if (data.player.color === 'white') blurs.reverse();
- data.game.moveCentis.forEach(function (time, x) {
+ data.game.moveCentis.forEach(function (centis, x) {
const node = tree[x + 1];
ply = node ? node.ply : ply + 1;
const san = node ? node.san : '-';
@@ -61,7 +61,7 @@ lichess.movetimeChart = function (data, trans, hunter) {
const color = ply & 1;
const colorName = color ? 'white' : 'black';
- const y = Math.pow(Math.log(0.005 * Math.min(time, 12e4) + 3), 2) - logC;
+ const y = Math.pow(Math.log(0.005 * Math.min(centis, 12e4) + 3), 2) - logC;
maxMove = Math.max(y, maxMove);
let label = turn + (color ? '. ' : '... ') + san;
@@ -81,18 +81,29 @@ lichess.movetimeChart = function (data, trans, hunter) {
label += ' [blur]';
}
- labels.push(label);
+ const seconds = (centis / 100).toFixed(centis >= 200 ? 1 : 2);
+ label += '
' + trans('nbSeconds', '' + seconds + '');
moveSeries[colorName].push(movePoint);
- const clock = node ? node.clock : x === data.game.moveCentis.length - 1 ? 0 : undefined;
- if (clock == undefined) showTotal = false;
- else {
+ let clock = node?.clock;
+ if (clock == undefined) {
+ if (x < data.game.moveCentis.length - 1) showTotal = false;
+ else if (data.game.status.name === 'outoftime') clock = 0;
+ else if (data.clock) {
+ const prevClock = tree[x - 1]?.clock;
+ if (prevClock) clock = prevClock + data.clock.increment + centis;
+ }
+ }
+ if (clock != undefined) {
+ label += '
' + formatClock(clock);
maxTotal = Math.max(clock, maxTotal);
totalSeries[colorName].push({
x,
y: color ? clock : -clock,
});
}
+
+ labels.push(label);
});
const disabled = {
@@ -157,12 +168,7 @@ lichess.movetimeChart = function (data, trans, hunter) {
},
tooltip: {
formatter: function () {
- let seconds = data.game.moveCentis[this.x] / 100;
- if (seconds) seconds = seconds.toFixed(seconds >= 2 ? 1 : 2);
- let text = labels[this.x] + '
' + trans('nbSeconds', '' + seconds + '');
- const node = tree[this.x + 1];
- if (node && node.clock) text += '
' + formatClock(node.clock);
- return text;
+ return labels[this.x];
},
},
plotOptions: {