UNPKG

@thi.ng/viz

Version:

Declarative, functional & multi-format data visualization toolkit based around @thi.ng/hiccup

25 lines (24 loc) 787 B
import { fit } from "@thi.ng/math/fit"; import { inRange } from "@thi.ng/math/interval"; import { roundTo } from "@thi.ng/math/prec"; import { mergeDeepObj } from "@thi.ng/object-utils/merge-deep"; import { filter } from "@thi.ng/transducers/filter"; import { range } from "@thi.ng/transducers/range"; import { axisDefaults } from "./common.js"; const linearScale = ([d1, d2], [r1, r2]) => (x) => fit(x, d1, d2, r1, r2); const linearAxis = (src) => { const spec = mergeDeepObj(axisDefaults(), src); !spec.scale && (spec.scale = linearScale(spec.domain, spec.range)); return spec; }; const linearTicks = (step) => ([d1, d2]) => [ ...filter( (x) => inRange(x, d1, d2), range(roundTo(d1, step), d2 + step, step) ) ]; export { linearAxis, linearScale, linearTicks };