-
Notifications
You must be signed in to change notification settings - Fork 0
Modularization and cleanup #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
14c2082
4824fac
0a619ce
6a788ee
0e8b27c
a978bd8
3041bfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { metricColor } from "../ui"; | ||
|
|
||
| type RowContent = string | number | boolean | ||
| type Range = {min: number, max: number} | ||
|
|
||
| export class Table { | ||
| tableElem: HTMLTableElement; | ||
|
|
||
| headers: string[]; | ||
| rows: RowContent[][]; | ||
| ranges: Map<string, Range>; | ||
|
|
||
| constructor(tableElemId: string, ranges: Map<string, Range>, headers: string[], rows: RowContent[][]) { | ||
| this.tableElem = document.getElementById(tableElemId) as HTMLTableElement; | ||
| this.headers = headers; | ||
| this.rows = rows; | ||
| this.ranges = ranges; | ||
| } | ||
|
|
||
| setHeaders(headers: string[]) { | ||
| this.headers = headers; | ||
| } | ||
|
|
||
| setRows(rows: RowContent[][]) { | ||
| this.rows = rows; | ||
| } | ||
|
|
||
| addRow(row: RowContent[]) { | ||
| this.rows.push(row); | ||
| } | ||
|
|
||
| redraw() { | ||
| this.tableElem.innerHTML = ""; | ||
|
|
||
| const table = document.createElement("table"); | ||
| table.className = "table"; | ||
|
|
||
| const head = document.createElement("thead"); | ||
| const headRow = document.createElement("tr"); | ||
|
|
||
| let first = false; | ||
|
|
||
| this.headers.forEach(header => { | ||
| let headerCol = document.createElement("th"); | ||
| let headerDiv = document.createElement("div"); | ||
| let headerSpan = document.createElement("span"); | ||
|
|
||
| if(!first) headerCol.className = "rotated-text"; | ||
|
|
||
| headerCol.scope = "col"; | ||
|
|
||
| headerSpan.innerHTML = header; | ||
| headerSpan.className = "border-bottom"; | ||
|
|
||
|
|
||
| headerDiv.appendChild(headerSpan); | ||
| headerCol.appendChild(headerDiv); | ||
| headRow.appendChild(headerCol); | ||
|
|
||
| first = false; | ||
| }); | ||
| head.appendChild(headRow); | ||
| table.appendChild(head); | ||
|
|
||
| this.rows.forEach(rowData => { | ||
| let row = document.createElement("tr"); | ||
|
|
||
| let firstCell = document.createElement("th"); | ||
| firstCell.innerHTML = rowData[0].toString(); | ||
| firstCell.scope = "row"; | ||
| firstCell.className = "border w-25"; | ||
| row.appendChild(firstCell); | ||
|
|
||
| var i = 1; | ||
| this.headers.forEach(header => { | ||
| let range = this.ranges.get(header)!; | ||
| let data = rowData[i] as number; | ||
| let cellContent: string = Math.round(data).toString(); | ||
|
|
||
| let cell = document.createElement("td"); | ||
|
|
||
| cell.innerHTML = cellContent; | ||
| cell.className = "border"; | ||
| cell.style.backgroundColor = metricColor(data, unitStats.get(category)!); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [tsc] <2304> reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [tsc] <2304> reported by reviewdog 🐶 |
||
|
|
||
| row.appendChild(cell); | ||
| i++; | ||
| }); | ||
| table.appendChild(row); | ||
| }); | ||
| tableElem.appendChild(table); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [tsc] <2663> reported by reviewdog 🐶 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [tsc] <6133> reported by reviewdog 🐶
'range' is declared but its value is never read.