@vielzeug/prism 26.10.1 → 26.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts/area/area-chart.cjs +1 -1
- package/dist/charts/area/area-chart.cjs.map +1 -1
- package/dist/charts/area/area-chart.d.ts.map +1 -1
- package/dist/charts/area/area-chart.js +1 -1
- package/dist/charts/area/area-chart.js.map +1 -1
- package/dist/charts/area/area-renderer.cjs +1 -1
- package/dist/charts/area/area-renderer.cjs.map +1 -1
- package/dist/charts/area/area-renderer.d.ts +3 -0
- package/dist/charts/area/area-renderer.d.ts.map +1 -1
- package/dist/charts/area/area-renderer.js +1 -1
- 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.d.ts.map +1 -1
- package/dist/charts/bar/bar-chart.js +1 -1
- package/dist/charts/bar/bar-chart.js.map +1 -1
- package/dist/charts/bar/bar-renderer.cjs +1 -1
- package/dist/charts/bar/bar-renderer.cjs.map +1 -1
- package/dist/charts/bar/bar-renderer.d.ts +2 -0
- package/dist/charts/bar/bar-renderer.d.ts.map +1 -1
- package/dist/charts/bar/bar-renderer.js +1 -1
- 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.d.ts.map +1 -1
- package/dist/charts/line/line-chart.js +1 -1
- package/dist/charts/line/line-chart.js.map +1 -1
- package/dist/charts/line/line-renderer.cjs +1 -1
- package/dist/charts/line/line-renderer.cjs.map +1 -1
- package/dist/charts/line/line-renderer.d.ts +3 -0
- package/dist/charts/line/line-renderer.d.ts.map +1 -1
- package/dist/charts/line/line-renderer.js +1 -1
- package/dist/charts/line/line-renderer.js.map +1 -1
- package/dist/charts/radar/radar-chart.cjs +1 -1
- package/dist/charts/radar/radar-chart.cjs.map +1 -1
- package/dist/charts/radar/radar-chart.d.ts.map +1 -1
- package/dist/charts/radar/radar-chart.js +1 -1
- package/dist/charts/radar/radar-chart.js.map +1 -1
- package/dist/core/datum-style.cjs +2 -0
- package/dist/core/datum-style.cjs.map +1 -0
- package/dist/core/datum-style.d.ts +18 -0
- package/dist/core/datum-style.d.ts.map +1 -0
- package/dist/core/datum-style.js +2 -0
- package/dist/core/datum-style.js.map +1 -0
- package/dist/core/series-id.cjs +2 -0
- package/dist/core/series-id.cjs.map +1 -0
- package/dist/core/series-id.d.ts +8 -0
- package/dist/core/series-id.d.ts.map +1 -0
- package/dist/core/series-id.js +2 -0
- package/dist/core/series-id.js.map +1 -0
- 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/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -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 { describeValues } from '../../interaction/announcer';\nimport { getMousePosition } from '../../interaction/events';\nimport { comparisonContent } from '../../interaction/tooltip';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarSeriesConfig, BarVariant, ChartEvent, ChartHandle, SeriesValue } from '../../types';\nimport { findCatIdx, findSeriesIdx } 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 let band: SVGRectElement | null = null;\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 band?.remove();\n band = null;\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 // Stacked segments stay square so they join cleanly.\n const themeRadius = stacked\n ? 0\n : Number.parseFloat(getComputedStyle(ctx.svg).getPropertyValue('--prism-bar-radius')) || 0;\n\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 ?? themeRadius,\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 groups.series.classList.toggle('prism-bars-stacked', stacked);\n\n if (!band || !ctx.chartArea.contains(band)) {\n band = createSvgElement('rect', { 'aria-hidden': 'true', class: 'prism-bar-band', 'pointer-events': 'none' });\n ctx.chartArea.insertBefore(band, groups.series);\n }\n\n band.style.display = 'none';\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const colors = seriesList.map((s, i) => seriesColor(i, s.color));\n const labelOf = (catIdx: number): string => String(model.labels.get(categories[catIdx]) ?? categories[catIdx]);\n let activeCat = -1;\n\n const valuesAt = (catIdx: number): SeriesValue[] =>\n seriesList.map((series, si) => ({ datum: allData[si]?.[catIdx], series }));\n\n const eventAt = (catIdx: number, seriesIdx: number, originalEvent: Event): ChartEvent | null => {\n const values = valuesAt(catIdx);\n const preferred = values[seriesIdx]?.datum ? seriesIdx : values.findIndex((v) => v.datum);\n const datum = values[preferred]?.datum;\n\n return datum ? { datum, originalEvent, series: seriesList[preferred], values } : null;\n };\n\n const setActive = (catIdx: number): void => {\n activeCat = catIdx;\n groups.series.classList.toggle('prism-bars-focused', catIdx >= 0);\n\n for (const group of groups.series.children) {\n for (const [i, rect] of [...group.children].entries())\n rect.classList.toggle('prism-bar--active', i === catIdx);\n }\n\n if (!band) return;\n\n band.style.display = catIdx < 0 ? 'none' : '';\n\n if (catIdx < 0) return;\n\n const start = sc.bandCenter(categories[catIdx]) - catScale.bandwidth() / 2 - catScale.gap() / 2;\n const size = catScale.bandwidth() + catScale.gap();\n const a = chartArea(ctx.dimensions.width, ctx.dimensions.height, ctx.dimensions.margin);\n\n setAttributes(\n band,\n horizontal\n ? { height: size, width: a.width, x: 0, y: start }\n : { height: a.height, width: size, x: start, y: 0 },\n );\n };\n\n const activate = (catIdx: number, seriesIdx: number, originalEvent: Event): void => {\n const event = eventAt(catIdx, seriesIdx, originalEvent);\n\n if (!event) return;\n\n setActive(catIdx);\n\n const values = event.values ?? [];\n const spoken = describeValues(labelOf(catIdx), values);\n\n if (tooltip) {\n const tops = values.map((v, si) =>\n stacked ? (stackedTops[si]?.[catIdx] ?? 0) : Math.max(0, v.datum?.value ?? 0),\n );\n const valuePx = valScale.map(Math.max(...tops));\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const { margin } = ctx.dimensions;\n const rows = values.flatMap((v, si) =>\n v.datum ? [{ color: colors[si], name: v.series.name, value: String(v.datum.value) }] : [],\n );\n\n tooltip.show(\n (horizontal ? valuePx : bandCenterPx) + margin.left,\n (horizontal ? bandCenterPx : valuePx) + margin.top,\n event.datum,\n event.series,\n comparisonContent(ctx.svg.ownerDocument, labelOf(catIdx), rows, spoken),\n );\n } else {\n ctx.announcer.announce(spoken);\n }\n\n config.onHover?.(event);\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hit = (event: MouseEvent): { catIdx: number; seriesIdx: number } | null => {\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 null;\n\n const catIdx = findCatIdx(horizontal ? pos.y : pos.x, categories, sc);\n\n return catIdx === -1\n ? null\n : { catIdx, seriesIdx: findSeriesIdx(pos, catIdx, categories, sc, seriesList.length) };\n };\n\n const onMouseMove = (event: MouseEvent) => {\n const target = hit(event);\n\n if (target) activate(target.catIdx, target.seriesIdx, event);\n else if (activeCat >= 0) deactivate();\n };\n\n const onClick = (event: MouseEvent) => {\n const target = config.onClick && hit(event);\n const chartEvent = target && eventAt(target.catIdx, target.seriesIdx, event);\n\n if (chartEvent) config.onClick?.(chartEvent);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n const last = categories.length - 1;\n const prev = activeCat < 0 ? last : Math.max(0, activeCat - 1);\n const next = activeCat < 0 ? 0 : Math.min(last, activeCat + 1);\n const target: Record<string, number> = {\n ArrowDown: next,\n ArrowLeft: prev,\n ArrowRight: next,\n ArrowUp: prev,\n End: last,\n Home: 0,\n };\n\n if (event.key in target) {\n event.preventDefault();\n activate(target[event.key], 0, event);\n } else if ((event.key === 'Enter' || event.key === ' ') && activeCat >= 0 && config.onClick) {\n event.preventDefault();\n\n const chartEvent = eventAt(activeCat, 0, event);\n\n if (chartEvent) config.onClick(chartEvent);\n } else if (event.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"u4BAkBA,SAAS,aAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAA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KAAK,IAAI,EAAM,EAAY,CAAC,EACvD,EAAiC,CACrC,UAAW,EACX,UAAW,EACX,WAAY,EACZ,QAAS,EACT,IAAK,EACL,KAAM,CACR,EAEA,GAAI,EAAM,OAAO,EACf,EAAM,eAAe,EACrB,SAAS,EAAO,EAAM,KAAM,EAAG,CAAK,OAC/B,IAAK,EAAM,MAAQ,SAAW,EAAM,MAAQ,MAAQ,GAAa,GAAK,EAAO,QAAS,CAC3F,EAAM,eAAe,EAErB,IAAM,EAAa,QAAQ,EAAW,EAAG,CAAK,EAE1C,GAAY,EAAO,QAAQ,CAAU,CAC3C,MAAW,EAAM,MAAQ,UACvB,WAAW,CAEf,EAEA,MAAO,CAAE,QAAS,UAAW,aAAc,WAAY,WAAY,CACrE,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
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 { seriesDomId } from '../../core/series-id';\nimport { describeValues } from '../../interaction/announcer';\nimport { getMousePosition } from '../../interaction/events';\nimport { comparisonContent } from '../../interaction/tooltip';\nimport { bandScale } from '../../scales/band';\nimport { linearScale } from '../../scales/linear';\nimport { createSvgElement, setAttributes } from '../../svg/element';\nimport { seriesColor } from '../../theme';\nimport type { BarChartConfig, BarSeriesConfig, BarVariant, ChartEvent, ChartHandle, SeriesValue } from '../../types';\nimport { findCatIdx, findSeriesIdx } 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 let band: SVGRectElement | null = null;\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 band?.remove();\n band = null;\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 // Stacked segments stay square so they join cleanly.\n const themeRadius = stacked\n ? 0\n : Number.parseFloat(getComputedStyle(ctx.svg).getPropertyValue('--prism-bar-radius')) || 0;\n\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 group.setAttribute('data-series-id', seriesDomId(series, i));\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, dash: datum?.dash, key, opacity: datum?.opacity, present: datum !== undefined, y: top };\n }\n\n return {\n base: 0,\n dash: datum?.dash,\n key,\n opacity: datum?.opacity,\n present: datum !== undefined,\n y: datum?.value ?? 0,\n };\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 ?? themeRadius,\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 groups.series.classList.toggle('prism-bars-stacked', stacked);\n\n if (!band || !ctx.chartArea.contains(band)) {\n band = createSvgElement('rect', { 'aria-hidden': 'true', class: 'prism-bar-band', 'pointer-events': 'none' });\n ctx.chartArea.insertBefore(band, groups.series);\n }\n\n band.style.display = 'none';\n\n // ─── Event handlers (close over render-derived state) ─────────────────────\n\n const colors = seriesList.map((s, i) => seriesColor(i, s.color));\n const labelOf = (catIdx: number): string => String(model.labels.get(categories[catIdx]) ?? categories[catIdx]);\n let activeCat = -1;\n\n const valuesAt = (catIdx: number): SeriesValue[] =>\n seriesList.map((series, si) => ({ datum: allData[si]?.[catIdx], series }));\n\n const eventAt = (catIdx: number, seriesIdx: number, originalEvent: Event): ChartEvent | null => {\n const values = valuesAt(catIdx);\n const preferred = values[seriesIdx]?.datum ? seriesIdx : values.findIndex((v) => v.datum);\n const datum = values[preferred]?.datum;\n\n return datum ? { datum, originalEvent, series: seriesList[preferred], values } : null;\n };\n\n const setActive = (catIdx: number): void => {\n activeCat = catIdx;\n groups.series.classList.toggle('prism-bars-focused', catIdx >= 0);\n\n for (const group of groups.series.children) {\n for (const [i, rect] of [...group.children].entries())\n rect.classList.toggle('prism-bar--active', i === catIdx);\n }\n\n if (!band) return;\n\n band.style.display = catIdx < 0 ? 'none' : '';\n\n if (catIdx < 0) return;\n\n const start = sc.bandCenter(categories[catIdx]) - catScale.bandwidth() / 2 - catScale.gap() / 2;\n const size = catScale.bandwidth() + catScale.gap();\n const a = chartArea(ctx.dimensions.width, ctx.dimensions.height, ctx.dimensions.margin);\n\n setAttributes(\n band,\n horizontal\n ? { height: size, width: a.width, x: 0, y: start }\n : { height: a.height, width: size, x: start, y: 0 },\n );\n };\n\n const activate = (catIdx: number, seriesIdx: number, originalEvent: Event): void => {\n const event = eventAt(catIdx, seriesIdx, originalEvent);\n\n if (!event) return;\n\n setActive(catIdx);\n\n const values = event.values ?? [];\n const spoken = describeValues(labelOf(catIdx), values);\n\n if (tooltip) {\n const tops = values.map((v, si) =>\n stacked ? (stackedTops[si]?.[catIdx] ?? 0) : Math.max(0, v.datum?.value ?? 0),\n );\n const valuePx = valScale.map(Math.max(...tops));\n const bandCenterPx = sc.bandCenter(categories[catIdx]);\n const { margin } = ctx.dimensions;\n const rows = values.flatMap((v, si) =>\n v.datum ? [{ color: colors[si], name: v.series.name, value: String(v.datum.value) }] : [],\n );\n\n tooltip.show(\n (horizontal ? valuePx : bandCenterPx) + margin.left,\n (horizontal ? bandCenterPx : valuePx) + margin.top,\n event.datum,\n event.series,\n comparisonContent(ctx.svg.ownerDocument, labelOf(catIdx), rows, spoken),\n );\n } else {\n ctx.announcer.announce(spoken);\n }\n\n config.onHover?.(event);\n };\n\n const deactivate = (): void => {\n setActive(-1);\n tooltip?.hide();\n ctx.announcer.clear();\n config.onHover?.(null);\n };\n\n const hit = (event: MouseEvent): { catIdx: number; seriesIdx: number } | null => {\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 null;\n\n const catIdx = findCatIdx(horizontal ? pos.y : pos.x, categories, sc);\n\n return catIdx === -1\n ? null\n : { catIdx, seriesIdx: findSeriesIdx(pos, catIdx, categories, sc, seriesList.length) };\n };\n\n const onMouseMove = (event: MouseEvent) => {\n const target = hit(event);\n\n if (target) activate(target.catIdx, target.seriesIdx, event);\n else if (activeCat >= 0) deactivate();\n };\n\n const onClick = (event: MouseEvent) => {\n const target = config.onClick && hit(event);\n const chartEvent = target && eventAt(target.catIdx, target.seriesIdx, event);\n\n if (chartEvent) config.onClick?.(chartEvent);\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n const last = categories.length - 1;\n const prev = activeCat < 0 ? last : Math.max(0, activeCat - 1);\n const next = activeCat < 0 ? 0 : Math.min(last, activeCat + 1);\n const target: Record<string, number> = {\n ArrowDown: next,\n ArrowLeft: prev,\n ArrowRight: next,\n ArrowUp: prev,\n End: last,\n Home: 0,\n };\n\n if (event.key in target) {\n event.preventDefault();\n activate(target[event.key], 0, event);\n } else if ((event.key === 'Enter' || event.key === ' ') && activeCat >= 0 && config.onClick) {\n event.preventDefault();\n\n const chartEvent = eventAt(activeCat, 0, event);\n\n if (chartEvent) config.onClick(chartEvent);\n } else if (event.key === 'Escape') {\n deactivate();\n }\n };\n\n return { onClick, onKeyDown, onMouseLeave: deactivate, onMouseMove };\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"67BAmBA,SAAS,aAAa,EAAgE,CACpF,MAAO,CACL,WAAY,IAAY,sBAAwB,IAAY,qBAC5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AAO,EAAW,OAAS,EAC3B,EAAO,EAAY,EAAI,EAAO,KAAK,IAAI,EAAG,EAAY,CAAC,EACvD,EAAO,EAAY,EAAI,EAAI,KAAK,IAAI,EAAM,EAAY,CAAC,EACvD,EAAiC,CACrC,UAAW,EACX,UAAW,EACX,WAAY,EACZ,QAAS,EACT,IAAK,EACL,KAAM,CACR,EAEA,GAAI,EAAM,OAAO,EACf,EAAM,eAAe,EACrB,SAAS,EAAO,EAAM,KAAM,EAAG,CAAK,OAC/B,IAAK,EAAM,MAAQ,SAAW,EAAM,MAAQ,MAAQ,GAAa,GAAK,EAAO,QAAS,CAC3F,EAAM,eAAe,EAErB,IAAM,EAAa,QAAQ,EAAW,EAAG,CAAK,EAE1C,GAAY,EAAO,QAAQ,CAAU,CAC3C,MAAW,EAAM,MAAQ,UACvB,WAAW,CAEf,EAEA,MAAO,CAAE,QAAS,UAAW,aAAc,WAAY,WAAY,CACrE,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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;
|
|
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`,e.setAttributes(_,{opacity:n.opacity,stroke:n.dash?c.color:void 0,"stroke-dasharray":n.dash,"stroke-width":n.dash?1:void 0}),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,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,
|
|
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; dash?: string; key: string; opacity?: number; 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 // Presentation attributes (not inline styles) so CSS interaction states\n // like the focus-dim rule keep winning over per-datum styling.\n setAttributes(rect, {\n opacity: d.opacity,\n stroke: d.dash ? options.color : undefined,\n 'stroke-dasharray': d.dash,\n 'stroke-width': d.dash ? 1 : undefined,\n });\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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EAAG,CAAO,CAAC,CAE1D,CACF,CAEA,GAAI,EAAQ,WAAY,CACtB,EAAoB,IAAI,CAAM,CAAC,GAAG,EAElC,IAAM,EAA0B,CAAC,EAE7B,EAAa,OAAS,GACxB,EAAQ,KAAK,EAAA,QAAQ,EAAc,EAAQ,WAAY,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"}
|
|
@@ -13,7 +13,9 @@ export interface BarRenderOptions {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function renderBars(parent: SVGGElement, data: {
|
|
15
15
|
base: number;
|
|
16
|
+
dash?: string;
|
|
16
17
|
key: string;
|
|
18
|
+
opacity?: number;
|
|
17
19
|
present: boolean;
|
|
18
20
|
y: number;
|
|
19
21
|
}[], xScale: BandScale, yScale: Scale<number>, baselineY: number, options: BarRenderOptions): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAID,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"bar-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/bar/bar-renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gGAAgG;IAChG,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAID,wBAAgB,UAAU,CACxB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EACnG,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,gBAAgB,GACxB,IAAI,CA8HN"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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};
|
|
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`,t(v,{opacity:r.opacity,stroke:r.dash?l.color:void 0,"stroke-dasharray":r.dash,"stroke-width":r.dash?1:void 0}),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};
|
|
2
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":"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,
|
|
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; dash?: string; key: string; opacity?: number; 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 // Presentation attributes (not inline styles) so CSS interaction states\n // like the focus-dim rule keep winning over per-datum styling.\n setAttributes(rect, {\n opacity: d.opacity,\n stroke: d.dash ? options.color : undefined,\n 'stroke-dasharray': d.dash,\n 'stroke-width': d.dash ? 1 : undefined,\n });\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,EAkBf,GAhBK,IACH,EAAO,EAAiB,OAAQ,CAAE,MAAO,WAAY,CAAC,EACtD,EAAO,YAAY,CAAI,GAGzB,EAAK,MAAM,QAAU,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AAC,EAClD,EAAa,KAAK,CAChB,MAAO,CAAE,OAAQ,CAAE,KAAM,EAAG,GAAI,CAAY,EAAG,EAAG,CAAE,KAAM,EAAc,GAAI,CAAO,CAAE,EACrF,GAAI,CACN,CAAC,GAED,EAAc,KAAK,CACjB,MAAO,CACL,OAAQ,CAAE,KAAM,OAAO,EAAK,aAAa,QAAQ,GAAK,CAAW,EAAG,GAAI,CAAY,EACpF,EAAG,CAAE,KAAM,OAAO,EAAK,aAAa,GAAG,GAAK,CAAM,EAAG,GAAI,CAAO,CAClE,EACA,GAAI,CACN,CAAC,EAGH,EAAc,EAAM,CAAE,OAAQ,EAAa,EAAG,CAAO,CAAC,CAE1D,CACF,CAEA,GAAI,EAAQ,WAAY,CACtB,EAAoB,IAAI,CAAM,CAAC,GAAG,EAElC,IAAM,EAA0B,CAAC,EAE7B,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"),
|
|
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("../../core/series-id.cjs"),s=require("../../interaction/crosshair.cjs"),c=require("../../interaction/series-interaction.cjs"),l=require("../../theme/index.cjs"),u=require("./line-renderer.cjs");function createLineChart(d,f){let p=null,m=null,h=null,g=f.series;return a.createChartScaffold(d,f,d=>{let{groups:_,legend:v,tooltip:y}=d,b=d.dimensions,x=g.some(e=>e.yAxis===`right`),S=g.some(e=>e.yAxis!==`right`&&e.data.length>0);b.margin.right=f.margin?.right??(x?f.rightYAxis?.label?72:50:i.resolveMargin(f.margin).right);let C=i.chartArea(b.width,b.height,b.margin),w=g.map(e=>e.data),T=w.flat().map(e=>e.key),E=g.filter(e=>e.yAxis!==`right`).flatMap(e=>e.data.map(e=>e.value)),D=g.filter(e=>e.yAxis===`right`).flatMap(e=>e.data.map(e=>e.value));if(T.length===0){a.clearCartesianDom(_,v,y,p),m?.replaceChildren(),h?.replaceChildren();return}f.crosshair&&!p&&(p=s.createCrosshair(d.chartArea,f.crosshair));let O=r.buildXScale(T,C.width),k=r.buildYScale(E,C.height),A=r.buildYScale(D,C.height);if(f.yAxis?.grid&&(!x||S)?n.renderGrid(_.grid,k,f.yAxis.grid,C.width,`horizontal`,t.resolveTickCount(f.yAxis,C.height,`left`)):_.grid.replaceChildren(),f.xAxis?.grid&&n.renderGrid(_.grid,O,f.xAxis.grid,C.height,`vertical`,t.resolveTickCount(f.xAxis,C.width,`bottom`)),f.xAxis&&(t.positionAxis(_.xAxis,f.xAxis.position??`bottom`,C.width,C.height),t.renderAxis(_.xAxis,O,f.xAxis,C.width,`bottom`)),f.yAxis&&(!x||S)){let e={...f.yAxis,position:x?`left`:f.yAxis.position??`left`};t.positionAxis(_.yAxis,e.position,C.width,C.height),t.renderAxis(_.yAxis,k,e,C.height,`left`)}else _.yAxis.replaceChildren();if(x){h||(h=e.createSvgElement(`g`,{class:`prism-y-axis-right`}),d.chartArea.appendChild(h));let n={...f.rightYAxis,position:`right`};t.positionAxis(h,`right`,C.width,C.height),t.renderAxis(h,A,n,C.height,`right`)}else h?.replaceChildren();for(;_.series.children.length>g.length;)_.series.removeChild(_.series.lastChild);let j=[];for(let t=0;t<g.length;t++){let n=g[t],r=_.series.children[t];r||(r=e.createSvgElement(`g`,{class:`prism-line-series`}),_.series.appendChild(r)),r.setAttribute(`data-series-id`,o.seriesDomId(n,t));let i=u.computePoints(w[t],O,n.yAxis===`right`?A:k);j.push(i),u.renderLine(r,i,{color:l.seriesColor(t,n.color),curve:n.curve??`linear`,disposalSignal:d.disposalSignal,marks:n.data,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth,transition:f.transition})}return v?.update(g.map((e,t)=>({color:l.seriesColor(t,e.color),name:e.name}))),y?.hide(),m=c.ensureMarkerGroup(d.chartArea,m),c.createSeriesInteraction({announcer:d.announcer,colors:()=>g.map((e,t)=>l.seriesColor(t,e.color)),crosshair:p,dims:()=>d.dimensions,getData:()=>w,getPoints:()=>j,getSeriesList:()=>g,markers:m,onClick:f.onClick,onHover:f.onHover,seriesGroup:_.series,svg:d.svg,tooltip:y})},e=>{g=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, resolveMargin } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } 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 markers: SVGGElement | null = null;\n let rightAxis: SVGGElement | 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 hasRight = seriesList.some((series) => series.yAxis === 'right');\n const hasLeftData = seriesList.some((series) => series.yAxis !== 'right' && series.data.length > 0);\n dims.margin.right =\n config.margin?.right ?? (hasRight ? (config.rightYAxis?.label ? 72 : 50) : resolveMargin(config.margin).right);\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 leftY = seriesList\n .filter((series) => series.yAxis !== 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n const rightY = seriesList\n .filter((series) => series.yAxis === 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n rightAxis?.replaceChildren();\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(leftY, area.height);\n const rightYScale = buildYScale(rightY, area.height);\n\n if (config.yAxis?.grid && (!hasRight || hasLeftData)) {\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 } else {\n groups.grid.replaceChildren();\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 && (!hasRight || hasLeftData)) {\n const axis = { ...config.yAxis, position: hasRight ? ('left' as const) : (config.yAxis.position ?? 'left') };\n positionAxis(groups.yAxis, axis.position, area.width, area.height);\n renderAxis(groups.yAxis, yScale, axis, area.height, 'left');\n } else {\n groups.yAxis.replaceChildren();\n }\n\n if (hasRight) {\n if (!rightAxis) {\n rightAxis = createSvgElement('g', { class: 'prism-y-axis-right' });\n ctx.chartArea.appendChild(rightAxis);\n }\n const axis = { ...config.rightYAxis, position: 'right' as const };\n positionAxis(rightAxis, 'right', area.width, area.height);\n renderAxis(rightAxis, rightYScale, axis, area.height, 'right');\n } else {\n rightAxis?.replaceChildren();\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, series.yAxis === 'right' ? rightYScale : 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,\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 markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"
|
|
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, resolveMargin } from '../../core/layout';\nimport { seriesDomId } from '../../core/series-id';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } 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 markers: SVGGElement | null = null;\n let rightAxis: SVGGElement | 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 hasRight = seriesList.some((series) => series.yAxis === 'right');\n const hasLeftData = seriesList.some((series) => series.yAxis !== 'right' && series.data.length > 0);\n dims.margin.right =\n config.margin?.right ?? (hasRight ? (config.rightYAxis?.label ? 72 : 50) : resolveMargin(config.margin).right);\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 leftY = seriesList\n .filter((series) => series.yAxis !== 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n const rightY = seriesList\n .filter((series) => series.yAxis === 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n rightAxis?.replaceChildren();\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(leftY, area.height);\n const rightYScale = buildYScale(rightY, area.height);\n\n if (config.yAxis?.grid && (!hasRight || hasLeftData)) {\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 } else {\n groups.grid.replaceChildren();\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 && (!hasRight || hasLeftData)) {\n const axis = { ...config.yAxis, position: hasRight ? ('left' as const) : (config.yAxis.position ?? 'left') };\n positionAxis(groups.yAxis, axis.position, area.width, area.height);\n renderAxis(groups.yAxis, yScale, axis, area.height, 'left');\n } else {\n groups.yAxis.replaceChildren();\n }\n\n if (hasRight) {\n if (!rightAxis) {\n rightAxis = createSvgElement('g', { class: 'prism-y-axis-right' });\n ctx.chartArea.appendChild(rightAxis);\n }\n const axis = { ...config.rightYAxis, position: 'right' as const };\n positionAxis(rightAxis, 'right', area.width, area.height);\n renderAxis(rightAxis, rightYScale, axis, area.height, 'right');\n } else {\n rightAxis?.replaceChildren();\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 group.setAttribute('data-series-id', seriesDomId(series, i));\n\n const points = computePoints(allData[i], xScale, series.yAxis === 'right' ? rightYScale : 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 marks: series.data,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth,\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 markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"mbAcA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAA8B,KAC9B,EAAgC,KAChC,EAAa,EAAO,OAExB,OAAO,EAAA,oBACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAW,EAAW,KAAM,GAAW,EAAO,QAAU,OAAO,EAC/D,EAAc,EAAW,KAAM,GAAW,EAAO,QAAU,SAAW,EAAO,KAAK,OAAS,CAAC,EAClG,EAAK,OAAO,MACV,EAAO,QAAQ,QAAU,EAAY,EAAO,YAAY,MAAQ,GAAK,GAAM,EAAA,cAAc,EAAO,MAAM,CAAC,CAAC,OAC1G,IAAM,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EACrD,EAAU,EAAW,IAAK,GAAW,EAAO,IAAI,EAChD,EAAO,EAAQ,KAAK,CAAC,CAAC,IAAK,GAAU,EAAM,GAAG,EAC9C,EAAQ,EACX,OAAQ,GAAW,EAAO,QAAU,OAAO,CAAC,CA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EAAU,EAAA,kBAAkB,EAAI,UAAW,CAAO,EAE3C,EAAA,wBAAwB,CAC7B,UAAW,EAAI,UACf,WAAc,EAAW,KAAK,EAAG,IAAM,EAAA,YAAY,EAAG,EAAE,KAAK,CAAC,EAC9D,YACA,SAAY,EAAI,WAChB,YAAe,EACf,cAAiB,EACjB,kBAAqB,EACrB,UACA,QAAS,EAAO,QAChB,QAAS,EAAO,QAChB,YAAa,EAAO,OACpB,IAAK,EAAI,IACT,SACF,CAAC,CACH,EACC,GAAS,CACR,EAAa,CACf,CACF,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"line-chart.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-chart.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGlF,wBAAgB,eAAe,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAoJhH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
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,resolveMargin as c}from"../../core/layout.js";import{clearCartesianDom as l,createChartScaffold as u}from"../../core/chart-scaffold.js";import{
|
|
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,resolveMargin as c}from"../../core/layout.js";import{clearCartesianDom as l,createChartScaffold as u}from"../../core/chart-scaffold.js";import{seriesDomId as d}from"../../core/series-id.js";import{createCrosshair as f}from"../../interaction/crosshair.js";import{createSeriesInteraction as p,ensureMarkerGroup as m}from"../../interaction/series-interaction.js";import{seriesColor as h}from"../../theme/index.js";import{computePoints as g,renderLine as _}from"./line-renderer.js";function createLineChart(v,y){let b=null,x=null,S=null,C=y.series;return u(v,y,u=>{let{groups:v,legend:w,tooltip:T}=u,E=u.dimensions,D=C.some(e=>e.yAxis===`right`),O=C.some(e=>e.yAxis!==`right`&&e.data.length>0);E.margin.right=y.margin?.right??(D?y.rightYAxis?.label?72:50:c(y.margin).right);let k=s(E.width,E.height,E.margin),A=C.map(e=>e.data),j=A.flat().map(e=>e.key),M=C.filter(e=>e.yAxis!==`right`).flatMap(e=>e.data.map(e=>e.value)),N=C.filter(e=>e.yAxis===`right`).flatMap(e=>e.data.map(e=>e.value));if(j.length===0){l(v,w,T,b),x?.replaceChildren(),S?.replaceChildren();return}y.crosshair&&!b&&(b=f(u.chartArea,y.crosshair));let P=a(j,k.width),F=o(M,k.height),I=o(N,k.height);if(y.yAxis?.grid&&(!D||O)?i(v.grid,F,y.yAxis.grid,k.width,`horizontal`,r(y.yAxis,k.height,`left`)):v.grid.replaceChildren(),y.xAxis?.grid&&i(v.grid,P,y.xAxis.grid,k.height,`vertical`,r(y.xAxis,k.width,`bottom`)),y.xAxis&&(t(v.xAxis,y.xAxis.position??`bottom`,k.width,k.height),n(v.xAxis,P,y.xAxis,k.width,`bottom`)),y.yAxis&&(!D||O)){let e={...y.yAxis,position:D?`left`:y.yAxis.position??`left`};t(v.yAxis,e.position,k.width,k.height),n(v.yAxis,F,e,k.height,`left`)}else v.yAxis.replaceChildren();if(D){S||(S=e(`g`,{class:`prism-y-axis-right`}),u.chartArea.appendChild(S));let r={...y.rightYAxis,position:`right`};t(S,`right`,k.width,k.height),n(S,I,r,k.height,`right`)}else S?.replaceChildren();for(;v.series.children.length>C.length;)v.series.removeChild(v.series.lastChild);let L=[];for(let t=0;t<C.length;t++){let n=C[t],r=v.series.children[t];r||(r=e(`g`,{class:`prism-line-series`}),v.series.appendChild(r)),r.setAttribute(`data-series-id`,d(n,t));let i=g(A[t],P,n.yAxis===`right`?I:F);L.push(i),_(r,i,{color:h(t,n.color),curve:n.curve??`linear`,disposalSignal:u.disposalSignal,marks:n.data,pointRadius:n.pointRadius??3,showPoints:n.showPoints??!1,strokeWidth:n.strokeWidth,transition:y.transition})}return w?.update(C.map((e,t)=>({color:h(t,e.color),name:e.name}))),T?.hide(),x=m(u.chartArea,x),p({announcer:u.announcer,colors:()=>C.map((e,t)=>h(t,e.color)),crosshair:b,dims:()=>u.dimensions,getData:()=>A,getPoints:()=>L,getSeriesList:()=>C,markers:x,onClick:y.onClick,onHover:y.onHover,seriesGroup:v.series,svg:u.svg,tooltip:T})},e=>{C=e})}export{createLineChart};
|
|
2
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, resolveMargin } from '../../core/layout';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } 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 markers: SVGGElement | null = null;\n let rightAxis: SVGGElement | 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 hasRight = seriesList.some((series) => series.yAxis === 'right');\n const hasLeftData = seriesList.some((series) => series.yAxis !== 'right' && series.data.length > 0);\n dims.margin.right =\n config.margin?.right ?? (hasRight ? (config.rightYAxis?.label ? 72 : 50) : resolveMargin(config.margin).right);\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 leftY = seriesList\n .filter((series) => series.yAxis !== 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n const rightY = seriesList\n .filter((series) => series.yAxis === 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n rightAxis?.replaceChildren();\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(leftY, area.height);\n const rightYScale = buildYScale(rightY, area.height);\n\n if (config.yAxis?.grid && (!hasRight || hasLeftData)) {\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 } else {\n groups.grid.replaceChildren();\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 && (!hasRight || hasLeftData)) {\n const axis = { ...config.yAxis, position: hasRight ? ('left' as const) : (config.yAxis.position ?? 'left') };\n positionAxis(groups.yAxis, axis.position, area.width, area.height);\n renderAxis(groups.yAxis, yScale, axis, area.height, 'left');\n } else {\n groups.yAxis.replaceChildren();\n }\n\n if (hasRight) {\n if (!rightAxis) {\n rightAxis = createSvgElement('g', { class: 'prism-y-axis-right' });\n ctx.chartArea.appendChild(rightAxis);\n }\n const axis = { ...config.rightYAxis, position: 'right' as const };\n positionAxis(rightAxis, 'right', area.width, area.height);\n renderAxis(rightAxis, rightYScale, axis, area.height, 'right');\n } else {\n rightAxis?.replaceChildren();\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, series.yAxis === 'right' ? rightYScale : 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,\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 markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\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, resolveMargin } from '../../core/layout';\nimport { seriesDomId } from '../../core/series-id';\nimport { createCrosshair } from '../../interaction/crosshair';\nimport { createSeriesInteraction, ensureMarkerGroup } 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 markers: SVGGElement | null = null;\n let rightAxis: SVGGElement | 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 hasRight = seriesList.some((series) => series.yAxis === 'right');\n const hasLeftData = seriesList.some((series) => series.yAxis !== 'right' && series.data.length > 0);\n dims.margin.right =\n config.margin?.right ?? (hasRight ? (config.rightYAxis?.label ? 72 : 50) : resolveMargin(config.margin).right);\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 leftY = seriesList\n .filter((series) => series.yAxis !== 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n const rightY = seriesList\n .filter((series) => series.yAxis === 'right')\n .flatMap((series) => series.data.map((datum) => datum.value));\n\n if (allX.length === 0) {\n clearCartesianDom(groups, legend, tooltip, crosshair);\n markers?.replaceChildren();\n rightAxis?.replaceChildren();\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(leftY, area.height);\n const rightYScale = buildYScale(rightY, area.height);\n\n if (config.yAxis?.grid && (!hasRight || hasLeftData)) {\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 } else {\n groups.grid.replaceChildren();\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 && (!hasRight || hasLeftData)) {\n const axis = { ...config.yAxis, position: hasRight ? ('left' as const) : (config.yAxis.position ?? 'left') };\n positionAxis(groups.yAxis, axis.position, area.width, area.height);\n renderAxis(groups.yAxis, yScale, axis, area.height, 'left');\n } else {\n groups.yAxis.replaceChildren();\n }\n\n if (hasRight) {\n if (!rightAxis) {\n rightAxis = createSvgElement('g', { class: 'prism-y-axis-right' });\n ctx.chartArea.appendChild(rightAxis);\n }\n const axis = { ...config.rightYAxis, position: 'right' as const };\n positionAxis(rightAxis, 'right', area.width, area.height);\n renderAxis(rightAxis, rightYScale, axis, area.height, 'right');\n } else {\n rightAxis?.replaceChildren();\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 group.setAttribute('data-series-id', seriesDomId(series, i));\n\n const points = computePoints(allData[i], xScale, series.yAxis === 'right' ? rightYScale : 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 marks: series.data,\n pointRadius: series.pointRadius ?? 3,\n showPoints: series.showPoints ?? false,\n strokeWidth: series.strokeWidth,\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 markers = ensureMarkerGroup(ctx.chartArea, markers);\n\n return createSeriesInteraction({\n announcer: ctx.announcer,\n colors: () => seriesList.map((s, i) => seriesColor(i, s.color)),\n crosshair,\n dims: () => ctx.dimensions,\n getData: () => allData,\n getPoints: () => allPoints,\n getSeriesList: () => seriesList,\n markers,\n onClick: config.onClick,\n onHover: config.onHover,\n seriesGroup: groups.series,\n svg: ctx.svg,\n tooltip,\n });\n },\n (data) => {\n seriesList = data;\n },\n );\n}\n"],"mappings":"kwBAcA,SAAgB,gBAAgB,EAAwB,EAA0D,CAChH,IAAI,EAAuD,KACvD,EAA8B,KAC9B,EAAgC,KAChC,EAAa,EAAO,OAExB,OAAO,EACL,EACA,EACC,GAAQ,CACP,GAAM,CAAE,SAAQ,SAAQ,WAAY,EAC9B,EAAO,EAAI,WACX,EAAW,EAAW,KAAM,GAAW,EAAO,QAAU,OAAO,EAC/D,EAAc,EAAW,KAAM,GAAW,EAAO,QAAU,SAAW,EAAO,KAAK,OAAS,CAAC,EAClG,EAAK,OAAO,MACV,EAAO,QAAQ,QAAU,EAAY,EAAO,YAAY,MAAQ,GAAK,GAAM,EAAc,EAAO,MAAM,CAAC,CAAC,OAC1G,IAAM,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,EAAQ,EACX,OAAQ,GAAW,EAAO,QAAU,OAAO,CAAC,CAC5C,QAAS,GAAW,EAAO,KAAK,IAAK,GAAU,EAAM,KAAK,CAAC,EACxD,EAAS,EACZ,OAAQ,GAAW,EAAO,QAAU,OAAO,CAAC,C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B,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
|
|
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("../../core/datum-style.cjs"),a=require("../../svg/path.cjs");var o=new WeakMap;function buildPath(e,t){return t===`monotone`?a.monotonePath(e):t===`step`?a.stepPath(e):a.linePath(e)}function renderLine(a,s,c){let l=i.hasStyledRuns(c.marks),u=c.marks??[],d=n.resolveMotion(c.transition,0),f=d.duration,p=t.resolveEasing(d.easing),m=null,h=[],g=[];if(l){h=i.computeStyleRuns(u,s.length);let t=[...a.querySelectorAll(`.prism-line-path`)];for(let e of t.slice(h.length))e.remove();g=h.map((n,r)=>{let i=t[r];if(i)return i;let o=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`});return a.appendChild(o),o});for(let[t,n]of h.entries())e.setAttributes(g[t],{opacity:n.opacity,stroke:c.color,"stroke-dasharray":n.dash,"stroke-width":c.strokeWidth??2}),g[t].style.strokeWidth=c.strokeWidth===void 0?``:String(c.strokeWidth)}else{let t=[...a.querySelectorAll(`.prism-line-path`)];m=t[0]??null;for(let e of t.slice(1))e.remove();m||(m=e.createSvgElement(`path`,{class:`prism-line-path`,fill:`none`}),a.appendChild(m)),e.setAttributes(m,{opacity:void 0,stroke:c.color,"stroke-dasharray":void 0,"stroke-width":c.strokeWidth??2}),m.style.strokeWidth=c.strokeWidth===void 0?``:String(c.strokeWidth)}let draw=t=>{if(l)for(let[n,r]of h.entries())e.setAttributes(g[n],{d:buildPath(t.slice(r.start,r.end+1),c.curve)});else e.setAttributes(m,{d:buildPath(t,c.curve)})},_=a.querySelector(`.prism-line-dots`);if(c.showPoints?_||(_=e.createSvgElement(`g`,{class:`prism-line-dots`}),a.appendChild(_)):_&&=(_.remove(),null),f===0){if(draw(s),_){for(;_.children.length>s.length;)_.removeChild(_.lastChild);for(let t=0;t<s.length;t++){let n=_.children[t];n||(n=e.createSvgElement(`circle`,{class:`prism-line-dot`}),_.appendChild(n)),e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,opacity:u[t]?.opacity,r:c.pointRadius})}}return}o.get(a)?.();let v=l?g.some(e=>e.hasAttribute(`d`)):!!m?.getAttribute(`d`),y=[],b=null;if(_){let t=_.children.length;for(let e=0;e<t;e++){let t=_.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};y.push(n),b=n}for(;_.children.length>s.length;)_.removeChild(_.lastChild);for(let t=_.children.length;t<s.length;t++){let n=e.createSvgElement(`circle`,{class:`prism-line-dot`});e.setAttributes(n,{cx:s[t].x,cy:s[t].y,fill:c.color,opacity:u[t]?.opacity,r:c.pointRadius}),_.appendChild(n)}for(let t=0;t<_.children.length;t++)e.setAttributes(_.children[t],{opacity:u[t]?.opacity})}for(let e=y.length;e<s.length;e++)y.push(b??s[e]);let x=null;function frame(t){if(c.disposalSignal?.aborted){o.delete(a);return}x===null&&(x=t);let n=Math.min(1,(t-x)/f),i=p(n),l=s.map((e,t)=>{let n=y[t]??e;return{x:r.tweenNumber(n.x,e.x,i),y:r.tweenNumber(n.y,e.y,i)}});if(draw(l),_)for(let t=0;t<s.length;t++){let n=_.children[t];n&&e.setAttributes(n,{cx:l[t].x,cy:l[t].y})}if(n<1){let e=requestAnimationFrame(frame);o.set(a,()=>cancelAnimationFrame(e))}else o.delete(a)}if(!v)draw(s);else{let e=requestAnimationFrame(frame);o.set(a,()=>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 /** Explicit width beats the `--prism-line-width` theme token. */\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 ?? 2 });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(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":"0NAqBA,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,aAAe,CAAE,CAAC,EACvF,EAAK,MAAM,YAAc,EAAQ,cAAgB,IAAA,GAAY,GAAK,O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AAM,CAAE,EAAG,UAAU,EAAQ,EAAQ,KAAK,CAAE,CAAC,MACtD,CACL,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
1
|
+
{"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 { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\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 styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\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 draw(points);\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, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = styled ? runPaths.some((p) => p.hasAttribute('d')) : !!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, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\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 draw(interpolated);\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 draw(points);\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":"kQAwBA,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,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAA,cAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAA,cAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GA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EzB,GAAG,EAAA,cAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAGF,GAAI,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,MACE,EAAiB,OAAO,CAAM,CAElC,CAEA,GAAI,CAAC,EACH,KAAK,CAAM,MACN,CACL,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DatumMark } from '../../core/datum-style';
|
|
1
2
|
import type { Point } from '../../svg/path';
|
|
2
3
|
import type { ContinuousDatum, Scale, TransitionConfig } from '../../types';
|
|
3
4
|
export interface LineRenderOptions {
|
|
@@ -5,6 +6,8 @@ export interface LineRenderOptions {
|
|
|
5
6
|
curve: 'linear' | 'monotone' | 'step';
|
|
6
7
|
/** Aborted when the owning chart is disposed: stops the transition's `requestAnimationFrame` loop from rescheduling. */
|
|
7
8
|
disposalSignal?: AbortSignal;
|
|
9
|
+
/** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */
|
|
10
|
+
marks?: readonly DatumMark[];
|
|
8
11
|
pointRadius: number;
|
|
9
12
|
showPoints: boolean;
|
|
10
13
|
/** Explicit width beats the `--prism-line-width` theme token. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"line-renderer.d.ts","sourceRoot":"","sources":["../../../src/charts/line/line-renderer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAoB,KAAK,SAAS,EAAgC,MAAM,wBAAwB,CAAC;AAExG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,wHAAwH;IACxH,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,6FAA6F;IAC7F,KAAK,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAoMjG;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAanH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{
|
|
1
|
+
import"../../_dev.js";import{createSvgElement as e,setAttributes as t}from"../../svg/element.js";import{resolveEasing as n}from"../../animation/easing.js";import{resolveMotion as r}from"../../animation/motion.js";import{tweenNumber as i}from"../../animation/tween.js";import{computeStyleRuns as a,hasStyledRuns as o}from"../../core/datum-style.js";import{linePath as s,monotonePath as c,stepPath as l}from"../../svg/path.js";var u=new WeakMap;function buildPath(e,t){return t===`monotone`?c(e):t===`step`?l(e):s(e)}function renderLine(s,c,l){let d=o(l.marks),f=l.marks??[],p=r(l.transition,0),m=p.duration,h=n(p.easing),g=null,_=[],v=[];if(d){_=a(f,c.length);let n=[...s.querySelectorAll(`.prism-line-path`)];for(let e of n.slice(_.length))e.remove();v=_.map((t,r)=>{let i=n[r];if(i)return i;let a=e(`path`,{class:`prism-line-path`,fill:`none`});return s.appendChild(a),a});for(let[e,n]of _.entries())t(v[e],{opacity:n.opacity,stroke:l.color,"stroke-dasharray":n.dash,"stroke-width":l.strokeWidth??2}),v[e].style.strokeWidth=l.strokeWidth===void 0?``:String(l.strokeWidth)}else{let n=[...s.querySelectorAll(`.prism-line-path`)];g=n[0]??null;for(let e of n.slice(1))e.remove();g||(g=e(`path`,{class:`prism-line-path`,fill:`none`}),s.appendChild(g)),t(g,{opacity:void 0,stroke:l.color,"stroke-dasharray":void 0,"stroke-width":l.strokeWidth??2}),g.style.strokeWidth=l.strokeWidth===void 0?``:String(l.strokeWidth)}let draw=e=>{if(d)for(let[n,r]of _.entries())t(v[n],{d:buildPath(e.slice(r.start,r.end+1),l.curve)});else t(g,{d:buildPath(e,l.curve)})},y=s.querySelector(`.prism-line-dots`);if(l.showPoints?y||(y=e(`g`,{class:`prism-line-dots`}),s.appendChild(y)):y&&=(y.remove(),null),m===0){if(draw(c),y){for(;y.children.length>c.length;)y.removeChild(y.lastChild);for(let n=0;n<c.length;n++){let r=y.children[n];r||(r=e(`circle`,{class:`prism-line-dot`}),y.appendChild(r)),t(r,{cx:c[n].x,cy:c[n].y,fill:l.color,opacity:f[n]?.opacity,r:l.pointRadius})}}return}u.get(s)?.();let b=d?v.some(e=>e.hasAttribute(`d`)):!!g?.getAttribute(`d`),x=[],S=null;if(y){let n=y.children.length;for(let e=0;e<n;e++){let t=y.children[e],n={x:Number(t.getAttribute(`cx`)),y:Number(t.getAttribute(`cy`))};x.push(n),S=n}for(;y.children.length>c.length;)y.removeChild(y.lastChild);for(let n=y.children.length;n<c.length;n++){let r=e(`circle`,{class:`prism-line-dot`});t(r,{cx:c[n].x,cy:c[n].y,fill:l.color,opacity:f[n]?.opacity,r:l.pointRadius}),y.appendChild(r)}for(let e=0;e<y.children.length;e++)t(y.children[e],{opacity:f[e]?.opacity})}for(let e=x.length;e<c.length;e++)x.push(S??c[e]);let C=null;function frame(e){if(l.disposalSignal?.aborted){u.delete(s);return}C===null&&(C=e);let n=Math.min(1,(e-C)/m),r=h(n),a=c.map((e,t)=>{let n=x[t]??e;return{x:i(n.x,e.x,r),y:i(n.y,e.y,r)}});if(draw(a),y)for(let e=0;e<c.length;e++){let n=y.children[e];n&&t(n,{cx:a[e].x,cy:a[e].y})}if(n<1){let e=requestAnimationFrame(frame);u.set(s,()=>cancelAnimationFrame(e))}else u.delete(s)}if(!b)draw(c);else{let e=requestAnimationFrame(frame);u.set(s,()=>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)}))}export{computePoints,renderLine};
|
|
2
2
|
//# sourceMappingURL=line-renderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-renderer.js","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 /** Explicit width beats the `--prism-line-width` theme token. */\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 ?? 2 });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(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":"yVAqBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAc,EAAO,MAAM,EAEtC,EAAO,EAAO,cAA8B,kBAAkB,EAE7D,IACH,EAAO,EAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAC1E,EAAO,YAAY,CAAI,GAGzB,EAAc,EAAM,CAAE,OAAQ,EAAQ,MAAO,eAAgB,EAAQ,aAAe,CAAE,CAAC,EACvF,EAAK,MAAM,YAAc,EAAQ,cAAgB,IAAA,GAAY,GAAK,OAAO,EAAQ,WAAW,EAE5F,IAAI,EAAY,EAAO,cAA2B,kBAAkB,EAYpE,GAVI,EAAQ,WACL,IACH,EAAY,EAAiB,IAAK,CAAE,MAAO,iBAAkB,CAAC,EAC9D,EAAO,YAAY,CAAS,GAEzB,AAEL,KADA,EAAU,OAAO,EACL,MAGV,IAAQ,EAAG,CAGb,GAFA,EAAc,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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EAAY,GAEpC,IAAM,EAAI,KAAK,IAAI,GAAI,EAAK,GAAa,CAAG,EACtC,EAAI,EAAO,CAAC,EACZ,EAAwB,EAAO,KAAK,EAAI,IAAM,CAClD,IAAM,EAAO,EAAQ,IAAM,EAE3B,MAAO,CAAE,EAAG,EAAY,EAAK,EAAG,EAAG,EAAG,CAAC,EAAG,EAAG,EAAY,EAAK,EAAG,EAAG,EAAG,CAAC,CAAE,CAC5E,CAAC,EAID,GAFA,EAAc,EAAO,CAAE,EAAG,UAAU,EAAc,EAAQ,KAAK,CAAE,CAAC,EAE9D,EACF,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAI,EAAU,SAAS,GAEzB,GAAG,EAAc,EAAG,CAAE,GAAI,EAAa,EAAE,CAAC,EAAG,GAAI,EAAa,EAAE,CAAC,CAAE,CAAC,CAC1E,CAGF,GAAI,EAAI,EAAG,CACT,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,MACE,EAAiB,OAAO,CAAM,CAElC,CAEA,GAAI,CAAC,EACH,EAAc,EAAM,CAAE,EAAG,UAAU,EAAQ,EAAQ,KAAK,CAAE,CAAC,MACtD,CACL,IAAM,EAAK,sBAAsB,KAAK,EAEtC,EAAiB,IAAI,MAAc,qBAAqB,CAAE,CAAC,CAC7D,CACF,CAEA,SAAgB,cAAc,EAAyB,EAA8B,EAAgC,CASnH,OARI,EAAK,KAAM,GAAM,EAAE,KAAO,IAAI,GAIvB,EAAK,KAAM,GAAM,OAAO,EAAE,KAAQ,QAAQ,EAI9C,EAAK,IAAK,IAAO,CACtB,EAAG,EAAO,IAAI,EAAE,GAAoB,EACpC,EAAG,EAAO,IAAI,EAAE,KAAK,CACvB,EAAE,CACJ"}
|
|
1
|
+
{"version":3,"file":"line-renderer.js","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 { computeStyleRuns, type DatumMark, hasStyledRuns, type StyleRun } from '../../core/datum-style';\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 /** Per-datum presentation parallel to `points`; styled runs split the line into subpaths. */\n marks?: readonly DatumMark[];\n pointRadius: number;\n showPoints: boolean;\n /** Explicit width beats the `--prism-line-width` theme token. */\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 styled = hasStyledRuns(options.marks);\n const marks = options.marks ?? [];\n const motion = resolveMotion(options.transition, 0);\n const dur = motion.duration;\n const easing = resolveEasing(motion.easing);\n\n let path: SVGPathElement | null = null;\n let runs: readonly StyleRun[] = [];\n let runPaths: SVGPathElement[] = [];\n\n if (styled) {\n runs = computeStyleRuns(marks, points.length);\n\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n for (const extra of existing.slice(runs.length)) extra.remove();\n\n runPaths = runs.map((_, r) => {\n const reuse = existing[r];\n\n if (reuse) return reuse;\n\n const created = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n\n parent.appendChild(created);\n\n return created;\n });\n\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], {\n opacity: run.opacity,\n stroke: options.color,\n 'stroke-dasharray': run.dash,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n runPaths[r].style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n } else {\n const existing = [...parent.querySelectorAll<SVGPathElement>('.prism-line-path')];\n\n path = existing[0] ?? null;\n\n for (const stale of existing.slice(1)) stale.remove();\n\n if (!path) {\n path = createSvgElement('path', { class: 'prism-line-path', fill: 'none' });\n parent.appendChild(path);\n }\n\n setAttributes(path, {\n opacity: undefined,\n stroke: options.color,\n 'stroke-dasharray': undefined,\n 'stroke-width': options.strokeWidth ?? 2,\n });\n path.style.strokeWidth = options.strokeWidth === undefined ? '' : String(options.strokeWidth);\n }\n\n const draw = (pts: Point[]): void => {\n if (styled) {\n for (const [r, run] of runs.entries()) {\n setAttributes(runPaths[r], { d: buildPath(pts.slice(run.start, run.end + 1), options.curve) });\n }\n } else {\n setAttributes(path!, { d: buildPath(pts, options.curve) });\n }\n };\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 draw(points);\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, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n }\n }\n\n return;\n }\n\n activeAnimations.get(parent)?.();\n\n const hasExisting = styled ? runPaths.some((p) => p.hasAttribute('d')) : !!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, {\n cx: points[i].x,\n cy: points[i].y,\n fill: options.color,\n opacity: marks[i]?.opacity,\n r: options.pointRadius,\n });\n dotsGroup.appendChild(c);\n }\n\n for (let i = 0; i < dotsGroup.children.length; i++) {\n setAttributes(dotsGroup.children[i] as SVGCircleElement, { opacity: marks[i]?.opacity });\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 draw(interpolated);\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 draw(points);\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":"yaAwBA,IAAM,EAAmB,IAAI,QAE7B,SAAS,UAAU,EAAc,EAA2C,CAC1E,OAAO,IAAU,WAAa,EAAa,CAAG,EAAI,IAAU,OAAS,EAAS,CAAG,EAAI,EAAS,CAAG,CACnG,CAEA,SAAgB,WAAW,EAAqB,EAAiB,EAAkC,CACjG,IAAM,EAAS,EAAc,EAAQ,KAAK,EACpC,EAAQ,EAAQ,OAAS,CAAC,EAC1B,EAAS,EAAc,EAAQ,WAAY,CAAC,EAC5C,EAAM,EAAO,SACb,EAAS,EAAc,EAAO,MAAM,EAEtC,EAA8B,KAC9B,EAA4B,CAAC,EAC7B,EAA6B,CAAC,EAElC,GAAI,EAAQ,CACV,EAAO,EAAiB,EAAO,EAAO,MAAM,EAE5C,IAAM,EAAW,CAAC,GAAG,EAAO,iBAAiC,kBAAkB,CAAC,EAEhF,IAAK,IAAM,KAAS,EAAS,MAAM,EAAK,MAAM,EAAG,EAAM,OAAO,EAE9D,EAAW,EAAK,KAAK,EAAG,IAAM,CAC5B,IAAM,EAAQ,EAAS,GAEvB,GAAI,EAAO,OAAO,EAElB,IAAM,EAAU,EAAiB,OAAQ,CAAE,MAAO,kBAAmB,KAAM,MAAO,CAAC,EAInF,OAFA,EAAO,YAAY,CAAO,EAEnB,CACT,CAAC,EAED,IAAK,GAAM,CAAC,EAAG,KAAQ,EAAK,QAAQ,EAClC,EAAc,EAAS,GAAI,CACzB,QAAS,EAAI,QACb,OAAQ,EAAQ,MAChB,mBAAoB,EAAI,KACxB,eAAgB,EAAQ,aAAe,CACzC,CAA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