migrate highcharts

js-sound-v2
Thibault Duplessis 2020-09-13 09:22:38 +02:00
parent a1bafa726c
commit 754ef73585
11 changed files with 36 additions and 42 deletions

View File

@ -83,7 +83,7 @@ object page {
info.ratingChart.map { ratingChart => info.ratingChart.map { ratingChart =>
frag( frag(
jsTag("chart/ratingHistory.js"), jsTag("chart/ratingHistory.js"),
embedJsUnsafeLoadThen(s"lichess.ratingHistoryChart($ratingChart);") embedJsUnsafeLoadThen(s"lichess.ratingHistoryChart($ratingChart)")
) )
}, },
withSearch option jsModule("game-search"), withSearch option jsModule("game-search"),

View File

@ -7,7 +7,7 @@ lichess.advantageChart = function(data, trans, el) {
lichess.chartCommon('highchart').then(function() { lichess.chartCommon('highchart').then(function() {
lichess.advantageChart.update = function(d) { lichess.advantageChart.update = function(d) {
$(el).highcharts().series[0].setData(makeSerieData(d)); el.highcharts && el.highcharts.series[0].setData(makeSerieData(d));
}; };
var blurs = [ toBlurArray(data.player), toBlurArray(data.opponent) ]; var blurs = [ toBlurArray(data.player), toBlurArray(data.opponent) ];
@ -15,7 +15,7 @@ lichess.advantageChart = function(data, trans, el) {
var makeSerieData = function(d) { var makeSerieData = function(d) {
var partial = !d.analysis || d.analysis.partial; var partial = !d.analysis || d.analysis.partial;
return d.treeParts.slice(1).map(function(node, i) { return d.treeParts.slice(1).map(function(node) {
var color = node.ply & 1, cp; var color = node.ply & 1, cp;
@ -57,7 +57,7 @@ lichess.advantageChart = function(data, trans, el) {
text: null text: null
}; };
var serieData = makeSerieData(data); var serieData = makeSerieData(data);
var chart = $(el).highcharts({ el.highcharts = Highcharts.chart(el, {
credits: disabled, credits: disabled,
legend: disabled, legend: disabled,
series: [{ series: [{

View File

@ -61,7 +61,7 @@ lichess.movetimeChart = function(data, trans) {
var noText = { var noText = {
text: null text: null
}; };
$this.highcharts({ this.highcharts = Highcharts.chart(this, {
credits: disabled, credits: disabled,
legend: disabled, legend: disabled,
series: [{ series: [{

View File

@ -22,7 +22,7 @@ lichess.ratingDistributionChart = function(data) {
var cumul = []; var cumul = [];
for (var i = 0; i < data.freq.length; i++) for (var i = 0; i < data.freq.length; i++)
cumul.push(Math.round(arraySum(data.freq.slice(0, i)) / sum * 100)); cumul.push(Math.round(arraySum(data.freq.slice(0, i)) / sum * 100));
$(this).highcharts({ Highcharts.chart(this, {
yAxis: { yAxis: {
title: noText title: noText
}, },

View File

@ -56,7 +56,7 @@ lichess.ratingHistoryChart = function(data, singlePerfName) {
'Dash', // Puzzle 'Dash', // Puzzle
'Dash' // Ultrabullet 'Dash' // Ultrabullet
].filter(indexFilter); ].filter(indexFilter);
$(this).highcharts('StockChart', { Highcharts.stockChart(this, {
yAxis: { yAxis: {
title: noText title: noText
}, },

View File

@ -1,4 +1,4 @@
$(function() { lichess.load.then(() => {
Highcharts.makeFont = function(size) { Highcharts.makeFont = function(size) {
return size + "px 'Noto Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif"; return size + "px 'Noto Sans', 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif";
@ -191,12 +191,13 @@ $(function() {
}; };
var charts = {}; var charts = {};
$('.server .meter').highcharts(buildChart({
Highcharts.chart(document.querySelector('.server .meter'), buildChart({
title: 'SERVER' title: 'SERVER'
}), function(c) { }), function(c) {
charts.server = c; charts.server = c;
}); });
$('.network .meter').highcharts(buildChart({ Highcharts.chart(document.querySelector('.network .meter'), buildChart({
title: 'PING' title: 'PING'
}), function(c) { }), function(c) {
charts.network = c; charts.network = c;
@ -215,20 +216,14 @@ $(function() {
$('.lag .answer span').hide().parent().find('.' + c).show(); $('.lag .answer span').hide().parent().find('.' + c).show();
}; };
lichess.socket = new lichess.StrongSocket('/socket/v4', false, { lichess.StrongSocket.firstConnect.then(() => lichess.socket.send('moveLat', true));
options: {
name: 'analyse' lichess.pubsub.on('socket.in.mlat', d => {
}, const v = parseInt(d);
receive(t, d) { charts.server.series[0].points[0].update(v);
if (t === 'mlat') { values.server = v;
var v = parseInt(d); updateAnswer();
charts.server.series[0].points[0].update(v);
values.server = v;
updateAnswer();
}
}
}); });
lichess.StrongSocket.firstConnect.then(() =>lichess.socket.send('moveLat', true));
setInterval(function() { setInterval(function() {
const v = Math.round(lichess.socket.averageLag); const v = Math.round(lichess.socket.averageLag);

View File

@ -357,7 +357,6 @@ interface Cash {
powerTip(options?: PowerTip.Options | 'show' | 'hide'): Cash; powerTip(options?: PowerTip.Options | 'show' | 'hide'): Cash;
sparkline: any; sparkline: any;
clock: any; clock: any;
highcharts(conf?: any): any;
} }
declare namespace PowerTip { declare namespace PowerTip {

View File

@ -38,7 +38,7 @@ export default function(element: HTMLElement, ctrl: AnalyseCtrl) {
lastFen = fen; lastFen = fen;
} }
if ($chart.length) { if ($chart.length) {
chart = window.Highcharts && $chart.highcharts(); chart = $chart[0]!['highcharts'];
if (chart) { if (chart) {
if (mainlinePly != chart.lastPly) { if (mainlinePly != chart.lastPly) {
if (mainlinePly === false) unselect(chart); if (mainlinePly === false) unselect(chart);
@ -52,7 +52,7 @@ export default function(element: HTMLElement, ctrl: AnalyseCtrl) {
} }
} }
if ($timeChart.length) { if ($timeChart.length) {
chart = window.Highcharts && $timeChart.highcharts(); chart = $timeChart[0]!['highcharts'];
if (chart) { if (chart) {
if (mainlinePly != chart.lastPly) { if (mainlinePly != chart.lastPly) {
if (mainlinePly === false) unselect(chart); if (mainlinePly === false) unselect(chart);
@ -109,7 +109,12 @@ export default function(element: HTMLElement, ctrl: AnalyseCtrl) {
setPanel(panel); setPanel(panel);
}); });
const stored = storage.get(); const stored = storage.get();
if (stored && $menu.children(`[data-panel="${stored}"]:visible`).length) setPanel(stored); const foundStored = stored && $menu.children(`[data-panel="${stored}"]`).
filter(function(this: HTMLElement) {
const display = window.getComputedStyle(this).display;
return !!display && display != 'none';
}).length;
if (foundStored) setPanel(stored!);
else { else {
const $menuCt = $menu.children('[data-panel="ctable"]'); const $menuCt = $menu.children('[data-panel="ctable"]');
($menuCt.length ? $menuCt : $menu.children(':first-child')).trigger('mousedown'); ($menuCt.length ? $menuCt : $menu.children(':first-child')).trigger('mousedown');

View File

@ -30,19 +30,14 @@ export function ctrl(root: AnalyseCtrl, chapterId: () => string): ServerEvalCtrl
li.pubsub.on('analysis.change', (_fen: string, _path: string, mainlinePly: number | false) => { li.pubsub.on('analysis.change', (_fen: string, _path: string, mainlinePly: number | false) => {
if (!li.advantageChart || lastPly() === mainlinePly) return; if (!li.advantageChart || lastPly() === mainlinePly) return;
const lp = lastPly(typeof mainlinePly === 'undefined' ? lastPly() : mainlinePly), const lp = lastPly(typeof mainlinePly === 'undefined' ? lastPly() : mainlinePly),
el = chartEl(); el = chartEl(),
if (el && window.Highcharts) { chart = el && el['highcharts'];
const $chart = $(el); if (chart) {
if ($chart.length) { if (lp === false) unselect(chart);
const chart = $chart.highcharts(); else {
if (chart) { const point = chart.series[0].data[lp - 1 - root.tree.root.ply];
if (lp === false) unselect(chart); if (defined(point)) point.select();
else { else unselect(chart);
const point = chart.series[0].data[lp - 1 - root.tree.root.ply];
if (defined(point)) point.select();
else unselect(chart);
}
} else lastPly(false);
} }
} else lastPly(false); } else lastPly(false);
}); });

View File

@ -216,7 +216,7 @@ function makeChart(el, data) {
} }
}; };
if (theme.colors) chartConf.colors = theme.colors; if (theme.colors) chartConf.colors = theme.colors;
$(el).highcharts(chartConf); Highcharts.chart(el, chartConf);
} }
function empty(txt) { function empty(txt) {

View File

@ -33,7 +33,7 @@
} }
p { p {
margin: 1em 0; margin: 1em;
} }
h2 { h2 {