- // FIXME: at some widths, calling sparkline() seems to push
- // #scorecontainer under the board.
- $('#scorespark').unbind('sparklineClick');
- $("#scorespark").sparkline(scores, {
- type: 'bar',
- zeroColor: 'gray',
- chartRangeMin: min_score,
- chartRangeMax: max_score,
- tooltipFormatter: function(sparkline, options, fields) {
- // score_history contains the Nth _position_, but format_tooltip
- // wants to format the Nth _move_; thus the -1.
- return format_tooltip(data, fields[0].offset + first_move_num - 1);
+
+ const h = scorespark.getBoundingClientRect().height;
+
+ let base_y = h - h * min_score / (min_score - max_score);
+ for (let i = 0; i < scores.length; ++i) {
+ let rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
+ //rect.setAttributeNS(null, 'stroke', "#000000");
+ rect.setAttributeNS(null, 'x', i * 5)
+ rect.setAttributeNS(null, 'width', 4);
+ let extent = scores[i] * h / (max_score - min_score);
+ if (extent > 0 && extent < 1) {
+ extent = 1;
+ } else if (extent < 0 && extent > -1) {
+ extent = -1;
+ }
+
+ let color;
+ if (scores[i] === 0) {
+ color = [0.5, 0.5, 0.5];
+ rect.setAttributeNS(null, 'y', base_y - 1);
+ rect.setAttributeNS(null, 'height', 1);
+ } else if (scores[i] > 0) {
+ color = [0.2, 0.4, 0.8];
+ rect.setAttributeNS(null, 'y', base_y - extent);
+ rect.setAttributeNS(null, 'height', extent);
+ } else {
+ color = [1.0, 0.267, 0.267];
+ rect.setAttributeNS(null, 'y', base_y);
+ rect.setAttributeNS(null, 'height', -extent);