olewave-user commited on
Commit
2502cef
·
verified ·
1 Parent(s): 78312b5

Refresh the board: sort arrows, Olewave wordmark above the table

Browse files
leaderboard.css CHANGED
@@ -528,3 +528,27 @@
528
  [data-theme="dark"] .fab-lb .fab-lb__barfill { background: var(--bar-night, var(--bar)); }
529
  [data-theme="dark"] .fab-lb .fab-lb__source a,
530
  [data-theme="dark"] .fab-lb .fab-lb__notes a { color: #9b85ff; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  [data-theme="dark"] .fab-lb .fab-lb__barfill { background: var(--bar-night, var(--bar)); }
529
  [data-theme="dark"] .fab-lb .fab-lb__source a,
530
  [data-theme="dark"] .fab-lb .fab-lb__notes a { color: #9b85ff; }
531
+
532
+ /* A numeric column's sort arrow: a small down triangle that sorts the table
533
+ by that column, highest first. Its active state marks the sorted column. */
534
+ .fab-lb table.fab-lb__tbl .fab-lb__sort {
535
+ display: inline-flex; align-items: center; justify-content: center;
536
+ width: 18px; height: 18px; margin: 0 0 0 4px; padding: 0; vertical-align: middle;
537
+ border: 0; border-radius: 4px; background: transparent; color: #9a9a9a; cursor: pointer;
538
+ }
539
+ .fab-lb table.fab-lb__tbl .fab-lb__sort svg { width: 10px; height: 10px; fill: currentColor; }
540
+ .fab-lb table.fab-lb__tbl .fab-lb__sort:hover,
541
+ .fab-lb table.fab-lb__tbl .fab-lb__sort.is-active { color: var(--fab-ink); }
542
+ .fab-lb table.fab-lb__tbl .fab-lb__sort:focus-visible { outline: 2px solid #5f3bff; outline-offset: 1px; }
543
+
544
+ /* The Olewave wordmark above the table, at its top right, so a crop of the table keeps it.
545
+ The white wordmark shows in dark mode. */
546
+ .fab-lb .fab-lb__mark { display: flex; justify-content: flex-end; margin: 0 0 8px; }
547
+ .fab-lb .fab-lb__mark img { display: block; width: 144px; height: 24px; }
548
+ .fab-lb .fab-lb__mark .fab-lb__mark--dark { display: none; }
549
+ html[data-theme="dark"] .fab-lb .fab-lb__mark--light { display: none; }
550
+ html[data-theme="dark"] .fab-lb .fab-lb__mark--dark { display: block; }
551
+ @media (prefers-color-scheme: dark) {
552
+ :root:not([data-theme="light"]) .fab-lb .fab-lb__mark--light { display: none; }
553
+ :root:not([data-theme="light"]) .fab-lb .fab-lb__mark--dark { display: block; }
554
+ }
leaderboard.js CHANGED
@@ -322,10 +322,34 @@
322
  on: f3(rec ? d.f1_mean4 : d.f1_mean4_recognized), drop: f3(d.f1_drop) });
323
  }
324
 
325
- function ranked(data, view, cell) {
 
 
 
 
 
 
 
 
 
326
  return data
327
  .filter(function (d) { return view === 'all' || d.access === view; })
328
- .sort(function (a, b) { return (b[cell] - a[cell]) || a.label.localeCompare(b.label); });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  }
330
 
331
  function Leaderboard(root, boards, logoBase) {
@@ -348,6 +372,8 @@
348
  this.boards = boards;
349
  this.view = 'all';
350
  this.cell = 'f1_mean4';
 
 
351
  this.words = 'reference';
352
  this.logoBase = logoBase;
353
  this.build();
@@ -415,7 +441,7 @@
415
  });
416
  this.select = el('select', { 'aria-label': 'Test cells to rank by' },
417
  CELLS.map(function (c) { return el('option', { value: c.key }, c.label); }));
