@vielzeug/prism 1.1.1
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/README.md +83 -0
- package/dist/_dev.cjs +2 -0
- package/dist/_dev.cjs.map +1 -0
- package/dist/_dev.d.ts +2 -0
- package/dist/_dev.d.ts.map +1 -0
- package/dist/_dev.js +12 -0
- package/dist/_dev.js.map +1 -0
- package/dist/animation/easing.cjs +2 -0
- package/dist/animation/easing.cjs.map +1 -0
- package/dist/animation/easing.d.ts +4 -0
- package/dist/animation/easing.d.ts.map +1 -0
- package/dist/animation/easing.js +14 -0
- package/dist/animation/easing.js.map +1 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/transition.cjs +2 -0
- package/dist/animation/transition.cjs.map +1 -0
- package/dist/animation/transition.d.ts +15 -0
- package/dist/animation/transition.d.ts.map +1 -0
- package/dist/animation/transition.js +28 -0
- package/dist/animation/transition.js.map +1 -0
- package/dist/animation/tween.cjs +2 -0
- package/dist/animation/tween.cjs.map +1 -0
- package/dist/animation/tween.d.ts +3 -0
- package/dist/animation/tween.d.ts.map +1 -0
- package/dist/animation/tween.js +8 -0
- package/dist/animation/tween.js.map +1 -0
- package/dist/axes/axis.cjs +2 -0
- package/dist/axes/axis.cjs.map +1 -0
- package/dist/axes/axis.d.ts +15 -0
- package/dist/axes/axis.d.ts.map +1 -0
- package/dist/axes/axis.js +60 -0
- package/dist/axes/axis.js.map +1 -0
- package/dist/axes/grid.cjs +2 -0
- package/dist/axes/grid.cjs.map +1 -0
- package/dist/axes/grid.d.ts +4 -0
- package/dist/axes/grid.d.ts.map +1 -0
- package/dist/axes/grid.js +30 -0
- package/dist/axes/grid.js.map +1 -0
- package/dist/axes/index.d.ts +3 -0
- package/dist/axes/index.d.ts.map +1 -0
- package/dist/axes/scale-utils.cjs +2 -0
- package/dist/axes/scale-utils.cjs.map +1 -0
- package/dist/axes/scale-utils.d.ts +17 -0
- package/dist/axes/scale-utils.d.ts.map +1 -0
- package/dist/axes/scale-utils.js +11 -0
- package/dist/axes/scale-utils.js.map +1 -0
- package/dist/axes/types.d.ts +2 -0
- package/dist/axes/types.d.ts.map +1 -0
- package/dist/charts/area/area-chart.cjs +2 -0
- package/dist/charts/area/area-chart.cjs.map +1 -0
- package/dist/charts/area/area-chart.d.ts +3 -0
- package/dist/charts/area/area-chart.d.ts.map +1 -0
- package/dist/charts/area/area-chart.js +58 -0
- package/dist/charts/area/area-chart.js.map +1 -0
- package/dist/charts/area/area-renderer.cjs +2 -0
- package/dist/charts/area/area-renderer.cjs.map +1 -0
- package/dist/charts/area/area-renderer.d.ts +14 -0
- package/dist/charts/area/area-renderer.d.ts.map +1 -0
- package/dist/charts/area/area-renderer.js +73 -0
- package/dist/charts/area/area-renderer.js.map +1 -0
- package/dist/charts/area/area-types.d.ts +2 -0
- package/dist/charts/area/area-types.d.ts.map +1 -0
- package/dist/charts/area/index.d.ts +2 -0
- package/dist/charts/area/index.d.ts.map +1 -0
- package/dist/charts/bar/bar-chart.cjs +2 -0
- package/dist/charts/bar/bar-chart.cjs.map +1 -0
- package/dist/charts/bar/bar-chart.d.ts +3 -0
- package/dist/charts/bar/bar-chart.d.ts.map +1 -0
- package/dist/charts/bar/bar-chart.js +151 -0
- package/dist/charts/bar/bar-chart.js.map +1 -0
- package/dist/charts/bar/bar-hit-test.cjs +2 -0
- package/dist/charts/bar/bar-hit-test.cjs.map +1 -0
- package/dist/charts/bar/bar-hit-test.d.ts +12 -0
- package/dist/charts/bar/bar-hit-test.d.ts.map +1 -0
- package/dist/charts/bar/bar-hit-test.js +29 -0
- package/dist/charts/bar/bar-hit-test.js.map +1 -0
- package/dist/charts/bar/bar-renderer.cjs +2 -0
- package/dist/charts/bar/bar-renderer.cjs.map +1 -0
- package/dist/charts/bar/bar-renderer.d.ts +19 -0
- package/dist/charts/bar/bar-renderer.d.ts.map +1 -0
- package/dist/charts/bar/bar-renderer.js +107 -0
- package/dist/charts/bar/bar-renderer.js.map +1 -0
- package/dist/charts/bar/bar-scale-context.d.ts +11 -0
- package/dist/charts/bar/bar-scale-context.d.ts.map +1 -0
- package/dist/charts/bar/bar-types.d.ts +2 -0
- package/dist/charts/bar/bar-types.d.ts.map +1 -0
- package/dist/charts/bar/index.d.ts +2 -0
- package/dist/charts/bar/index.d.ts.map +1 -0
- package/dist/charts/index.d.ts +6 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/line/index.d.ts +2 -0
- package/dist/charts/line/index.d.ts.map +1 -0
- package/dist/charts/line/line-chart.cjs +2 -0
- package/dist/charts/line/line-chart.cjs.map +1 -0
- package/dist/charts/line/line-chart.d.ts +3 -0
- package/dist/charts/line/line-chart.d.ts.map +1 -0
- package/dist/charts/line/line-chart.js +59 -0
- package/dist/charts/line/line-chart.js.map +1 -0
- package/dist/charts/line/line-renderer.cjs +2 -0
- package/dist/charts/line/line-renderer.cjs.map +1 -0
- package/dist/charts/line/line-renderer.d.ts +15 -0
- package/dist/charts/line/line-renderer.d.ts.map +1 -0
- package/dist/charts/line/line-renderer.js +100 -0
- package/dist/charts/line/line-renderer.js.map +1 -0
- package/dist/charts/line/line-types.d.ts +2 -0
- package/dist/charts/line/line-types.d.ts.map +1 -0
- package/dist/charts/pie/index.d.ts +2 -0
- package/dist/charts/pie/index.d.ts.map +1 -0
- package/dist/charts/pie/pie-chart.cjs +2 -0
- package/dist/charts/pie/pie-chart.cjs.map +1 -0
- package/dist/charts/pie/pie-chart.d.ts +3 -0
- package/dist/charts/pie/pie-chart.d.ts.map +1 -0
- package/dist/charts/pie/pie-chart.js +156 -0
- package/dist/charts/pie/pie-chart.js.map +1 -0
- package/dist/charts/pie/pie-renderer.cjs +2 -0
- package/dist/charts/pie/pie-renderer.cjs.map +1 -0
- package/dist/charts/pie/pie-renderer.d.ts +23 -0
- package/dist/charts/pie/pie-renderer.d.ts.map +1 -0
- package/dist/charts/pie/pie-renderer.js +77 -0
- package/dist/charts/pie/pie-renderer.js.map +1 -0
- package/dist/charts/sparkline/index.d.ts +2 -0
- package/dist/charts/sparkline/index.d.ts.map +1 -0
- package/dist/charts/sparkline/sparkline.cjs +2 -0
- package/dist/charts/sparkline/sparkline.cjs.map +1 -0
- package/dist/charts/sparkline/sparkline.d.ts +3 -0
- package/dist/charts/sparkline/sparkline.d.ts.map +1 -0
- package/dist/charts/sparkline/sparkline.js +187 -0
- package/dist/charts/sparkline/sparkline.js.map +1 -0
- package/dist/core/cartesian-scales.cjs +2 -0
- package/dist/core/cartesian-scales.cjs.map +1 -0
- package/dist/core/cartesian-scales.d.ts +4 -0
- package/dist/core/cartesian-scales.d.ts.map +1 -0
- package/dist/core/cartesian-scales.js +54 -0
- package/dist/core/cartesian-scales.js.map +1 -0
- package/dist/core/chart-base.cjs +2 -0
- package/dist/core/chart-base.cjs.map +1 -0
- package/dist/core/chart-base.d.ts +14 -0
- package/dist/core/chart-base.d.ts.map +1 -0
- package/dist/core/chart-base.js +60 -0
- package/dist/core/chart-base.js.map +1 -0
- package/dist/core/chart-scaffold.cjs +2 -0
- package/dist/core/chart-scaffold.cjs.map +1 -0
- package/dist/core/chart-scaffold.d.ts +54 -0
- package/dist/core/chart-scaffold.d.ts.map +1 -0
- package/dist/core/chart-scaffold.js +104 -0
- package/dist/core/chart-scaffold.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/layout.cjs +2 -0
- package/dist/core/layout.cjs.map +1 -0
- package/dist/core/layout.d.ts +7 -0
- package/dist/core/layout.d.ts.map +1 -0
- package/dist/core/layout.js +23 -0
- package/dist/core/layout.js.map +1 -0
- package/dist/core/responsive.cjs +2 -0
- package/dist/core/responsive.cjs.map +1 -0
- package/dist/core/responsive.d.ts +2 -0
- package/dist/core/responsive.d.ts.map +1 -0
- package/dist/core/responsive.js +20 -0
- package/dist/core/responsive.js.map +1 -0
- package/dist/devtools/index.d.ts +52 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools.cjs +2 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.js +19 -0
- package/dist/devtools.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/interaction/crosshair.cjs +2 -0
- package/dist/interaction/crosshair.cjs.map +1 -0
- package/dist/interaction/crosshair.d.ts +13 -0
- package/dist/interaction/crosshair.d.ts.map +1 -0
- package/dist/interaction/crosshair.js +46 -0
- package/dist/interaction/crosshair.js.map +1 -0
- package/dist/interaction/events.cjs +2 -0
- package/dist/interaction/events.cjs.map +1 -0
- package/dist/interaction/events.d.ts +3 -0
- package/dist/interaction/events.d.ts.map +1 -0
- package/dist/interaction/events.js +12 -0
- package/dist/interaction/events.js.map +1 -0
- package/dist/interaction/hit-test.cjs +2 -0
- package/dist/interaction/hit-test.cjs.map +1 -0
- package/dist/interaction/hit-test.d.ts +3 -0
- package/dist/interaction/hit-test.d.ts.map +1 -0
- package/dist/interaction/hit-test.js +14 -0
- package/dist/interaction/hit-test.js.map +1 -0
- package/dist/interaction/index.d.ts +9 -0
- package/dist/interaction/index.d.ts.map +1 -0
- package/dist/interaction/legend.cjs +2 -0
- package/dist/interaction/legend.cjs.map +1 -0
- package/dist/interaction/legend.d.ts +12 -0
- package/dist/interaction/legend.d.ts.map +1 -0
- package/dist/interaction/legend.js +31 -0
- package/dist/interaction/legend.js.map +1 -0
- package/dist/interaction/series-interaction.cjs +2 -0
- package/dist/interaction/series-interaction.cjs.map +1 -0
- package/dist/interaction/series-interaction.d.ts +18 -0
- package/dist/interaction/series-interaction.d.ts.map +1 -0
- package/dist/interaction/series-interaction.js +58 -0
- package/dist/interaction/series-interaction.js.map +1 -0
- package/dist/interaction/tooltip.cjs +2 -0
- package/dist/interaction/tooltip.cjs.map +1 -0
- package/dist/interaction/tooltip.d.ts +10 -0
- package/dist/interaction/tooltip.d.ts.map +1 -0
- package/dist/interaction/tooltip.js +53 -0
- package/dist/interaction/tooltip.js.map +1 -0
- package/dist/prism.cjs +2 -0
- package/dist/prism.cjs.map +1 -0
- package/dist/prism.iife.js +2 -0
- package/dist/prism.iife.js.map +1 -0
- package/dist/prism.js +2 -0
- package/dist/prism.js.map +1 -0
- package/dist/scales/band.cjs +2 -0
- package/dist/scales/band.cjs.map +1 -0
- package/dist/scales/band.d.ts +3 -0
- package/dist/scales/band.d.ts.map +1 -0
- package/dist/scales/band.js +40 -0
- package/dist/scales/band.js.map +1 -0
- package/dist/scales/index.d.ts +4 -0
- package/dist/scales/index.d.ts.map +1 -0
- package/dist/scales/linear.cjs +2 -0
- package/dist/scales/linear.cjs.map +1 -0
- package/dist/scales/linear.d.ts +4 -0
- package/dist/scales/linear.d.ts.map +1 -0
- package/dist/scales/linear.js +44 -0
- package/dist/scales/linear.js.map +1 -0
- package/dist/scales/time.cjs +2 -0
- package/dist/scales/time.cjs.map +1 -0
- package/dist/scales/time.d.ts +4 -0
- package/dist/scales/time.d.ts.map +1 -0
- package/dist/scales/time.js +62 -0
- package/dist/scales/time.js.map +1 -0
- package/dist/scales/types.d.ts +19 -0
- package/dist/scales/types.d.ts.map +1 -0
- package/dist/svg/element.cjs +2 -0
- package/dist/svg/element.cjs.map +1 -0
- package/dist/svg/element.d.ts +4 -0
- package/dist/svg/element.d.ts.map +1 -0
- package/dist/svg/element.js +23 -0
- package/dist/svg/element.js.map +1 -0
- package/dist/svg/index.d.ts +5 -0
- package/dist/svg/index.d.ts.map +1 -0
- package/dist/svg/path.cjs +2 -0
- package/dist/svg/path.cjs.map +1 -0
- package/dist/svg/path.d.ts +9 -0
- package/dist/svg/path.d.ts.map +1 -0
- package/dist/svg/path.js +49 -0
- package/dist/svg/path.js.map +1 -0
- package/dist/svg/text.cjs +2 -0
- package/dist/svg/text.cjs.map +1 -0
- package/dist/svg/text.d.ts +7 -0
- package/dist/svg/text.d.ts.map +1 -0
- package/dist/svg/text.js +10 -0
- package/dist/svg/text.js.map +1 -0
- package/dist/theme/index.cjs +2 -0
- package/dist/theme/index.cjs.map +1 -0
- package/dist/theme/index.d.ts +6 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme/prism.css +342 -0
- package/dist/types.d.ts +204 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vielzeug/prism — debug utilities for chart visualisation.
|
|
3
|
+
*
|
|
4
|
+
* Import from the dedicated sub-path so debug code is tree-shaken from
|
|
5
|
+
* production bundles:
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { debugChart } from '@vielzeug/prism/devtools';
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Internal validation warnings (misuse of the public API) are emitted
|
|
11
|
+
* automatically in development builds and live in the private `src/_dev.ts`
|
|
12
|
+
* module. They are not part of this sub-path.
|
|
13
|
+
*/
|
|
14
|
+
import type { ChartHandle } from '../types';
|
|
15
|
+
/** Options for {@link debugChart}. */
|
|
16
|
+
export interface DebugChartOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Label used in log prefixes. Defaults to `'chart'`, producing `[prism:chart]`.
|
|
19
|
+
* Useful when debugging multiple charts on the same page so their log output
|
|
20
|
+
* can be distinguished:
|
|
21
|
+
* ```ts
|
|
22
|
+
* debugChart(createLineChart(el, config), { label: 'revenue' });
|
|
23
|
+
* // [prism:revenue] mounted
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
label?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wraps an already-created {@link ChartHandle} with lifecycle logging pre-wired to
|
|
30
|
+
* `console.debug`, imported from a dedicated sub-path so `console.debug` references
|
|
31
|
+
* and the `ResizeObserver` it uses are tree-shaken from production bundles when this
|
|
32
|
+
* sub-path is not imported.
|
|
33
|
+
*
|
|
34
|
+
* Logs the chart's mount, every resize (via its own `ResizeObserver` on `handle.el`,
|
|
35
|
+
* independent of the chart's internal one), and disposal, each with `[prism:<label>]`
|
|
36
|
+
* prefixes. Returns the same handle unchanged so it can wrap any `create*Chart()` call
|
|
37
|
+
* in place.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { createLineChart } from '@vielzeug/prism';
|
|
42
|
+
* import { debugChart } from '@vielzeug/prism/devtools';
|
|
43
|
+
*
|
|
44
|
+
* const chart = debugChart(createLineChart(container, config), { label: 'revenue' });
|
|
45
|
+
* // [prism:revenue] mounted
|
|
46
|
+
* // [prism:revenue] resized 600×300
|
|
47
|
+
* chart.dispose();
|
|
48
|
+
* // [prism:revenue] disposed
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function debugChart<T extends ChartHandle>(handle: T, options?: DebugChartOptions): T;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,CAAC,CA2B3F"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){let n=`[prism:${t?.label??`chart`}]`;console.debug(`${n} mounted`);let r=new ResizeObserver(e=>{let t=e[0];if(t){let{height:e,width:r}=t.contentRect;console.debug(`${n} resized ${Math.round(r)}×${Math.round(e)}`)}});return r.observe(e.el),e.disposalSignal.addEventListener(`abort`,()=>{r.disconnect(),console.debug(`${n} disposed`)},{once:!0}),e}exports.debugChart=e;
|
|
2
|
+
//# sourceMappingURL=devtools.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.cjs","names":[],"sources":["../src/devtools/index.ts"],"sourcesContent":["/**\n * @vielzeug/prism — debug utilities for chart visualisation.\n *\n * Import from the dedicated sub-path so debug code is tree-shaken from\n * production bundles:\n * ```ts\n * import { debugChart } from '@vielzeug/prism/devtools';\n * ```\n *\n * Internal validation warnings (misuse of the public API) are emitted\n * automatically in development builds and live in the private `src/_dev.ts`\n * module. They are not part of this sub-path.\n */\n\nimport type { ChartHandle } from '../types';\n\n/** Options for {@link debugChart}. */\nexport interface DebugChartOptions {\n /**\n * Label used in log prefixes. Defaults to `'chart'`, producing `[prism:chart]`.\n * Useful when debugging multiple charts on the same page so their log output\n * can be distinguished:\n * ```ts\n * debugChart(createLineChart(el, config), { label: 'revenue' });\n * // [prism:revenue] mounted\n * ```\n */\n label?: string;\n}\n\n/**\n * Wraps an already-created {@link ChartHandle} with lifecycle logging pre-wired to\n * `console.debug`, imported from a dedicated sub-path so `console.debug` references\n * and the `ResizeObserver` it uses are tree-shaken from production bundles when this\n * sub-path is not imported.\n *\n * Logs the chart's mount, every resize (via its own `ResizeObserver` on `handle.el`,\n * independent of the chart's internal one), and disposal, each with `[prism:<label>]`\n * prefixes. Returns the same handle unchanged so it can wrap any `create*Chart()` call\n * in place.\n *\n * @example\n * ```ts\n * import { createLineChart } from '@vielzeug/prism';\n * import { debugChart } from '@vielzeug/prism/devtools';\n *\n * const chart = debugChart(createLineChart(container, config), { label: 'revenue' });\n * // [prism:revenue] mounted\n * // [prism:revenue] resized 600×300\n * chart.dispose();\n * // [prism:revenue] disposed\n * ```\n */\nexport function debugChart<T extends ChartHandle>(handle: T, options?: DebugChartOptions): T {\n const prefix = `[prism:${options?.label ?? 'chart'}]`;\n\n console.debug(`${prefix} mounted`);\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0];\n\n if (entry) {\n const { height, width } = entry.contentRect;\n\n console.debug(`${prefix} resized ${Math.round(width)}×${Math.round(height)}`);\n }\n });\n\n resizeObserver.observe(handle.el);\n\n handle.disposalSignal.addEventListener(\n 'abort',\n () => {\n resizeObserver.disconnect();\n console.debug(`${prefix} disposed`);\n },\n { once: true },\n );\n\n return handle;\n}\n"],"mappings":"mEAqDA,SAAgB,EAAkC,EAAW,EAAgC,CAC3F,IAAM,EAAS,UAAU,GAAS,OAAS,QAAQ,GAEnD,QAAQ,MAAM,GAAG,EAAO,SAAS,EAEjC,IAAM,EAAiB,IAAI,eAAgB,GAAY,CACrD,IAAM,EAAQ,EAAQ,GAEtB,GAAI,EAAO,CACT,GAAM,CAAE,SAAQ,SAAU,EAAM,YAEhC,QAAQ,MAAM,GAAG,EAAO,YAAY,KAAK,MAAM,CAAK,EAAE,GAAG,KAAK,MAAM,CAAM,GAAG,CAC/E,CACF,CAAC,EAaD,OAXA,EAAe,QAAQ,EAAO,EAAE,EAEhC,EAAO,eAAe,iBACpB,YACM,CACJ,EAAe,WAAW,EAC1B,QAAQ,MAAM,GAAG,EAAO,UAAU,CACpC,EACA,CAAE,KAAM,EAAK,CACf,EAEO,CACT"}
|
package/dist/devtools.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/devtools/index.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
let n = `[prism:${t?.label ?? "chart"}]`;
|
|
4
|
+
console.debug(`${n} mounted`);
|
|
5
|
+
let r = new ResizeObserver((e) => {
|
|
6
|
+
let t = e[0];
|
|
7
|
+
if (t) {
|
|
8
|
+
let { height: e, width: r } = t.contentRect;
|
|
9
|
+
console.debug(`${n} resized ${Math.round(r)}×${Math.round(e)}`);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return r.observe(e.el), e.disposalSignal.addEventListener("abort", () => {
|
|
13
|
+
r.disconnect(), console.debug(`${n} disposed`);
|
|
14
|
+
}, { once: !0 }), e;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { e as debugChart };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=devtools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools/index.ts"],"sourcesContent":["/**\n * @vielzeug/prism — debug utilities for chart visualisation.\n *\n * Import from the dedicated sub-path so debug code is tree-shaken from\n * production bundles:\n * ```ts\n * import { debugChart } from '@vielzeug/prism/devtools';\n * ```\n *\n * Internal validation warnings (misuse of the public API) are emitted\n * automatically in development builds and live in the private `src/_dev.ts`\n * module. They are not part of this sub-path.\n */\n\nimport type { ChartHandle } from '../types';\n\n/** Options for {@link debugChart}. */\nexport interface DebugChartOptions {\n /**\n * Label used in log prefixes. Defaults to `'chart'`, producing `[prism:chart]`.\n * Useful when debugging multiple charts on the same page so their log output\n * can be distinguished:\n * ```ts\n * debugChart(createLineChart(el, config), { label: 'revenue' });\n * // [prism:revenue] mounted\n * ```\n */\n label?: string;\n}\n\n/**\n * Wraps an already-created {@link ChartHandle} with lifecycle logging pre-wired to\n * `console.debug`, imported from a dedicated sub-path so `console.debug` references\n * and the `ResizeObserver` it uses are tree-shaken from production bundles when this\n * sub-path is not imported.\n *\n * Logs the chart's mount, every resize (via its own `ResizeObserver` on `handle.el`,\n * independent of the chart's internal one), and disposal, each with `[prism:<label>]`\n * prefixes. Returns the same handle unchanged so it can wrap any `create*Chart()` call\n * in place.\n *\n * @example\n * ```ts\n * import { createLineChart } from '@vielzeug/prism';\n * import { debugChart } from '@vielzeug/prism/devtools';\n *\n * const chart = debugChart(createLineChart(container, config), { label: 'revenue' });\n * // [prism:revenue] mounted\n * // [prism:revenue] resized 600×300\n * chart.dispose();\n * // [prism:revenue] disposed\n * ```\n */\nexport function debugChart<T extends ChartHandle>(handle: T, options?: DebugChartOptions): T {\n const prefix = `[prism:${options?.label ?? 'chart'}]`;\n\n console.debug(`${prefix} mounted`);\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0];\n\n if (entry) {\n const { height, width } = entry.contentRect;\n\n console.debug(`${prefix} resized ${Math.round(width)}×${Math.round(height)}`);\n }\n });\n\n resizeObserver.observe(handle.el);\n\n handle.disposalSignal.addEventListener(\n 'abort',\n () => {\n resizeObserver.disconnect();\n console.debug(`${prefix} disposed`);\n },\n { once: true },\n );\n\n return handle;\n}\n"],"mappings":";AAqDA,SAAgB,EAAkC,GAAW,GAAgC;CAC3F,IAAM,IAAS,UAAU,GAAS,SAAS,QAAQ;CAEnD,QAAQ,MAAM,GAAG,EAAO,SAAS;CAEjC,IAAM,IAAiB,IAAI,gBAAgB,MAAY;EACrD,IAAM,IAAQ,EAAQ;EAEtB,IAAI,GAAO;GACT,IAAM,EAAE,WAAQ,aAAU,EAAM;GAEhC,QAAQ,MAAM,GAAG,EAAO,YAAY,KAAK,MAAM,CAAK,EAAE,GAAG,KAAK,MAAM,CAAM,GAAG;EAC/E;CACF,CAAC;CAaD,OAXA,EAAe,QAAQ,EAAO,EAAE,GAEhC,EAAO,eAAe,iBACpB,eACM;EAEJ,AADA,EAAe,WAAW,GAC1B,QAAQ,MAAM,GAAG,EAAO,UAAU;CACpC,GACA,EAAE,MAAM,GAAK,CACf,GAEO;AACT"}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},t=class extends e{},n=class extends e{};exports.PrismDisposedError=t,exports.PrismError=e,exports.PrismRenderError=n;
|
|
2
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all prism errors. Use `instanceof PrismError` to catch any prism-originated error. */\nexport class PrismError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is PrismError {\n return err instanceof PrismError;\n }\n}\n\n/**\n * Reserved for future disposal-sensitive APIs on `ChartHandle`. Currently, calling\n * `dispose()` more than once is a documented no-op rather than an error — no code path\n * throws this yet.\n */\nexport class PrismDisposedError extends PrismError {}\n\n/** Thrown when a chart is given a structurally invalid configuration it cannot render at all (e.g. a non-Element `container`). Recoverable issues like empty or malformed data emit a dev-mode warning instead — see the package docs for details. */\nexport class PrismRenderError extends PrismError {}\n"],"mappings":"AACA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,IAAI,OAAO,KACvB,OAAO,eAAe,KAAM,IAAI,OAAO,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAOa,EAAb,cAAwC,CAAW,CAAC,EAGvC,EAAb,cAAsC,CAAW,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Base class for all prism errors. Use `instanceof PrismError` to catch any prism-originated error. */
|
|
2
|
+
export declare class PrismError extends Error {
|
|
3
|
+
constructor(message: string, opts?: ErrorOptions);
|
|
4
|
+
static is(err: unknown): err is PrismError;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Reserved for future disposal-sensitive APIs on `ChartHandle`. Currently, calling
|
|
8
|
+
* `dispose()` more than once is a documented no-op rather than an error — no code path
|
|
9
|
+
* throws this yet.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PrismDisposedError extends PrismError {
|
|
12
|
+
}
|
|
13
|
+
/** Thrown when a chart is given a structurally invalid configuration it cannot render at all (e.g. a non-Element `container`). Recoverable issues like empty or malformed data emit a dev-mode warning instead — see the package docs for details. */
|
|
14
|
+
export declare class PrismRenderError extends PrismError {
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;IAMhD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,UAAU;CAG3C;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;CAAG;AAErD,sPAAsP;AACtP,qBAAa,gBAAiB,SAAQ,UAAU;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var e = class e extends Error {
|
|
3
|
+
constructor(e, t) {
|
|
4
|
+
super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
+
}
|
|
6
|
+
static is(t) {
|
|
7
|
+
return t instanceof e;
|
|
8
|
+
}
|
|
9
|
+
}, t = class extends e {}, n = class extends e {};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as PrismDisposedError, e as PrismError, n as PrismRenderError };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Base class for all prism errors. Use `instanceof PrismError` to catch any prism-originated error. */\nexport class PrismError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is PrismError {\n return err instanceof PrismError;\n }\n}\n\n/**\n * Reserved for future disposal-sensitive APIs on `ChartHandle`. Currently, calling\n * `dispose()` more than once is a documented no-op rather than an error — no code path\n * throws this yet.\n */\nexport class PrismDisposedError extends PrismError {}\n\n/** Thrown when a chart is given a structurally invalid configuration it cannot render at all (e.g. a non-Element `container`). Recoverable issues like empty or malformed data emit a dev-mode warning instead — see the package docs for details. */\nexport class PrismRenderError extends PrismError {}\n"],"mappings":";AACA,IAAa,IAAb,MAAa,UAAmB,MAAM;CACpC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAM,GAAS,CAAI,GACnB,KAAK,OAAO,IAAI,OAAO,MACvB,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;CAEA,OAAO,GAAG,GAAiC;EACzC,OAAO,aAAe;CACxB;AACF,GAOa,IAAb,cAAwC,EAAW,CAAC,GAGvC,IAAb,cAAsC,EAAW,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./scales/linear.cjs"),n=require("./scales/time.cjs"),r=require("./theme/index.cjs"),i=require("./charts/area/area-chart.cjs"),a=require("./scales/band.cjs"),o=require("./animation/transition.cjs"),s=require("./charts/bar/bar-chart.cjs"),c=require("./charts/line/line-chart.cjs"),l=require("./charts/pie/pie-chart.cjs"),u=require("./charts/sparkline/sparkline.cjs");exports.PrismDisposedError=e.PrismDisposedError,exports.PrismError=e.PrismError,exports.PrismRenderError=e.PrismRenderError,exports.animate=o.animate,exports.bandScale=a.bandScale,exports.createAreaChart=i.createAreaChart,exports.createBarChart=s.createBarChart,exports.createLineChart=c.createLineChart,exports.createPieChart=l.createPieChart,exports.createSparkline=u.createSparkline,exports.linearScale=t.linearScale,exports.resetTheme=r.resetTheme,exports.seriesColor=r.seriesColor,exports.setTheme=r.setTheme,exports.timeScale=n.timeScale;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type { AreaChartConfig, AreaSeriesConfig, AxisConfig, AxisPosition, BandScale, BarChartConfig, BarSeriesConfig, BarVariant, BaseChartConfig, ChartDimensions, ChartEvent, ChartHandle, ChartMargin, ChartPlugin, ChartPluginContext, CrosshairConfig, Datum, GridConfig, LegendConfig, LegendPosition, LineChartConfig, LineSeriesConfig, MaybeSignal, PieChartConfig, PieSliceConfig, PieVariant, PrismTheme, Scale, Series, SparklineConfig, SparklineVariant, StackSegment, TooltipConfig, TransitionConfig, } from './types';
|
|
2
|
+
export { PrismDisposedError, PrismError, PrismRenderError } from './errors';
|
|
3
|
+
export { createAreaChart } from './charts/area';
|
|
4
|
+
export { createBarChart } from './charts/bar';
|
|
5
|
+
export { createLineChart } from './charts/line';
|
|
6
|
+
export { createPieChart } from './charts/pie';
|
|
7
|
+
export { createSparkline } from './charts/sparkline';
|
|
8
|
+
export { bandScale } from './scales/band';
|
|
9
|
+
export { linearScale } from './scales/linear';
|
|
10
|
+
export { timeScale } from './scales/time';
|
|
11
|
+
export { animate } from './animation/transition';
|
|
12
|
+
export type { AnimationTarget } from './animation/transition';
|
|
13
|
+
export type { EasingFn } from './animation/easing';
|
|
14
|
+
export type { LegendState } from './interaction/legend';
|
|
15
|
+
export type { TooltipState } from './interaction/tooltip';
|
|
16
|
+
export type { Point } from './svg/path';
|
|
17
|
+
export type { ChartEventHandlers, RadialScaffoldContext, ScaffoldContext, ScaffoldGroups } from './core/chart-scaffold';
|
|
18
|
+
export { resetTheme, seriesColor, setTheme } from './theme';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,eAAe,EACf,UAAU,EACV,eAAe,EACf,eAAe,EACf,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,KAAK,EACL,UAAU,EACV,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,cAAc,EACd,UAAU,EACV,UAAU,EACV,KAAK,EACL,MAAM,EACN,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAGnD,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1D,YAAY,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIxC,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGxH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismDisposedError as e, PrismError as t, PrismRenderError as n } from "./errors.js";
|
|
2
|
+
import { linearScale as r } from "./scales/linear.js";
|
|
3
|
+
import { timeScale as i } from "./scales/time.js";
|
|
4
|
+
import { resetTheme as a, seriesColor as o, setTheme as s } from "./theme/index.js";
|
|
5
|
+
import { createAreaChart as c } from "./charts/area/area-chart.js";
|
|
6
|
+
import { bandScale as l } from "./scales/band.js";
|
|
7
|
+
import { animate as u } from "./animation/transition.js";
|
|
8
|
+
import { createBarChart as d } from "./charts/bar/bar-chart.js";
|
|
9
|
+
import { createLineChart as f } from "./charts/line/line-chart.js";
|
|
10
|
+
import { createPieChart as p } from "./charts/pie/pie-chart.js";
|
|
11
|
+
import { createSparkline as m } from "./charts/sparkline/sparkline.js";
|
|
12
|
+
export { e as PrismDisposedError, t as PrismError, n as PrismRenderError, u as animate, l as bandScale, c as createAreaChart, d as createBarChart, f as createLineChart, p as createPieChart, m as createSparkline, r as linearScale, a as resetTheme, o as seriesColor, s as setTheme, i as timeScale };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../svg/element.cjs");function t(t,n){let r=n===!0||n?.vertical!==!1,i=n!==!0&&n?.horizontal===!0,a=n===!0||n?.snap!==!1,o=e.createSvgElement(`g`,{"aria-hidden":`true`,class:`prism-crosshair`,style:`display:none`}),s=r?e.createSvgElement(`line`,{class:`prism-crosshair-v`,"stroke-dasharray":`var(--prism-crosshair-dash, 4 2)`}):null,c=i?e.createSvgElement(`line`,{class:`prism-crosshair-h`,"stroke-dasharray":`var(--prism-crosshair-dash, 4 2)`}):null;s&&o.appendChild(s),c&&o.appendChild(c),t.appendChild(o);let l=e.createSvgElement(`text`,{"aria-live":`polite`,class:`prism-crosshair-live`,role:`status`,x:-9999,y:-9999});return t.appendChild(l),{hide(){o.style.display=`none`,l.textContent=``},show(t,n,r,i,a){o.style.display=``,s&&e.setAttributes(s,{x1:t,x2:t,y1:0,y2:i}),c&&e.setAttributes(c,{x1:0,x2:r,y1:n,y2:n}),a!==void 0&&(l.textContent=a)},snap:a}}exports.createCrosshair=t;
|
|
2
|
+
//# sourceMappingURL=crosshair.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crosshair.cjs","names":[],"sources":["../../src/interaction/crosshair.ts"],"sourcesContent":["import type { CrosshairConfig } from '../types';\n\nimport { createSvgElement, setAttributes } from '../svg/element';\n\nexport interface CrosshairState {\n hide(): void;\n /** When `false`, the crosshair follows the raw mouse position instead of snapping to the nearest datum. */\n readonly snap: boolean;\n /**\n * @param announceText Optional text describing the value at the crosshair position,\n * announced via the crosshair's ARIA live region — used when no tooltip is also shown.\n */\n show(x: number, y: number, width: number, height: number, announceText?: string): void;\n}\n\nexport function createCrosshair(parent: SVGGElement, config?: CrosshairConfig | true): CrosshairState {\n const showVertical = config === true || config?.vertical !== false;\n const showHorizontal = config !== true && config?.horizontal === true;\n const snap = config === true || config?.snap !== false;\n\n const group = createSvgElement('g', { 'aria-hidden': 'true', class: 'prism-crosshair', style: 'display:none' });\n\n const vLine = showVertical\n ? createSvgElement('line', { class: 'prism-crosshair-v', 'stroke-dasharray': 'var(--prism-crosshair-dash, 4 2)' })\n : null;\n const hLine = showHorizontal\n ? createSvgElement('line', { class: 'prism-crosshair-h', 'stroke-dasharray': 'var(--prism-crosshair-dash, 4 2)' })\n : null;\n\n if (vLine) group.appendChild(vLine);\n\n if (hLine) group.appendChild(hLine);\n\n parent.appendChild(group);\n\n // Non-modal status region for screen readers — the visual crosshair lines above are\n // aria-hidden (purely decorative), so the current value is announced here instead.\n // Positioned off-canvas rather than visually hidden via CSS so it works without prism's stylesheet.\n const liveRegion = createSvgElement('text', {\n 'aria-live': 'polite',\n class: 'prism-crosshair-live',\n role: 'status',\n x: -9999,\n y: -9999,\n });\n\n parent.appendChild(liveRegion);\n\n return {\n hide() {\n group.style.display = 'none';\n liveRegion.textContent = '';\n },\n show(x: number, y: number, width: number, height: number, announceText?: string) {\n group.style.display = '';\n\n if (vLine) setAttributes(vLine, { x1: x, x2: x, y1: 0, y2: height });\n\n if (hLine) setAttributes(hLine, { x1: 0, x2: width, y1: y, y2: y });\n\n if (announceText !== undefined) liveRegion.textContent = announceText;\n },\n snap,\n };\n}\n"],"mappings":"sCAeA,SAAgB,EAAgB,EAAqB,EAAiD,CACpG,IAAM,EAAe,IAAW,IAAQ,GAAQ,WAAa,GACvD,EAAiB,IAAW,IAAQ,GAAQ,aAAe,GAC3D,EAAO,IAAW,IAAQ,GAAQ,OAAS,GAE3C,EAAQ,EAAA,iBAAiB,IAAK,CAAE,cAAe,OAAQ,MAAO,kBAAmB,MAAO,cAAe,CAAC,EAExG,EAAQ,EACV,EAAA,iBAAiB,OAAQ,CAAE,MAAO,oBAAqB,mBAAoB,kCAAmC,CAAC,EAC/G,KACE,EAAQ,EACV,EAAA,iBAAiB,OAAQ,CAAE,MAAO,oBAAqB,mBAAoB,kCAAmC,CAAC,EAC/G,KAEA,GAAO,EAAM,YAAY,CAAK,EAE9B,GAAO,EAAM,YAAY,CAAK,EAElC,EAAO,YAAY,CAAK,EAKxB,IAAM,EAAa,EAAA,iBAAiB,OAAQ,CAC1C,YAAa,SACb,MAAO,uBACP,KAAM,SACN,EAAG,MACH,EAAG,KACL,CAAC,EAID,OAFA,EAAO,YAAY,CAAU,EAEtB,CACL,MAAO,CACL,EAAM,MAAM,QAAU,OACtB,EAAW,YAAc,EAC3B,EACA,KAAK,EAAW,EAAW,EAAe,EAAgB,EAAuB,CAC/E,EAAM,MAAM,QAAU,GAElB,GAAO,EAAA,cAAc,EAAO,CAAE,GAAI,EAAG,GAAI,EAAG,GAAI,EAAG,GAAI,CAAO,CAAC,EAE/D,GAAO,EAAA,cAAc,EAAO,CAAE,GAAI,EAAG,GAAI,EAAO,GAAI,EAAG,GAAI,CAAE,CAAC,EAE9D,IAAiB,IAAA,KAAW,EAAW,YAAc,EAC3D,EACA,MACF,CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CrosshairConfig } from '../types';
|
|
2
|
+
export interface CrosshairState {
|
|
3
|
+
hide(): void;
|
|
4
|
+
/** When `false`, the crosshair follows the raw mouse position instead of snapping to the nearest datum. */
|
|
5
|
+
readonly snap: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @param announceText Optional text describing the value at the crosshair position,
|
|
8
|
+
* announced via the crosshair's ARIA live region — used when no tooltip is also shown.
|
|
9
|
+
*/
|
|
10
|
+
show(x: number, y: number, width: number, height: number, announceText?: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function createCrosshair(parent: SVGGElement, config?: CrosshairConfig | true): CrosshairState;
|
|
13
|
+
//# sourceMappingURL=crosshair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crosshair.d.ts","sourceRoot":"","sources":["../../src/interaction/crosshair.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAIhD,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,IAAI,CAAC;IACb,2GAA2G;IAC3G,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,cAAc,CAiDpG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createSvgElement as e, setAttributes as t } from "../svg/element.js";
|
|
2
|
+
//#region src/interaction/crosshair.ts
|
|
3
|
+
function n(n, r) {
|
|
4
|
+
let i = r === !0 || r?.vertical !== !1, a = r !== !0 && r?.horizontal === !0, o = r === !0 || r?.snap !== !1, s = e("g", {
|
|
5
|
+
"aria-hidden": "true",
|
|
6
|
+
class: "prism-crosshair",
|
|
7
|
+
style: "display:none"
|
|
8
|
+
}), c = i ? e("line", {
|
|
9
|
+
class: "prism-crosshair-v",
|
|
10
|
+
"stroke-dasharray": "var(--prism-crosshair-dash, 4 2)"
|
|
11
|
+
}) : null, l = a ? e("line", {
|
|
12
|
+
class: "prism-crosshair-h",
|
|
13
|
+
"stroke-dasharray": "var(--prism-crosshair-dash, 4 2)"
|
|
14
|
+
}) : null;
|
|
15
|
+
c && s.appendChild(c), l && s.appendChild(l), n.appendChild(s);
|
|
16
|
+
let u = e("text", {
|
|
17
|
+
"aria-live": "polite",
|
|
18
|
+
class: "prism-crosshair-live",
|
|
19
|
+
role: "status",
|
|
20
|
+
x: -9999,
|
|
21
|
+
y: -9999
|
|
22
|
+
});
|
|
23
|
+
return n.appendChild(u), {
|
|
24
|
+
hide() {
|
|
25
|
+
s.style.display = "none", u.textContent = "";
|
|
26
|
+
},
|
|
27
|
+
show(e, n, r, i, a) {
|
|
28
|
+
s.style.display = "", c && t(c, {
|
|
29
|
+
x1: e,
|
|
30
|
+
x2: e,
|
|
31
|
+
y1: 0,
|
|
32
|
+
y2: i
|
|
33
|
+
}), l && t(l, {
|
|
34
|
+
x1: 0,
|
|
35
|
+
x2: r,
|
|
36
|
+
y1: n,
|
|
37
|
+
y2: n
|
|
38
|
+
}), a !== void 0 && (u.textContent = a);
|
|
39
|
+
},
|
|
40
|
+
snap: o
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { n as createCrosshair };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=crosshair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crosshair.js","names":[],"sources":["../../src/interaction/crosshair.ts"],"sourcesContent":["import type { CrosshairConfig } from '../types';\n\nimport { createSvgElement, setAttributes } from '../svg/element';\n\nexport interface CrosshairState {\n hide(): void;\n /** When `false`, the crosshair follows the raw mouse position instead of snapping to the nearest datum. */\n readonly snap: boolean;\n /**\n * @param announceText Optional text describing the value at the crosshair position,\n * announced via the crosshair's ARIA live region — used when no tooltip is also shown.\n */\n show(x: number, y: number, width: number, height: number, announceText?: string): void;\n}\n\nexport function createCrosshair(parent: SVGGElement, config?: CrosshairConfig | true): CrosshairState {\n const showVertical = config === true || config?.vertical !== false;\n const showHorizontal = config !== true && config?.horizontal === true;\n const snap = config === true || config?.snap !== false;\n\n const group = createSvgElement('g', { 'aria-hidden': 'true', class: 'prism-crosshair', style: 'display:none' });\n\n const vLine = showVertical\n ? createSvgElement('line', { class: 'prism-crosshair-v', 'stroke-dasharray': 'var(--prism-crosshair-dash, 4 2)' })\n : null;\n const hLine = showHorizontal\n ? createSvgElement('line', { class: 'prism-crosshair-h', 'stroke-dasharray': 'var(--prism-crosshair-dash, 4 2)' })\n : null;\n\n if (vLine) group.appendChild(vLine);\n\n if (hLine) group.appendChild(hLine);\n\n parent.appendChild(group);\n\n // Non-modal status region for screen readers — the visual crosshair lines above are\n // aria-hidden (purely decorative), so the current value is announced here instead.\n // Positioned off-canvas rather than visually hidden via CSS so it works without prism's stylesheet.\n const liveRegion = createSvgElement('text', {\n 'aria-live': 'polite',\n class: 'prism-crosshair-live',\n role: 'status',\n x: -9999,\n y: -9999,\n });\n\n parent.appendChild(liveRegion);\n\n return {\n hide() {\n group.style.display = 'none';\n liveRegion.textContent = '';\n },\n show(x: number, y: number, width: number, height: number, announceText?: string) {\n group.style.display = '';\n\n if (vLine) setAttributes(vLine, { x1: x, x2: x, y1: 0, y2: height });\n\n if (hLine) setAttributes(hLine, { x1: 0, x2: width, y1: y, y2: y });\n\n if (announceText !== undefined) liveRegion.textContent = announceText;\n },\n snap,\n };\n}\n"],"mappings":";;AAeA,SAAgB,EAAgB,GAAqB,GAAiD;CACpG,IAAM,IAAe,MAAW,MAAQ,GAAQ,aAAa,IACvD,IAAiB,MAAW,MAAQ,GAAQ,eAAe,IAC3D,IAAO,MAAW,MAAQ,GAAQ,SAAS,IAE3C,IAAQ,EAAiB,KAAK;EAAE,eAAe;EAAQ,OAAO;EAAmB,OAAO;CAAe,CAAC,GAExG,IAAQ,IACV,EAAiB,QAAQ;EAAE,OAAO;EAAqB,oBAAoB;CAAmC,CAAC,IAC/G,MACE,IAAQ,IACV,EAAiB,QAAQ;EAAE,OAAO;EAAqB,oBAAoB;CAAmC,CAAC,IAC/G;CAMJ,AAJI,KAAO,EAAM,YAAY,CAAK,GAE9B,KAAO,EAAM,YAAY,CAAK,GAElC,EAAO,YAAY,CAAK;CAKxB,IAAM,IAAa,EAAiB,QAAQ;EAC1C,aAAa;EACb,OAAO;EACP,MAAM;EACN,GAAG;EACH,GAAG;CACL,CAAC;CAID,OAFA,EAAO,YAAY,CAAU,GAEtB;EACL,OAAO;GAEL,AADA,EAAM,MAAM,UAAU,QACtB,EAAW,cAAc;EAC3B;EACA,KAAK,GAAW,GAAW,GAAe,GAAgB,GAAuB;GAO/E,AANA,EAAM,MAAM,UAAU,IAElB,KAAO,EAAc,GAAO;IAAE,IAAI;IAAG,IAAI;IAAG,IAAI;IAAG,IAAI;GAAO,CAAC,GAE/D,KAAO,EAAc,GAAO;IAAE,IAAI;IAAG,IAAI;IAAO,IAAI;IAAG,IAAI;GAAE,CAAC,GAE9D,MAAiB,KAAA,MAAW,EAAW,cAAc;EAC3D;EACA;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.cjs","names":[],"sources":["../../src/interaction/events.ts"],"sourcesContent":["import type { Point } from '../svg/path';\n\nexport function getMousePosition(svg: SVGSVGElement, event: MouseEvent, offsetX: number, offsetY: number): Point {\n const rect = svg.getBoundingClientRect();\n\n return {\n x: event.clientX - rect.left - offsetX,\n y: event.clientY - rect.top - offsetY,\n };\n}\n"],"mappings":"AAEA,SAAgB,EAAiB,EAAoB,EAAmB,EAAiB,EAAwB,CAC/G,IAAM,EAAO,EAAI,sBAAsB,EAEvC,MAAO,CACL,EAAG,EAAM,QAAU,EAAK,KAAO,EAC/B,EAAG,EAAM,QAAU,EAAK,IAAM,CAChC,CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/interaction/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAO/G"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/interaction/events.ts
|
|
2
|
+
function e(e, t, n, r) {
|
|
3
|
+
let i = e.getBoundingClientRect();
|
|
4
|
+
return {
|
|
5
|
+
x: t.clientX - i.left - n,
|
|
6
|
+
y: t.clientY - i.top - r
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { e as getMousePosition };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","names":[],"sources":["../../src/interaction/events.ts"],"sourcesContent":["import type { Point } from '../svg/path';\n\nexport function getMousePosition(svg: SVGSVGElement, event: MouseEvent, offsetX: number, offsetY: number): Point {\n const rect = svg.getBoundingClientRect();\n\n return {\n x: event.clientX - rect.left - offsetX,\n y: event.clientY - rect.top - offsetY,\n };\n}\n"],"mappings":";AAEA,SAAgB,EAAiB,GAAoB,GAAmB,GAAiB,GAAwB;CAC/G,IAAM,IAAO,EAAI,sBAAsB;CAEvC,OAAO;EACL,GAAG,EAAM,UAAU,EAAK,OAAO;EAC/B,GAAG,EAAM,UAAU,EAAK,MAAM;CAChC;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.cjs","names":[],"sources":["../../src/interaction/hit-test.ts"],"sourcesContent":["import type { Point } from '../svg/path';\n\nexport function nearestPointX(points: Point[], targetX: number): number {\n if (points.length === 0) return -1;\n\n let minDist = Infinity;\n let minIdx = 0;\n\n for (let i = 0; i < points.length; i++) {\n const dist = Math.abs(points[i].x - targetX);\n\n if (dist < minDist) {\n minDist = dist;\n minIdx = i;\n }\n }\n\n return minIdx;\n}\n"],"mappings":"AAEA,SAAgB,EAAc,EAAiB,EAAyB,CACtE,GAAI,EAAO,SAAW,EAAG,MAAO,GAEhC,IAAI,EAAU,IACV,EAAS,EAEb,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAO,KAAK,IAAI,EAAO,EAAE,CAAC,EAAI,CAAO,EAEvC,EAAO,IACT,EAAU,EACV,EAAS,EAEb,CAEA,OAAO,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.d.ts","sourceRoot":"","sources":["../../src/interaction/hit-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAgBtE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/interaction/hit-test.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
if (e.length === 0) return -1;
|
|
4
|
+
let n = Infinity, r = 0;
|
|
5
|
+
for (let i = 0; i < e.length; i++) {
|
|
6
|
+
let a = Math.abs(e[i].x - t);
|
|
7
|
+
a < n && (n = a, r = i);
|
|
8
|
+
}
|
|
9
|
+
return r;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { e as nearestPointX };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=hit-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.js","names":[],"sources":["../../src/interaction/hit-test.ts"],"sourcesContent":["import type { Point } from '../svg/path';\n\nexport function nearestPointX(points: Point[], targetX: number): number {\n if (points.length === 0) return -1;\n\n let minDist = Infinity;\n let minIdx = 0;\n\n for (let i = 0; i < points.length; i++) {\n const dist = Math.abs(points[i].x - targetX);\n\n if (dist < minDist) {\n minDist = dist;\n minIdx = i;\n }\n }\n\n return minIdx;\n}\n"],"mappings":";AAEA,SAAgB,EAAc,GAAiB,GAAyB;CACtE,IAAI,EAAO,WAAW,GAAG,OAAO;CAEhC,IAAI,IAAU,UACV,IAAS;CAEb,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAAK;EACtC,IAAM,IAAO,KAAK,IAAI,EAAO,EAAE,CAAC,IAAI,CAAO;EAE3C,AAAI,IAAO,MACT,IAAU,GACV,IAAS;CAEb;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createCrosshair } from './crosshair';
|
|
2
|
+
export type { CrosshairState } from './crosshair';
|
|
3
|
+
export { getMousePosition } from './events';
|
|
4
|
+
export { nearestPointX } from './hit-test';
|
|
5
|
+
export { createLegend } from './legend';
|
|
6
|
+
export type { LegendState } from './legend';
|
|
7
|
+
export { createTooltip } from './tooltip';
|
|
8
|
+
export type { TooltipState } from './tooltip';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){return e===!0?`bottom`:e.position??`bottom`}function t(t,n){let r=e(n),i=document.createElement(`div`);i.className=`prism-legend prism-legend-${r}`,r===`top`?t.insertBefore(i,t.firstChild):t.appendChild(i);let a=()=>{i.remove()};return{dispose:a,el:i,[Symbol.dispose]:a,update(e){i.innerHTML=``;for(let t of e){let e=document.createElement(`div`);e.className=`prism-legend-item`;let n=document.createElement(`span`);n.className=`prism-legend-dot`,n.style.backgroundColor=t.color;let r=document.createElement(`span`);r.className=`prism-legend-label`,r.textContent=t.name,e.appendChild(n),e.appendChild(r),i.appendChild(e)}}}}exports.createLegend=t;
|
|
2
|
+
//# sourceMappingURL=legend.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.cjs","names":[],"sources":["../../src/interaction/legend.ts"],"sourcesContent":["import type { LegendConfig, LegendPosition } from '../types';\n\nexport interface LegendState {\n dispose(): void;\n [Symbol.dispose](): void;\n el: HTMLDivElement | null;\n update(series: { color: string; name: string }[]): void;\n}\n\nfunction resolvePosition(config: LegendConfig | true): LegendPosition {\n if (config === true) return 'bottom';\n\n return config.position ?? 'bottom';\n}\n\nexport function createLegend(container: HTMLElement, config: LegendConfig | true): LegendState {\n const position = resolvePosition(config);\n const el = document.createElement('div');\n\n el.className = `prism-legend prism-legend-${position}`;\n\n if (position === 'top') {\n container.insertBefore(el, container.firstChild);\n } else {\n container.appendChild(el);\n }\n\n const disposeHandle = (): void => {\n el.remove();\n };\n\n return {\n dispose: disposeHandle,\n el,\n [Symbol.dispose]: disposeHandle,\n update(series) {\n el.innerHTML = '';\n for (const s of series) {\n const item = document.createElement('div');\n\n item.className = 'prism-legend-item';\n\n const dot = document.createElement('span');\n\n dot.className = 'prism-legend-dot';\n dot.style.backgroundColor = s.color;\n\n const label = document.createElement('span');\n\n label.className = 'prism-legend-label';\n label.textContent = s.name;\n\n item.appendChild(dot);\n item.appendChild(label);\n el.appendChild(item);\n }\n },\n };\n}\n"],"mappings":"AASA,SAAS,EAAgB,EAA6C,CAGpE,OAFI,IAAW,GAAa,SAErB,EAAO,UAAY,QAC5B,CAEA,SAAgB,EAAa,EAAwB,EAA0C,CAC7F,IAAM,EAAW,EAAgB,CAAM,EACjC,EAAK,SAAS,cAAc,KAAK,EAEvC,EAAG,UAAY,6BAA6B,IAExC,IAAa,MACf,EAAU,aAAa,EAAI,EAAU,UAAU,EAE/C,EAAU,YAAY,CAAE,EAG1B,IAAM,MAA4B,CAChC,EAAG,OAAO,CACZ,EAEA,MAAO,CACL,QAAS,EACT,MACC,OAAO,SAAU,EAClB,OAAO,EAAQ,CACb,EAAG,UAAY,GACf,IAAK,IAAM,KAAK,EAAQ,CACtB,IAAM,EAAO,SAAS,cAAc,KAAK,EAEzC,EAAK,UAAY,oBAEjB,IAAM,EAAM,SAAS,cAAc,MAAM,EAEzC,EAAI,UAAY,mBAChB,EAAI,MAAM,gBAAkB,EAAE,MAE9B,IAAM,EAAQ,SAAS,cAAc,MAAM,EAE3C,EAAM,UAAY,qBAClB,EAAM,YAAc,EAAE,KAEtB,EAAK,YAAY,CAAG,EACpB,EAAK,YAAY,CAAK,EACtB,EAAG,YAAY,CAAI,CACrB,CACF,CACF,CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LegendConfig } from '../types';
|
|
2
|
+
export interface LegendState {
|
|
3
|
+
dispose(): void;
|
|
4
|
+
[Symbol.dispose](): void;
|
|
5
|
+
el: HTMLDivElement | null;
|
|
6
|
+
update(series: {
|
|
7
|
+
color: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}[]): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createLegend(container: HTMLElement, config: LegendConfig | true): LegendState;
|
|
12
|
+
//# sourceMappingURL=legend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/interaction/legend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,UAAU,CAAC;AAE7D,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,IAAI,CAAC;IAChB,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;IACzB,EAAE,EAAE,cAAc,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,IAAI,CAAC;CACzD;AAQD,wBAAgB,YAAY,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,WAAW,CA2C7F"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/interaction/legend.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e === !0 ? "bottom" : e.position ?? "bottom";
|
|
4
|
+
}
|
|
5
|
+
function t(t, n) {
|
|
6
|
+
let r = e(n), i = document.createElement("div");
|
|
7
|
+
i.className = `prism-legend prism-legend-${r}`, r === "top" ? t.insertBefore(i, t.firstChild) : t.appendChild(i);
|
|
8
|
+
let a = () => {
|
|
9
|
+
i.remove();
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
dispose: a,
|
|
13
|
+
el: i,
|
|
14
|
+
[Symbol.dispose]: a,
|
|
15
|
+
update(e) {
|
|
16
|
+
i.innerHTML = "";
|
|
17
|
+
for (let t of e) {
|
|
18
|
+
let e = document.createElement("div");
|
|
19
|
+
e.className = "prism-legend-item";
|
|
20
|
+
let n = document.createElement("span");
|
|
21
|
+
n.className = "prism-legend-dot", n.style.backgroundColor = t.color;
|
|
22
|
+
let r = document.createElement("span");
|
|
23
|
+
r.className = "prism-legend-label", r.textContent = t.name, e.appendChild(n), e.appendChild(r), i.appendChild(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { t as createLegend };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=legend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legend.js","names":[],"sources":["../../src/interaction/legend.ts"],"sourcesContent":["import type { LegendConfig, LegendPosition } from '../types';\n\nexport interface LegendState {\n dispose(): void;\n [Symbol.dispose](): void;\n el: HTMLDivElement | null;\n update(series: { color: string; name: string }[]): void;\n}\n\nfunction resolvePosition(config: LegendConfig | true): LegendPosition {\n if (config === true) return 'bottom';\n\n return config.position ?? 'bottom';\n}\n\nexport function createLegend(container: HTMLElement, config: LegendConfig | true): LegendState {\n const position = resolvePosition(config);\n const el = document.createElement('div');\n\n el.className = `prism-legend prism-legend-${position}`;\n\n if (position === 'top') {\n container.insertBefore(el, container.firstChild);\n } else {\n container.appendChild(el);\n }\n\n const disposeHandle = (): void => {\n el.remove();\n };\n\n return {\n dispose: disposeHandle,\n el,\n [Symbol.dispose]: disposeHandle,\n update(series) {\n el.innerHTML = '';\n for (const s of series) {\n const item = document.createElement('div');\n\n item.className = 'prism-legend-item';\n\n const dot = document.createElement('span');\n\n dot.className = 'prism-legend-dot';\n dot.style.backgroundColor = s.color;\n\n const label = document.createElement('span');\n\n label.className = 'prism-legend-label';\n label.textContent = s.name;\n\n item.appendChild(dot);\n item.appendChild(label);\n el.appendChild(item);\n }\n },\n };\n}\n"],"mappings":";AASA,SAAS,EAAgB,GAA6C;CAGpE,OAFI,MAAW,KAAa,WAErB,EAAO,YAAY;AAC5B;AAEA,SAAgB,EAAa,GAAwB,GAA0C;CAC7F,IAAM,IAAW,EAAgB,CAAM,GACjC,IAAK,SAAS,cAAc,KAAK;CAIvC,AAFA,EAAG,YAAY,6BAA6B,KAExC,MAAa,QACf,EAAU,aAAa,GAAI,EAAU,UAAU,IAE/C,EAAU,YAAY,CAAE;CAG1B,IAAM,UAA4B;EAChC,EAAG,OAAO;CACZ;CAEA,OAAO;EACL,SAAS;EACT;GACC,OAAO,UAAU;EAClB,OAAO,GAAQ;GACb,EAAG,YAAY;GACf,KAAK,IAAM,KAAK,GAAQ;IACtB,IAAM,IAAO,SAAS,cAAc,KAAK;IAEzC,EAAK,YAAY;IAEjB,IAAM,IAAM,SAAS,cAAc,MAAM;IAGzC,AADA,EAAI,YAAY,oBAChB,EAAI,MAAM,kBAAkB,EAAE;IAE9B,IAAM,IAAQ,SAAS,cAAc,MAAM;IAO3C,AALA,EAAM,YAAY,sBAClB,EAAM,cAAc,EAAE,MAEtB,EAAK,YAAY,CAAG,GACpB,EAAK,YAAY,CAAK,GACtB,EAAG,YAAY,CAAI;GACrB;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../core/layout.cjs"),t=require("./events.cjs"),n=require("./hit-test.cjs");function r(e,t,n){let r=0,i=1/0;for(let a=0;a<e.length;a++){let o=e[a]?.[t];if(o){let e=Math.abs(o.y-n);e<i&&(i=e,r=a)}}return r}function i(i){return{onClick:a=>{if(!i.onClick)return;let o=i.getPoints();if(o.length===0||o[0].length===0)return;let s=i.dims(),c=t.getMousePosition(i.svg,a,s.margin.left,s.margin.top),l=e.chartArea(s.width,s.height,s.margin);if(c.x<0||c.x>l.width||c.y<0||c.y>l.height)return;let u=n.nearestPointX(o[0],c.x);if(u<0)return;let d=r(o,u,c.y),f=i.getData()[d]?.[u],p=i.getSeriesList()[d];f&&p&&i.onClick({datum:f,originalEvent:a,series:p})},onMouseLeave:()=>{i.crosshair?.hide(),i.tooltip?.hide(),i.onHover?.(null)},onMouseMove:a=>{let o=i.getPoints();if(o.length===0||o[0].length===0)return;let s=i.dims(),c=t.getMousePosition(i.svg,a,s.margin.left,s.margin.top),l=e.chartArea(s.width,s.height,s.margin);if(c.x<0||c.x>l.width||c.y<0||c.y>l.height){i.crosshair?.hide(),i.tooltip?.hide();return}let u=o[0]??[],d=n.nearestPointX(u,c.x);if(d<0)return;let f=u[d],p=i.crosshair?.snap===!1?c.x:f.x,m=i.crosshair?.snap===!1?c.y:f.y,h=r(o,d,c.y),g=o[h]?.[d],_=i.getData()[h]?.[d],v=i.getSeriesList()[h];i.crosshair?.show(p,m,l.width,l.height,v&&_?`${v.name}: ${_.value}`:void 0),g&&_&&v&&(i.tooltip?.show(g.x+s.margin.left,g.y+s.margin.top,_,v),i.onHover?.({datum:_,originalEvent:a,series:v}))}}}exports.createSeriesInteraction=i;
|
|
2
|
+
//# sourceMappingURL=series-interaction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"series-interaction.cjs","names":[],"sources":["../../src/interaction/series-interaction.ts"],"sourcesContent":["import type { ChartEventHandlers } from '../core/chart-scaffold';\nimport type { Point } from '../svg/path';\nimport type { ChartDimensions, ChartEvent, Datum, Series } from '../types';\nimport type { CrosshairState } from './crosshair';\nimport type { TooltipState } from './tooltip';\n\nimport { chartArea } from '../core/layout';\nimport { getMousePosition } from './events';\nimport { nearestPointX } from './hit-test';\n\nexport interface SeriesInteractionOptions {\n crosshair?: CrosshairState | null;\n dims: () => ChartDimensions;\n getData: () => Datum[][];\n getPoints: () => Point[][];\n getSeriesList: () => Series[];\n onClick?: ((event: ChartEvent) => void) | undefined;\n onHover?: ((event: ChartEvent | null) => void) | undefined;\n svg: SVGSVGElement;\n tooltip?: TooltipState | null;\n}\n\nfunction findNearestSeries(allPoints: Point[][], idx: number, posY: number): number {\n let nearestSi = 0;\n let minYDist = Infinity;\n\n for (let si = 0; si < allPoints.length; si++) {\n const pt = allPoints[si]?.[idx];\n\n if (pt) {\n const d = Math.abs(pt.y - posY);\n\n if (d < minYDist) {\n minYDist = d;\n nearestSi = si;\n }\n }\n }\n\n return nearestSi;\n}\n\nexport function createSeriesInteraction(opts: SeriesInteractionOptions): ChartEventHandlers {\n const onMouseMove = (event: MouseEvent) => {\n const allPoints = opts.getPoints();\n\n if (allPoints.length === 0 || allPoints[0].length === 0) return;\n\n const dims = opts.dims();\n const pos = getMousePosition(opts.svg, event, dims.margin.left, dims.margin.top);\n const area = chartArea(dims.width, dims.height, dims.margin);\n\n if (pos.x < 0 || pos.x > area.width || pos.y < 0 || pos.y > area.height) {\n opts.crosshair?.hide();\n opts.tooltip?.hide();\n\n return;\n }\n\n const baseSeries = allPoints[0] ?? [];\n const idx = nearestPointX(baseSeries, pos.x);\n\n if (idx < 0) return;\n\n const pt = baseSeries[idx];\n const crosshairX = opts.crosshair?.snap === false ? pos.x : pt.x;\n const crosshairY = opts.crosshair?.snap === false ? pos.y : pt.y;\n\n const nearestSi = findNearestSeries(allPoints, idx, pos.y);\n const siPt = allPoints[nearestSi]?.[idx];\n const dataPoint = opts.getData()[nearestSi]?.[idx];\n const series = opts.getSeriesList()[nearestSi];\n\n opts.crosshair?.show(\n crosshairX,\n crosshairY,\n area.width,\n area.height,\n series && dataPoint ? `${series.name}: ${dataPoint.value}` : undefined,\n );\n\n if (siPt && dataPoint && series) {\n opts.tooltip?.show(siPt.x + dims.margin.left, siPt.y + dims.margin.top, dataPoint, series);\n opts.onHover?.({ datum: dataPoint, originalEvent: event, series });\n }\n };\n\n const onMouseLeave = () => {\n opts.crosshair?.hide();\n opts.tooltip?.hide();\n opts.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!opts.onClick) return;\n\n const allPoints = opts.getPoints();\n\n if (allPoints.length === 0 || allPoints[0].length === 0) return;\n\n const dims = opts.dims();\n const pos = getMousePosition(opts.svg, event, dims.margin.left, dims.margin.top);\n const area = chartArea(dims.width, dims.height, dims.margin);\n\n if (pos.x < 0 || pos.x > area.width || pos.y < 0 || pos.y > area.height) return;\n\n const idx = nearestPointX(allPoints[0], pos.x);\n\n if (idx < 0) return;\n\n const nearestSi = findNearestSeries(allPoints, idx, pos.y);\n const dataPoint = opts.getData()[nearestSi]?.[idx];\n const series = opts.getSeriesList()[nearestSi];\n\n if (dataPoint && series) {\n opts.onClick({ datum: dataPoint, originalEvent: event, series });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n}\n"],"mappings":"4FAsBA,SAAS,EAAkB,EAAsB,EAAa,EAAsB,CAClF,IAAI,EAAY,EACZ,EAAW,IAEf,IAAK,IAAI,EAAK,EAAG,EAAK,EAAU,OAAQ,IAAM,CAC5C,IAAM,EAAK,EAAU,EAAG,GAAG,GAE3B,GAAI,EAAI,CACN,IAAM,EAAI,KAAK,IAAI,EAAG,EAAI,CAAI,EAE1B,EAAI,IACN,EAAW,EACX,EAAY,EAEhB,CACF,CAEA,OAAO,CACT,CAEA,SAAgB,EAAwB,EAAoD,CA6E1F,MAAO,CAAE,QA1BQ,GAAsB,CACrC,GAAI,CAAC,EAAK,QAAS,OAEnB,IAAM,EAAY,EAAK,UAAU,EAEjC,GAAI,EAAU,SAAW,GAAK,EAAU,EAAE,CAAC,SAAW,EAAG,OAEzD,IAAM,EAAO,EAAK,KAAK,EACjB,EAAM,EAAA,iBAAiB,EAAK,IAAK,EAAO,EAAK,OAAO,KAAM,EAAK,OAAO,GAAG,EACzE,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EAE3D,GAAI,EAAI,EAAI,GAAK,EAAI,EAAI,EAAK,OAAS,EAAI,EAAI,GAAK,EAAI,EAAI,EAAK,OAAQ,OAEzE,IAAM,EAAM,EAAA,cAAc,EAAU,GAAI,EAAI,CAAC,EAE7C,GAAI,EAAM,EAAG,OAEb,IAAM,EAAY,EAAkB,EAAW,EAAK,EAAI,CAAC,EACnD,EAAY,EAAK,QAAQ,CAAC,CAAC,EAAU,GAAG,GACxC,EAAS,EAAK,cAAc,CAAC,CAAC,GAEhC,GAAa,GACf,EAAK,QAAQ,CAAE,MAAO,EAAW,cAAe,EAAO,QAAO,CAAC,CAEnE,EAEkB,iBAhCS,CACzB,EAAK,WAAW,KAAK,EACrB,EAAK,SAAS,KAAK,EACnB,EAAK,UAAU,IAAI,CACrB,EA4BgC,YA5EX,GAAsB,CACzC,IAAM,EAAY,EAAK,UAAU,EAEjC,GAAI,EAAU,SAAW,GAAK,EAAU,EAAE,CAAC,SAAW,EAAG,OAEzD,IAAM,EAAO,EAAK,KAAK,EACjB,EAAM,EAAA,iBAAiB,EAAK,IAAK,EAAO,EAAK,OAAO,KAAM,EAAK,OAAO,GAAG,EACzE,EAAO,EAAA,UAAU,EAAK,MAAO,EAAK,OAAQ,EAAK,MAAM,EAE3D,GAAI,EAAI,EAAI,GAAK,EAAI,EAAI,EAAK,OAAS,EAAI,EAAI,GAAK,EAAI,EAAI,EAAK,OAAQ,CACvE,EAAK,WAAW,KAAK,EACrB,EAAK,SAAS,KAAK,EAEnB,MACF,CAEA,IAAM,EAAa,EAAU,IAAM,CAAC,EAC9B,EAAM,EAAA,cAAc,EAAY,EAAI,CAAC,EAE3C,GAAI,EAAM,EAAG,OAEb,IAAM,EAAK,EAAW,GAChB,EAAa,EAAK,WAAW,OAAS,GAAQ,EAAI,EAAI,EAAG,EACzD,EAAa,EAAK,WAAW,OAAS,GAAQ,EAAI,EAAI,EAAG,EAEzD,EAAY,EAAkB,EAAW,EAAK,EAAI,CAAC,EACnD,EAAO,EAAU,EAAU,GAAG,GAC9B,EAAY,EAAK,QAAQ,CAAC,CAAC,EAAU,GAAG,GACxC,EAAS,EAAK,cAAc,CAAC,CAAC,GAEpC,EAAK,WAAW,KACd,EACA,EACA,EAAK,MACL,EAAK,OACL,GAAU,EAAY,GAAG,EAAO,KAAK,IAAI,EAAU,QAAU,IAAA,EAC/D,EAEI,GAAQ,GAAa,IACvB,EAAK,SAAS,KAAK,EAAK,EAAI,EAAK,OAAO,KAAM,EAAK,EAAI,EAAK,OAAO,IAAK,EAAW,CAAM,EACzF,EAAK,UAAU,CAAE,MAAO,EAAW,cAAe,EAAO,QAAO,CAAC,EAErE,CAkC4C,CAC9C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ChartEventHandlers } from '../core/chart-scaffold';
|
|
2
|
+
import type { Point } from '../svg/path';
|
|
3
|
+
import type { ChartDimensions, ChartEvent, Datum, Series } from '../types';
|
|
4
|
+
import type { CrosshairState } from './crosshair';
|
|
5
|
+
import type { TooltipState } from './tooltip';
|
|
6
|
+
export interface SeriesInteractionOptions {
|
|
7
|
+
crosshair?: CrosshairState | null;
|
|
8
|
+
dims: () => ChartDimensions;
|
|
9
|
+
getData: () => Datum[][];
|
|
10
|
+
getPoints: () => Point[][];
|
|
11
|
+
getSeriesList: () => Series[];
|
|
12
|
+
onClick?: ((event: ChartEvent) => void) | undefined;
|
|
13
|
+
onHover?: ((event: ChartEvent | null) => void) | undefined;
|
|
14
|
+
svg: SVGSVGElement;
|
|
15
|
+
tooltip?: TooltipState | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function createSeriesInteraction(opts: SeriesInteractionOptions): ChartEventHandlers;
|
|
18
|
+
//# sourceMappingURL=series-interaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"series-interaction.d.ts","sourceRoot":"","sources":["../../src/interaction/series-interaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAM9C,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAClC,IAAI,EAAE,MAAM,eAAe,CAAC;IAC5B,OAAO,EAAE,MAAM,KAAK,EAAE,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,KAAK,EAAE,EAAE,CAAC;IAC3B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACpD,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC3D,GAAG,EAAE,aAAa,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CAC/B;AAsBD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,kBAAkB,CA8E1F"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { chartArea as e } from "../core/layout.js";
|
|
2
|
+
import { getMousePosition as t } from "./events.js";
|
|
3
|
+
import { nearestPointX as n } from "./hit-test.js";
|
|
4
|
+
//#region src/interaction/series-interaction.ts
|
|
5
|
+
function r(e, t, n) {
|
|
6
|
+
let r = 0, i = Infinity;
|
|
7
|
+
for (let a = 0; a < e.length; a++) {
|
|
8
|
+
let o = e[a]?.[t];
|
|
9
|
+
if (o) {
|
|
10
|
+
let e = Math.abs(o.y - n);
|
|
11
|
+
e < i && (i = e, r = a);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return r;
|
|
15
|
+
}
|
|
16
|
+
function i(i) {
|
|
17
|
+
return {
|
|
18
|
+
onClick: (a) => {
|
|
19
|
+
if (!i.onClick) return;
|
|
20
|
+
let o = i.getPoints();
|
|
21
|
+
if (o.length === 0 || o[0].length === 0) return;
|
|
22
|
+
let s = i.dims(), c = t(i.svg, a, s.margin.left, s.margin.top), l = e(s.width, s.height, s.margin);
|
|
23
|
+
if (c.x < 0 || c.x > l.width || c.y < 0 || c.y > l.height) return;
|
|
24
|
+
let u = n(o[0], c.x);
|
|
25
|
+
if (u < 0) return;
|
|
26
|
+
let d = r(o, u, c.y), f = i.getData()[d]?.[u], p = i.getSeriesList()[d];
|
|
27
|
+
f && p && i.onClick({
|
|
28
|
+
datum: f,
|
|
29
|
+
originalEvent: a,
|
|
30
|
+
series: p
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
onMouseLeave: () => {
|
|
34
|
+
i.crosshair?.hide(), i.tooltip?.hide(), i.onHover?.(null);
|
|
35
|
+
},
|
|
36
|
+
onMouseMove: (a) => {
|
|
37
|
+
let o = i.getPoints();
|
|
38
|
+
if (o.length === 0 || o[0].length === 0) return;
|
|
39
|
+
let s = i.dims(), c = t(i.svg, a, s.margin.left, s.margin.top), l = e(s.width, s.height, s.margin);
|
|
40
|
+
if (c.x < 0 || c.x > l.width || c.y < 0 || c.y > l.height) {
|
|
41
|
+
i.crosshair?.hide(), i.tooltip?.hide();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let u = o[0] ?? [], d = n(u, c.x);
|
|
45
|
+
if (d < 0) return;
|
|
46
|
+
let f = u[d], p = i.crosshair?.snap === !1 ? c.x : f.x, m = i.crosshair?.snap === !1 ? c.y : f.y, h = r(o, d, c.y), g = o[h]?.[d], _ = i.getData()[h]?.[d], v = i.getSeriesList()[h];
|
|
47
|
+
i.crosshair?.show(p, m, l.width, l.height, v && _ ? `${v.name}: ${_.value}` : void 0), g && _ && v && (i.tooltip?.show(g.x + s.margin.left, g.y + s.margin.top, _, v), i.onHover?.({
|
|
48
|
+
datum: _,
|
|
49
|
+
originalEvent: a,
|
|
50
|
+
series: v
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { i as createSeriesInteraction };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=series-interaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"series-interaction.js","names":[],"sources":["../../src/interaction/series-interaction.ts"],"sourcesContent":["import type { ChartEventHandlers } from '../core/chart-scaffold';\nimport type { Point } from '../svg/path';\nimport type { ChartDimensions, ChartEvent, Datum, Series } from '../types';\nimport type { CrosshairState } from './crosshair';\nimport type { TooltipState } from './tooltip';\n\nimport { chartArea } from '../core/layout';\nimport { getMousePosition } from './events';\nimport { nearestPointX } from './hit-test';\n\nexport interface SeriesInteractionOptions {\n crosshair?: CrosshairState | null;\n dims: () => ChartDimensions;\n getData: () => Datum[][];\n getPoints: () => Point[][];\n getSeriesList: () => Series[];\n onClick?: ((event: ChartEvent) => void) | undefined;\n onHover?: ((event: ChartEvent | null) => void) | undefined;\n svg: SVGSVGElement;\n tooltip?: TooltipState | null;\n}\n\nfunction findNearestSeries(allPoints: Point[][], idx: number, posY: number): number {\n let nearestSi = 0;\n let minYDist = Infinity;\n\n for (let si = 0; si < allPoints.length; si++) {\n const pt = allPoints[si]?.[idx];\n\n if (pt) {\n const d = Math.abs(pt.y - posY);\n\n if (d < minYDist) {\n minYDist = d;\n nearestSi = si;\n }\n }\n }\n\n return nearestSi;\n}\n\nexport function createSeriesInteraction(opts: SeriesInteractionOptions): ChartEventHandlers {\n const onMouseMove = (event: MouseEvent) => {\n const allPoints = opts.getPoints();\n\n if (allPoints.length === 0 || allPoints[0].length === 0) return;\n\n const dims = opts.dims();\n const pos = getMousePosition(opts.svg, event, dims.margin.left, dims.margin.top);\n const area = chartArea(dims.width, dims.height, dims.margin);\n\n if (pos.x < 0 || pos.x > area.width || pos.y < 0 || pos.y > area.height) {\n opts.crosshair?.hide();\n opts.tooltip?.hide();\n\n return;\n }\n\n const baseSeries = allPoints[0] ?? [];\n const idx = nearestPointX(baseSeries, pos.x);\n\n if (idx < 0) return;\n\n const pt = baseSeries[idx];\n const crosshairX = opts.crosshair?.snap === false ? pos.x : pt.x;\n const crosshairY = opts.crosshair?.snap === false ? pos.y : pt.y;\n\n const nearestSi = findNearestSeries(allPoints, idx, pos.y);\n const siPt = allPoints[nearestSi]?.[idx];\n const dataPoint = opts.getData()[nearestSi]?.[idx];\n const series = opts.getSeriesList()[nearestSi];\n\n opts.crosshair?.show(\n crosshairX,\n crosshairY,\n area.width,\n area.height,\n series && dataPoint ? `${series.name}: ${dataPoint.value}` : undefined,\n );\n\n if (siPt && dataPoint && series) {\n opts.tooltip?.show(siPt.x + dims.margin.left, siPt.y + dims.margin.top, dataPoint, series);\n opts.onHover?.({ datum: dataPoint, originalEvent: event, series });\n }\n };\n\n const onMouseLeave = () => {\n opts.crosshair?.hide();\n opts.tooltip?.hide();\n opts.onHover?.(null);\n };\n\n const onClick = (event: MouseEvent) => {\n if (!opts.onClick) return;\n\n const allPoints = opts.getPoints();\n\n if (allPoints.length === 0 || allPoints[0].length === 0) return;\n\n const dims = opts.dims();\n const pos = getMousePosition(opts.svg, event, dims.margin.left, dims.margin.top);\n const area = chartArea(dims.width, dims.height, dims.margin);\n\n if (pos.x < 0 || pos.x > area.width || pos.y < 0 || pos.y > area.height) return;\n\n const idx = nearestPointX(allPoints[0], pos.x);\n\n if (idx < 0) return;\n\n const nearestSi = findNearestSeries(allPoints, idx, pos.y);\n const dataPoint = opts.getData()[nearestSi]?.[idx];\n const series = opts.getSeriesList()[nearestSi];\n\n if (dataPoint && series) {\n opts.onClick({ datum: dataPoint, originalEvent: event, series });\n }\n };\n\n return { onClick, onMouseLeave, onMouseMove };\n}\n"],"mappings":";;;;AAsBA,SAAS,EAAkB,GAAsB,GAAa,GAAsB;CAClF,IAAI,IAAY,GACZ,IAAW;CAEf,KAAK,IAAI,IAAK,GAAG,IAAK,EAAU,QAAQ,KAAM;EAC5C,IAAM,IAAK,EAAU,EAAG,GAAG;EAE3B,IAAI,GAAI;GACN,IAAM,IAAI,KAAK,IAAI,EAAG,IAAI,CAAI;GAE9B,AAAI,IAAI,MACN,IAAW,GACX,IAAY;EAEhB;CACF;CAEA,OAAO;AACT;AAEA,SAAgB,EAAwB,GAAoD;CA6E1F,OAAO;EAAE,UA1BQ,MAAsB;GACrC,IAAI,CAAC,EAAK,SAAS;GAEnB,IAAM,IAAY,EAAK,UAAU;GAEjC,IAAI,EAAU,WAAW,KAAK,EAAU,EAAE,CAAC,WAAW,GAAG;GAEzD,IAAM,IAAO,EAAK,KAAK,GACjB,IAAM,EAAiB,EAAK,KAAK,GAAO,EAAK,OAAO,MAAM,EAAK,OAAO,GAAG,GACzE,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM;GAE3D,IAAI,EAAI,IAAI,KAAK,EAAI,IAAI,EAAK,SAAS,EAAI,IAAI,KAAK,EAAI,IAAI,EAAK,QAAQ;GAEzE,IAAM,IAAM,EAAc,EAAU,IAAI,EAAI,CAAC;GAE7C,IAAI,IAAM,GAAG;GAEb,IAAM,IAAY,EAAkB,GAAW,GAAK,EAAI,CAAC,GACnD,IAAY,EAAK,QAAQ,CAAC,CAAC,EAAU,GAAG,IACxC,IAAS,EAAK,cAAc,CAAC,CAAC;GAEpC,AAAI,KAAa,KACf,EAAK,QAAQ;IAAE,OAAO;IAAW,eAAe;IAAO;GAAO,CAAC;EAEnE;EAEkB,oBAhCS;GAGzB,AAFA,EAAK,WAAW,KAAK,GACrB,EAAK,SAAS,KAAK,GACnB,EAAK,UAAU,IAAI;EACrB;EA4BgC,cA5EX,MAAsB;GACzC,IAAM,IAAY,EAAK,UAAU;GAEjC,IAAI,EAAU,WAAW,KAAK,EAAU,EAAE,CAAC,WAAW,GAAG;GAEzD,IAAM,IAAO,EAAK,KAAK,GACjB,IAAM,EAAiB,EAAK,KAAK,GAAO,EAAK,OAAO,MAAM,EAAK,OAAO,GAAG,GACzE,IAAO,EAAU,EAAK,OAAO,EAAK,QAAQ,EAAK,MAAM;GAE3D,IAAI,EAAI,IAAI,KAAK,EAAI,IAAI,EAAK,SAAS,EAAI,IAAI,KAAK,EAAI,IAAI,EAAK,QAAQ;IAEvE,AADA,EAAK,WAAW,KAAK,GACrB,EAAK,SAAS,KAAK;IAEnB;GACF;GAEA,IAAM,IAAa,EAAU,MAAM,CAAC,GAC9B,IAAM,EAAc,GAAY,EAAI,CAAC;GAE3C,IAAI,IAAM,GAAG;GAEb,IAAM,IAAK,EAAW,IAChB,IAAa,EAAK,WAAW,SAAS,KAAQ,EAAI,IAAI,EAAG,GACzD,IAAa,EAAK,WAAW,SAAS,KAAQ,EAAI,IAAI,EAAG,GAEzD,IAAY,EAAkB,GAAW,GAAK,EAAI,CAAC,GACnD,IAAO,EAAU,EAAU,GAAG,IAC9B,IAAY,EAAK,QAAQ,CAAC,CAAC,EAAU,GAAG,IACxC,IAAS,EAAK,cAAc,CAAC,CAAC;GAUpC,AARA,EAAK,WAAW,KACd,GACA,GACA,EAAK,OACL,EAAK,QACL,KAAU,IAAY,GAAG,EAAO,KAAK,IAAI,EAAU,UAAU,KAAA,CAC/D,GAEI,KAAQ,KAAa,MACvB,EAAK,SAAS,KAAK,EAAK,IAAI,EAAK,OAAO,MAAM,EAAK,IAAI,EAAK,OAAO,KAAK,GAAW,CAAM,GACzF,EAAK,UAAU;IAAE,OAAO;IAAW,eAAe;IAAO;GAAO,CAAC;EAErE;CAkC4C;AAC9C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../_dev.cjs");let t=require("@vielzeug/orbit");function n(n,r){getComputedStyle(n).position===`static`&&(n.style.position=`relative`);let i=document.createElement(`div`);i.className=`prism-tooltip`,i.style.position=`absolute`,i.style.pointerEvents=`none`,i.style.top=`0`,i.style.left=`0`,i.setAttribute(`role`,`status`),i.setAttribute(`aria-live`,`polite`),n.appendChild(i);let a=r!==!0&&r?.offset||8,o=r===!0?void 0:r?.render,s=r===!0?void 0:r?.sanitize;o&&!s&&e.warn("createTooltip: `render` is set without `sanitize` — falling back to plain-text rendering of the returned string to avoid an XSS risk. Pass `sanitize` to render HTML.");let c=()=>{i.remove()};return{dispose:c,el:i,hide(){i.style.opacity=`0`,i.textContent=``},show(e,r,c,l){if(!n.isConnected)return;if(o){let e=o(c,l);s?i.innerHTML=s(e):i.textContent=e}else i.textContent=`${l.name}: ${c.value}`;let{x:u,y:d}=(0,t.computePosition)({getBoundingClientRect:()=>{let t=n.getBoundingClientRect();return{bottom:t.top+r,height:0,left:t.left+e,right:t.left+e,top:t.top+r,width:0,x:t.left+e,y:t.top+r}}},i,{middleware:[(0,t.offset)(a),(0,t.flip)(),(0,t.shift)({padding:8})],placement:`top`}),f=n.getBoundingClientRect();i.style.left=`${u-f.left}px`,i.style.top=`${d-f.top}px`,i.style.opacity=`1`},[Symbol.dispose]:c}}exports.createTooltip=n;
|
|
2
|
+
//# sourceMappingURL=tooltip.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.cjs","names":[],"sources":["../../src/interaction/tooltip.ts"],"sourcesContent":["import { computePosition, flip, offset, shift } from '@vielzeug/orbit';\n\nimport type { Datum, Series, TooltipConfig } from '../types';\n\nimport { warn } from '../_dev';\n\nexport interface TooltipState {\n dispose(): void;\n [Symbol.dispose](): void;\n el: HTMLDivElement | null;\n hide(): void;\n show(x: number, y: number, datum: Datum, series: Series): void;\n}\n\nexport function createTooltip(container: HTMLElement, config?: TooltipConfig | true): TooltipState {\n if (getComputedStyle(container).position === 'static') {\n container.style.position = 'relative';\n }\n\n const el = document.createElement('div');\n\n el.className = 'prism-tooltip';\n el.style.position = 'absolute';\n el.style.pointerEvents = 'none';\n el.style.top = '0';\n el.style.left = '0';\n // Non-modal status text — announced by assistive tech whenever content/hide state changes.\n el.setAttribute('role', 'status');\n el.setAttribute('aria-live', 'polite');\n container.appendChild(el);\n\n const tooltipOffset: number = (config !== true && config?.offset) || 8;\n const render = config !== true ? config?.render : undefined;\n const sanitize = config !== true ? config?.sanitize : undefined;\n\n if (render && !sanitize) {\n warn(\n 'createTooltip: `render` is set without `sanitize` — falling back to plain-text rendering of the returned string to avoid an XSS risk. Pass `sanitize` to render HTML.',\n );\n }\n\n const disposeHandle = (): void => {\n el.remove();\n };\n\n return {\n dispose: disposeHandle,\n el,\n hide() {\n el.style.opacity = '0';\n // Clear the live region's text too — otherwise assistive tech keeps announcing the\n // last-hovered value as \"current\" even after the pointer leaves the chart.\n el.textContent = '';\n },\n show(x: number, y: number, datum: Datum, series: Series) {\n if (!container.isConnected) return;\n\n if (render) {\n const html = render(datum, series);\n\n if (sanitize) {\n el.innerHTML = sanitize(html);\n } else {\n // No sanitizer provided — never inject the raw string as HTML. Render it as text instead.\n el.textContent = html;\n }\n } else {\n el.textContent = `${series.name}: ${datum.value}`;\n }\n\n const virtualRef = {\n getBoundingClientRect: () => {\n const rect = container.getBoundingClientRect();\n\n return {\n bottom: rect.top + y,\n height: 0,\n left: rect.left + x,\n right: rect.left + x,\n top: rect.top + y,\n width: 0,\n x: rect.left + x,\n y: rect.top + y,\n };\n },\n };\n\n const { x: posX, y: posY } = computePosition(virtualRef, el, {\n middleware: [offset(tooltipOffset), flip(), shift({ padding: 8 })],\n placement: 'top',\n });\n\n const rect = container.getBoundingClientRect();\n\n el.style.left = `${posX - rect.left}px`;\n el.style.top = `${posY - rect.top}px`;\n el.style.opacity = '1';\n },\n [Symbol.dispose]: disposeHandle,\n };\n}\n"],"mappings":"gEAcA,SAAgB,EAAc,EAAwB,EAA6C,CAC7F,iBAAiB,CAAS,CAAC,CAAC,WAAa,WAC3C,EAAU,MAAM,SAAW,YAG7B,IAAM,EAAK,SAAS,cAAc,KAAK,EAEvC,EAAG,UAAY,gBACf,EAAG,MAAM,SAAW,WACpB,EAAG,MAAM,cAAgB,OACzB,EAAG,MAAM,IAAM,IACf,EAAG,MAAM,KAAO,IAEhB,EAAG,aAAa,OAAQ,QAAQ,EAChC,EAAG,aAAa,YAAa,QAAQ,EACrC,EAAU,YAAY,CAAE,EAExB,IAAM,EAAyB,IAAW,IAAQ,GAAQ,QAAW,EAC/D,EAAS,IAAW,GAAwB,IAAA,GAAjB,GAAQ,OACnC,EAAW,IAAW,GAA0B,IAAA,GAAnB,GAAQ,SAEvC,GAAU,CAAC,GACb,EAAA,KACE,uKACF,EAGF,IAAM,MAA4B,CAChC,EAAG,OAAO,CACZ,EAEA,MAAO,CACL,QAAS,EACT,KACA,MAAO,CACL,EAAG,MAAM,QAAU,IAGnB,EAAG,YAAc,EACnB,EACA,KAAK,EAAW,EAAW,EAAc,EAAgB,CACvD,GAAI,CAAC,EAAU,YAAa,OAE5B,GAAI,EAAQ,CACV,IAAM,EAAO,EAAO,EAAO,CAAM,EAE7B,EACF,EAAG,UAAY,EAAS,CAAI,EAG5B,EAAG,YAAc,CAErB,KACE,GAAG,YAAc,GAAG,EAAO,KAAK,IAAI,EAAM,QAoB5C,GAAM,CAAE,EAAG,EAAM,EAAG,IAAA,EAAA,EAAA,gBAAA,CAAyB,CAhB3C,0BAA6B,CAC3B,IAAM,EAAO,EAAU,sBAAsB,EAE7C,MAAO,CACL,OAAQ,EAAK,IAAM,EACnB,OAAQ,EACR,KAAM,EAAK,KAAO,EAClB,MAAO,EAAK,KAAO,EACnB,IAAK,EAAK,IAAM,EAChB,MAAO,EACP,EAAG,EAAK,KAAO,EACf,EAAG,EAAK,IAAM,CAChB,CACF,CAG2C,EAAY,EAAI,CAC3D,WAAY,cAAQ,CAAa,aAAQ,cAAS,CAAE,QAAS,CAAE,CAAC,CAAC,EACjE,UAAW,KACb,CAAC,EAEK,EAAO,EAAU,sBAAsB,EAE7C,EAAG,MAAM,KAAO,GAAG,EAAO,EAAK,KAAK,IACpC,EAAG,MAAM,IAAM,GAAG,EAAO,EAAK,IAAI,IAClC,EAAG,MAAM,QAAU,GACrB,GACC,OAAO,SAAU,CACpB,CACF"}
|