Skip to content

Commit 590b7cc

Browse files
committed
Minimize dependency on Chart in space utility.
/kind cleanup
1 parent ca9f662 commit 590b7cc

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/samplers/builtIn.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import clamp from 'clamp'
33
import utils from '../utils'
44
import { builtIn as evaluate } from '../helpers/eval'
55

6-
import { Chart } from '../index'
6+
import { Chart } from '../chart'
77
import { FunctionPlotDatum } from '../types'
88

99
function checkAsymptote(
@@ -106,15 +106,15 @@ function split(chart: Chart, d: FunctionPlotDatum, data: number[][]) {
106106
}
107107

108108
function linear(chart: Chart, d: FunctionPlotDatum, range: [number, number], n: number) {
109-
const allX = utils.space(chart, range, n)
109+
const allX = utils.space(chart.options.xAxis.type, range, n)
110110
const yDomain = chart.meta.yScale.domain()
111111
const yDomainMargin = yDomain[1] - yDomain[0]
112112
const yMin = yDomain[0] - yDomainMargin * 1e5
113113
const yMax = yDomain[1] + yDomainMargin * 1e5
114114
let data = []
115115
for (let i = 0; i < allX.length; i += 1) {
116116
const x = allX[i]
117-
const y = evaluate(d, 'fn', { x: x })
117+
const y = evaluate(d, 'fn', { x })
118118
if (utils.isValidNumber(x) && utils.isValidNumber(y)) {
119119
data.push([x, clamp(y, yMin, yMax)])
120120
}
@@ -127,7 +127,7 @@ function parametric(chart: Chart, d: FunctionPlotDatum, range: [number, number],
127127
// range is mapped to canvas coordinates from the input
128128
// for parametric plots the range will tell the start/end points of the `t` param
129129
const parametricRange = d.range || [0, 2 * Math.PI]
130-
const tCoords = utils.space(chart, parametricRange, nSamples)
130+
const tCoords = utils.space(chart.options.xAxis.type, parametricRange, nSamples)
131131
const samples = []
132132
for (let i = 0; i < tCoords.length; i += 1) {
133133
const t = tCoords[i]
@@ -142,7 +142,7 @@ function polar(chart: Chart, d: FunctionPlotDatum, range: [number, number], nSam
142142
// range is mapped to canvas coordinates from the input
143143
// for polar plots the range will tell the start/end points of the `theta` param
144144
const polarRange = d.range || [-Math.PI, Math.PI]
145-
const thetaSamples = utils.space(chart, polarRange, nSamples)
145+
const thetaSamples = utils.space(chart.options.xAxis.type, polarRange, nSamples)
146146
const samples = []
147147
for (let i = 0; i < thetaSamples.length; i += 1) {
148148
const theta = thetaSamples[i]

src/samplers/interval.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import intervalArithmeticEval, { Interval } from 'interval-arithmetic-eval'
2+
import { Chart } from '../chart'
3+
import { FunctionPlotDatum } from '../types'
24

35
import { interval as evaluate } from '../helpers/eval'
46
import utils from '../utils'
57

6-
import { Chart } from '../index'
7-
import { FunctionPlotDatum } from '../types'
8-
9-
// const Interval = (intervalArithmeticEval as any).Interval
10-
118
// disable the use of typed arrays in interval-arithmetic to improve the performance
129
;(intervalArithmeticEval as any).policies.disableRounding()
1310

1411
function interval1d(chart: Chart, d: FunctionPlotDatum, range: [number, number], nSamples: number) {
15-
const xCoords = utils.space(chart, range, nSamples)
12+
const xCoords = utils.space(chart.options.xAxis.type, range, nSamples)
1613
const xScale = chart.meta.xScale
1714
const yScale = chart.meta.yScale
1815
const yMin = yScale.domain()[0]

src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import globals from './globals'
22

3-
import { Chart } from './index'
43
import { FunctionPlotDatum } from './types'
54

65
const utils = {
@@ -17,10 +16,10 @@ const utils = {
1716
return typeof v === 'number' && !isNaN(v)
1817
},
1918

20-
space: function (chart: Chart, range: [number, number], n: number) {
19+
space: function (type: string, range: [number, number], n: number) {
2120
const lo = range[0]
2221
const hi = range[1]
23-
if (chart.options.xAxis.type === 'log') {
22+
if (type === 'log') {
2423
return this.logspace(Math.log10(lo), Math.log10(hi), n)
2524
}
2625
// default is linear

0 commit comments

Comments
 (0)