-
Notifications
You must be signed in to change notification settings - Fork 115
/
datum-validation.ts
28 lines (25 loc) · 959 Bytes
/
datum-validation.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
import { FunctionPlotDatum } from './types.js'
import { assert } from './utils.mjs'
export default function datumValidation(d: FunctionPlotDatum) {
validateGraphType(d)
validateFnType(d)
}
function validateGraphType(d: FunctionPlotDatum) {
// defaulted to 'interval' in datumDefaults.
assert('graphType' in d, `graphType isn't defined`)
}
function validateFnType(d: FunctionPlotDatum) {
const invalid = `invalid option fnType=${d.fnType} with graphType=${d.graphType}`
if (d.fnType === 'linear') {
assert(d.graphType === 'polyline' || d.graphType === 'interval' || d.graphType === 'scatter', invalid)
}
if (d.fnType === 'parametric' || d.fnType === 'polar' || d.fnType === 'vector') {
assert(d.graphType === 'polyline', invalid)
}
if (d.fnType === 'points') {
assert(d.graphType === 'polyline' || d.graphType === 'scatter', invalid)
}
if (d.fnType === 'implicit') {
assert(d.graphType === 'interval', invalid)
}
}