forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
337 lines (304 loc) · 6.88 KB
/
types.ts
File metadata and controls
337 lines (304 loc) · 6.88 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import {Tensor2D} from '@tensorflow/tfjs';
/*
* @license
* Copyright 2018 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.
* =============================================================================
*/
// Types shared across the project and that users will commonly interact with
/**
* The public api of a 'surface'
*/
export interface Surface {
/**
* The containing HTML element for this surface
*/
container: HTMLElement;
/**
* A textual label for the surface.
*/
label: HTMLElement;
/**
* A container for plots and other renderings
*/
drawArea: HTMLElement;
}
/**
* Options used to specify a surface.
*
* name and tab are also used for retrieval of a surface instance.
*/
export interface SurfaceInfo {
/**
* The name / label of this surface
*/
name: string;
/**
* The name of the tab this surface should appear on
*/
tab?: string;
/**
* Display Styles for the surface
*/
styles?: StyleOptions;
}
/**
* Internally all surfaces must have a tab.
*/
export interface SurfaceInfoStrict extends SurfaceInfo {
name: string;
tab: string;
styles?: StyleOptions;
}
/**
* Style properties are generally optional as components will specify defaults.
*/
export interface StyleOptions {
width?: string;
height?: string;
maxWidth?: string;
maxHeight?: string;
}
/**
* @docalias HTMLElement|{name: string, tab?: string}|Surface|{drawArea:
* HTMLElement}
*/
export type Drawable = HTMLElement|Surface|SurfaceInfo|{
drawArea: HTMLElement;
};
export function isSurfaceInfo(drawable: Drawable): drawable is SurfaceInfo {
if ((drawable as SurfaceInfo).name != null) {
return true;
}
return false;
}
export function isSurface(drawable: Drawable): drawable is Surface {
if ((drawable as Surface).drawArea instanceof HTMLElement) {
return true;
}
return false;
}
/**
* Common visualisation options for '.render' functions.
*/
export interface VisOptions {
/**
* Width of chart in px
*/
width?: number;
/**
* Height of chart in px
*/
height?: number;
/**
* Label for xAxis
*/
xLabel?: string;
/**
* Label for yAxis
*/
yLabel?: string;
/**
* Fontsize in px
*/
fontSize?: number;
/**
* Will be set automatically
*/
xType?: 'quantitative'|'ordinal'|'nominal';
/**
* Will be set automatically
*/
yType?: 'quantitative'|'ordinal'|'nominal';
}
/**
* Options for XY plots
*/
export interface XYPlotOptions extends VisOptions {
/**
* domain of the x axis. Overriden by zoomToFit
*/
xAxisDomain?: [number, number];
/**
* domain of the y axis. Overriden by zoomToFit
*/
yAxisDomain?: [number, number];
/**
* Set the chart bounds to just fit the data. This may modify the axis scales
* but allows fitting more data into view.
*/
zoomToFit?: boolean;
/**
* Colors to for each series plotted. An array of valid CSS color strings.
*/
seriesColors?: string[];
}
/**
* Data format for XY plots
*/
export interface XYPlotData {
/**
* An array (or nested array) of {x, y} tuples.
*/
values: Point2D[][]|Point2D[];
/**
* Series names/labels
*/
series?: string[];
}
/**
* Histogram options.
*/
export interface HistogramOpts extends VisOptions {
/**
* By default a histogram will also compute and display summary statistics.
* If stats is set to false then summary statistics will not be displayed.
*
* Pre computed stats can also be passed in and should have the following
* format:
* {
* numVals?: number,
* min?: number,
* max?: number,
* numNans?: number,
* numZeros?: number,
* numInfs?: number,
* }
*/
stats?: HistogramStats|false;
/**
* Maximum number of bins in histogram.
*/
maxBins?: number;
/**
* Fill color for bars. Should be a valid CSS color string
*/
color?: string;
}
/**
* Bar chart options.
*/
export interface BarChartOpts extends VisOptions {
/**
* Fill color for bars. Should be a valid CSS color string
*/
color?: string|string[];
}
/**
* Summary statistics for histogram.
*/
export interface HistogramStats {
numVals?: number;
min?: number;
max?: number;
numNans?: number;
numZeros?: number;
numInfs?: number;
}
/**
* Type alias for typed arrays
*/
export type TypedArray = Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|
Uint32Array|Uint8ClampedArray|Float32Array|Float64Array;
/**
* An object with a 'values' property and a 'labels' property.
*/
export interface ConfusionMatrixData {
/**
* a square matrix of numbers representing counts for each (label, prediction)
* pair
*/
values: number[][];
/**
* Human readable labels for each class in the matrix. Optional
*/
tickLabels?: string[];
}
export interface ConfusionMatrixOptions extends VisOptions {
/**
* Color cells on the diagonal. Defaults to true
*/
shadeDiagonal?: boolean;
/**
* render the values of each cell as text. Defaults to true
*/
showTextOverlay?: boolean;
}
/**
* Datum format for scatter and line plots
*/
export interface Point2D {
x: number;
y: number;
}
/**
* An object with a 'values' property and a 'labels' property.
*/
export interface HeatmapData {
/**
* Matrix of values in column-major order.
*
* Row major order is supported by setting a boolean in options.
*/
values: number[][]|Tensor2D;
/**
* x axis tick labels
*/
xTickLabels?: string[];
/**
* y axis tick labels
*/
yTickLabels?: string[];
}
/**
* Color map names.
*/
/** @docinline */
export type NamedColorMap = 'greyscale'|'viridis'|'blues';
/**
* Visualization options for Heatmap
*/
export interface HeatmapOptions extends VisOptions {
/**
* Defaults to viridis
*/
colorMap?: NamedColorMap;
/**
* Custom output domain for the color scale.
* Useful if you want to plot multiple heatmaps using the same scale.
*/
domain?: number[];
/**
* Pass in data values in row-major order.
*
* Internally this will transpose the data values before rendering.
*/
rowMajor?: boolean;
}
/**
* Data format for render.table
*/
export interface TableData {
/**
* Column names
*/
headers: string[];
/**
* An array of arrays (one for each row). The inner
* array length usually matches the length of data.headers.
*
* Typically the values are numbers or strings.
*/
// tslint:disable-next-line:no-any
values: any[][];
}