@vielzeug/prism 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/easing.cjs.map +1 -1
- package/dist/animation/easing.js.map +1 -1
- package/dist/animation/index.d.ts +2 -2
- package/dist/animation/index.d.ts.map +1 -1
- package/dist/axes/axis.cjs.map +1 -1
- package/dist/axes/axis.d.ts.map +1 -1
- package/dist/axes/axis.js.map +1 -1
- package/dist/axes/grid.cjs.map +1 -1
- package/dist/axes/grid.d.ts.map +1 -1
- package/dist/axes/grid.js.map +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.d.ts.map +1 -1
- package/dist/charts/area/area-chart.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +14 -14
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
- package/dist/charts/bar/bar-renderer.js +24 -24
- package/dist/charts/bar/bar-renderer.js.map +1 -1
- package/dist/charts/line/line-chart.cjs.map +1 -1
- package/dist/charts/line/line-chart.d.ts.map +1 -1
- package/dist/charts/line/line-chart.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +34 -34
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/pie/pie-chart.cjs +1 -1
- package/dist/charts/pie/pie-chart.cjs.map +1 -1
- package/dist/charts/pie/pie-chart.d.ts.map +1 -1
- package/dist/charts/pie/pie-chart.js +34 -34
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/sparkline/sparkline.cjs +1 -1
- package/dist/charts/sparkline/sparkline.cjs.map +1 -1
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -1
- package/dist/charts/sparkline/sparkline.js +64 -64
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs.map +1 -1
- package/dist/core/cartesian-model.d.ts.map +1 -1
- package/dist/core/cartesian-model.js.map +1 -1
- package/dist/core/cartesian-scales.cjs.map +1 -1
- package/dist/core/cartesian-scales.d.ts.map +1 -1
- package/dist/core/cartesian-scales.js.map +1 -1
- package/dist/core/chart-base.cjs +1 -1
- package/dist/core/chart-base.cjs.map +1 -1
- package/dist/core/chart-base.d.ts +1 -1
- package/dist/core/chart-base.d.ts.map +1 -1
- package/dist/core/chart-base.js +12 -12
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.d.ts +2 -2
- package/dist/core/chart-scaffold.d.ts.map +1 -1
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/interaction/crosshair.cjs.map +1 -1
- package/dist/interaction/crosshair.d.ts +2 -2
- package/dist/interaction/crosshair.d.ts.map +1 -1
- package/dist/interaction/crosshair.js.map +1 -1
- package/dist/interaction/index.d.ts +3 -3
- package/dist/interaction/index.d.ts.map +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.d.ts +1 -1
- package/dist/interaction/legend.d.ts.map +1 -1
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/series-interaction.cjs.map +1 -1
- package/dist/interaction/series-interaction.d.ts.map +1 -1
- package/dist/interaction/series-interaction.js.map +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.d.ts +1 -1
- package/dist/interaction/tooltip.d.ts.map +1 -1
- package/dist/interaction/tooltip.js.map +1 -1
- package/dist/prism.cjs +1 -1
- package/dist/prism.cjs.map +1 -1
- package/dist/prism.iife.js +1 -1
- package/dist/prism.iife.js.map +1 -1
- package/dist/prism.js +1 -1
- package/dist/prism.js.map +1 -1
- package/dist/scales/band.cjs.map +1 -1
- package/dist/scales/band.d.ts.map +1 -1
- package/dist/scales/band.js.map +1 -1
- package/dist/scales/linear.cjs.map +1 -1
- package/dist/scales/linear.js.map +1 -1
- package/dist/svg/index.d.ts +1 -1
- package/dist/svg/index.d.ts.map +1 -1
- package/dist/svg/text.cjs.map +1 -1
- package/dist/svg/text.js.map +1 -1
- package/package.json +32 -32
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 -
|
|
1
|
+
{"version":3,"file":"easing.cjs","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":"AAEA,IAAa,EAAoC,CAC/C,UAAY,GAAM,EAAI,EACtB,cAAgB,GAAO,EAAI,GAAM,EAAI,EAAI,EAAI,GAAK,GAAK,EAAI,IAAM,EAAI,EACrE,WAAa,GAAM,GAAK,EAAI,IAAM,EAAI,GACtC,OAAS,GAAM,CACjB,EAEA,SAAgB,EAAc,EAAgE,CAS5F,OARI,OAAO,GAAW,WAAmB,EAMrC,IAAW,IAAA,IAAa,OAAO,OAAO,EAAS,CAAM,EAAU,EAAQ,GAEpE,EAAQ,WACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 -
|
|
1
|
+
{"version":3,"file":"easing.js","names":[],"sources":["../../src/animation/easing.ts"],"sourcesContent":["export type EasingFn = (t: number) => number;\n\nexport const easings: Record<string, EasingFn> = {\n 'ease-in': (t) => t * t,\n 'ease-in-out': (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2),\n 'ease-out': (t) => 1 - (1 - t) * (1 - t),\n linear: (t) => t,\n};\n\nexport function resolveEasing(easing: string | ((t: number) => number) | undefined): EasingFn {\n if (typeof easing === 'function') return easing;\n\n // `Object.hasOwn` guards against `easing` being a prototype-chain key (e.g. `'__proto__'`,\n // `'constructor'`) — a plain bracket lookup on those would silently resolve to an\n // `Object.prototype` value instead of `undefined`, which is either not callable (throws)\n // or callable but not an easing function (produces garbage interpolation).\n if (easing !== undefined && Object.hasOwn(easings, easing)) return easings[easing];\n\n return easings['ease-out'];\n}\n"],"mappings":";AAEA,IAAa,IAAoC;CAC/C,YAAY,MAAM,IAAI;CACtB,gBAAgB,MAAO,IAAI,KAAM,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,MAAM,IAAI;CACrE,aAAa,MAAM,KAAK,IAAI,MAAM,IAAI;CACtC,SAAS,MAAM;AACjB;AAEA,SAAgB,EAAc,GAAgE;CAS5F,OARI,OAAO,KAAW,aAAmB,IAMrC,MAAW,KAAA,KAAa,OAAO,OAAO,GAAS,CAAM,IAAU,EAAQ,KAEpE,EAAQ;AACjB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { resolveEasing } from './easing';
|
|
2
1
|
export type { EasingFn } from './easing';
|
|
3
|
-
export {
|
|
2
|
+
export { resolveEasing } from './easing';
|
|
4
3
|
export type { AnimationTarget } from './transition';
|
|
4
|
+
export { animate } from './transition';
|
|
5
5
|
export { tweenColor, tweenNumber } from './tween';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/animation/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/animation/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/axes/axis.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"axis.cjs","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 3.5 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 4}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":"kGAKA,IAAM,EAAqB,GACzB,aAAa,KAAO,EAAE,mBAAmB,IAAA,GAAW,CAAE,MAAO,QAAS,KAAM,SAAU,CAAC,EAAI,OAAO,CAAC,EAOrG,SAAgB,EAAiB,EAAoB,EAAgB,EAAuC,CAC1G,IAAM,EAAW,EAAO,UAAY,EAE9B,EADe,IAAa,UAAY,IAAa,MACnB,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAAI,KAAK,IAAI,EAAG,KAAK,MAAM,EAAS,EAAE,CAAC,EAElH,OAAO,EAAO,WAAa,CAC7B,CAOA,SAAgB,EACd,EACA,EACA,EACA,EACA,EAAgC,SAC1B,CACN,EAAA,eAAe,CAAM,EAErB,IAAM,EAAW,EAAO,UAAY,EAC9B,EAAe,IAAa,UAAY,IAAa,MACrD,EAAa,IAAa,OAAS,IAAa,OAEhD,EAAgB,EAAa,GAAK,EAElC,EAAW,EAAA,iBAAiB,OAAQ,CACxC,cAAe,OACf,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|
+
{"version":3,"file":"axis.d.ts","sourceRoot":"","sources":["../../src/axes/axis.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AAKvD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,GAAG,MAAM,CAM1G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,GAAE,YAAuB,GACvC,IAAI,CAiEN"}
|
package/dist/axes/axis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"axis.js","names":[],"sources":["../../src/axes/axis.ts"],"sourcesContent":["import { createSvgElement, removeChildren, setAttributes } from '../svg/element';\nimport { createTextElement } from '../svg/text';\nimport type { AxisConfig, AxisPosition } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nconst defaultTickFormat = (v: Date | number | string): string =>\n v instanceof Date ? v.toLocaleDateString(undefined, { month: 'short', year: 'numeric' }) : String(v);\n\n/**\n * Resolves the tick count an axis will render for a given scale/length — shared with\n * `renderGrid` so gridlines line up with axis ticks. `defaultPosition` must match the\n * one passed to the corresponding `renderAxis` call ('bottom' for xAxis, 'left' for yAxis).\n */\nexport function resolveTickCount(config: AxisConfig, length: number, defaultPosition: AxisPosition): number {\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const defaultTickCount = isHorizontal ? Math.max(2, Math.floor(length / 80)) : Math.max(2, Math.floor(length / 50));\n\n return config.tickCount ?? defaultTickCount;\n}\n\n/**\n * `defaultPosition` is applied when `config.position` is unset — pass `'bottom'` for an\n * xAxis call and `'left'` for a yAxis call so an unconfigured axis renders on its\n * conventional side instead of always defaulting to a horizontal bottom axis.\n */\nexport function renderAxis(\n parent: SVGGElement,\n scale: AnyScale,\n config: AxisConfig,\n length: number,\n defaultPosition: AxisPosition = 'bottom',\n): void {\n removeChildren(parent);\n\n const position = config.position ?? defaultPosition;\n const isHorizontal = position === 'bottom' || position === 'top';\n const isInverted = position === 'top' || position === 'left';\n const tickSize = 6;\n const tickDirection = isInverted ? -1 : 1;\n\n const axisLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-line',\n x1: isHorizontal ? 0 : 0,\n x2: isHorizontal ? length : 0,\n y1: isHorizontal ? 0 : 0,\n y2: isHorizontal ? 0 : length,\n });\n\n parent.appendChild(axisLine);\n\n const ticks = scale.ticks(resolveTickCount(config, length, defaultPosition));\n const format = config.tickFormat ?? defaultTickFormat;\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const tickLine = createSvgElement('line', {\n 'aria-hidden': 'true',\n class: 'prism-axis-tick',\n x1: isHorizontal ? pos : 0,\n x2: isHorizontal ? pos : tickSize * tickDirection,\n y1: isHorizontal ? 0 : pos,\n y2: isHorizontal ? tickSize * tickDirection : pos,\n });\n\n parent.appendChild(tickLine);\n\n const label = createTextElement(format(tick), {\n 'aria-hidden': 'true',\n class: 'prism-axis-label',\n 'dominant-baseline': isHorizontal ? (isInverted ? 'auto' : 'hanging') : 'middle',\n 'text-anchor': isHorizontal ? 'middle' : isInverted ? 'end' : 'start',\n x: isHorizontal ? pos : tickSize * tickDirection * 1.5,\n y: isHorizontal ? tickSize * tickDirection * 1.5 : pos,\n });\n\n parent.appendChild(label);\n }\n\n if (config.label) {\n const labelEl = createTextElement(config.label, {\n class: 'prism-axis-title',\n 'dominant-baseline': 'middle',\n 'text-anchor': 'middle',\n });\n\n if (isHorizontal) {\n setAttributes(labelEl, { x: length / 2, y: tickSize * tickDirection * 3.5 });\n } else {\n setAttributes(labelEl, {\n transform: `translate(${tickSize * tickDirection * 4}, ${length / 2}) rotate(-90)`,\n });\n }\n\n parent.appendChild(labelEl);\n }\n}\n"],"mappings":";;;;AAKA,IAAM,KAAqB,MACzB,aAAa,OAAO,EAAE,mBAAmB,KAAA,GAAW;CAAE,OAAO;CAAS,MAAM;AAAU,CAAC,IAAI,OAAO,CAAC;AAOrG,SAAgB,EAAiB,GAAoB,GAAgB,GAAuC;CAC1G,IAAM,IAAW,EAAO,YAAY,GAE9B,IADe,MAAa,YAAY,MAAa,QACnB,KAAK,IAAI,GAAG,KAAK,MAAM,IAAS,EAAE,CAAC,IAAI,KAAK,IAAI,GAAG,KAAK,MAAM,IAAS,EAAE,CAAC;CAElH,OAAO,EAAO,aAAa;AAC7B;AAOA,SAAgB,EACd,GACA,GACA,GACA,GACA,IAAgC,UAC1B;CACN,EAAe,CAAM;CAErB,IAAM,IAAW,EAAO,YAAY,GAC9B,IAAe,MAAa,YAAY,MAAa,OACrD,IAAa,MAAa,SAAS,MAAa,QAEhD,IAAgB,IAAa,KAAK,GAElC,IAAW,EAAiB,QAAQ;EACxC,eAAe;EACf,OAAO;EACP,IAAmB;EACnB,IAAI,IAAe,IAAS;EAC5B,IAAmB;EACnB,IAAI,IAAe,IAAI;CACzB,CAAC;CAED,EAAO,YAAY,CAAQ;CAE3B,IAAM,IAAQ,EAAM,MAAM,EAAiB,GAAQ,GAAQ,CAAe,CAAC,GACrE,IAAS,EAAO,cAAc;CAEpC,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAM,IAAM,EAAQ,GAAO,CAAI,GACzB,IAAW,EAAiB,QAAQ;GACxC,eAAe;GACf,OAAO;GACP,IAAI,IAAe,IAAM;GACzB,IAAI,IAAe,IAAM,IAAW;GACpC,IAAI,IAAe,IAAI;GACvB,IAAI,IAAe,IAAW,IAAgB;EAChD,CAAC;EAED,EAAO,YAAY,CAAQ;EAE3B,IAAM,IAAQ,EAAkB,EAAO,CAAI,GAAG;GAC5C,eAAe;GACf,OAAO;GACP,qBAAqB,IAAgB,IAAa,SAAS,YAAa;GACxE,eAAe,IAAe,WAAW,IAAa,QAAQ;GAC9D,GAAG,IAAe,IAAM,IAAW,IAAgB;GACnD,GAAG,IAAe,IAAW,IAAgB,MAAM;EACrD,CAAC;EAED,EAAO,YAAY,CAAK;CAC1B;CAEA,IAAI,EAAO,OAAO;EAChB,IAAM,IAAU,EAAkB,EAAO,OAAO;GAC9C,OAAO;GACP,qBAAqB;GACrB,eAAe;EACjB,CAAC;EAUD,AARI,IACF,EAAc,GAAS;GAAE,GAAG,IAAS;GAAG,GAAG,IAAW,IAAgB;EAAI,CAAC,IAE3E,EAAc,GAAS,EACrB,WAAW,aAAa,IAAW,IAAgB,EAAE,IAAI,IAAS,EAAE,eACtE,CAAC,GAGH,EAAO,YAAY,CAAO;CAC5B;AACF"}
|
package/dist/axes/grid.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.cjs","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"grid.cjs","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":"qEAIA,SAAgB,EACd,EACA,EACA,EACA,EACA,EACA,EAAY,GACN,CACN,EAAA,eAAe,CAAM,EAErB,IAAM,EAAS,IAAW,IAAQ,EAAO,OAAU,IAAA,GAC7C,EAAQ,IAAW,IAAQ,EAAO,MAAS,IAAA,GAC3C,EAAQ,EAAM,MAAM,CAAS,EAEnC,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAA,QAAQ,EAAO,CAAI,EACzB,EAAqD,CACzD,MAAO,kBACP,OAAQ,GAAS,0BACjB,mBAAoB,EACpB,iBAAkB,2BACpB,EAEI,IAAc,WAChB,OAAO,OAAO,EAAO,CAAE,GAAI,EAAK,GAAI,EAAK,GAAI,EAAG,GAAI,CAAY,CAAC,EAEjE,OAAO,OAAO,EAAO,CAAE,GAAI,EAAG,GAAI,EAAa,GAAI,EAAK,GAAI,CAAI,CAAC,EAGnE,EAAO,YAAY,EAAA,iBAAiB,OAAQ,CAAK,CAAC,CACpD,CACF"}
|
package/dist/axes/grid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../src/axes/grid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../src/axes/grid.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,QAAQ,EAAW,MAAM,eAAe,CAAC;AAEvD,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,YAAY,GAAG,UAAU,EACpC,SAAS,SAAK,GACb,IAAI,CAwBN"}
|
package/dist/axes/grid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid.js","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"grid.js","names":[],"sources":["../../src/axes/grid.ts"],"sourcesContent":["import { createSvgElement, removeChildren } from '../svg/element';\nimport type { GridConfig } from '../types';\nimport { type AnyScale, mapTick } from './scale-utils';\n\nexport function renderGrid(\n parent: SVGGElement,\n scale: AnyScale,\n config: GridConfig | true,\n crossLength: number,\n direction: 'horizontal' | 'vertical',\n tickCount = 10,\n): void {\n removeChildren(parent);\n\n const color = (config !== true && config.color) || undefined;\n const dash = (config !== true && config.dash) || undefined;\n const ticks = scale.ticks(tickCount);\n\n for (const tick of ticks) {\n const pos = mapTick(scale, tick);\n const attrs: Record<string, number | string | undefined> = {\n class: 'prism-grid-line',\n stroke: color ?? 'var(--prism-grid-color)',\n 'stroke-dasharray': dash,\n 'stroke-opacity': 'var(--prism-grid-opacity)',\n };\n\n if (direction === 'vertical') {\n Object.assign(attrs, { x1: pos, x2: pos, y1: 0, y2: crossLength });\n } else {\n Object.assign(attrs, { x1: 0, x2: crossLength, y1: pos, y2: pos });\n }\n\n parent.appendChild(createSvgElement('line', attrs));\n }\n}\n"],"mappings":";;;AAIA,SAAgB,EACd,GACA,GACA,GACA,GACA,GACA,IAAY,IACN;CACN,EAAe,CAAM;CAErB,IAAM,IAAS,MAAW,MAAQ,EAAO,SAAU,KAAA,GAC7C,IAAQ,MAAW,MAAQ,EAAO,QAAS,KAAA,GAC3C,IAAQ,EAAM,MAAM,CAAS;CAEnC,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAM,IAAM,EAAQ,GAAO,CAAI,GACzB,IAAqD;GACzD,OAAO;GACP,QAAQ,KAAS;GACjB,oBAAoB;GACpB,kBAAkB;EACpB;EAQA,AANI,MAAc,aAChB,OAAO,OAAO,GAAO;GAAE,IAAI;GAAK,IAAI;GAAK,IAAI;GAAG,IAAI;EAAY,CAAC,IAEjE,OAAO,OAAO,GAAO;GAAE,IAAI;GAAG,IAAI;GAAa,IAAI;GAAK,IAAI;EAAI,CAAC,GAGnE,EAAO,YAAY,EAAiB,QAAQ,CAAK,CAAC;CACpD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-chart.cjs","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\
|
|
1
|
+
{"version":3,"file":"area-chart.cjs","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const allData = seriesList.map((s) => (isReactive(s.data) ? s.data.value : s.data));\n const allX = allData.flat().map((d) => d.key as Date | number);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n warn('createAreaChart: no data');\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX as (Date | number)[], area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fillOpacity: series.fillOpacity ?? 0.3,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions.value,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => (isReactive(config.series) ? config.series.value : config.series),\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n });\n}\n"],"mappings":"ycAeA,SAAgB,EAAg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OAAO,EAAA,WAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,OAAQ,MAAM,EAE7E,EAAO,OAAO,SAAS,OAAS,EAAW,QAChD,EAAO,OAAO,YAAY,EAAO,OAAO,SAAU,EAGpD,IAAM,EAAuB,CAAC,EAE9B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAC1C,IAAM,EAAS,EAAW,GACtB,EAAQ,EAAO,OAAO,SAAS,GAE9B,IACH,EAAQ,EAAA,iBAAiB,IAAK,CAAE,MAAO,mBAAoB,CAAC,EAC5D,EAAO,OAAO,YAAY,CAAK,GAGjC,IAAM,EAAS,EAAA,kBAAkB,EAAQ,GAAI,EAAQ,CAAM,EAE3D,EAAU,KAAK,CAAM,EAErB,EAAA,WAAW,EAAO,EAAQ,EAAW,CACnC,MAAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,GACnC,SAAU,EAAO,WAAa,GAC9B,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAA,YAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAA,wBAAwB,CAC7B,YACA,SAAY,EAAI,WAAW,MAC3B,YAAe,EACf,cAAiB,EACjB,mBAAA,EAAsB,EAAA,WAAA,CAAW,EAAO,MAAM,EAAI,EAAO,OAAO,MAAQ,EAAO,OAC/E,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,CAAC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-chart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"area-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-chart.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhE,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAoG5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-chart.js","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\
|
|
1
|
+
{"version":3,"file":"area-chart.js","names":[],"sources":["../../../src/charts/area/area-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { buildXScale, buildYScale } from '../../core/cartesian-scales';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction } from '../../interaction/series-interaction';\nimport { createSvgElement } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { seriesColor } from '../../theme';\nimport type { AreaChartConfig, ChartHandle } from '../../types';\nimport { computeAreaPoints, renderArea } from './area-renderer';\n\nexport function createAreaChart(container: HTMLElement, config: AreaChartConfig): ChartHandle {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const allData = seriesList.map((s) => (isReactive(s.data) ? s.data.value : s.data));\n const allX = allData.flat().map((d) => d.key as Date | number);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\n warn('createAreaChart: no data');\n clearCartesianDom(groups, legend, tooltip, crosshair);\n\n return;\n }\n\n if (config.crosshair && !crosshair) {\n crosshair = createCrosshair(ctx.chartArea, config.crosshair);\n }\n\n const xScale = buildXScale(allX as (Date | number)[], area.width);\n const yScale = buildYScale(allY, area.height);\n const baselineY = yScale.map(0);\n\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n yScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n xScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n\n while (groups.series.children.length > seriesList.length) {\n groups.series.removeChild(groups.series.lastChild!);\n }\n\n const allPoints: Point[][] = [];\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-area-series' });\n groups.series.appendChild(group);\n }\n\n const points = computeAreaPoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderArea(group, points, baselineY, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n fillOpacity: series.fillOpacity ?? 0.3,\n showLine: series.showLine !== false,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n return createSeriesInteraction({\n crosshair,\n dims: () => ctx.dimensions.value,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => (isReactive(config.series) ? config.series.value : config.series),\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,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W,SAChD,EAAO,OAAO,YAAY,EAAO,OAAO,SAAU;EAGpD,IAAM,IAAuB,CAAC;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAW,QAAQ,KAAK;GAC1C,IAAM,IAAS,EAAW,IACtB,IAAQ,EAAO,OAAO,SAAS;GAEnC,AAAK,MACH,IAAQ,EAAiB,KAAK,EAAE,OAAO,oBAAoB,CAAC,GAC5D,EAAO,OAAO,YAAY,CAAK;GAGjC,IAAM,IAAS,EAAkB,EAAQ,IAAI,GAAQ,CAAM;GAI3D,AAFA,EAAU,KAAK,CAAM,GAErB,EAAW,GAAO,GAAQ,GAAW;IACnC,OAAO,EAAY,GAAG,EAAO,KAAK;IAClC,OAAO,EAAO,SAAS;IACvB,gBAAgB,EAAI;IACpB,aAAa,EAAO,eAAe;IACnC,UAAU,EAAO,aAAa;IAC9B,YAAY,EAAO;GACrB,CAAC;EACH;EAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,GAAG,OAAO;GAAE,OAAO,EAAY,GAAG,EAAE,KAAK;GAAG,MAAM,EAAE;EAAK,EAAE,CAAC,GAC3F,GAAS,KAAK,GAEP,EAAwB;GAC7B;GACA,YAAY,EAAI,WAAW;GAC3B,eAAe;GACf,iBAAiB;GACjB,qBAAsB,EAAW,EAAO,MAAM,IAAI,EAAO,OAAO,QAAQ,EAAO;GAC/E,SAAS,EAAO;GAChB,SAAS,EAAO;GAChB,KAAK,EAAI;GACT;EACF,CAAC;CACH,CAAC;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("../../animation/easing.cjs"),t=require("../../animation/motion.cjs"),n=require("../../animation/tween.cjs");require("../../_dev.cjs");const r=require("../../svg/element.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap,o=new WeakMap;function s(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function c(c,l,u,d){let f=t.resolveMotion(d.transition,0),p=f.duration,m=e.resolveEasing(f.easing),h=c.querySelector(`.prism-area-fill`);h||(h=r.createSvgElement(`path`,{class:`prism-area-fill`}),c.appendChild(h)),r.setAttributes(h,{fill:d.color,"fill-opacity":d.fillOpacity,stroke:`none`});let g=null;if(d.showLine?(g=c.querySelector(`.prism-area-line`),g||(g=r.createSvgElement(`path`,{class:`prism-area-line`,fill:`none`}),c.appendChild(g)),r.setAttributes(g,{stroke:d.color,"stroke-width":2})):c.querySelector(`.prism-area-line`)?.remove(),p===0){let e=l.map(e=>({x:e.x,y:u}));r.setAttributes(h,{d:i.areaPath(l,e,d.curve)}),g&&r.setAttributes(g,{d:s(l,d.curve)});return}if(a.get(c)?.(),!h.hasAttribute(`d`)){let e=l.map(e=>({x:e.x,y:u}));r.setAttributes(h,{d:i.areaPath(l,e,d.curve)}),g&&r.setAttributes(g,{d:s(l,d.curve)}),o.set(c,l);return}let _=o.get(c)??l,v=l.map((e,t)=>_[t]??_[_.length-1]??l[t]),y=null;function b(e){if(d.disposalSignal?.aborted){a.delete(c);return}y===null&&(y=e);let t=Math.min(1,(e-y)/p),f=m(t),_=l.map((e,t)=>({x:n.tweenNumber(v[t].x,e.x,f),y:n.tweenNumber(v[t].y,e.y,f)})),x=_.map(e=>({x:e.x,y:u}));if(r.setAttributes(h,{d:i.areaPath(_,x,d.curve)}),g&&r.setAttributes(g,{d:s(_,d.curve)}),t<1){let e=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(e))}else a.delete(c),o.set(c,l)}o.set(c,v);let x=requestAnimationFrame(b);a.set(c,()=>cancelAnimationFrame(x))}function l(e,t,n){return e.some(e=>e.key==null)||e.some(e=>typeof e.key==`string`),e.map(e=>({x:t.map(e.key),y:n.map(e.value)}))}exports.computeAreaPoints=l,exports.renderArea=c;
|
|
2
2
|
//# sourceMappingURL=area-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-renderer.cjs","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"area-renderer.cjs","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":"gOAmBA,IAAM,EAAuB,IAAI,QAC3B,EAAiB,IAAI,QAE3B,SAAS,EAAc,EAAc,EAA2C,CAC9E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,EAAW,EAAqB,EAAiB,EAAmB,EAAkC,CACpH,IAAM,EAAS,EAAA,cAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAA,cAAc,EAAO,MAAM,EAEtC,EAAO,EAAO,cAA8B,kBAAkB,EAE7D,IACH,EAAO,EAAA,iBAAiB,OAAQ,CAAE,MAAO,iBAAkB,CAAC,EAC5D,EAAO,YAAY,CAAI,GAGzB,EAAA,cAAc,EAAM,CAAE,KAAM,EAAQ,MAAO,eAAgB,EAAQ,YAAa,OAAQ,MAAO,CAAC,EAEhG,IAAI,EAA8B,KAelC,GAbI,EAAQ,UACV,EAAO,EAAO,cAA8B,kBAAkB,EAEzD,IACH,EAAO,EAAA,iBAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAC1E,EAAO,YAAY,CAAI,GAGzB,EAAA,cAAc,EAAM,CAAE,OAAQ,EAAQ,MAAO,eAAgB,CAAE,CAAC,GAEhE,EAAO,cAAc,kBAAkB,CAAC,EAAE,OAAO,EAG/C,IAAQ,EAAG,CACb,IAAM,EAAe,EAAO,IAAK,IAAO,CAAE,EAAG,EAAE,EAAG,EAAG,CAAU,EAAE,EAEjE,EAAA,cAAc,EAAM,CAAE,EAAG,EAAA,SAAS,EAAQ,EAAc,EAAQ,KAAK,CAAE,CAAC,EAEpE,GAAM,EAAA,cAAc,EAAM,CAAE,EAAG,EAAc,EAAQ,EAAQ,K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C,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,MACE,EAAqB,OAAO,CAAM,EAClC,EAAe,IAAI,EAAQ,CAAM,CAErC,CAEA,EAAe,IAAI,EAAQ,CAAU,EAErC,IAAM,EAAK,sBAAsB,CAAK,EAEtC,EAAqB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CACjE,CAEA,SAAgB,EAAkB,EAAe,EAA8B,EAAgC,CAS7G,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"area-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/area/area-renderer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,yHAAyH;IACzH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AASD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAgGpH;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAa7G"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { resolveEasing as e } from "../../animation/easing.js";
|
|
2
|
+
import { resolveMotion as t } from "../../animation/motion.js";
|
|
3
|
+
import { tweenNumber as n } from "../../animation/tween.js";
|
|
1
4
|
import "../../_dev.js";
|
|
2
|
-
import { createSvgElement as
|
|
3
|
-
import { resolveEasing as n } from "../../animation/easing.js";
|
|
4
|
-
import { resolveMotion as r } from "../../animation/motion.js";
|
|
5
|
-
import { tweenNumber as i } from "../../animation/tween.js";
|
|
5
|
+
import { createSvgElement as r, setAttributes as i } from "../../svg/element.js";
|
|
6
6
|
import { areaPath as a, linePath as o, monotonePath as s, stepPath as c } from "../../svg/path.js";
|
|
7
7
|
//#region src/charts/area/area-renderer.ts
|
|
8
8
|
var l = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap();
|
|
@@ -10,17 +10,17 @@ function d(e, t) {
|
|
|
10
10
|
return t === "monotone" ? s(e) : t === "step" ? c(e) : o(e);
|
|
11
11
|
}
|
|
12
12
|
function f(o, s, c, f) {
|
|
13
|
-
let p =
|
|
14
|
-
g || (g =
|
|
13
|
+
let p = t(f.transition, 0), m = p.duration, h = e(p.easing), g = o.querySelector(".prism-area-fill");
|
|
14
|
+
g || (g = r("path", { class: "prism-area-fill" }), o.appendChild(g)), i(g, {
|
|
15
15
|
fill: f.color,
|
|
16
16
|
"fill-opacity": f.fillOpacity,
|
|
17
17
|
stroke: "none"
|
|
18
18
|
});
|
|
19
19
|
let _ = null;
|
|
20
|
-
if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ =
|
|
20
|
+
if (f.showLine ? (_ = o.querySelector(".prism-area-line"), _ || (_ = r("path", {
|
|
21
21
|
class: "prism-area-line",
|
|
22
22
|
fill: "none"
|
|
23
|
-
}), o.appendChild(_)),
|
|
23
|
+
}), o.appendChild(_)), i(_, {
|
|
24
24
|
stroke: f.color,
|
|
25
25
|
"stroke-width": 2
|
|
26
26
|
})) : o.querySelector(".prism-area-line")?.remove(), m === 0) {
|
|
@@ -28,7 +28,7 @@ function f(o, s, c, f) {
|
|
|
28
28
|
x: e.x,
|
|
29
29
|
y: c
|
|
30
30
|
}));
|
|
31
|
-
|
|
31
|
+
i(g, { d: a(s, e, f.curve) }), _ && i(_, { d: d(s, f.curve) });
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
if (l.get(o)?.(), !g.hasAttribute("d")) {
|
|
@@ -36,7 +36,7 @@ function f(o, s, c, f) {
|
|
|
36
36
|
x: e.x,
|
|
37
37
|
y: c
|
|
38
38
|
}));
|
|
39
|
-
|
|
39
|
+
i(g, { d: a(s, e, f.curve) }), _ && i(_, { d: d(s, f.curve) }), u.set(o, s);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
let v = u.get(o) ?? s, y = s.map((e, t) => v[t] ?? v[v.length - 1] ?? s[t]), b = null;
|
|
@@ -46,14 +46,14 @@ function f(o, s, c, f) {
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
b === null && (b = e);
|
|
49
|
-
let
|
|
50
|
-
x:
|
|
51
|
-
y:
|
|
49
|
+
let t = Math.min(1, (e - b) / m), r = h(t), p = s.map((e, t) => ({
|
|
50
|
+
x: n(y[t].x, e.x, r),
|
|
51
|
+
y: n(y[t].y, e.y, r)
|
|
52
52
|
})), v = p.map((e) => ({
|
|
53
53
|
x: e.x,
|
|
54
54
|
y: c
|
|
55
55
|
}));
|
|
56
|
-
if (
|
|
56
|
+
if (i(g, { d: a(p, v, f.curve) }), _ && i(_, { d: d(p, f.curve) }), t < 1) {
|
|
57
57
|
let e = requestAnimationFrame(x);
|
|
58
58
|
l.set(o, () => cancelAnimationFrame(e));
|
|
59
59
|
} else l.delete(o), u.set(o, s);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"area-renderer.js","names":[],"sources":["../../../src/charts/area/area-renderer.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { resolveEasing } from '../../animation/easing';\nimport { resolveMotion } from '../../animation/motion';\nimport { tweenNumber } from '../../animation/tween';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { Point } from '../../svg/path';\nimport { areaPath, linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { Datum, Scale, TransitionConfig } from '../../types';\n\nexport interface AreaRenderOptions {\n color: string;\n curve: 'linear' | 'monotone' | 'step';\n /** Aborted when the owning chart is disposed — stops the transition's `requestAnimationFrame` loop from rescheduling. */\n disposalSignal?: AbortSignal;\n fillOpacity: number;\n showLine: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeAreaAnimations = new WeakMap<SVGGElement, () => void>();\nconst previousPoints = new WeakMap<SVGGElement, Point[]>();\n\nfunction buildLinePath(pts: Point[], curve: AreaRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderArea(parent: SVGGElement, points: Point[], baselineY: number, options: AreaRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let fill = parent.querySelector<SVGPathElement>('.prism-area-fill');\n\n if (!fill) {\n fill = createSvgElement('path', { class: 'prism-area-fill' });\n parent.appendChild(fill);\n }\n\n setAttributes(fill, { fill: options.color, 'fill-opacity': options.fillOpacity, stroke: 'none' });\n\n let line: SVGPathElement | null = null;\n\n if (options.showLine) {\n line = parent.querySelector<SVGPathElement>('.prism-area-line');\n\n if (!line) {\n line = createSvgElement('path', { class: 'prism-area-line', fill: 'none' });\n parent.appendChild(line);\n }\n\n setAttributes(line, { stroke: options.color, 'stroke-width': 2 });\n } else {\n parent.querySelector('.prism-area-line')?.remove();\n }\n\n if (dur === 0) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n return;\n }\n\n activeAreaAnimations.get(parent)?.();\n\n const hasExisting = fill.hasAttribute('d');\n\n if (!hasExisting) {\n const bottomPoints = points.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill, { d: areaPath(points, bottomPoints, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(points, options.curve) });\n\n previousPoints.set(parent, points);\n\n return;\n }\n\n const rawFrom = previousPoints.get(parent) ?? points;\n const fromPoints: Point[] = points.map((_, i) => rawFrom[i] ?? rawFrom[rawFrom.length - 1] ?? points[i]);\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAreaAnimations.delete(parent);\n\n return;\n }\n\n if (startTime === null) startTime = ts;\n\n const t = Math.min(1, (ts - startTime) / dur);\n const e = easing(t);\n const interpolated: Point[] = points.map((to, i) => ({\n x: tweenNumber(fromPoints[i].x, to.x, e),\n y: tweenNumber(fromPoints[i].y, to.y, e),\n }));\n const interpolatedBottom = interpolated.map((p) => ({ x: p.x, y: baselineY }));\n\n setAttributes(fill!, { d: areaPath(interpolated, interpolatedBottom, options.curve) });\n\n if (line) setAttributes(line, { d: buildLinePath(interpolated, options.curve) });\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAreaAnimations.delete(parent);\n previousPoints.set(parent, points);\n }\n }\n\n previousPoints.set(parent, fromPoints);\n\n const id = requestAnimationFrame(frame);\n\n activeAreaAnimations.set(parent, () => cancelAnimationFrame(id));\n}\n\nexport function computeAreaPoints(data: Datum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computeAreaPoints: datum.key is null or undefined — data must use the Datum shape { key, value }. Did you pass { x, y } instead?',\n );\n } else if (data.some((d) => typeof d.key === 'string')) {\n warn('computeAreaPoints: string keys are not supported for line/area charts — use numeric or Date keys.');\n }\n\n return data.map((d) => ({\n x: xScale.map(d.key as Date | number),\n y: yScale.map(d.value),\n }));\n}\n"],"mappings":";;;;;;;AAmBA,IAAM,oBAAuB,IAAI,QAAiC,GAC5D,oBAAiB,IAAI,QAA8B;AAEzD,SAAS,EAAc,GAAc,GAA2C;CAC9E,OAAO,MAAU,aAAa,EAAa,CAAG,IAAI,MAAU,SAAS,EAAS,CAAG,IAAI,EAAS,CAAG;AACnG;AAEA,SAAgB,EAAW,GAAqB,GAAiB,GAAmB,GAAkC;CACpH,IAAM,IAAS,EAAc,EAAQ,YAAY,CAAC,GAC5C,IAAM,EAAO,UACb,IAAS,EAAc,EAAO,MAAM,GAEtC,IAAO,EAAO,cAA8B,kBAAkB;CAOlE,AALK,MACH,IAAO,EAAiB,QAAQ,EAAE,OAAO,kBAAkB,CAAC,GAC5D,EAAO,YAAY,CAAI,IAGzB,EAAc,GAAM;EAAE,MAAM,EAAQ;EAAO,gBAAgB,EAAQ;EAAa,QAAQ;CAAO,CAAC;CAEhG,IAAI,IAA8B;CAelC,IAbI,EAAQ,YACV,IAAO,EAAO,cAA8B,kBAAkB,GAEzD,MACH,IAAO,EAAiB,QAAQ;EAAE,OAAO;EAAmB,MAAM;CAAO,CAAC,GAC1E,EAAO,YAAY,CAAI,IAGzB,EAAc,GAAM;EAAE,QAAQ,EAAQ;EAAO,gBAAgB;CAAE,CAAC,KAEhE,EAAO,cAAc,kBAAkB,CAAC,EAAE,OAAO,GAG/C,MAAQ,GAAG;EACb,IAAM,IAAe,EAAO,KAAK,OAAO;GAAE,GAAG,EAAE;GAAG,GAAG;EAAU,EAAE;EAIjE,AAFA,EAAc,GAAM,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AAQ,KAAK,EAAE,CAAC,GAE3E,IAAI,GAAG;GACT,IAAM,IAAK,sBAAsB,CAAK;GAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;EACjE,OAEE,AADA,EAAqB,OAAO,CAAM,GAClC,EAAe,IAAI,GAAQ,CAAM;CAErC;CAEA,EAAe,IAAI,GAAQ,CAAU;CAErC,IAAM,IAAK,sBAAsB,CAAK;CAEtC,EAAqB,IAAI,SAAc,qBAAqB,CAAE,CAAC;AACjE;AAEA,SAAgB,EAAkB,GAAe,GAA8B,GAAgC;CAS7G,OARI,EAAK,MAAM,MAAM,EAAE,OAAO,IAAI,KAIvB,EAAK,MAAM,MAAM,OAAO,EAAE,OAAQ,QAAQ,GAI9C,EAAK,KAAK,OAAO;EACtB,GAAG,EAAO,IAAI,EAAE,GAAoB;EACpC,GAAG,EAAO,IAAI,EAAE,KAAK;CACvB,EAAE;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":"sfAmBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAqC,CAC1F,OAAO,EAAA,oBAAoB,EAAW,EAAS,GAAQ,CACrD,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WAAW,MACtB,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,GAAA,EAAa,EAAA,WAAA,CAAW,EAAO,MAAM,EAAI,EAAO,OAAO,MAAQ,EAAO,OACtE,EAAa,EAAW,IAAK,IAAA,EAAY,EAAA,WAAA,CAAW,EAAO,IAAI,EAAI,EAAO,KAAK,MAAQ,EAAO,IAAK,EACnG,EAAQ,EAAA,yBAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACnB,EAAU,EAAM,OAAO,KAAK,CAAE,WAAY,EAAW,IAAK,GAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,EACjF,EA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AAU,GAAG,IAAW,EAAM,MAAS,EAAM,MACjF,EAAU,EAAS,IAAI,CAAU,EAEjC,EAAW,EAAa,EAAU,EAAE,OAAO,KAAO,EAAe,EAAE,OAAO,KAC1E,EAAW,EAAa,EAAe,EAAE,OAAO,IAAM,EAAU,EAAE,OAAO,IAE/E,GAAS,KAAK,EAAU,EAAU,EAAO,EAAW,EAAU,EAC9D,EAAO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,CAAC,CACH"}
|
|
1
|
+
{"version":3,"file":"bar-chart.cjs","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":"sfAiBA,SAAS,EAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,EAAe,EAAwB,EAAqC,CAC1F,OAAO,EAAA,oBAAoB,EAAW,EAAS,GAAQ,CACrD,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WAAW,MACtB,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,GAAA,EAAa,EAAA,WAAA,CAAW,EAAO,MAAM,EAAI,EAAO,OAAO,MAAQ,EAAO,OACtE,EAAa,EAAW,IAAK,IAAA,EAAY,EAAA,WAAA,CAAW,EAAO,IAAI,EAAI,EAAO,KAAK,MAAQ,EAAO,IAAK,EACnG,EAAQ,EAAA,yBAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACnB,EAAU,EAAM,OAAO,KAAK,CAAE,WAAY,EAAW,IAAK,GAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,EACjF,EAAgB,GAA4D,CAC3E,KAEL,MAAO,CACL,GAAG,EACH,WAAa,GAAkC,CAC7C,IAAM,EAAM,OAAO,CAAK,EAClB,EAAQ,EAAM,OAAO,IAAI,CAAG,GAAK,EAEvC,OAAO,EAAK,WAAa,EAAK,WAAW,CAAK,EAAI,OAAO,CAAK,CAChE,CACF,CACF,EAEA,GAAI,EAAW,SAAW,EAAG,CAE3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AO,UAAU,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CACxF,CACF,CA6B4C,CAC9C,CAAC,CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-chart.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAc,WAAW,EAAE,MAAM,aAAa,CAAC;AAc3E,wBAAgB,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,GAAG,WAAW,CAwP1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\n\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAqC;CAC1F,OAAO,EAAoB,GAAW,IAAS,MAAQ;EACrD,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,WAAW,OACtB,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAW,EAAO,MAAM,IAAI,EAAO,OAAO,QAAQ,EAAO,QACtE,IAAa,EAAW,KAAK,MAAY,EAAW,EAAO,IAAI,IAAI,EAAO,KAAK,QAAQ,EAAO,IAAK,GACnG,IAAQ,EAAyB,GAAY,CAAU,GACvD,IAAa,EAAM,QACnB,IAAU,EAAM,OAAO,KAAK,EAAE,eAAY,EAAW,KAAK,MAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,GACjF,KAAgB,MAA4D;GAC3E,OAEL,OAAO;IACL,GAAG;IACH,aAAa,MAAkC;KAC7C,IAAM,IAAM,OAAO,CAAK,GAClB,IAAQ,EAAM,OAAO,IAAI,CAAG,KAAK;KAEvC,OAAO,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AAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { isReactive } from '@vielzeug/ripple';\nimport { warn } from '../../_dev';\nimport { renderAxis, resolveTickCount } from '../../axes/axis';\nimport { renderGrid } from '../../axes/grid';\nimport { normalizeCartesianSeries } from '../../core/cartesian-model';\nimport { clearCartesianDom, createChartScaffold } from '../../core/chart-scaffold';\nimport { chartArea } from '../../core/layout';\nimport { getMousePosition } from '../../interaction/events';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarVariant, ChartHandle } from '../../types';\nimport { findCatIdx, findSeriesIdx, isOutsideBars } from './bar-hit-test';\nimport { renderBars } from './bar-renderer';\nimport type { BarScaleContext } from './bar-scale-context';\n\nfunction variantFlags(variant: BarVariant): { horizontal: boolean; stacked: boolean } {\n return {\n horizontal: variant === 'grouped-horizontal' || variant === 'stacked-horizontal',\n stacked: variant === 'stacked' || variant === 'stacked-horizontal',\n };\n}\n\n// ─── Chart ────────────────────────────────────────────────────────────────────\n\nexport function createBarChart(container: HTMLElement, config: BarChartConfig): ChartHandle {\n return createChartScaffold(container, config, (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions.value;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const seriesList = isReactive(config.series) ? config.series.value : config.series;\n const sourceData = seriesList.map((series) => (isReactive(series.data) ? series.data.value : series.data));\n const model = normalizeCartesianSeries(seriesList, sourceData);\n const categories = model.domain;\n const allData = model.series.map(({ byKey }) => categories.map((key) => byKey.get(key)));\n const categoryAxis = (axis: BarChartConfig['xAxis'] | BarChartConfig['yAxis']) => {\n if (!axis) return undefined;\n\n return {\n ...axis,\n tickFormat: (value: Date | number | string) => {\n const key = String(value);\n const label = model.labels.get(key) ?? value;\n\n return axis.tickFormat ? axis.tickFormat(label) : String(label);\n },\n };\n };\n\n if (categories.length === 0) {\n warn('createBarChart: no data');\n clearCartesianDom(groups, legend, tooltip);\n\n return;\n }\n\n const { horizontal, stacked } = variantFlags(config.variant ?? 'grouped');\n\n // Value domain\n let vMax: number;\n let vMin: number;\n\n if (stacked) {\n if (allData.some((seriesData) => seriesData.some((datum) => (datum?.value ?? 0) < 0))) {\n warn(\n 'createBarChart: negative values in a stacked/stacked-horizontal series are clamped to 0 — stacking mixed-sign data is not supported.',\n );\n }\n\n const sums = categories.map((_, categoryIndex) =>\n allData.reduce((sum, seriesData) => sum + Math.max(0, seriesData[categoryIndex]?.value ?? 0), 0),\n );\n\n vMax = Math.max(...sums);\n vMin = 0;\n } else {\n const allY = allData.flatMap((seriesData) => seriesData.flatMap((datum) => (datum ? [datum.value] : [])));\n\n vMax = Math.max(...allY);\n vMin = Math.min(0, ...allY);\n }\n\n // Build uniform scale context\n const catScale = horizontal\n ? bandScale({ domain: categories, range: [0, area.height] })\n : bandScale({ domain: categories, range: [0, area.width] });\n\n const valScale = horizontal\n ? linearScale({ domain: [vMin, vMax], range: [0, area.width] })\n : linearScale({ domain: [vMin, vMax], range: [area.height, 0] });\n\n const stackedTops: number[][] = [];\n const stackTops = Object.create(null) as Record<string, number>;\n\n for (const cat of categories) stackTops[cat] = 0;\n\n const sc: BarScaleContext = {\n bandCenter: (cat) => catScale.map(cat) + catScale.bandwidth() / 2,\n bandwidth: catScale.bandwidth(),\n baselinePx: valScale.map(0),\n horizontal,\n stacked,\n stackedTops,\n valueScale: valScale,\n };\n\n // Axes & grid\n if (horizontal) {\n if (config.xAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.xAxis.grid,\n area.height,\n 'vertical',\n resolveTickCount(config.xAxis, area.width, 'bottom'),\n );\n }\n\n const yAxis = categoryAxis(config.yAxis);\n\n if (yAxis) renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n\n if (config.xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, valScale, config.xAxis, area.width, 'bottom');\n }\n } else {\n if (config.yAxis?.grid) {\n renderGrid(\n groups.grid,\n valScale,\n config.yAxis.grid,\n area.width,\n 'horizontal',\n resolveTickCount(config.yAxis, area.height, 'left'),\n );\n }\n\n const xAxis = categoryAxis(config.xAxis);\n\n if (xAxis) {\n groups.xAxis.setAttribute('transform', `translate(0,${area.height})`);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\n\n // Series groups\n while (groups.series.children.length > seriesList.length) {\n const last = groups.series.lastElementChild;\n\n if (last) groups.series.removeChild(last);\n }\n\n for (let i = 0; i < seriesList.length; i++) {\n const series = seriesList[i];\n let group = groups.series.children[i] as SVGGElement | undefined;\n\n if (!group) {\n group = createSvgElement('g', { class: 'prism-bar-series' });\n groups.series.appendChild(group);\n }\n\n const barData = categories.map((key, categoryIndex) => {\n const datum = allData[i]?.[categoryIndex];\n\n if (stacked) {\n const base = stackTops[key] ?? 0;\n const top = base + Math.max(0, datum?.value ?? 0);\n\n stackTops[key] = top;\n\n return { base, key, present: datum !== undefined, y: top };\n }\n\n return { base: 0, key, present: datum !== undefined, y: datum?.value ?? 0 };\n });\n\n stackedTops[i] = barData.map((d) => d.y);\n\n const baselineYs = stacked ? barData.map((d) => valScale.map(d.base)) : undefined;\n\n renderBars(group, barData, catScale, valScale, sc.baselinePx, {\n baselineYs,\n borderRadius: series.borderRadius ?? 0,\n color: seriesColor(i, series.color),\n disposalSignal: ctx.disposalSignal,\n horizontal,\n seriesCount: seriesList.length,\n seriesIndex: i,\n stacked,\n transition: config.transition,\n });\n }\n\n legend?.update(seriesList.map((s, i) => ({ color: seriesColor(i, s.color), name: s.name })));\n tooltip?.hide();\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const onMouseMove = (event: MouseEvent) => {\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) {\n tooltip?.hide();\n\n return;\n }\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) {\n tooltip?.hide();\n\n return;\n }\n\n if (isOutsideBars(pos, catIdx, allData, sc, seriesList.length)) {\n tooltip?.hide();\n\n return;\n }\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const stackedTop = stacked ? (stackedTops[seriesIdx]?.[catIdx] ?? point.value) : point.value;\n const valuePx = valScale.map(stackedTop);\n\n const tooltipX = horizontal ? valuePx + d.margin.left : bandCenterPx + d.margin.left;\n const tooltipY = horizontal ? bandCenterPx + d.margin.top : valuePx + d.margin.top;\n\n tooltip?.show(tooltipX, tooltipY, point, seriesList[seriesIdx]);\n config.onHover?.({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\n };\n\n const onMouseLeave = () => {\n tooltip?.hide();\n config.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!config.onClick) return;\n\n const d = ctx.dimensions.value;\n const pos = getMousePosition(ctx.svg, event, d.margin.left, d.margin.top);\n const a = chartArea(d.width, d.height, d.margin);\n\n if (pos.x < 0 || pos.x > a.width || pos.y < 0 || pos.y > a.height) return;\n\n const posBand = horizontal ? pos.y : pos.x;\n const catIdx = findCatIdx(posBand, categories, sc);\n\n if (catIdx === -1) return;\n\n const seriesIdx = findSeriesIdx(pos, catIdx, categories, sc, seriesList.length);\n const point = allData[seriesIdx]?.[catIdx];\n\n if (point) {\n config.onClick({ datum: point, originalEvent: event, series: seriesList[seriesIdx] });\n }\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EAAE,MAAM;IAE/C,IAAI,EAAI,IAAI,KAAK,EAAI,IAAI,EAAE,SAAS,EAAI,IAAI,KAAK,EAAI,IAAI,EAAE,QAAQ;KACjE,GAAS,KAAK;KAEd;IACF;IAEA,IAAM,IAAU,IAAa,EAAI,IAAI,EAAI,GACnC,IAAS,EAAW,GAAS,GAAY,CAAE;IAEjD,IAAI,MAAW,IAAI;KACjB,GAAS,KAAK;KAEd;IACF;IAEA,IAAI,EAAc,GAAK,GAAQ,GAAS,GAAI,EAAW,MAAM,GAAG;KAC9D,GAAS,KAAK;KAEd;IACF;IAEA,IAAM,IAAY,EAAc,GAAK,GAAQ,GAAY,GAAI,EAAW,MAAM,GACxE,IAAQ,EAAQ,EAAU,GAAG;IAEnC,IAAI,GAAO;KACT,IAAM,IAAe,EAAG,WAAW,EAAW,EAAO,GAC/C,IAAa,IAAW,EAAY,EAAU,GAAG,MAAW,EAAM,QAAS,EAAM,OACjF,IAAU,EAAS,IAAI,CAAU,GAEjC,IAAW,IAAa,IAAU,EAAE,OAAO,OAAO,IAAe,EAAE,OAAO,MAC1E,IAAW,IAAa,IAAe,EAAE,OAAO,MAAM,IAAU,EAAE,OAAO;KAG/E,AADA,GAAS,KAAK,GAAU,GAAU,GAAO,EAAW,EAAU,GAC9D,EAAO,UAAU;MAAE,OAAO;MAAO,eAAe;MAAO,QAAQ,EAAW;KAAW,CAAC;IACxF;GACF;EA6B4C;CAC9C,CAAC;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../
|
|
1
|
+
const e=require("../../animation/transition.cjs"),t=require("../../svg/element.cjs");var n=new WeakMap;function r(r,i,a,o,s,c){for(;r.children.length>i.length;){let e=r.lastElementChild;e&&r.removeChild(e)}let l=a.bandwidth(),u=c.stacked?l:l/c.seriesCount,d=c.stacked?0:u*c.seriesIndex,f=c.horizontal??!1,p=[],m=[];for(let e=0;e<i.length;e++){let n=i[e],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[e]:s,g=o.map(n.y),_=r.children[e],v=!_;if(_||(_=t.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),_.style.display=n.present?``:`none`,f){let e=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);t.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(t.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:e},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??e),to:e},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):t.setAttributes(_,{width:e,x:n})}else{let e=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);t.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(t.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:e},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??e),to:e},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):t.setAttributes(_,{height:e,y:n})}}if(c.transition){n.get(r)?.();let t=[];p.length>0&&t.push(e.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&t.push(e.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let e of t)e()})}}exports.renderBars=r;
|
|
2
2
|
//# sourceMappingURL=bar-renderer.cjs.map
|