UNPKG

@thi.ng/viz

Version:

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

30 lines (29 loc) 813 B
import { map } from "@thi.ng/transducers/map"; import { __resolveData, __valueMapper } from "./utils.js"; const barPlot = (data, opts = {}) => (spec) => { opts = { interleave: 1, offset: 0, width: 5, shape: (_, a, b) => ["line", {}, a, b], ...opts }; const mapper = __valueMapper(spec.xaxis, spec.yaxis, spec.project); const offset = (opts.offset + 0.5) * opts.width - 0.5 * opts.interleave * opts.width; const y0 = spec.yaxis.domain[0]; return [ "g", { weight: opts.width, ...opts.attribs }, ...map((datum) => { const [x, val] = datum; const a = mapper([x, y0]); a[0] += offset; const b = mapper([x, val]); b[0] += offset; return opts.shape(datum, a, b); }, __resolveData(data, spec.xaxis.domain)) ]; }; export { barPlot };