Skip to content

Commit 310bae6

Browse files
committed
Refactor exported types in src/index.ts
1 parent 651aa08 commit 310bae6

File tree

8 files changed

+34
-56
lines changed

8 files changed

+34
-56
lines changed

src/chart.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { interpolateRound as d3InterpolateRound } from 'd3-interpolate'
88
import EventEmitter from 'events'
99

1010
import { FunctionPlotDatum, FunctionPlotOptions, FunctionPlotScale, FunctionPlotOptionsAxis } from './types.js'
11+
import { IntervalWorkerPool } from './samplers/interval_worker_pool.js'
1112

1213
import { Mark } from './graph-types/mark.js'
1314
import { interval, polyline, scatter, text } from './graph-types/index.js'
@@ -869,3 +870,9 @@ export class Chart extends EventEmitter.EventEmitter {
869870
.remove()
870871
}
871872
}
873+
874+
export function withWebWorkers(nWorkers = 8, WorkerConstructor = window.Worker, publicPath = window.location.href) {
875+
// @ts-ignore
876+
window.__webpack_public_path__ = publicPath
877+
globals.workerPool = new IntervalWorkerPool(nWorkers, WorkerConstructor)
878+
}

src/graph-types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import { Interval, interval } from './interval.js'
22
import { Polyline, polyline } from './polyline.js'
33
import { Scatter, scatter } from './scatter.js'
44
import { Text, text } from './text.js'
5+
import { Attr, Mark } from './mark.js'
56

6-
export { Polyline, polyline, Scatter, scatter, Interval, interval, Text, text }
7+
export { Polyline, polyline, Scatter, scatter, Interval, interval, Text, text, Attr, Mark }

src/graph-types/interval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { select as d3Select, Selection } from 'd3-selection'
1+
import { Selection } from 'd3-selection'
22

33
import { asyncIntervalEvaluate, intervalEvaluate } from '../evaluate-datum.js'
44
import { infinity, color } from '../utils.mjs'

src/graph-types/mark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Chart } from '../index.js'
22

3-
interface Attr {
3+
export interface Attr {
44
[key: string]: any
55
}
66

src/graph-types/types.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/index.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import './polyfills.js'
22

3-
import { IntervalWorkerPool } from './samplers/interval_worker_pool.js'
43
import { FunctionPlotOptions } from './types.js'
5-
import { Chart, ChartMeta, ChartMetaMargin } from './chart.js'
4+
import { Chart, ChartMeta, ChartMetaMargin, withWebWorkers } from './chart.js'
65

76
import globals from './globals.mjs'
87
import { interval, polyline, scatter, text } from './graph-types/index.js'
9-
import { Mark } from './graph-types/mark.js'
10-
import { interval as intervalEval, builtIn as builtInEval, registerSampler } from './samplers/eval.mjs'
8+
import { interval as intervalSampler, builtIn as builtInSampler } from './samplers/eval.mjs'
119

12-
function withWebWorkers(nWorkers = 8, WorkerConstructor = window.Worker, publicPath = window.location.href) {
13-
// @ts-ignore
14-
window.__webpack_public_path__ = publicPath
15-
globals.workerPool = new IntervalWorkerPool(nWorkers, WorkerConstructor)
16-
}
10+
declare const __COMMIT_HASH__: string
11+
functionPlot.version = __COMMIT_HASH__
1712

1813
/**
1914
* functionPlot is a function plotter of 2d functions.
2015
*
2116
* functionPlot creates an instance of {@link Chart} with the param options
22-
* and immediately calls {@link Chart#build} on it.
17+
* and immediately calls {@link Chart#plot} on it.
2318
*
2419
* `options` is augmented with additional internal computed data,
2520
* therefore, if you want to rerender graphs it's important to reuse
@@ -36,30 +31,30 @@ export default function functionPlot(options: FunctionPlotOptions) {
3631
return instance.plot()
3732
}
3833

39-
declare const __COMMIT_HASH__: string
40-
functionPlot.version = __COMMIT_HASH__
4134
functionPlot.globals = globals
42-
functionPlot.$eval = {
43-
builtIn: builtInEval,
44-
interval: intervalEval
45-
}
4635
functionPlot.withWebWorkers = withWebWorkers
4736

48-
functionPlot.text = text
37+
functionPlot.builtInSampler = builtInSampler
38+
functionPlot.intervalSampler = intervalSampler
39+
4940
functionPlot.interval = interval
5041
functionPlot.polyline = polyline
5142
functionPlot.scatter = scatter
43+
functionPlot.text = text
5244

5345
export * from './types.js'
54-
export { Chart, ChartMeta, ChartMetaMargin }
5546
export { withWebWorkers }
56-
export { registerSampler }
57-
export { Mark }
58-
export { builtIn as EvalBuiltIn, interval as EvalInterval } from './samplers/eval.mjs'
47+
export { Chart, ChartMeta, ChartMetaMargin }
5948
export {
60-
interval as GraphTypeInterval,
61-
polyline as GraphTypePolyline,
62-
scatter as GraphTypeScatter,
63-
text as GraphTypeText
49+
interval as IntervalGraph,
50+
Interval,
51+
polyline as PolylineGraph,
52+
Polyline,
53+
scatter as ScatterGraph,
54+
Scatter,
55+
text as TextGraph,
56+
Text,
57+
Mark,
58+
Attr
6459
} from './graph-types/index.js'
65-
export { GraphTypePlotter, GraphTypeBuilder } from './graph-types/types.js'
60+
export { builtIn as BuiltInSampler, interval as IntervalSampler, registerSampler } from './samplers/eval.mjs'

src/tip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default function mouseTip(config: FunctionPlotTip) {
9999
tip.move = function (coordinates: { x: number; y: number }) {
100100
let minDist = Infinity
101101
let closestIndex = -1
102-
let x, y
102+
let x: number, y: number
103103

104104
const selection = tipInnerJoin.merge(tipInnerEnter)
105105
const meta = config.owner.meta
@@ -122,7 +122,7 @@ export default function mouseTip(config: FunctionPlotTip) {
122122
}
123123

124124
const range = data[i].range || [-infinity(), infinity()]
125-
let candidateY
125+
let candidateY: number
126126
if (x0 > range[0] - globals.TIP_X_EPS && x0 < range[1] + globals.TIP_X_EPS) {
127127
try {
128128
candidateY = builtInEvaluator(data[i], 'fn', { x: x0 })

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { ScaleLinear, ScaleLogarithmic } from 'd3-scale'
22

3-
import { Mark } from './graph-types/mark.js'
4-
53
export interface Interval {
64
lo: number
75
hi: number

0 commit comments

Comments
 (0)