|
2 | 2 |
|
3 | 3 | import { Tooltip } from "bootstrap";
|
4 | 4 | import { TreeView } from "./tree_view.js";
|
| 5 | +import { StatisticsView } from "./statistics.js"; |
5 | 6 | import { Popover } from "./popover.js";
|
6 | 7 | import { WebSocketClient } from "./websocket.js";
|
7 | 8 | import { debounce } from "./debounce.js";
|
8 | 9 |
|
9 | 10 | import "../css/editor.css";
|
10 | 11 | import "../css/syntax.css";
|
11 | 12 |
|
12 |
| -import DataTable from "datatables.net"; |
13 |
| -import "datatables.net-bs5/css/dataTables.bootstrap5.min.css"; |
14 |
| - |
15 | 13 | import "ace-builds/src-min-noconflict/ace";
|
16 | 14 | import "ace-builds/src-min-noconflict/ext-language_tools";
|
17 | 15 | import "ace-builds/src-min-noconflict/mode-swift";
|
@@ -55,7 +53,9 @@ export class App {
|
55 | 53 | this.popover = new Popover();
|
56 | 54 |
|
57 | 55 | this.syntaxMapContainer = document.getElementById("syntax-map");
|
58 |
| - this.statisticsContainer = document.getElementById("statistics"); |
| 56 | + this.statisticsView = new StatisticsView( |
| 57 | + document.getElementById("statistics-container") |
| 58 | + ); |
59 | 59 |
|
60 | 60 | this.init();
|
61 | 61 | }
|
@@ -476,51 +476,28 @@ export class App {
|
476 | 476 | }
|
477 | 477 |
|
478 | 478 | updateStatistics(statistics) {
|
479 |
| - const tbody = this.statisticsContainer.querySelector(":scope > tbody"); |
480 |
| - tbody.innerHTML = ""; |
481 |
| - |
482 |
| - for (const row of statistics) { |
483 |
| - const tr = document.createElement("tr"); |
484 |
| - tr.innerHTML = `<td style="font-family: 'Menlo', sans-serif, monospace;">${row.text}</td><td><div>${row.ranges.length}</div></td>`; |
485 |
| - tbody.appendChild(tr); |
486 |
| - |
487 |
| - tr.addEventListener("mouseover", (event) => { |
488 |
| - event.preventDefault(); |
489 |
| - event.stopPropagation(); |
490 |
| - |
491 |
| - for (const range of row.ranges) { |
492 |
| - this.editor.session.addMarker( |
493 |
| - new Range( |
494 |
| - range.startRow, |
495 |
| - range.startColumn, |
496 |
| - range.endRow, |
497 |
| - range.endColumn |
498 |
| - ), |
499 |
| - "editor-marker", |
500 |
| - "text" |
501 |
| - ); |
502 |
| - } |
503 |
| - }); |
504 |
| - tr.addEventListener("mouseout", (event) => { |
505 |
| - event.preventDefault(); |
506 |
| - event.stopPropagation(); |
507 |
| - |
508 |
| - const markers = this.editor.session.getMarkers(); |
509 |
| - for (const [key, value] of Object.entries(markers)) { |
510 |
| - this.editor.session.removeMarker(value.id); |
511 |
| - } |
512 |
| - }); |
513 |
| - } |
514 |
| - |
515 |
| - if (this.dataTable) { |
516 |
| - this.dataTable.destroy(); |
517 |
| - } |
518 |
| - this.dataTable = new DataTable("#statistics", { |
519 |
| - autoWidth: false, |
520 |
| - info: false, |
521 |
| - paging: false, |
522 |
| - searching: false, |
523 |
| - }); |
| 479 | + this.statisticsView.update(statistics); |
| 480 | + |
| 481 | + this.statisticsView.onmouseover = (event, target, ranges) => { |
| 482 | + for (const range of ranges) { |
| 483 | + this.editor.session.addMarker( |
| 484 | + new Range( |
| 485 | + range.startRow, |
| 486 | + range.startColumn, |
| 487 | + range.endRow, |
| 488 | + range.endColumn |
| 489 | + ), |
| 490 | + "editor-marker", |
| 491 | + "text" |
| 492 | + ); |
| 493 | + } |
| 494 | + }; |
| 495 | + this.statisticsView.onmouseout = (event, target) => { |
| 496 | + const markers = this.editor.session.getMarkers(); |
| 497 | + for (const [key, value] of Object.entries(markers)) { |
| 498 | + this.editor.session.removeMarker(value.id); |
| 499 | + } |
| 500 | + }; |
524 | 501 | }
|
525 | 502 | }
|
526 | 503 |
|
|
0 commit comments