-
Notifications
You must be signed in to change notification settings - Fork 115
/
types.ts
420 lines (342 loc) · 8.85 KB
/
types.ts
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import { ScaleLinear, ScaleLogarithmic } from 'd3-scale'
export interface Interval {
lo: number
hi: number
}
export type FunctionPlotScale = ScaleLinear<number, number> | ScaleLogarithmic<number, number>
export interface FunctionPlotOptionsAxis {
/**
* The type of axis
*/
type?: 'linear' | 'log'
/**
* Initial ends of the axis
*/
domain?: [number, number]
/**
* The label to display next to the axis
*/
label?: string
/**
* True to invert the direction of the axis
*/
invert?: boolean
/**
* The position of the axis
*
* - `sticky`: The axis will be in the center.
* - `left`: The axis will be positioned on the left side. (Only for the yAxis)
* - `bottom`: The axis will be positioned at the bottom. (Only for the xAxis)
*
* Default values:
* - `xAxis`: `bottom`
* - `yAxis`: `left`
*/
position?: 'sticky' | 'left' | 'bottom'
}
export interface FunctionPlotTip {
/**
* True to display a vertical line on mouseover
*/
xLine?: boolean
/**
* True to display a horizontal line on mouseover
*/
yLine?: boolean
/**
* A function to override what's rendered on mouseover
*/
renderer?: (x: number, y: number, index: number) => string
/**
* Internal reference to the {@link Chart} instance
*/
owner?: any
}
export interface FunctionPlotDatumScope {
[key: string]: any
}
/**
* The string or function to evaluate
*
* - when `fnType: 'linear'`, a string expressed in terms of `x`
* - when `fnType: 'implicit'`, a string expressed in terms of `x` and `y`
* - when `fnType: 'polar'`, a string expressed in terms of `theta`
* - when `fnType: 'parametric'`, a string expressed in terms of `t`
*/
export type Function = string | ((scope: FunctionPlotDatumScope) => any)
export interface SecantDatum {
/**
* (optional) True to update the secant line by evaluating `fn` with the current mouse position
* (`x0` is the fixed point and `x1` is computed dynamically based on the current mouse position)
*/
updateOnMouseMove?: boolean
/**
* The abscissa of the first point i.e. the secant will always intersect the point `(x0, fn(x0))`
*/
x0: number
/**
* (optional if `updateOnMouseMove` is set) The abscissa of the second point i.e.
* the secant will always intersect the point `(x1, fn(x1))`, requires x0 to be set
*/
x1?: number
/**
* The function to render
*/
fn?: Function
/**
* Additional information available during function evaluation
*/
scope?: FunctionPlotDatumScope
$$mouseListener?: any
}
export interface DerivativeDatum {
/**
* True to compute the tangent line by evaluating `derivative.fn` with the current mouse position
* (i.e. let `x0` be the abscissa of the mouse position transformed to local coordinates,
* the tangent line to the point `x0, fn(x0)`)
*/
updateOnMouseMove?: boolean
/**
* The abscissa of the point which belongs to the curve represented by `fn` whose tangent will be computed
* (i.e. the tangent line to the point `x0, fn(x0)`)
*/
x0?: number
/**
* The derivative of the parent data `fn`
*/
fn?: Function
/**
* Additional information available during function evaluation
*/
scope?: FunctionPlotDatumScope
$$mouseListener?: any
}
export interface AbstractFunctionDatum {
/**
* The type of graph to render
*
* - polyline: uses the builtIn sampler to render a disjoint set of line segments
* - interval: uses the interval arithmetic sampler to render a disjoint set of rectangles
* - scatter: uses the builtIn sampler to render a disjoint set of points
* - text: text
*/
graphType?: 'polyline' | 'interval' | 'scatter' | 'text'
/**
* The type of function to render
*/
fnType?: 'linear' | 'parametric' | 'implicit' | 'polar' | 'points' | 'vector'
/**
* The sampler to take samples from `range`, available values are `builtIn|interval|asyncInterval`
*
* - **NOTE: `builtIn` should only be used when `graphType` is `polyline|scatter`**
*/
sampler?: 'interval' | 'builtIn' | 'asyncInterval'
/**
* The number of values to be taken from `range` to evaluate the function,
* note that if interval-arithmetic is used the function
* will be evaluated with intervals instead of single values
*/
nSamples?: number
/**
* Additional information available during function evaluation
*/
scope?: FunctionPlotDatumScope
/**
* The secants configuration
*/
secants?: SecantDatum[]
/**
* The derivative configuration
*/
derivative?: DerivativeDatum
/**
* (only if `graphType: 'polyline'` or `graphType: 'scatter'`) True to close the path,
* for any segment of the closed area graph `y0` will be 0 and `y1` will be `f(x)`
*/
closed?: boolean
/**
* The color of the function to render
*/
color?: string
/**
* True to make the tip ignore this function
*/
skipTip?: boolean
/**
* Additional attributes set on the svg node that represents this datum
*/
attr?: any
/**
* An array with two numbers, the function will only be evaluated with values that belong to this interval
*
* default value for `fnType: 'polar'`: `[-Math.PI, Math.PI]`
* default value for `fnType: 'parametric'`: `[0, 2 * Math.PI]`
* default value for the other functions: `[-Infinity, Infinity]`
*/
range?: [number, number]
/**
* @private
* The datum index
*/
index?: number
/**
* @private
* True if the datum is a helper function
*/
isHelper?: boolean
/**
* @private
* True to bypass the range limits, used for helper functions
*/
skipBoundsCheck?: boolean
}
export interface LinearDatum {
/**
* The function to render
*/
fn: Function
/**
*/
fnType?: 'linear'
}
export type LinearFunction = AbstractFunctionDatum & LinearDatum
export interface ImplicitDatum {
/**
* The function to render
*/
fn: Function
/**
*/
fnType: 'implicit'
/**
* The graphType for an implicit function is always 'interval'
*/
graphType: 'interval'
}
export type ImplicitFunction = AbstractFunctionDatum & ImplicitDatum
export interface PolarDatum {
/**
* The function to render (only used for polar functions)
*/
r: Function
fnType: 'polar'
}
export type PolarFunction = AbstractFunctionDatum & PolarDatum
export interface ParametricDatum {
/**
* The x-function to render (only used for parametric functions)
*/
x: Function
/**
* The y-function to render (only used for parametric functions)
*/
y: Function
fnType: 'parametric'
}
export type ParametricFunction = AbstractFunctionDatum & ParametricDatum
export interface PointDatum {
/**
* An array of 2-number array which hold the coordinates of the points to render when `fnType: 'points'`
*/
points: Array<[number, number]>
fnType: 'points'
}
export type PointFunction = AbstractFunctionDatum & PointDatum
export interface VectorDatum {
/**
* An array of 2-number array which hold the coordinates of the points to render when `fnType: 'vector'`
*/
vector: [number, number]
/**
* Vector offset when `fnType: 'vector'`
*/
offset?: [number, number]
fnType: 'vector'
}
export type VectorFunction = AbstractFunctionDatum & VectorDatum
export interface TextDatum {
graphType: 'text'
/**
* Used as text if `graphType: 'text'`
*/
text: string
/**
* An array of 2-number array for the position of the text when `graphType: 'text'`
*/
location?: [number, number]
}
export type TextFunction = AbstractFunctionDatum & TextDatum
export type FunctionPlotDatum =
| AbstractFunctionDatum
| LinearFunction
| ImplicitFunction
| ParametricFunction
| PolarFunction
| VectorFunction
| PointFunction
| TextFunction
export interface FunctionPlotAnnotation {
/**
* If set a vertical line will be rendered at this location
*/
x?: number
/**
* If set a horizontal line will be rendered at this location
*/
y?: number
/**
* The label displayed next to the line
*/
label?: string
}
export interface FunctionPlotOptions {
/**
* @private
* For internal usage
*/
id?: string
/**
* A css selector or DOM node of the parent element that will contain the graph
*/
target: string | HTMLElement
/**
* The chart title
*/
title?: string
/**
* The chart width (set on the svg element)
*/
width?: number
/**
* The chart height (set on the svg element)
*/
height?: number
/**
* x-axis configuration
*/
x?: FunctionPlotOptionsAxis
/**
* y-axis configuration
*/
y?: FunctionPlotOptionsAxis
/**
* The tip configuration
*/
tip?: FunctionPlotTip
/**
* True to display a grid
*/
grid?: boolean
/**
* True to disable panning and zoom
*/
disableZoom?: boolean
/**
* The functions to plot
*/
data?: FunctionPlotDatum[]
/**
* The annotations displayed in the graph
*/
annotations?: FunctionPlotAnnotation[]
}