Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/views/analyse/replay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ object replay:
),
div(cls := "analyse__underboard__panels")(
game.analysable option div(cls := "computer-analysis")(
if analysis.isDefined || analysisStarted then div(id := "acpl-chart")
if analysis.isDefined || analysisStarted then
div(id := "acpl-chart-container")(canvas(id := "acpl-chart"))
else
postForm(
cls := s"future-game-analysis${ctx.isAnon so " must-login"}",
Expand All @@ -184,7 +185,7 @@ object replay:
)
),
div(cls := "move-times")(
game.ply > 1 option div(id := "movetimes-chart")
game.ply > 1 option div(id := "movetimes-chart-container")(canvas(id := "movetimes-chart"))
),
div(cls := "fen-pgn")(
div(
Expand Down
1 change: 0 additions & 1 deletion app/views/insight.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object insight:
views.html.base.layout(
title = trans.insight.xChessInsights.txt(u.username),
moreJs = frag(
highchartsLatestTag,
iifeModule("javascripts/insight-refresh.js"),
jsModuleInit(
"insight",
Expand Down
7 changes: 6 additions & 1 deletion app/views/stat/ratingDistribution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ object ratingDistribution:
)
)
),
div(id := "rating_distribution_chart")(spinner)
div(id := "rating_distribution")(
canvas(
id := "rating_distribution_chart",
ariaTitle(trans.weeklyPerfTypeRatingDistribution.txt(perfType.trans))
)(spinner)
)
)
)
}
Expand Down
72 changes: 51 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ui/analyse/css/_round-underboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ $col2-panel-height: 240px;
}
}

#acpl-chart,
#movetimes-chart {
#acpl-chart-container,
#movetimes-chart-container {
width: 100%;
height: var(--panel-height);
background: linear-gradient(
Expand All @@ -133,11 +133,11 @@ $col2-panel-height: 240px;
cursor: pointer;
}

#acpl-chart {
#acpl-chart-container {
cursor: pointer;
}

