forked from tensorflow/tfjs-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
105 lines (95 loc) · 3.75 KB
/
ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @license
* Copyright 2019 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
const statusElement = document.getElementById('status');
const rowCountOutputElement = document.getElementById('row-count-output');
const columnNamesMessageElement =
document.getElementById('column-names-message');
const columnNamesOutputContainerElement =
document.getElementById('column-names-output-container');
const sampleRowMessageElement = document.getElementById('sample-row-message');
const sampleRowOutputContainerElement =
document.getElementById('sample-row-output-container');
const whichSampleInputElement = document.getElementById('which-sample-input');
/** Updates the large message at the top of the info table */
export function updateStatus(message) {
statusElement.value = message;
};
/** Updates the message in the "count rows" output row. */
export function updateRowCountOutput(message) {
rowCountOutputElement.textContent = message;
};
/** Updates the message in the "column names" output row. */
export function updateColumnNamesMessage(message) {
columnNamesMessageElement.textContent = message;
};
/**
* Creates an HTML ordered list to display the column names, represented in the
* `colNames` argument as a list of strings.
*/
export function updateColumnNamesOutput(colNames) {
const container = columnNamesOutputContainerElement;
container.align = 'left';
while (container.firstChild) {
container.removeChild(container.firstChild);
}
const olList = document.createElement('ol');
for (const name of colNames) {
const item = document.createElement('li');
item.textContent = name;
olList.appendChild(item);
}
container.appendChild(olList);
};
// Updates the message in the "sample" output row.
export function updateSampleRowMessage(message) {
sampleRowMessageElement.textContent = message;
};
/**
* Creates an HTML table, using div elements, to display the key-value pairs
* represented in the input `rawRow`. This HTML table is inserted into the
* sample row.
*/
export function updateSampleRowOutput(rawRow) {
sampleRowOutputContainerElement.textContent = '';
const row = rawRow;
for (const key in row) {
if (row.hasOwnProperty(key)) {
const oneKeyRow = document.createElement('div');
oneKeyRow.className = 'divTableRow';
oneKeyRow.align = 'left';
const keyDiv = document.createElement('div');
const valueDiv = document.createElement('div');
// TODO(bileschi): There is probably a better way to style this.
keyDiv.className = 'divTableCellKey';
valueDiv.className = 'divTableCell';
keyDiv.textContent = key + ': ';
valueDiv.textContent = row[key];
oneKeyRow.appendChild(keyDiv);
oneKeyRow.appendChild(valueDiv);
// add the div child to updateSampleRowOutput
sampleRowOutputContainerElement.appendChild(oneKeyRow);
}
}
};
// Returns current value of the selected sample index as a number.
export function getSampleIndex() {
return whichSampleInputElement.valueAsNumber;
}
// Returns the currently specified URL, from which to access the CSV file.
export const getQueryElement = () => {
return document.getElementById('query-url');
}