418
- this.select.addEventListener('change', function () { self.cell = self.select.value; self.render(); });
419
 
420
  this.live = el('div', { class: 'fab-lb__sr', 'aria-live': 'polite' });
421
  this.notes = el('div', { class: 'fab-lb__notes' });
@@ -433,9 +459,16 @@
433
  ]));
434
  // Outside the scrolling wrap, so on a phone it wraps to the card's width.
435
  b.drop = b.track === 1 ? el('p', { class: 'fab-lb__drop' }, dropLine(b)) : null;
436
- self.drawTable(b, ranked(b.data, 'all', 'f1_mean4'), 'f1_mean4', 'all');
437
  });
438
- var table = el('div', { class: 'fab-lb__table is-board' }, this.boards.map(function (b) { return [b.wrap, b.drop]; }));
 
 
 
 
 
 
 
439
 
440
  var controls = el('div', { class: 'fab-lb__controls' }, [
441
  el('div', { class: 'fab-lb__seg', role: 'group', 'aria-label': 'Systems to show' }, this.viewButtons),
@@ -524,17 +557,20 @@
524
  };
525
 
526
  Leaderboard.prototype.visible = function () {
527
- return ranked(this.data, this.view, this.cell);
528
  };
529
 
530
  Leaderboard.prototype.render = function () {
531
  var list = this.visible(), cell = this.cell;
532
  this.subEl.textContent = SUBTITLE[cell];
533
- this.drawTable(this.board, list, cell, this.view);
534
  this.drawNotes(list);
535
  var cellLabel = CELLS.filter(function (c) { return c.key === cell; })[0].label;
536
- this.live.textContent = tf('{title}. {n} systems, ranked by {cell}.', {
537
- title: boardTitle(this.board), n: list.length, cell: cellLabel.toLowerCase() });
 
 
 
538
  };
539
 
540
  // The sorted column draws each ranked row's value as a bar in its
@@ -547,9 +583,10 @@
547
  // shows it. A view of one cell shows that cell's F1
548
  // and error rate alone, since the mean, F1 Drop and the other
549
  // cells' numbers would sit beside a ranking they don't follow.
550
- Leaderboard.prototype.drawTable = function (b, list, cell, view) {
551
  var self = this;
552
- var spans = view === 'all' && cell === 'f1_mean4';
 
553
  var top = niceMax(Math.max.apply(null, list.map(function (d) {
554
  return d[cell + '_hi'] != null ? d[cell + '_hi'] : d[cell];
555
  }).concat([0])));
@@ -581,10 +618,19 @@
581
  b.caption.textContent = captionOf(b, cell);
582
  // The F1 Drop line goes with its column, which a view of one cell drops.
583
  if (b.drop && this.board === b) b.drop.hidden = cell !== 'f1_mean4';
 
584
  b.thead.textContent = '';
585
  b.thead.appendChild(el('tr', null, cols.map(function (c) {
 
 
 
 
 
 
 
 
586
  return el('th', { class: (c.num ? 'num' : '') + (c.key === cell ? ' is-sorted' : ''), scope: 'col',
587
- 'aria-sort': c.key === cell ? 'descending' : null }, c.label);
588
  })));
589
  b.tbody.textContent = '';
590
  list.forEach(function (d, i) {
@@ -638,6 +684,14 @@
638
  }
639
  };
640
 
 
 
 
 
 
 
 
 
641
  Leaderboard.prototype.drawNotes = function (list) {
642
  var seen = {}, lines = [], hrefs = this.hrefs;
643
  list.forEach(function (d) {
 
322
  on: f3(rec ? d.f1_mean4 : d.f1_mean4_recognized), drop: f3(d.f1_drop) });
323
  }
324
 
325
+ // Error, price and drop columns are better when smaller, so they sort from the smallest.
326
+ function lowerIsBetter(key) { return /^(wer_|per_|mae_)/.test(key) || key === 'price_usd_per_hour' || key === 'f1_drop'; }
327
+ // A column's number for sorting; a missing one sorts last either way.
328
+ function numOf(v, low) {
329
+ if (v === null || v === undefined || v === '' || isNaN(v)) return low ? Infinity : -Infinity;
330
+ return +v;
331
+ }
332
+ // Rows sorted by the column key, its better end first, ties by name.
333
+ function ranked(data, view, key) {
334
+ var low = lowerIsBetter(key);
335
  return data
336
  .filter(function (d) { return view === 'all' || d.access === view; })
337
+ .sort(function (a, b) {
338
+ var x = numOf(a[key], low), y = numOf(b[key], low);
339
+ if (x !== y) return (x < y) === !low ? 1 : -1;
340
+ return a.label.localeCompare(b.label);
341
+ });
342
+ }
343
+ // The arrow on a sortable column's header: down for highest first, up for smallest first.
344
+ function sortArrow(low) {
345
+ var NS = 'http://www.w3.org/2000/svg', svg = document.createElementNS(NS, 'svg');
346
+ svg.setAttribute('viewBox', '0 0 10 10');
347
+ svg.setAttribute('aria-hidden', 'true');
348
+ svg.setAttribute('focusable', 'false');
349
+ var p = document.createElementNS(NS, 'path');
350
+ p.setAttribute('d', low ? 'M5 1.5 1.5 6.5h7z' : 'M5 8.5 1.5 3.5h7z');
351
+ svg.appendChild(p);
352
+ return svg;
353
  }
354
 
355
  function Leaderboard(root, boards, logoBase) {
 
372
  this.boards = boards;
373
  this.view = 'all';
374
  this.cell = 'f1_mean4';
375
+ // The column the table is sorted by, or null to sort by the cell it ranks by.
376
+ this.sortKey = null;
377
  this.words = 'reference';
378
  this.logoBase = logoBase;
379
  this.build();
 
441
  });
442
  this.select = el('select', { 'aria-label': 'Test cells to rank by' },
443
  CELLS.map(function (c) { return el('option', { value: c.key }, c.label); }));
444
+ this.select.addEventListener('change', function () { self.cell = self.select.value; self.sortKey = null; self.render(); });
445
 
446
  this.live = el('div', { class: 'fab-lb__sr', 'aria-live': 'polite' });
447
  this.notes = el('div', { class: 'fab-lb__notes' });
 
459
  ]));