#acpl-chart-loader {
#acpl-chart-container-loader {
font-size: 0.9em;
position: absolute;
top: 91px;
Expand Down
1 change: 0 additions & 1 deletion ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ export default class AnalyseCtrl {
);
if (data.division) this.data.game.division = data.division;
if (this.retro) this.retro.onMergeAnalysisData();
if (this.study) this.study.serverEval.onMergeAnalysisData();
lichess.pubsub.emit('analysis.server.progress', this.data);
this.redraw();
}
Expand Down
30 changes: 15 additions & 15 deletions ui/analyse/src/serverSideUnderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { ChartGame, AcplChart } from 'chart';
export default function (element: HTMLElement, ctrl: AnalyseCtrl) {
$(element).replaceWith(ctrl.opts.$underboard!);

$('#adv-chart').attr('id', 'acpl-chart');

const data = ctrl.data,
$panels = $('.analyse__underboard__panels > div'),
$menu = $('.analyse__underboard__menu'),
Expand Down Expand Up @@ -42,7 +40,6 @@ export default function (element: HTMLElement, ctrl: AnalyseCtrl) {
lichess.pubsub.on('analysis.comp.toggle', (v: boolean) => {
if (v) {
setTimeout(() => $menu.find('.computer-analysis').first().trigger('mousedown'), 50);
advChart?.reflow();
} else {
$menu.find('span:not(.computer-analysis)').first().trigger('mousedown');
}
Expand All @@ -57,26 +54,29 @@ export default function (element: HTMLElement, ctrl: AnalyseCtrl) {
});
lichess.pubsub.on('analysis.server.progress', (d: AnalyseData) => {
if (!advChart) startAdvantageChart();
else advChart?.updateData(d, ctrl.mainline);
if (d.analysis && !d.analysis.partial) $('#acpl-chart-loader').remove();
else advChart.updateData(d, ctrl.mainline);
if (d.analysis && !d.analysis.partial) $('#acpl-chart-container-loader').remove();
});
}

const chartLoader = () =>
`<div id="acpl-chart-loader"><span>Stockfish 16<br>server analysis</span>${lichess.spinnerHtml}</div>`;
`<div id="acpl-chart-container-loader"><span>Stockfish 16<br>server analysis</span>${lichess.spinnerHtml}</div>`;

function startAdvantageChart() {
if (advChart || lichess.blindMode) return;
const loading = !ctrl.tree.root.eval || !Object.keys(ctrl.tree.root.eval).length;
const $panel = $panels.filter('.computer-analysis');
if (!$('#acpl-chart').length) $panel.html('<div id="acpl-chart"></div>' + (loading ? chartLoader() : ''));
else if (loading && !$('#acpl-chart-loader').length) $panel.append(chartLoader());
lichess
.loadEsm<ChartGame>('chart.game')
.then(m => m.acpl($('#acpl-chart')[0] as HTMLElement, data, ctrl.mainline, ctrl.trans))
.then(chart => {
if (!$('#acpl-chart-container').length)
$panel.html(
'<div id="acpl-chart-container"><canvas id="acpl-chart"></canvas></div>' +
(loading ? chartLoader() : ''),
);
else if (loading && !$('#acpl-chart-container-loader').length) $panel.append(chartLoader());
lichess.loadEsm<ChartGame>('chart.game').then(m =>
m.acpl($('#acpl-chart')[0] as HTMLCanvasElement, data, ctrl.mainline, ctrl.trans).then(chart => {
advChart = chart;
});
}),
);
}

const storage = lichess.storage.make('analysis.panel');
Expand All @@ -90,9 +90,9 @@ export default function (element: HTMLElement, ctrl: AnalyseCtrl) {
if ((panel == 'move-times' || ctrl.opts.hunter) && !timeChartLoaded)
lichess.loadEsm<ChartGame>('chart.game').then(m => {
timeChartLoaded = true;
m.movetime($('#movetimes-chart')[0] as HTMLElement, data, ctrl.trans, ctrl.opts.hunter);
m.movetime($('#movetimes-chart')[0] as HTMLCanvasElement, data, ctrl.trans, ctrl.opts.hunter);
});
if ((panel == 'computer-analysis' || ctrl.opts.hunter) && $('#acpl-chart').length)
if ((panel == 'computer-analysis' || ctrl.opts.hunter) && $('#acpl-chart-container').length)
setTimeout(startAdvantageChart, 200);
};
$menu.on('mousedown', 'span', function (this: HTMLElement) {
Expand Down
11 changes: 5 additions & 6 deletions ui/analyse/src/study/serverEval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export default class ServerEval {
this.requested = false;
};

onMergeAnalysisData = () => this.chart?.updateData(this.root.data, this.root.mainline);

request = () => {
this.root.socket.send('requestAnalysis', this.chapterId());
this.requested = true;
Expand All @@ -31,14 +29,13 @@ export function view(ctrl: ServerEval): VNode {

if (!ctrl.root.showComputer()) return disabled();
if (!analysis) return ctrl.requested ? requested() : requestButton(ctrl);

return h(
'div.study__server-eval.ready.' + analysis.id,
const chart = h(
'canvas.study__server-eval.ready.' + analysis.id,
{
hook: onInsert(el => {
lichess.requestIdleCallback(async () => {
(await lichess.loadEsm<ChartGame>('chart.game')).acpl(
el,
el as HTMLCanvasElement,
ctrl.root.data,
ctrl.root.mainline,
ctrl.root.trans,
Expand All @@ -48,6 +45,8 @@ export function view(ctrl: ServerEval): VNode {
},
[h('div.study__message', spinnerVdom())],
);

return h('div.study__server-eval.ready.', chart);
}

const disabled = () => h('div.study__server-eval.disabled.padded', 'You disabled computer analysis.');
Expand Down
Loading