fix computer analysis live display
there was a race condition in the listeners of the socket eventpull/5077/head
parent
fce08ff636
commit
edd8f07068
|
@ -6,14 +6,15 @@ lichess.advantageChart = function(data, trans, el) {
|
|||
lichess.loadScript('javascripts/chart/division.js').done(function() {
|
||||
lichess.chartCommon('highchart').done(function() {
|
||||
|
||||
lichess.advantageChart.update = function(d, partial) {
|
||||
$(el).highcharts().series[0].setData(makeSerieData(d, partial));
|
||||
lichess.advantageChart.update = function(d) {
|
||||
$(el).highcharts().series[0].setData(makeSerieData(d));
|
||||
};
|
||||
|
||||
var blurs = [ toBlurArray(data.player), toBlurArray(data.opponent) ];
|
||||
if (data.player.color === 'white') blurs.reverse();
|
||||
|
||||
var makeSerieData = function(d, partial) {
|
||||
var makeSerieData = function(d) {
|
||||
var partial = !d.analysis || d.analysis.partial;
|
||||
return d.treeParts.slice(1).map(function(node, i) {
|
||||
|
||||
var color = node.ply & 1, cp;
|
||||
|
|
|
@ -43,7 +43,7 @@ interface Lichess {
|
|||
absolute(date: number | Date): string;
|
||||
}
|
||||
advantageChart: {
|
||||
update(data: any, partial: boolean): void;
|
||||
update(data: any): void;
|
||||
(data: any, trans: Trans, el: HTMLElement): void;
|
||||
}
|
||||
dispatchEvent(el: HTMLElement | Window, eventName: string): void;
|
||||
|
|
|
@ -734,6 +734,7 @@ 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();
|
||||
li.pubsub.emit('analysis.server.progress')(this.data);
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ window.lichess.AnalyseNVUI = function(redraw: Redraw) {
|
|||
moveStyle = styleSetting(),
|
||||
analysisInProgress = prop(false);
|
||||
|
||||
window.lichess.pubsub.on('analysis.server.complete', () => notify.set('Server-side analysis complete'));
|
||||
window.lichess.pubsub.on('analysis.server.progress', (data: AnalyseData) => {
|
||||
if (data.analysis && !data.analysis.partial) notify.set('Server-side analysis complete')
|
||||
});
|
||||
|
||||
return {
|
||||
render(ctrl: AnalyseController): VNode {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import AnalyseCtrl from './ctrl';
|
||||
import { defined } from 'common';
|
||||
import { baseUrl } from './util';
|
||||
import { AnalyseData } from './interfaces';
|
||||
|
||||
export default function(element: HTMLElement, ctrl: AnalyseCtrl) {
|
||||
|
||||
|
@ -64,14 +65,10 @@ export default function(element: HTMLElement, ctrl: AnalyseCtrl) {
|
|||
}
|
||||
}
|
||||
});
|
||||
li.pubsub.on('socket.in.analysisProgress', d => {
|
||||
const partial = !d.tree.eval;
|
||||
li.pubsub.on('analysis.server.progress', (d: AnalyseData) => {
|
||||
if (!li.advantageChart) startAdvantageChart();
|
||||
else if (li.advantageChart.update) li.advantageChart.update(data, partial);
|
||||
if (!partial) {
|
||||
li.pubsub.emit('analysis.server.complete')();
|
||||
$("#adv-chart-loader").remove();
|
||||
}
|
||||
else if (li.advantageChart.update) li.advantageChart.update(d);
|
||||
if (d.analysis && !d.analysis.partial) $("#adv-chart-loader").remove();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ export function ctrl(root: AnalyseCtrl, chapterId: () => string): ServerEvalCtrl
|
|||
},
|
||||
chapterId,
|
||||
onMergeAnalysisData() {
|
||||
if (li.advantageChart) li.advantageChart.update(root.data, false);
|
||||
if (li.advantageChart) li.advantageChart.update(root.data);
|
||||
},
|
||||
request() {
|
||||
root.socket.send('requestAnalysis', chapterId());
|
||||
|
|
Loading…
Reference in New Issue