X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;h=ee2432494a50ddc09af28940442579add471bac6;hb=ff326bc273274569e355b4646701e98ad7502b55;hp=1b905a34949de7b67e9b46ffdd19ac710c764fda;hpb=b3aae4b92383a29a31b7c9557655efc45922c3ad;p=remoteglot diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index 1b905a3..ee24324 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -380,9 +380,7 @@ let sync_server_clock = function(server_date_string) { let clear_arrows = function() { for (let i = 0; i < arrows.length; ++i) { if (arrows[i].svg) { - if (arrows[i].svg.parentElement) { - arrows[i].svg.parentElement.removeChild(arrows[i].svg); - } + arrows[i].svg.remove(); delete arrows[i].svg; } } @@ -506,11 +504,12 @@ let position_arrow = function(arrow) { return; } - let zoom_factor = document.getElementById("board").getBoundingClientRect().width / 400.0; + let board_width = parseInt(document.querySelector(".board-b72b1").style.width, 10); + let zoom_factor = board_width / 400.0; let line_width = arrow.line_width * zoom_factor; let arrow_size = arrow.arrow_size * zoom_factor; - let square_width = document.querySelector(".square-a8").getBoundingClientRect().width; + let square_width = board_width / 8; let from_y, to_y, from_x, to_x; if (board.orientation() === 'black') { from_y = (arrow.from_row + 0.5)*square_width; @@ -527,8 +526,8 @@ let position_arrow = function(arrow) { let SVG_NS = "http://www.w3.org/2000/svg"; let XHTML_NS = "http://www.w3.org/1999/xhtml"; let svg = document.createElementNS(SVG_NS, "svg"); - svg.setAttribute("width", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().width)); - svg.setAttribute("height", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().height)); + svg.setAttribute("width", board_width); + svg.setAttribute("height", board_width); svg.setAttribute("style", "position: absolute"); svg.setAttribute("position", "absolute"); svg.setAttribute("version", "1.1"); @@ -1393,16 +1392,12 @@ let update_sparkline = function(data) { let max_score = 1; let last_score = null; let scores = []; - let scores_missing = []; for (let halfmove_num = first_move_num; halfmove_num <= last_move_num; ++halfmove_num) { if (data['score_history'][halfmove_num]) { let score = compute_plot_score(data['score_history'][halfmove_num]); last_score = score; if (score < min_score) min_score = score; if (score > max_score) max_score = score; - scores_missing.push(false); - } else { - scores_missing.push(true); } scores.push(last_score); } @@ -1412,6 +1407,13 @@ let update_sparkline = function(data) { if (score < min_score) min_score = score; if (score > max_score) max_score = score; } + if (max_score - min_score < 100) { + if (Math.abs(max_score) >= Math.abs(min_score)) { + max_score = min_score + 100; + } else { + min_score = max_score - 100; + } + } const h = scorespark.getBoundingClientRect().height; @@ -1448,8 +1450,7 @@ let update_sparkline = function(data) { hlcolor[1] = Math.min(hlcolor[1] * 1.4, 1.0); hlcolor[2] = Math.min(hlcolor[2] * 1.4, 1.0); } - let alpha = scores_missing[i] ? 50 : 100; - rect.style.fill = 'rgba(' + color[0]*100.0 + '%, ' + color[1]*100.0 + '%, ' + color[2]*100.0 + '%, ' + alpha + '%)'; + rect.style.fill = 'rgb(' + color[0]*100.0 + '%, ' + color[1]*100.0 + '%, ' + color[2]*100.0 + '%)'; // score_history contains the Nth _position_, but format_tooltip // wants to format the Nth _move_; thus the -1.