Skip to content

Refactor exported types in src/index.ts #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { interpolateRound as d3InterpolateRound } from 'd3-interpolate'
import EventEmitter from 'events'

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

import { Mark } from './graph-types/mark.js'
import { interval, polyline, scatter, text } from './graph-types/index.js'
Expand Down Expand Up @@ -869,3 +870,9 @@ export class Chart extends EventEmitter.EventEmitter {
.remove()
}
}

export function withWebWorkers(nWorkers = 8, WorkerConstructor = window.Worker, publicPath = window.location.href) {
// @ts-ignore
window.__webpack_public_path__ = publicPath
globals.workerPool = new IntervalWorkerPool(nWorkers, WorkerConstructor)
}
3 changes: 2 additions & 1 deletion src/graph-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { Interval, interval } from './interval.js'
import { Polyline, polyline } from './polyline.js'
import { Scatter, scatter } from './scatter.js'
import { Text, text } from './text.js'
import { Attr, Mark } from './mark.js'

export { Polyline, polyline, Scatter, scatter, Interval, interval, Text, text }
export { Polyline, polyline, Scatter, scatter, Interval, interval, Text, text, Attr, Mark }
2 changes: 1 addition & 1 deletion src/graph-types/interval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { select as d3Select, Selection } from 'd3-selection'
import { Selection } from 'd3-selection'

import { asyncIntervalEvaluate, intervalEvaluate } from '../evaluate-datum.js'
import { infinity, color } from '../utils.mjs'
Expand Down
2 changes: 1 addition & 1 deletion src/graph-types/mark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chart } from '../index.js'

interface Attr {
export interface Attr {
[key: string]: any
}

Expand Down
23 changes: 0 additions & 23 deletions src/graph-types/types.ts

This file was deleted.

47 changes: 21 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import './polyfills.js'

import { IntervalWorkerPool } from './samplers/interval_worker_pool.js'
import { FunctionPlotOptions } from './types.js'
import { Chart, ChartMeta, ChartMetaMargin } from './chart.js'
import { Chart, ChartMeta, ChartMetaMargin, withWebWorkers } from './chart.js'

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

function withWebWorkers(nWorkers = 8, WorkerConstructor = window.Worker, publicPath = window.location.href) {
// @ts-ignore
window.__webpack_public_path__ = publicPath
globals.workerPool = new IntervalWorkerPool(nWorkers, WorkerConstructor)
}
declare const __COMMIT_HASH__: string
functionPlot.version = __COMMIT_HASH__

/**
* 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.
* and immediately calls {@link Chart#plot} on it.
*
* `options` is augmented with additional internal computed data,
* therefore, if you want to rerender graphs it's important to reuse
Expand All @@ -36,30 +31,30 @@ export default function functionPlot(options: FunctionPlotOptions) {
return instance.plot()
}

declare const __COMMIT_HASH__: string
functionPlot.version = __COMMIT_HASH__
functionPlot.globals = globals
functionPlot.$eval = {
builtIn: builtInEval,
interval: intervalEval
}
functionPlot.withWebWorkers = withWebWorkers

functionPlot.text = text
functionPlot.builtInSampler = builtInSampler
functionPlot.intervalSampler = intervalSampler

functionPlot.interval = interval
functionPlot.polyline = polyline
functionPlot.scatter = scatter
functionPlot.text = text

export * from './types.js'
export { Chart, ChartMeta, ChartMetaMargin }
export { withWebWorkers }
export { registerSampler }
export { Mark }
export { builtIn as EvalBuiltIn, interval as EvalInterval } from './samplers/eval.mjs'
export { Chart, ChartMeta, ChartMetaMargin }
export {
interval as GraphTypeInterval,
polyline as GraphTypePolyline,
scatter as GraphTypeScatter,
text as GraphTypeText
interval as IntervalGraph,
Interval,
polyline as PolylineGraph,
Polyline,
scatter as ScatterGraph,
Scatter,
text as TextGraph,
Text,
Mark,
Attr
} from './graph-types/index.js'
export { GraphTypePlotter, GraphTypeBuilder } from './graph-types/types.js'
export { builtIn as BuiltInSampler, interval as IntervalSampler, registerSampler } from './samplers/eval.mjs'
4 changes: 2 additions & 2 deletions src/tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function mouseTip(config: FunctionPlotTip) {
tip.move = function (coordinates: { x: number; y: number }) {
let minDist = Infinity
let closestIndex = -1
let x, y
let x: number, y: number

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

const range = data[i].range || [-infinity(), infinity()]
let candidateY
let candidateY: number
if (x0 > range[0] - globals.TIP_X_EPS && x0 < range[1] + globals.TIP_X_EPS) {
try {
candidateY = builtInEvaluator(data[i], 'fn', { x: x0 })
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ScaleLinear, ScaleLogarithmic } from 'd3-scale'

import { Mark } from './graph-types/mark.js'

export interface Interval {
lo: number
hi: number
Expand Down