-
Notifications
You must be signed in to change notification settings - Fork 115
/
index.ts
65 lines (58 loc) · 2.27 KB
/
index.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
import './polyfills.js'
import { IntervalWorkerPool } from './samplers/interval_worker_pool.js'
import { FunctionPlotOptions } from './types.js'
import { Chart, ChartMeta, ChartMetaMargin } from './chart.js'
import globals, { registerGraphType } from './globals.mjs'
import { polyline, interval, scatter, text } from './graph-types/index.js'
import { interval as intervalEval, builtIn as builtInEval, registerEvaluator } from './samplers/eval.mjs'
// register common graphTypes on library load.
registerGraphType('polyline', polyline)
registerGraphType('interval', interval)
registerGraphType('scatter', scatter)
registerGraphType('text', text)
function withWebWorkers(nWorkers = 8, WorkerConstructor = window.Worker, publicPath = window.location.href) {
// @ts-ignore
window.__webpack_public_path__ = publicPath
globals.workerPool = new IntervalWorkerPool(nWorkers, WorkerConstructor)
}
/**
* functionPlot is a function plotter of 2d functions.
*
* functionPlot creates an instance of {@link Chart} with the param options
* and immediately calls {@link Chart#build} on it.
*
* `options` is augmented with additional internal computed data,
* therefore, if you want to rerender graphs it's important to reuse
* the same object to preserve state across builds.
*
* @param options The options sent to Chart
*/
export default function functionPlot(options: FunctionPlotOptions) {
options.data = options.data || []
let instance = Chart.cache[options.id]
if (!instance) {
instance = new Chart(options)
}
return instance.plot()
}
declare const __COMMIT_HASH__: string
functionPlot.version = __COMMIT_HASH__
functionPlot.globals = globals
functionPlot.$eval = {
builtIn: builtInEval,
interval: intervalEval
}
functionPlot.graphTypes = { interval, polyline, scatter }
functionPlot.withWebWorkers = withWebWorkers
export * from './types.js'
export { Chart, ChartMeta, ChartMetaMargin }
export { registerGraphType, withWebWorkers }
export { registerEvaluator }
export { builtIn as EvalBuiltIn, interval as EvalInterval } from './samplers/eval.mjs'
export {
interval as GraphTypeInterval,
polyline as GraphTypePolyline,
scatter as GraphTypeScatter
} from './graph-types/index.js'
export { GraphTypePlotter, GraphTypeBuilder } from './graph-types/types.js'
export * from './helpers/index.js'