@vielzeug/prism 3.0.0 → 26.10.0
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/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -5
- package/dist/_dev.js.map +1 -1
- package/dist/animation/easing.cjs +1 -1
- package/dist/animation/easing.cjs.map +1 -1
- package/dist/animation/easing.js +1 -13
- package/dist/animation/easing.js.map +1 -1
- package/dist/animation/motion.cjs +1 -1
- package/dist/animation/motion.cjs.map +1 -1
- package/dist/animation/motion.js +1 -12
- package/dist/animation/motion.js.map +1 -1
- package/dist/animation/transition.cjs +1 -1
- package/dist/animation/transition.cjs.map +1 -1
- package/dist/animation/transition.js +1 -28
- package/dist/animation/transition.js.map +1 -1
- package/dist/animation/tween.cjs +1 -1
- package/dist/animation/tween.cjs.map +1 -1
- package/dist/animation/tween.js +1 -7
- package/dist/animation/tween.js.map +1 -1
- package/dist/axes/axis.cjs +1 -1
- package/dist/axes/axis.cjs.map +1 -1
- package/dist/axes/axis.js +1 -63
- package/dist/axes/axis.js.map +1 -1
- package/dist/axes/grid.cjs +1 -1
- package/dist/axes/grid.cjs.map +1 -1
- package/dist/axes/grid.js +1 -29
- package/dist/axes/grid.js.map +1 -1
- package/dist/axes/scale-utils.cjs +1 -1
- package/dist/axes/scale-utils.cjs.map +1 -1
- package/dist/axes/scale-utils.js +1 -10
- package/dist/axes/scale-utils.js.map +1 -1
- package/dist/charts/area/area-chart.cjs +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.js +1 -57
- 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.js +1 -73
- package/dist/charts/area/area-renderer.js.map +1 -1
- package/dist/charts/bar/bar-chart.cjs +1 -1
- package/dist/charts/bar/bar-chart.cjs.map +1 -1
- package/dist/charts/bar/bar-chart.js +1 -169
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-hit-test.cjs +1 -1
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -1
- package/dist/charts/bar/bar-hit-test.js +1 -29
- package/dist/charts/bar/bar-hit-test.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.js +1 -106
- package/dist/charts/bar/bar-renderer.js.map +1 -1
- package/dist/charts/line/line-chart.cjs +1 -1
- package/dist/charts/line/line-chart.cjs.map +1 -1
- package/dist/charts/line/line-chart.js +1 -58
- 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.js +1 -100
- 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.js +1 -165
- package/dist/charts/pie/pie-chart.js.map +1 -1
- package/dist/charts/pie/pie-renderer.cjs +1 -1
- package/dist/charts/pie/pie-renderer.cjs.map +1 -1
- package/dist/charts/pie/pie-renderer.js +1 -76
- package/dist/charts/pie/pie-renderer.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.js +1 -191
- package/dist/charts/sparkline/sparkline.js.map +1 -1
- package/dist/core/cartesian-model.cjs +1 -1
- package/dist/core/cartesian-model.cjs.map +1 -1
- package/dist/core/cartesian-model.js +1 -30
- package/dist/core/cartesian-model.js.map +1 -1
- package/dist/core/cartesian-scales.cjs +1 -1
- package/dist/core/cartesian-scales.cjs.map +1 -1
- package/dist/core/cartesian-scales.js +1 -37
- 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.js +1 -53
- package/dist/core/chart-base.js.map +1 -1
- package/dist/core/chart-scaffold.cjs +1 -1
- package/dist/core/chart-scaffold.cjs.map +1 -1
- package/dist/core/chart-scaffold.js +1 -89
- package/dist/core/chart-scaffold.js.map +1 -1
- package/dist/core/layout.cjs +1 -1
- package/dist/core/layout.cjs.map +1 -1
- package/dist/core/layout.js +1 -22
- package/dist/core/layout.js.map +1 -1
- package/dist/core/responsive.cjs +1 -1
- package/dist/core/responsive.cjs.map +1 -1
- package/dist/core/responsive.js +1 -19
- package/dist/core/responsive.js.map +1 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +1 -18
- package/dist/devtools.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/index.js +1 -11
- package/dist/interaction/crosshair.cjs +1 -1
- package/dist/interaction/crosshair.cjs.map +1 -1
- package/dist/interaction/crosshair.js +1 -45
- package/dist/interaction/crosshair.js.map +1 -1
- package/dist/interaction/events.cjs +1 -1
- package/dist/interaction/events.cjs.map +1 -1
- package/dist/interaction/events.js +1 -11
- package/dist/interaction/events.js.map +1 -1
- package/dist/interaction/legend.cjs +1 -1
- package/dist/interaction/legend.cjs.map +1 -1
- package/dist/interaction/legend.js +1 -30
- package/dist/interaction/legend.js.map +1 -1
- package/dist/interaction/series-interaction.cjs +1 -1
- package/dist/interaction/series-interaction.cjs.map +1 -1
- package/dist/interaction/series-interaction.js +1 -97
- package/dist/interaction/series-interaction.js.map +1 -1
- package/dist/interaction/tooltip.cjs +1 -1
- package/dist/interaction/tooltip.cjs.map +1 -1
- package/dist/interaction/tooltip.js +1 -63
- 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 +1 -1
- package/dist/scales/band.cjs.map +1 -1
- package/dist/scales/band.js +1 -39
- package/dist/scales/band.js.map +1 -1
- package/dist/scales/linear.cjs +1 -1
- package/dist/scales/linear.cjs.map +1 -1
- package/dist/scales/linear.js +1 -43
- package/dist/scales/linear.js.map +1 -1
- package/dist/scales/time.cjs +1 -1
- package/dist/scales/time.cjs.map +1 -1
- package/dist/scales/time.js +1 -61
- package/dist/scales/time.js.map +1 -1
- package/dist/svg/element.cjs +1 -1
- package/dist/svg/element.cjs.map +1 -1
- package/dist/svg/element.js +1 -22
- package/dist/svg/element.js.map +1 -1
- package/dist/svg/path.cjs +1 -1
- package/dist/svg/path.cjs.map +1 -1
- package/dist/svg/path.js +1 -48
- package/dist/svg/path.js.map +1 -1
- package/dist/svg/text.cjs +1 -1
- package/dist/svg/text.cjs.map +1 -1
- package/dist/svg/text.js +1 -9
- package/dist/svg/text.js.map +1 -1
- package/dist/theme/index.cjs +1 -1
- package/dist/theme/index.cjs.map +1 -1
- package/dist/theme/index.js +1 -19
- package/dist/theme/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { positionAxis, 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, BarSeriesConfig, 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<BarSeriesConfig[]> {\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const sourceData = seriesList.map((series) => 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 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) {\n positionAxis(groups.yAxis, yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, 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 positionAxis(groups.xAxis, xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\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;\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;\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 (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,EAAa,GAAgE;CACpF,OAAO;EACL,YAAY,MAAY,wBAAwB,MAAY;EAC5D,SAAS,MAAY,aAAa,MAAY;CAChD;AACF;AAIA,SAAgB,EAAe,GAAwB,GAAwD;CAC7G,IAAI,IAAa,EAAO;CAExB,OAAO,EACL,GACA,IACC,MAAQ;EACP,IAAM,EAAE,WAAQ,WAAQ,eAAY,GAC9B,IAAO,EAAI,YACX,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM,GACrD,IAAa,EAAW,KAAK,MAAW,EAAO,IAAI,GAC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A,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,IACC,MAAS;EACR,IAAa;CACf,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"bar-chart.js","names":[],"sources":["../../../src/charts/bar/bar-chart.ts"],"sourcesContent":["import { warn } from '../../_dev';\nimport { positionAxis, 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, BarSeriesConfig, 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<BarSeriesConfig[]> {\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const sourceData = seriesList.map((series) => 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 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) {\n positionAxis(groups.yAxis, yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, catScale, yAxis, area.height, 'left');\n }\n\n if (config.xAxis) {\n positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, 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 positionAxis(groups.xAxis, xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, catScale, xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, valScale, config.yAxis, area.height, 'left');\n }\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;\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;\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 (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"swBAgBA,SAAS,aAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5D,QAAS,IAAY,WAAa,IAAY,oBAChD,CACF,CAIA,SAAgB,eAAe,EAAwB,EAAwD,CAC7G,IAAI,EAAa,EAAO,OAExB,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAa,EAAW,IAAK,GAAW,EAAO,IAAI,EACnD,EAAQ,EAAyB,EAAY,CAAU,EACvD,EAAa,EAAM,OACnB,EAAU,EAAM,OAAO,KAAK,CAAE,WAAY,EAAW,IAAK,GAAQ,EAAM,IAAI,CAAG,CAAC,CAAC,EACjF,aAAgB,GAA4D,CAC3E,KAEL,MAAO,CACL,GAAG,EACH,WAAa,GAAkC,CAC7C,IAAM,EAAM,OAAO,CAAK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AEnB,IAAM,EAAY,EAAc,EAAK,EAAQ,EAAY,EAAI,EAAW,MAAM,EACxE,EAAQ,EAAQ,EAAU,GAAG,GAE/B,GACF,EAAO,QAAQ,CAAE,MAAO,EAAO,cAAe,EAAO,OAAQ,EAAW,EAAW,CAAC,CAExF,EAEA,MAAO,CAAE,QAAS,aAAc,WAAY,CAC9C,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function findCatIdx(e,t,n){for(let r=0;r<t.length;r++){let i=n.bandCenter(t[r])-n.bandwidth/2;if(e>=i&&e<i+n.bandwidth)return r}return-1}function findSeriesIdx(e,t,n,r,i){if(r.stacked){if(r.horizontal){for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)>=e.x)return n;return i-1}for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)<=e.y)return n;return i-1}{let a=r.bandwidth/i,o=r.bandCenter(n[t])-r.bandwidth/2,s=r.horizontal?e.y-o:e.x-o,c=Math.floor(s/a);return Math.max(0,Math.min(i-1,c))}}function isOutsideBars(e,t,n,r,i){let a=i-1,o=r.stacked?r.stackedTops[a]?.[t]??0:Math.max(...Array.from({length:i},(e,r)=>n[r]?.[t]?.value??0)),s=r.valueScale.map(o);return r.horizontal?e.x>s:e.y<s}exports.findCatIdx=findCatIdx,exports.findSeriesIdx=findSeriesIdx,exports.isOutsideBars=isOutsideBars;
|
|
2
2
|
//# sourceMappingURL=bar-hit-test.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,
|
|
1
|
+
{"version":3,"file":"bar-hit-test.cjs","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"AAGA,SAAgB,WAAW,EAAa,EAAsB,EAA6B,CACzF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAW,OAAQ,IAAK,CAE1C,IAAM,EADS,EAAG,WAAW,EAAW,EAC1B,EAAS,EAAG,UAAY,EAEtC,GAAI,GAAO,GAAS,EAAM,EAAQ,EAAG,UAAW,OAAO,CACzD,CAEA,MAAO,EACT,CAEA,SAAgB,cACd,EACA,EACA,EACA,EACA,EACQ,CACR,GAAI,EAAG,QAAS,CACd,GAAI,EAAG,WAAY,CACjB,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFe,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE7D,GAAU,EAAI,EAAG,OAAO,EAG9B,OAAO,EAAc,CACvB,CACE,IAAK,IAAI,EAAK,EAAG,EAAK,EAAa,IAGjC,GAFa,EAAG,WAAW,IAAI,EAAG,YAAY,EAAG,GAAG,IAAW,CAE3D,GAAQ,EAAI,EAAG,OAAO,EAG5B,OAAO,EAAc,CAEzB,CAAO,CACL,IAAM,EAAU,EAAG,UAAY,EACzB,EAAY,EAAG,WAAW,EAAW,EAAO,EAAI,EAAG,UAAY,EAC/D,EAAS,EAAG,WAAa,EAAI,EAAI,EAAY,EAAI,EAAI,EACrD,EAAS,KAAK,MAAM,EAAS,CAAO,EAE1C,OAAO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAc,EAAG,CAAM,CAAC,CACtD,CACF,CAEA,SAAgB,cACd,EACA,EACA,EACA,EACA,EACS,CACT,IAAM,EAAS,EAAc,EACvB,EAAS,EAAG,QACb,EAAG,YAAY,EAAO,GAAG,IAAW,EACrC,KAAK,IAAI,GAAG,MAAM,KAAK,CAAE,OAAQ,CAAY,GAAI,EAAG,IAAO,EAAQ,EAAG,GAAG,EAAO,EAAE,OAAS,CAAC,CAAC,EAC3F,EAAQ,EAAG,WAAW,IAAI,CAAM,EAEtC,OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
|
|
@@ -1,30 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e, t, n) {
|
|
3
|
-
for (let r = 0; r < t.length; r++) {
|
|
4
|
-
let i = n.bandCenter(t[r]) - n.bandwidth / 2;
|
|
5
|
-
if (e >= i && e < i + n.bandwidth) return r;
|
|
6
|
-
}
|
|
7
|
-
return -1;
|
|
8
|
-
}
|
|
9
|
-
function t(e, t, n, r, i) {
|
|
10
|
-
if (r.stacked) {
|
|
11
|
-
if (r.horizontal) {
|
|
12
|
-
for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) >= e.x) return n;
|
|
13
|
-
return i - 1;
|
|
14
|
-
}
|
|
15
|
-
for (let n = 0; n < i; n++) if (r.valueScale.map(r.stackedTops[n]?.[t] ?? 0) <= e.y) return n;
|
|
16
|
-
return i - 1;
|
|
17
|
-
}
|
|
18
|
-
{
|
|
19
|
-
let a = r.bandwidth / i, o = r.bandCenter(n[t]) - r.bandwidth / 2, s = r.horizontal ? e.y - o : e.x - o, c = Math.floor(s / a);
|
|
20
|
-
return Math.max(0, Math.min(i - 1, c));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function n(e, t, n, r, i) {
|
|
24
|
-
let a = i - 1, o = r.stacked ? r.stackedTops[a]?.[t] ?? 0 : Math.max(...Array.from({ length: i }, (e, r) => n[r]?.[t]?.value ?? 0)), s = r.valueScale.map(o);
|
|
25
|
-
return r.horizontal ? e.x > s : e.y < s;
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { e as findCatIdx, t as findSeriesIdx, n as isOutsideBars };
|
|
29
|
-
|
|
1
|
+
function findCatIdx(e,t,n){for(let r=0;r<t.length;r++){let i=n.bandCenter(t[r])-n.bandwidth/2;if(e>=i&&e<i+n.bandwidth)return r}return-1}function findSeriesIdx(e,t,n,r,i){if(r.stacked){if(r.horizontal){for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)>=e.x)return n;return i-1}for(let n=0;n<i;n++)if(r.valueScale.map(r.stackedTops[n]?.[t]??0)<=e.y)return n;return i-1}{let a=r.bandwidth/i,o=r.bandCenter(n[t])-r.bandwidth/2,s=r.horizontal?e.y-o:e.x-o,c=Math.floor(s/a);return Math.max(0,Math.min(i-1,c))}}function isOutsideBars(e,t,n,r,i){let a=i-1,o=r.stacked?r.stackedTops[a]?.[t]??0:Math.max(...Array.from({length:i},(e,r)=>n[r]?.[t]?.value??0)),s=r.valueScale.map(o);return r.horizontal?e.x>s:e.y<s}export{findCatIdx,findSeriesIdx,isOutsideBars};
|
|
30
2
|
//# sourceMappingURL=bar-hit-test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal ? pos.x > maxPx : pos.y < maxPx;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bar-hit-test.js","names":[],"sources":["../../../src/charts/bar/bar-hit-test.ts"],"sourcesContent":["import type { Datum } from '../../types';\nimport type { BarScaleContext } from './bar-scale-context';\n\nexport function findCatIdx(pos: number, categories: string[], sc: BarScaleContext): number {\n for (let i = 0; i < categories.length; i++) {\n const center = sc.bandCenter(categories[i]);\n const start = center - sc.bandwidth / 2;\n\n if (pos >= start && pos < start + sc.bandwidth) return i;\n }\n\n return -1;\n}\n\nexport function findSeriesIdx(\n pos: { x: number; y: number },\n catIdx: number,\n categories: string[],\n sc: BarScaleContext,\n seriesCount: number,\n): number {\n if (sc.stacked) {\n if (sc.horizontal) {\n for (let si = 0; si < seriesCount; si++) {\n const rightX = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (rightX >= pos.x) return si;\n }\n\n return seriesCount - 1;\n } else {\n for (let si = 0; si < seriesCount; si++) {\n const topY = sc.valueScale.map(sc.stackedTops[si]?.[catIdx] ?? 0);\n\n if (topY <= pos.y) return si;\n }\n\n return seriesCount - 1;\n }\n } else {\n const subSize = sc.bandwidth / seriesCount;\n const bandStart = sc.bandCenter(categories[catIdx]) - sc.bandwidth / 2;\n const offset = sc.horizontal ? pos.y - bandStart : pos.x - bandStart;\n const subIdx = Math.floor(offset / subSize);\n\n return Math.max(0, Math.min(seriesCount - 1, subIdx));\n }\n}\n\nexport function isOutsideBars(\n pos: { x: number; y: number },\n catIdx: number,\n allData: (Datum | undefined)[][],\n sc: BarScaleContext,\n seriesCount: number,\n): boolean {\n const lastSi = seriesCount - 1;\n const maxVal = sc.stacked\n ? (sc.stackedTops[lastSi]?.[catIdx] ?? 0)\n : Math.max(...Array.from({ length: seriesCount }, (_, si) => allData[si]?.[catIdx]?.value ?? 0));\n const maxPx = sc.valueScale.map(maxVal);\n\n return sc.horizontal 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OAAO,EAAG,WAAa,EAAI,EAAI,EAAQ,EAAI,EAAI,CACjD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../animation/transition.cjs");var n=new WeakMap;function renderBars(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 t=0;t<i.length;t++){let n=i[t],l=a.map(n.key)+d,h=c.baselineYs?c.baselineYs[t]:s,g=o.map(n.y),_=r.children[t],v=!_;if(_||(_=e.createSvgElement(`rect`,{class:`prism-bar`}),r.appendChild(_)),_.style.display=n.present?``:`none`,f){let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,height:Math.max(0,u-1),rx:c.borderRadius,ry:c.borderRadius,y:l}),c.transition?v?(e.setAttributes(_,{width:0,x:h}),p.push({attrs:{width:{from:0,to:t},x:{from:h,to:n}},el:_})):m.push({attrs:{width:{from:Number(_.getAttribute(`width`)??t),to:t},x:{from:Number(_.getAttribute(`x`)??n),to:n}},el:_}):e.setAttributes(_,{width:t,x:n})}else{let t=Math.max(0,Math.abs(h-g)),n=Math.min(g,h);e.setAttributes(_,{fill:c.color,rx:c.borderRadius,ry:c.borderRadius,width:Math.max(0,u-1),x:l}),c.transition?v?(e.setAttributes(_,{height:0,y:h}),p.push({attrs:{height:{from:0,to:t},y:{from:h,to:n}},el:_})):m.push({attrs:{height:{from:Number(_.getAttribute(`height`)??t),to:t},y:{from:Number(_.getAttribute(`y`)??n),to:n}},el:_}):e.setAttributes(_,{height:t,y:n})}}if(c.transition){n.get(r)?.();let e=[];p.length>0&&e.push(t.animate(p,c.transition,void 0,c.disposalSignal)),m.length>0&&e.push(t.animate(m,{...c.transition,stagger:0},void 0,c.disposalSignal)),n.set(r,()=>{for(let t of e)t()})}}exports.renderBars=renderBars;
|
|
2
2
|
//# sourceMappingURL=bar-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.cjs","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"qFAkBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,
|
|
1
|
+
{"version":3,"file":"bar-renderer.cjs","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels)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AY,IAAA,GAAW,EAAQ,cAAc,CAAC,EAGvF,EAAc,OAAS,GACzB,EAAQ,KAAK,EAAA,QAAQ,EAAe,CAAE,GAAG,EAAQ,WAAY,QAAS,CAAE,EAAG,IAAA,GAAW,EAAQ,cAAc,CAAC,EAG/G,EAAoB,IAAI,MAAc,CACpC,IAAK,IAAM,KAAU,EAAS,EAAO,CACvC,CAAC,CACH,CACF"}
|
|
@@ -1,107 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { animate as n } from "../../animation/transition.js";
|
|
3
|
-
//#region src/charts/bar/bar-renderer.ts
|
|
4
|
-
var r = /* @__PURE__ */ new WeakMap();
|
|
5
|
-
function i(i, a, o, s, c, l) {
|
|
6
|
-
for (; i.children.length > a.length;) {
|
|
7
|
-
let e = i.lastElementChild;
|
|
8
|
-
e && i.removeChild(e);
|
|
9
|
-
}
|
|
10
|
-
let u = o.bandwidth(), d = l.stacked ? u : u / l.seriesCount, f = l.stacked ? 0 : d * l.seriesIndex, p = l.horizontal ?? !1, m = [], h = [];
|
|
11
|
-
for (let n = 0; n < a.length; n++) {
|
|
12
|
-
let r = a[n], u = o.map(r.key) + f, g = l.baselineYs ? l.baselineYs[n] : c, _ = s.map(r.y), v = i.children[n], y = !v;
|
|
13
|
-
if (v || (v = e("rect", { class: "prism-bar" }), i.appendChild(v)), v.style.display = r.present ? "" : "none", p) {
|
|
14
|
-
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
15
|
-
t(v, {
|
|
16
|
-
fill: l.color,
|
|
17
|
-
height: Math.max(0, d - 1),
|
|
18
|
-
rx: l.borderRadius,
|
|
19
|
-
ry: l.borderRadius,
|
|
20
|
-
y: u
|
|
21
|
-
}), l.transition ? y ? (t(v, {
|
|
22
|
-
width: 0,
|
|
23
|
-
x: g
|
|
24
|
-
}), m.push({
|
|
25
|
-
attrs: {
|
|
26
|
-
width: {
|
|
27
|
-
from: 0,
|
|
28
|
-
to: e
|
|
29
|
-
},
|
|
30
|
-
x: {
|
|
31
|
-
from: g,
|
|
32
|
-
to: n
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
el: v
|
|
36
|
-
})) : h.push({
|
|
37
|
-
attrs: {
|
|
38
|
-
width: {
|
|
39
|
-
from: Number(v.getAttribute("width") ?? e),
|
|
40
|
-
to: e
|
|
41
|
-
},
|
|
42
|
-
x: {
|
|
43
|
-
from: Number(v.getAttribute("x") ?? n),
|
|
44
|
-
to: n
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
el: v
|
|
48
|
-
}) : t(v, {
|
|
49
|
-
width: e,
|
|
50
|
-
x: n
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
let e = Math.max(0, Math.abs(g - _)), n = Math.min(_, g);
|
|
54
|
-
t(v, {
|
|
55
|
-
fill: l.color,
|
|
56
|
-
rx: l.borderRadius,
|
|
57
|
-
ry: l.borderRadius,
|
|
58
|
-
width: Math.max(0, d - 1),
|
|
59
|
-
x: u
|
|
60
|
-
}), l.transition ? y ? (t(v, {
|
|
61
|
-
height: 0,
|
|
62
|
-
y: g
|
|
63
|
-
}), m.push({
|
|
64
|
-
attrs: {
|
|
65
|
-
height: {
|
|
66
|
-
from: 0,
|
|
67
|
-
to: e
|
|
68
|
-
},
|
|
69
|
-
y: {
|
|
70
|
-
from: g,
|
|
71
|
-
to: n
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
el: v
|
|
75
|
-
})) : h.push({
|
|
76
|
-
attrs: {
|
|
77
|
-
height: {
|
|
78
|
-
from: Number(v.getAttribute("height") ?? e),
|
|
79
|
-
to: e
|
|
80
|
-
},
|
|
81
|
-
y: {
|
|
82
|
-
from: Number(v.getAttribute("y") ?? n),
|
|
83
|
-
to: n
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
el: v
|
|
87
|
-
}) : t(v, {
|
|
88
|
-
height: e,
|
|
89
|
-
y: n
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (l.transition) {
|
|
94
|
-
r.get(i)?.();
|
|
95
|
-
let e = [];
|
|
96
|
-
m.length > 0 && e.push(n(m, l.transition, void 0, l.disposalSignal)), h.length > 0 && e.push(n(h, {
|
|
97
|
-
...l.transition,
|
|
98
|
-
stagger: 0
|
|
99
|
-
}, void 0, l.disposalSignal)), r.set(i, () => {
|
|
100
|
-
for (let t of e) t();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
export { i as renderBars };
|
|
106
|
-
|
|
1
|
+
import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{animate as n}from"../../animation/transition.js";var r=new WeakMap;function renderBars(i,a,o,s,c,l){for(;i.children.length>a.length;){let e=i.lastElementChild;e&&i.removeChild(e)}let u=o.bandwidth(),d=l.stacked?u:u/l.seriesCount,f=l.stacked?0:d*l.seriesIndex,p=l.horizontal??!1,m=[],h=[];for(let n=0;n<a.length;n++){let r=a[n],u=o.map(r.key)+f,g=l.baselineYs?l.baselineYs[n]:c,_=s.map(r.y),v=i.children[n],y=!v;if(v||(v=e(`rect`,{class:`prism-bar`}),i.appendChild(v)),v.style.display=r.present?``:`none`,p){let e=Math.max(0,Math.abs(g-_)),n=Math.min(_,g);t(v,{fill:l.color,height:Math.max(0,d-1),rx:l.borderRadius,ry:l.borderRadius,y:u}),l.transition?y?(t(v,{width:0,x:g}),m.push({attrs:{width:{from:0,to:e},x:{from:g,to:n}},el:v})):h.push({attrs:{width:{from:Number(v.getAttribute(`width`)??e),to:e},x:{from:Number(v.getAttribute(`x`)??n),to:n}},el:v}):t(v,{width:e,x:n})}else{let e=Math.max(0,Math.abs(g-_)),n=Math.min(_,g);t(v,{fill:l.color,rx:l.borderRadius,ry:l.borderRadius,width:Math.max(0,d-1),x:u}),l.transition?y?(t(v,{height:0,y:g}),m.push({attrs:{height:{from:0,to:e},y:{from:g,to:n}},el:v})):h.push({attrs:{height:{from:Number(v.getAttribute(`height`)??e),to:e},y:{from:Number(v.getAttribute(`y`)??n),to:n}},el:v}):t(v,{height:e,y:n})}}if(l.transition){r.get(i)?.();let e=[];m.length>0&&e.push(n(m,l.transition,void 0,l.disposalSignal)),h.length>0&&e.push(n(h,{...l.transition,stagger:0},void 0,l.disposalSignal)),r.set(i,()=>{for(let t of e)t()})}}export{renderBars};
|
|
107
2
|
//# sourceMappingURL=bar-renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.js","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bar-renderer.js","names":[],"sources":["../../../src/charts/bar/bar-renderer.ts"],"sourcesContent":["import type { AnimationTarget } from '../../animation/transition';\nimport { animate } from '../../animation/transition';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport type { BandScale, Scale, TransitionConfig } from '../../types';\n\nexport interface BarRenderOptions {\n baselineYs?: number[];\n borderRadius: number;\n color: string;\n /** Aborted when the owning chart is disposed — stops in-flight transitions from rescheduling. */\n disposalSignal?: AbortSignal;\n horizontal?: boolean;\n seriesCount: number;\n seriesIndex: number;\n stacked?: boolean;\n transition?: TransitionConfig;\n}\n\nconst activeBarAnimations = new WeakMap<SVGGElement, () => void>();\n\nexport function renderBars(\n parent: SVGGElement,\n data: { base: number; key: string; present: boolean; y: number }[],\n xScale: BandScale,\n yScale: Scale<number>,\n baselineY: number,\n options: BarRenderOptions,\n): void {\n while (parent.children.length > data.length) {\n const last = parent.lastElementChild;\n\n if (last) parent.removeChild(last);\n }\n\n const bandwidth = xScale.bandwidth();\n const barBand = options.stacked ? bandwidth : bandwidth / options.seriesCount;\n const offset = options.stacked ? 0 : barBand * options.seriesIndex;\n const horizontal = options.horizontal ?? false;\n\n const enterTargets: AnimationTarget[] = [];\n const updateTargets: AnimationTarget[] = [];\n\n for (let i = 0; i < data.length; i++) {\n const d = data[i];\n const bandPos = xScale.map(d.key) + offset;\n const barBaselineY = options.baselineYs ? options.baselineYs[i] : baselineY;\n const valuePx = yScale.map(d.y);\n\n let rect = parent.children[i] as SVGRectElement | undefined;\n\n const isNew = !rect;\n\n if (!rect) {\n rect = createSvgElement('rect', { class: 'prism-bar' });\n parent.appendChild(rect);\n }\n\n rect.style.display = d.present ? '' : 'none';\n\n if (horizontal) {\n // Horizontal: category on Y axis, value on X axis\n // baselineY here is actually the baseline X (yScale.map(0) in value-space mapped to screen X)\n const finalWidth = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalX = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n height: Math.max(0, barBand - 1),\n rx: options.borderRadius,\n ry: options.borderRadius,\n y: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { width: 0, x: barBaselineY });\n enterTargets.push({\n attrs: { width: { from: 0, to: finalWidth }, x: { from: barBaselineY, to: finalX } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n width: { from: Number(rect.getAttribute('width') ?? finalWidth), to: finalWidth },\n x: { from: Number(rect.getAttribute('x') ?? finalX), to: finalX },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { width: finalWidth, x: finalX });\n }\n } else {\n // Vertical (default)\n const finalHeight = Math.max(0, Math.abs(barBaselineY - valuePx));\n const finalY = Math.min(valuePx, barBaselineY);\n\n setAttributes(rect, {\n fill: options.color,\n rx: options.borderRadius,\n ry: options.borderRadius,\n width: Math.max(0, barBand - 1),\n x: bandPos,\n });\n\n if (options.transition) {\n if (isNew) {\n setAttributes(rect, { height: 0, y: barBaselineY });\n enterTargets.push({\n attrs: { height: { from: 0, to: finalHeight }, y: { from: barBaselineY, to: finalY } },\n el: rect,\n });\n } else {\n updateTargets.push({\n attrs: {\n height: { from: Number(rect.getAttribute('height') ?? finalHeight), to: finalHeight },\n y: { from: Number(rect.getAttribute('y') ?? finalY), to: finalY },\n },\n el: rect,\n });\n }\n } else {\n setAttributes(rect, { height: finalHeight, y: finalY });\n }\n }\n }\n\n if (options.transition) {\n activeBarAnimations.get(parent)?.();\n\n const cancels: (() => void)[] = [];\n\n if (enterTargets.length > 0) {\n cancels.push(animate(enterTargets, options.transition, undefined, options.disposalSignal));\n }\n\n if (updateTargets.length > 0) {\n cancels.push(animate(updateTargets, { ...options.transition, stagger: 0 }, undefined, options.disposalSignal));\n }\n\n activeBarAnimations.set(parent, () => {\n for (const cancel of cancels) cancel();\n });\n }\n}\n"],"mappings":"mIAkBA,IAAM,EAAsB,IAAI,QAEhC,SAAgB,WACd,EACA,EACA,EACA,EACA,EACA,EACM,CACN,KAAO,EAAO,SAAS,OAAS,EAAK,QAAQ,CAC3C,IAAM,EAAO,EAAO,iBAEhB,GAAM,EAAO,YAAY,CAAI,CACnC,CAEA,IAAM,EAAY,EAAO,UAAU,EAC7B,EAAU,EAAQ,QAAU,EAAY,EAAY,EAAQ,YAC5D,EAAS,EAAQ,QAAU,EAAI,EAAU,EAAQ,YACjD,EAAa,EAAQ,YAAc,GAEnC,EAAkC,CAAC,EACnC,EAAmC,CAAC,EAE1C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,CACpC,IAAM,EAAI,EAAK,GACT,EAAU,EAAO,IAAI,EAAE,GAAG,EAAI,EAC9B,EAAe,EAAQ,WAAa,EAAQ,WAAW,GAAK,EAC5D,EAAU,EAAO,IAAI,EAAE,CAAC,EAE1B,EAAO,EAAO,SAAS,GAErB,EAAQ,CAAC,EASf,GAPK,IACH,EAAO,EAAiB,OAAQ,CAAE,MAAO,WAAY,CAAC,EACtD,EAAO,YAAY,CAAI,GAGzB,EAAK,MAAM,QAAU,EAAE,QAAU,GAAK,OAElC,EAAY,CAGd,IAAM,EAAa,KAAK,IAAI,EAAG,KAAK,IAAI,EAAe,CAAO,CAAC,EACzD,EAAS,KAAK,IAAI,EAAS,CAAY,EAE7C,EAAc,EAAM,CAClB,KAAM,EAAQ,MACd,OAAQ,KAAK,IAAI,EAAG,EAAU,CAAC,EAC/B,GAAI,EAAQ,aACZ,GAAI,EAAQ,aACZ,EAAG,CACL,CAAC,EAEG,EAAQ,WACN,GACF,EAAc,EAAM,CAAE,MAAO,EAAG,EAAG,CAAa,CAAC,EACjD,EAAa,KAAK,CAChB,MAA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EAAa,OAAS,GACxB,EAAQ,KAAK,EAAQ,EAAc,EAAQ,WAAY,IAAA,GAAW,EAAQ,cAAc,CAAC,EAGvF,EAAc,OAAS,GACzB,EAAQ,KAAK,EAAQ,EAAe,CAAE,GAAG,EAAQ,WAAY,QAAS,CAAE,EAAG,IAAA,GAAW,EAAQ,cAAc,CAAC,EAG/G,EAAoB,IAAI,MAAc,CACpC,IAAK,IAAM,KAAU,EAAS,EAAO,CACvC,CAAC,CACH,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../interaction/crosshair.cjs"),s=require("../../interaction/series-interaction.cjs"),c=require("../../theme/index.cjs"),l=require("./line-renderer.cjs");function
|
|
1
|
+
const e=require("../../svg/element.cjs"),t=require("../../axes/axis.cjs"),n=require("../../axes/grid.cjs"),r=require("../../core/cartesian-scales.cjs"),i=require("../../core/layout.cjs"),a=require("../../core/chart-scaffold.cjs"),o=require("../../interaction/crosshair.cjs"),s=require("../../interaction/series-interaction.cjs"),c=require("../../theme/index.cjs"),l=require("./line-renderer.cjs");function createLineChart(u,d){let f=null,p=d.series;return a.createChartScaffold(u,d,u=>{let{groups:m,legend:h,tooltip:g}=u,_=u.dimensions,v=i.chartArea(_.width,_.height,_.margin),y=p.map(e=>e.data),b=y.flat().map(e=>e.key),x=y.flat().map(e=>e.value);if(b.length===0){a.clearCartesianDom(m,h,g,f);return}d.crosshair&&!f&&(f=o.createCrosshair(u.chartArea,d.crosshair));let S=r.buildXScale(b,v.width),C=r.buildYScale(x,v.height);for(d.yAxis?.grid&&n.renderGrid(m.grid,C,d.yAxis.grid,v.width,`horizontal`,t.resolveTickCount(d.yAxis,v.height,`left`)),d.xAxis?.grid&&n.renderGrid(m.grid,S,d.xAxis.grid,v.height,`vertical`,t.resolveTickCount(d.xAxis,v.width,`bottom`)),d.xAxis&&(t.positionAxis(m.xAxis,d.xAxis.position??`bottom`,v.width,v.height),t.renderAxis(m.xAxis,S,d.xAxis,v.width,`bottom`)),d.yAxis&&(t.positionAxis(m.yAxis,d.yAxis.position??`left`,v.width,v.height),t.renderAxis(m.yAxis,C,d.yAxis,v.height,`left`));m.series.children.length>p.length;)m.series.removeChild(m.series.lastChild);let w=[];for(let t=0;t<p.length;t++){let n=p[t],r=m.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-line-series`}),m.series.appendChild(r));let i=l.computePoints(y[t],S,C);w.push(i),l.renderLine(r,i,{color:c.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:u.disposalSignal,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth??2,transition:d.transition})}return h?.update(p.map((e,t)=>({color:c.seriesColor(t,e.color),name:e.name}))),g?.hide(),s.createSeriesInteraction({crosshair:f,dims:()=>u.dimensions,getData:()=>y,getPoints:()=>w,getSeriesList:()=>p,onClick:d.onClick,onHover:d.onHover,svg:u.svg,tooltip:g})},e=>{p=e})}exports.createLineChart=createLineChart;
|
|
2
2
|
//# sourceMappingURL=line-chart.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, 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 { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\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, area.width);\n const yScale = buildYScale(allY, area.height);\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 positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\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-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\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,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"6YAaA,SAAgB,
|
|
1
|
+
{"version":3,"file":"line-chart.cjs","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, 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 { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\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, area.width);\n const yScale = buildYScale(allY, area.height);\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 positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\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-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\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,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.sv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AAK,MAAM,EACnF,EAAA,WAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,OAAQ,MAAM,GAG7D,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,cAAc,EAAQ,GAAI,EAAQ,CAAM,EAEvD,EAAU,KAAK,CAAM,EAErB,EAAA,WAAW,EAAO,EAAQ,CACxB,MAAO,EAAA,YAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,YAAc,GACjC,YAAa,EAAO,aAAe,EACnC,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,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { positionAxis as t, renderAxis as n, resolveTickCount as r } from "../../axes/axis.js";
|
|
3
|
-
import { renderGrid as i } from "../../axes/grid.js";
|
|
4
|
-
import { buildXScale as a, buildYScale as o } from "../../core/cartesian-scales.js";
|
|
5
|
-
import { chartArea as s } from "../../core/layout.js";
|
|
6
|
-
import { clearCartesianDom as c, createChartScaffold as l } from "../../core/chart-scaffold.js";
|
|
7
|
-
import { createCrosshair as u } from "../../interaction/crosshair.js";
|
|
8
|
-
import { createSeriesInteraction as d } from "../../interaction/series-interaction.js";
|
|
9
|
-
import { seriesColor as f } from "../../theme/index.js";
|
|
10
|
-
import { computePoints as p, renderLine as m } from "./line-renderer.js";
|
|
11
|
-
//#region src/charts/line/line-chart.ts
|
|
12
|
-
function h(h, g) {
|
|
13
|
-
let _ = null, v = g.series;
|
|
14
|
-
return l(h, g, (l) => {
|
|
15
|
-
let { groups: h, legend: y, tooltip: b } = l, x = l.dimensions, S = s(x.width, x.height, x.margin), C = v.map((e) => e.data), w = C.flat().map((e) => e.key), T = C.flat().map((e) => e.value);
|
|
16
|
-
if (w.length === 0) {
|
|
17
|
-
c(h, y, b, _);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
g.crosshair && !_ && (_ = u(l.chartArea, g.crosshair));
|
|
21
|
-
let E = a(w, S.width), D = o(T, S.height);
|
|
22
|
-
for (g.yAxis?.grid && i(h.grid, D, g.yAxis.grid, S.width, "horizontal", r(g.yAxis, S.height, "left")), g.xAxis?.grid && i(h.grid, E, g.xAxis.grid, S.height, "vertical", r(g.xAxis, S.width, "bottom")), g.xAxis && (t(h.xAxis, g.xAxis.position ?? "bottom", S.width, S.height), n(h.xAxis, E, g.xAxis, S.width, "bottom")), g.yAxis && (t(h.yAxis, g.yAxis.position ?? "left", S.width, S.height), n(h.yAxis, D, g.yAxis, S.height, "left")); h.series.children.length > v.length;) h.series.removeChild(h.series.lastChild);
|
|
23
|
-
let O = [];
|
|
24
|
-
for (let t = 0; t < v.length; t++) {
|
|
25
|
-
let n = v[t], r = h.series.children[t];
|
|
26
|
-
r || (r = e("g", { class: "prism-line-series" }), h.series.appendChild(r));
|
|
27
|
-
let i = p(C[t], E, D);
|
|
28
|
-
O.push(i), m(r, i, {
|
|
29
|
-
color: f(t, n.color),
|
|
30
|
-
curve: n.curve ?? "linear",
|
|
31
|
-
disposalSignal: l.disposalSignal,
|
|
32
|
-
pointRadius: n.pointRadius ?? 3,
|
|
33
|
-
showPoints: n.showPoints ?? !1,
|
|
34
|
-
strokeWidth: n.strokeWidth ?? 2,
|
|
35
|
-
transition: g.transition
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return y?.update(v.map((e, t) => ({
|
|
39
|
-
color: f(t, e.color),
|
|
40
|
-
name: e.name
|
|
41
|
-
}))), b?.hide(), d({
|
|
42
|
-
crosshair: _,
|
|
43
|
-
dims: () => l.dimensions,
|
|
44
|
-
getData: () => C,
|
|
45
|
-
getPoints: () => O,
|
|
46
|
-
getSeriesList: () => v,
|
|
47
|
-
onClick: g.onClick,
|
|
48
|
-
onHover: g.onHover,
|
|
49
|
-
svg: l.svg,
|
|
50
|
-
tooltip: b
|
|
51
|
-
});
|
|
52
|
-
}, (e) => {
|
|
53
|
-
v = e;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { h as createLineChart };
|
|
58
|
-
|
|
1
|
+
import{createSvgElement as e}from"../../svg/element.js";import{positionAxis as t,renderAxis as n,resolveTickCount as r}from"../../axes/axis.js";import{renderGrid as i}from"../../axes/grid.js";import{buildXScale as a,buildYScale as o}from"../../core/cartesian-scales.js";import{chartArea as s}from"../../core/layout.js";import{clearCartesianDom as c,createChartScaffold as l}from"../../core/chart-scaffold.js";import{createCrosshair as u}from"../../interaction/crosshair.js";import{createSeriesInteraction as d}from"../../interaction/series-interaction.js";import{seriesColor as f}from"../../theme/index.js";import{computePoints as p,renderLine as m}from"./line-renderer.js";function createLineChart(h,g){let _=null,v=g.series;return l(h,g,l=>{let{groups:h,legend:y,tooltip:b}=l,x=l.dimensions,S=s(x.width,x.height,x.margin),C=v.map(e=>e.data),w=C.flat().map(e=>e.key),T=C.flat().map(e=>e.value);if(w.length===0){c(h,y,b,_);return}g.crosshair&&!_&&(_=u(l.chartArea,g.crosshair));let E=a(w,S.width),D=o(T,S.height);for(g.yAxis?.grid&&i(h.grid,D,g.yAxis.grid,S.width,`horizontal`,r(g.yAxis,S.height,`left`)),g.xAxis?.grid&&i(h.grid,E,g.xAxis.grid,S.height,`vertical`,r(g.xAxis,S.width,`bottom`)),g.xAxis&&(t(h.xAxis,g.xAxis.position??`bottom`,S.width,S.height),n(h.xAxis,E,g.xAxis,S.width,`bottom`)),g.yAxis&&(t(h.yAxis,g.yAxis.position??`left`,S.width,S.height),n(h.yAxis,D,g.yAxis,S.height,`left`));h.series.children.length>v.length;)h.series.removeChild(h.series.lastChild);let O=[];for(let t=0;t<v.length;t++){let n=v[t],r=h.series.children[t];r||(r=e(`g`,{class:`prism-line-series`}),h.series.appendChild(r));let i=p(C[t],E,D);O.push(i),m(r,i,{color:f(t,n.color),curve:n.curve??`linear`,disposalSignal:l.disposalSignal,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth??2,transition:g.transition})}return y?.update(v.map((e,t)=>({color:f(t,e.color),name:e.name}))),b?.hide(),d({crosshair:_,dims:()=>l.dimensions,getData:()=>C,getPoints:()=>O,getSeriesList:()=>v,onClick:g.onClick,onHover:g.onHover,svg:l.svg,tooltip:b})},e=>{v=e})}export{createLineChart};
|
|
59
2
|
//# sourceMappingURL=line-chart.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.js","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, 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 { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\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, area.width);\n const yScale = buildYScale(allY, area.height);\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 positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\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-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\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,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"line-chart.js","names":[],"sources":["../../../src/charts/line/line-chart.ts"],"sourcesContent":["import { positionAxis, 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 { ChartHandle, LineChartConfig, LineSeriesConfig } from '../../types';\nimport { computePoints, renderLine } from './line-renderer';\n\nexport function createLineChart(container: HTMLElement, config: LineChartConfig): ChartHandle<LineSeriesConfig[]> {\n let crosshair: ReturnType<typeof createCrosshair> | null = null;\n let seriesList = config.series;\n\n return createChartScaffold(\n container,\n config,\n (ctx) => {\n const { groups, legend, tooltip } = ctx;\n const dims = ctx.dimensions;\n const area = chartArea(dims.width, dims.height, dims.margin);\n const allData = seriesList.map((series) => series.data);\n const allX = allData.flat().map((datum) => datum.key);\n const allY = allData.flat().map((d) => d.value);\n\n if (allX.length === 0) {\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, area.width);\n const yScale = buildYScale(allY, area.height);\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 positionAxis(groups.xAxis, config.xAxis.position ?? 'bottom', area.width, area.height);\n renderAxis(groups.xAxis, xScale, config.xAxis, area.width, 'bottom');\n }\n\n if (config.yAxis) {\n positionAxis(groups.yAxis, config.yAxis.position ?? 'left', area.width, area.height);\n renderAxis(groups.yAxis, yScale, config.yAxis, area.height, 'left');\n }\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-line-series' });\n groups.series.appendChild(group);\n }\n\n const points = computePoints(allData[i], xScale, yScale);\n\n allPoints.push(points);\n\n renderLine(group, points, {\n color: seriesColor(i, series.color),\n curve: series.curve ?? 'linear',\n disposalSignal: ctx.disposalSignal,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth ?? 2,\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,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n onClick: config.onClick,\n onHover: config.onHover,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"kqBAaA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAAa,EAAO,OAExB,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAO,EAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAM,EAAE,KAAK,EAE9C,GAAI,EAAK,SAAW,EAAG,CACrB,EAAkB,EAAQ,EAAQ,EAAS,CAAS,EAEpD,MACF,CAEI,EAAO,WAAa,CAAC,IACvB,EAAY,EAAgB,EAAI,UAAW,EAAO,SAAS,GAG7D,IAAM,EAAS,EAAY,EAAM,EAAK,KAAK,EACrC,EAAS,EAAY,EAAM,EAAK,MAAM,EAkC5C,IAhCI,EAAO,OAAO,MAChB,EACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,MACL,aACA,EAAiB,EAAO,MAAO,EAAK,OAAQ,MAAM,CACpD,EAGE,EAAO,OAAO,MAChB,EACE,EAAO,KACP,EACA,EAAO,MAAM,KACb,EAAK,OACL,WACA,EAAiB,EAAO,MAAO,EAAK,MAAO,QAAQ,CACrD,EAGE,EAAO,QACT,EAAa,EAAO,MAAO,EAAO,MAAM,UAAY,SAAU,EAAK,MAAO,EAAK,MAAM,EACrF,EAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,MAAO,QAAQ,GAGjE,EAAO,QACT,EAAa,EAAO,MAAO,EAAO,MAAM,UAAY,OAAQ,EAAK,MAAO,EAAK,MAAM,EACnF,EAAW,EAAO,MAAO,EAAQ,EAAO,MAAO,EAAK,OAAQ,MAAM,GAG7D,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,EAAiB,IAAK,CAAE,MAAO,mBAAoB,CAAC,EAC5D,EAAO,OAAO,YAAY,CAAK,GAGjC,IAAM,EAAS,EAAc,EAAQ,GAAI,EAAQ,CAAM,EAEvD,EAAU,KAAK,CAAM,EAErB,EAAW,EAAO,EAAQ,CACxB,MAAO,EAAY,EAAG,EAAO,KAAK,EAClC,MAAO,EAAO,OAAS,SACvB,eAAgB,EAAI,eACpB,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,YAAc,GACjC,YAAa,EAAO,aAAe,EACnC,WAAY,EAAO,UACrB,CAAC,CACH,CAKA,OAHA,GAAQ,OAAO,EAAW,KAAK,EAAG,KAAO,CAAE,MAAO,EAAY,EAAG,EAAE,KAAK,EAAG,KAAM,EAAE,IAAK,EAAE,CAAC,EAC3F,GAAS,KAAK,EAEP,EAAwB,CAC7B,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap;function
|
|
1
|
+
require("../../_dev.cjs");const e=require("../../svg/element.cjs"),t=require("../../animation/easing.cjs"),n=require("../../animation/motion.cjs"),r=require("../../animation/tween.cjs"),i=require("../../svg/path.cjs");var a=new WeakMap;function buildPath(e,t){return t===`monotone`?i.monotonePath(e):t===`step`?i.stepPath(e):i.linePath(e)}function renderLine(i,o,s){let c=n.resolveMotion(s.transition,0),l=c.duration,u=t.resolveEasing(c.easing),d=i.querySelector(`.prism-line-path`);d||(d=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),i.appendChild(d)),e.setAttributes(d,{stroke:s.color,"stroke-width":s.strokeWidth});let f=i.querySelector(`.prism-line-dots`);if(s.showPoints?f||(f=e.createSvgElement(`g`,{class:`prism-line-dots`}),i.appendChild(f)):f&&=(f.remove(),null),l===0){if(e.setAttributes(d,{d:buildPath(o,s.curve)}),f){for(;f.children.length>o.length;)f.removeChild(f.lastChild);for(let t=0;t<o.length;t++){let n=f.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),f.appendChild(n)),e.setAttributes(n,{cx:o[t].x,cy:o[t].y,fill:s.color,r:s.pointRadius})}}return}a.get(i)?.();let p=!!d.getAttribute(`d`),m=[],h=null;if(f){let t=f.children.length;for(let e=0;e<t;e++){let t=f.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};m.push(n),h=n}for(;f.children.length>o.length;)f.removeChild(f.lastChild);for(let t=f.children.length;t<o.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{cx:o[t].x,cy:o[t].y,fill:s.color,r:s.pointRadius}),f.appendChild(n)}}for(let e=m.length;e<o.length;e++)m.push(h??o[e]);let g=null;function frame(t){if(s.disposalSignal?.aborted){a.delete(i);return}g===null&&(g=t);let n=Math.min(1,(t-g)/l),c=u(n),p=o.map((e,t)=>{let n=m[t]??e;return{x:r.tweenNumber(n.x,e.x,c),y:r.tweenNumber(n.y,e.y,c)}});if(e.setAttributes(d,{d:buildPath(p,s.curve)}),f)for(let t=0;t<o.length;t++){let n=f.children[t];n&&e.setAttributes(n,{cx:p[t].x,cy:p[t].y})}if(n<1){let e=requestAnimationFrame(frame);a.set(i,()=>cancelAnimationFrame(e))}else a.delete(i)}if(!p)e.setAttributes(d,{d:buildPath(o,s.curve)});else{let e=requestAnimationFrame(frame);a.set(i,()=>cancelAnimationFrame(e))}}function computePoints(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.computePoints=computePoints,exports.renderLine=renderLine;
|
|
2
2
|
//# sourceMappingURL=line-renderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-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 { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\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 pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path = parent.querySelector<SVGPathElement>('.prism-line-path');\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, { stroke: options.color, 'stroke-width': options.strokeWidth });\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = !!path.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n dotsGroup.appendChild(c);\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAnimations.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 const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n setAttributes(path!, { d: buildPath(interpolated, options.curve) });\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAnimations.delete(parent);\n }\n }\n\n if (!hasExisting) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n } else {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n }\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: 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":"0NAoBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,
|
|
1
|
+
{"version":3,"file":"line-renderer.cjs","names":[],"sources":["../../../src/charts/line/line-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 { linePath, monotonePath, stepPath } from '../../svg/path';\nimport type { ContinuousDatum, Scale, TransitionConfig } from '../../types';\n\nexport interface LineRenderOptions {\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 pointRadius: number;\n showPoints: boolean;\n strokeWidth: number;\n transition?: TransitionConfig;\n}\n\nconst activeAnimations = new WeakMap<SVGGElement, () => void>();\n\nfunction buildPath(pts: Point[], curve: LineRenderOptions['curve']): string {\n return curve === 'monotone' ? monotonePath(pts) : curve === 'step' ? stepPath(pts) : linePath(pts);\n}\n\nexport function renderLine(parent: SVGGElement, points: Point[], options: LineRenderOptions): void {\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path = parent.querySelector<SVGPathElement>('.prism-line-path');\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, { stroke: options.color, 'stroke-width': options.strokeWidth });\n\n let dotsGroup = parent.querySelector<SVGGElement>('.prism-line-dots');\n\n if (options.showPoints) {\n if (!dotsGroup) {\n dotsGroup = createSvgElement('g', { class: 'prism-line-dots' });\n parent.appendChild(dotsGroup);\n }\n } else if (dotsGroup) {\n dotsGroup.remove();\n dotsGroup = null;\n }\n\n if (dur === 0) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n\n if (dotsGroup) {\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = 0; i < points.length; i++) {\n let c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (!c) {\n c = createSvgElement('circle', { class: 'prism-line-dot' });\n dotsGroup.appendChild(c);\n }\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = !!path.getAttribute('d');\n\n const fromPts: Point[] = [];\n let lastKnown: Point | null = null;\n\n if (dotsGroup) {\n const existingCount = dotsGroup.children.length;\n\n for (let i = 0; i < existingCount; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement;\n const pt = { x: Number(c.getAttribute('cx')), y: Number(c.getAttribute('cy')) };\n\n fromPts.push(pt);\n lastKnown = pt;\n }\n\n while (dotsGroup.children.length > points.length) dotsGroup.removeChild(dotsGroup.lastChild!);\n\n for (let i = dotsGroup.children.length; i < points.length; i++) {\n const c = createSvgElement('circle', { class: 'prism-line-dot' });\n\n setAttributes(c, { cx: points[i].x, cy: points[i].y, fill: options.color, r: options.pointRadius });\n dotsGroup.appendChild(c);\n }\n }\n\n for (let i = fromPts.length; i < points.length; i++) {\n fromPts.push(lastKnown ?? points[i]);\n }\n\n let startTime: number | null = null;\n\n function frame(ts: number) {\n if (options.disposalSignal?.aborted) {\n activeAnimations.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 const from = fromPts[i] ?? to;\n\n return { x: tweenNumber(from.x, to.x, e), y: tweenNumber(from.y, to.y, e) };\n });\n\n setAttributes(path!, { d: buildPath(interpolated, options.curve) });\n\n if (dotsGroup) {\n for (let i = 0; i < points.length; i++) {\n const c = dotsGroup.children[i] as SVGCircleElement | undefined;\n\n if (c) setAttributes(c, { cx: interpolated[i].x, cy: interpolated[i].y });\n }\n }\n\n if (t < 1) {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n } else {\n activeAnimations.delete(parent);\n }\n }\n\n if (!hasExisting) {\n setAttributes(path, { d: buildPath(points, options.curve) });\n } else {\n const id = requestAnimationFrame(frame);\n\n activeAnimations.set(parent, () => cancelAnimationFrame(id));\n }\n}\n\nexport function computePoints(data: ContinuousDatum[], xScale: Scale<Date | number>, yScale: Scale<number>): Point[] {\n if (data.some((d) => d.key == null)) {\n warn(\n 'computePoints: 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('computePoints: 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":"0NAoBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAA,aAAa,CAAG,EAAI,IAAU,OAAS,EAAA,SAAS,CAAG,EAAI,EAAA,SAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,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,kBAAmB,KAAM,MAAO,CAAC,EAC1E,EAAO,YAAY,CAAI,GAGzB,EAAA,cAAc,EAAM,CAAE,OAAQ,EAAQ,MAAO,eAAgB,EAAQ,WAAY,CAAC,EAElF,IAAI,EAAY,EAAO,cAA2B,kBAAkB,EAYpE,GAVI,EAAQ,WACL,IACH,EAAY,EAAA,iBAAiB,IAAK,CAAE,MAAO,iBAAkB,CAAC,EAC9D,EAAO,YAAY,CAAS,GAEzB,AAEL,KADA,EAAU,OAAO,EACL,MAGV,IAAQ,EAAG,CAGb,GAFA,EAAA,cAAc,EAAM,CAAE,EAAG,UAAU,EAAQ,EAAQ,KAAK,CAAE,CAAC,EAEvD,EAAW,CACb,KAAO,EAAU,SAAS,OAAS,EAAO,QAAQ,EAAU,YAAY,EAAU,SAAU,EAE5F,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAI,EAAI,EAAU,SAAS,GAEtB,IACH,EAAI,EAAA,iBAAiB,SAAU,CAAE,MAAO,gBAAiB,CAAC,EAC1D,EAAU,YAAY,CAAC,GAGzB,EAAA,cAAc,EAAG,CAAE,GAAI,EAAO,EAAE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