460
  // Outside the scrolling wrap, so on a phone it wraps to the card's width.
461
  b.drop = b.track === 1 ? el('p', { class: 'fab-lb__drop' }, dropLine(b)) : null;
462
+ self.drawTable(b, ranked(b.data, 'all', 'f1_mean4'), 'f1_mean4', 'all', 'f1_mean4');
463
  });
464
+ // The Olewave wordmark sits above the table at its top right, so a crop of the table keeps it.
465
+ var mark = el('div', { class: 'fab-lb__mark' }, [
466
+ el('img', { class: 'fab-lb__mark--light', src: this.logoBase + 'olewave-wordmark.png', alt: 'Olewave',
467
+ width: 144, height: 24, decoding: 'async' }),
468
+ el('img', { class: 'fab-lb__mark--dark', src: this.logoBase + 'olewave-wordmark-white.png', alt: 'Olewave',
469
+ width: 144, height: 24, decoding: 'async' })
470
+ ]);
471
+ var table = el('div', { class: 'fab-lb__table is-board' }, [mark].concat(this.boards.map(function (b) { return [b.wrap, b.drop]; })));
472
 
473
  var controls = el('div', { class: 'fab-lb__controls' }, [
474
  el('div', { class: 'fab-lb__seg', role: 'group', 'aria-label': 'Systems to show' }, this.viewButtons),
 
557
  };
558
 
559
  Leaderboard.prototype.visible = function () {
560
+ return ranked(this.data, this.view, this.sortKey || this.cell);
561
  };
562
 
563
  Leaderboard.prototype.render = function () {
564
  var list = this.visible(), cell = this.cell;
565
  this.subEl.textContent = SUBTITLE[cell];
566
+ this.drawTable(this.board, list, cell, this.view, this.sortKey || cell);
567
  this.drawNotes(list);
568
  var cellLabel = CELLS.filter(function (c) { return c.key === cell; })[0].label;
569
+ this.live.textContent = this.sortKey && this.sortKey !== cell
570
+ ? tf(lowerIsBetter(this.sortKey) ? '{title}. {n} systems, sorted by {column}, smallest first.' : '{title}. {n} systems, sorted by {column}, highest first.', {
571
+ title: boardTitle(this.board), n: list.length, column: this.board.sortLabel })
572
+ : tf('{title}. {n} systems, ranked by {cell}.', {
573
+ title: boardTitle(this.board), n: list.length, cell: cellLabel.toLowerCase() });
574
  };
575
 
576
  // The sorted column draws each ranked row's value as a bar in its
 
583
  // shows it. A view of one cell shows that cell's F1
584
  // and error rate alone, since the mean, F1 Drop and the other
585
  // cells' numbers would sit beside a ranking they don't follow.
586
+ Leaderboard.prototype.drawTable = function (b, list, cell, view, sortKey) {
587
  var self = this;
588
+ sortKey = sortKey || cell;
589
+ var spans = view === 'all' && cell === 'f1_mean4' && sortKey === 'f1_mean4';
590
  var top = niceMax(Math.max.apply(null, list.map(function (d) {
591
  return d[cell + '_hi'] != null ? d[cell + '_hi'] : d[cell];
592
  }).concat([0])));
 
618
  b.caption.textContent = captionOf(b, cell);
619
  // The F1 Drop line goes with its column, which a view of one cell drops.
620
  if (b.drop && this.board === b) b.drop.hidden = cell !== 'f1_mean4';
621
+ b.sortLabel = (cols.filter(function (c) { return c.key === sortKey; })[0] || {}).label;
622
  b.thead.textContent = '';
623
  b.thead.appendChild(el('tr', null, cols.map(function (c) {
624
+ var arrow = null;
625
+ if (c.num && c.key !== 'rank' && c.key !== 'range') {
626
+ var low = lowerIsBetter(c.key);
627
+ var sortTip = tf(low ? 'Sort by {column}, smallest first' : 'Sort by {column}, highest first', { column: c.label });
628
+ arrow = el('button', { type: 'button', class: 'fab-lb__sort' + (c.key === sortKey ? ' is-active' : ''),
629
+ 'data-key': c.key, 'aria-label': sortTip, title: sortTip }, [sortArrow(low)]);
630
+ arrow.addEventListener('click', function () { self.sortBy(c.key); });
631
+ }
632
  return el('th', { class: (c.num ? 'num' : '') + (c.key === cell ? ' is-sorted' : ''), scope: 'col',
633
+ 'aria-sort': c.key === sortKey ? 'descending' : null }, [c.label, arrow]);
634
  })));
635
  b.tbody.textContent = '';
636
  list.forEach(function (d, i) {
 
684
  }
685
  };
686
 
687
+ // A column's arrow sorts the table by it, highest first, and keeps focus on it.
688
+ Leaderboard.prototype.sortBy = function (key) {
689
+ this.sortKey = key;
690
+ this.render();
691
+ var btn = this.board.thead.querySelector('[data-key="' + key + '"]');
692
+ if (btn) btn.focus({ preventScroll: true });
693
+ };
694
+
695
  Leaderboard.prototype.drawNotes = function (list) {
696
  var seen = {}, lines = [], hrefs = this.hrefs;
697
  list.forEach(function (d) {
logos/olewave-wordmark-white.png ADDED