layerchart 0.0.1 → 0.0.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.
Files changed (70) hide show
  1. package/components/Area.svelte +38 -0
  2. package/components/Area.svelte.d.ts +28 -0
  3. package/components/AreaStack.svelte +40 -0
  4. package/components/AreaStack.svelte.d.ts +20 -0
  5. package/components/AxisX.svelte +52 -0
  6. package/components/AxisX.svelte.d.ts +23 -0
  7. package/components/AxisY.svelte +69 -0
  8. package/components/AxisY.svelte.d.ts +23 -0
  9. package/components/Bar.svelte +93 -0
  10. package/components/Bar.svelte.d.ts +32 -0
  11. package/components/Baseline.svelte +21 -0
  12. package/components/Baseline.svelte.d.ts +17 -0
  13. package/components/Chart.svelte +50 -0
  14. package/components/Chart.svelte.d.ts +24 -0
  15. package/components/Circle.svelte +15 -0
  16. package/components/Circle.svelte.d.ts +22 -0
  17. package/components/ClevelandDotPlot.svelte +44 -0
  18. package/components/ClevelandDotPlot.svelte.d.ts +21 -0
  19. package/components/HighlightBar.svelte +27 -0
  20. package/components/HighlightBar.svelte.d.ts +18 -0
  21. package/components/HighlightLine.svelte +52 -0
  22. package/components/HighlightLine.svelte.d.ts +17 -0
  23. package/components/Label.svelte +96 -0
  24. package/components/Label.svelte.d.ts +22 -0
  25. package/components/Line.svelte +18 -0
  26. package/components/Line.svelte.d.ts +23 -0
  27. package/components/Path.svelte +36 -0
  28. package/components/Path.svelte.d.ts +25 -0
  29. package/components/Rect.svelte +25 -0
  30. package/components/Rect.svelte.d.ts +25 -0
  31. package/components/Scatter.svelte +25 -0
  32. package/components/Scatter.svelte.d.ts +33 -0
  33. package/components/Text.svelte +129 -0
  34. package/components/Text.svelte.d.ts +28 -0
  35. package/components/Threshold.svelte +83 -0
  36. package/components/Threshold.svelte.d.ts +35 -0
  37. package/components/Tooltip.svelte +120 -0
  38. package/components/Tooltip.svelte.d.ts +33 -0
  39. package/docs/Blockquote.svelte +7 -0
  40. package/docs/Blockquote.svelte.d.ts +23 -0
  41. package/docs/Code.svelte +6 -0
  42. package/docs/Code.svelte.d.ts +23 -0
  43. package/docs/Layout.svelte +20 -0
  44. package/docs/Layout.svelte.d.ts +29 -0
  45. package/docs/Link.svelte +7 -0
  46. package/docs/Link.svelte.d.ts +27 -0
  47. package/docs/Preview.svelte +19 -0
  48. package/docs/Preview.svelte.d.ts +19 -0
  49. package/package.json +73 -26
  50. package/stores/motionStore.d.ts +8 -0
  51. package/stores/motionStore.js +16 -0
  52. package/utils/event.d.ts +4 -0
  53. package/utils/event.js +42 -0
  54. package/utils/genData.d.ts +19 -0
  55. package/utils/genData.js +35 -0
  56. package/utils/pivot.d.ts +14 -0
  57. package/utils/pivot.js +36 -0
  58. package/utils/scales.d.ts +10 -0
  59. package/utils/scales.js +21 -0
  60. package/utils/string.d.ts +4 -0
  61. package/utils/string.js +27 -0
  62. package/utils/ticks.d.ts +3 -0
  63. package/utils/ticks.js +157 -0
  64. package/.prettierrc +0 -6
  65. package/src/app.html +0 -12
  66. package/src/global.d.ts +0 -1
  67. package/src/routes/index.svelte +0 -2
  68. package/static/favicon.png +0 -0
  69. package/svelte.config.js +0 -15
  70. package/tsconfig.json +0 -31
@@ -0,0 +1,35 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { CurveFactory } from 'd3-shape';
3
+ declare const __propDef: {
4
+ props: {
5
+ data?: any;
6
+ x?: any;
7
+ y0?: any;
8
+ y1?: any;
9
+ curve?: CurveFactory;
10
+ defined?: (d: [number, number], index: number, data: [number, number][]) => boolean;
11
+ id?: string;
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {
17
+ pathAbove: {
18
+ areaPathData: string;
19
+ clipPath: string;
20
+ linePathData: string;
21
+ };
22
+ pathBelow: {
23
+ areaPathData: string;
24
+ clipPath: string;
25
+ linePathData: string;
26
+ };
27
+ default: {};
28
+ };
29
+ };
30
+ export declare type ThresholdProps = typeof __propDef.props;
31
+ export declare type ThresholdEvents = typeof __propDef.events;
32
+ export declare type ThresholdSlots = typeof __propDef.slots;
33
+ export default class Threshold extends SvelteComponentTyped<ThresholdProps, ThresholdEvents, ThresholdSlots> {
34
+ }
35
+ export {};
@@ -0,0 +1,120 @@
1
+ <script >import { getContext, createEventDispatcher } from 'svelte';
2
+ import { spring } from 'svelte/motion';
3
+ import { fade } from 'svelte/transition';
4
+ import { writable } from 'svelte/store';
5
+ import { bisector } from 'd3-array';
6
+ import { Svg, Html } from './Chart.svelte';
7
+ import { localPoint } from '../utils/event';
8
+ import { isScaleBand, scaleBandInvert } from '../utils/scales';
9
+ const dispatch = createEventDispatcher();
10
+ const { flatData, x, xScale, xGet, yScale, yGet, width, height, padding } = getContext('LayerCake');
11
+ export let snapToDataX = false;
12
+ export let snapToDataY = false;
13
+ export let findTooltipData = 'closest';
14
+ export let topOffset = 10;
15
+ export let leftOffset = 10;
16
+ export let contained = 'container'; // TODO: Support 'window' using getBoundingClientRect()
17
+ export let animate = true;
18
+ let tooltip = null;
19
+ let tooltipWidth = 0;
20
+ let tooltipHeight = 0;
21
+ let top = animate ? spring(0) : writable(0);
22
+ $: if (tooltip) {
23
+ const containerHeight = $height + $padding.bottom;
24
+ if (contained === 'container' && tooltip.top + topOffset + tooltipHeight > containerHeight) {
25
+ // change side
26
+ $top = tooltip.top - (topOffset + tooltipHeight);
27
+ }
28
+ else {
29
+ $top = tooltip.top + topOffset;
30
+ }
31
+ }
32
+ let left = animate ? spring(0) : writable(0);
33
+ $: if (tooltip) {
34
+ const containerWidth = $width + $padding.right;
35
+ if (contained === 'container' && tooltip.left + leftOffset + tooltipWidth > containerWidth) {
36
+ // change side
37
+ $left = tooltip.left - (leftOffset + tooltipWidth);
38
+ }
39
+ else {
40
+ $left = tooltip.left + leftOffset;
41
+ }
42
+ }
43
+ function handleTooltip(event) {
44
+ const point = localPoint(event.target, event);
45
+ const localX = point?.x ?? 0;
46
+ const localY = point?.y ?? 0;
47
+ let tooltipData;
48
+ if (isScaleBand($xScale)) {
49
+ // `x` value at mouse coordinate
50
+ const xValue = scaleBandInvert($xScale)(localX);
51
+ tooltipData = $flatData.find((d) => $x(d) === xValue);
52
+ }
53
+ else {
54
+ // `x` value at mouse coordinate
55
+ const xValue = $xScale.invert(localX);
56
+ const bisectX = bisector($x).left;
57
+ const index = bisectX($flatData, xValue, 1);
58
+ const data0 = $flatData[index - 1];
59
+ const data1 = $flatData[index];
60
+ switch (findTooltipData) {
61
+ case 'closest':
62
+ tooltipData =
63
+ Number(xValue) - Number($x(data0)) > Number($x(data1)) - Number(xValue) ? data1 : data0;
64
+ break;
65
+ case 'left':
66
+ tooltipData = data0;
67
+ break;
68
+ case 'right':
69
+ default:
70
+ tooltipData = data1;
71
+ }
72
+ }
73
+ if (tooltipData) {
74
+ tooltip = {
75
+ left: snapToDataX ? $xGet(tooltipData) : localX,
76
+ top: snapToDataY ? $yGet(tooltipData) : localY,
77
+ data: tooltipData
78
+ };
79
+ }
80
+ }
81
+ function hideTooltip(event) {
82
+ tooltip = null;
83
+ }
84
+ </script>
85
+
86
+ <Html>
87
+ <div
88
+ class="absolute"
89
+ style="width: {$width}px; height: {$height}px; background: _red; z-index: 9999"
90
+ on:touchstart={handleTooltip}
91
+ on:touchmove={handleTooltip}
92
+ on:mousemove={handleTooltip}
93
+ on:mouseleave={hideTooltip}
94
+ on:click={(e) => {
95
+ dispatch('click', { data: tooltip?.data });
96
+ }}
97
+ />
98
+ </Html>
99
+
100
+ {#if tooltip}
101
+ <Html>
102
+ <div
103
+ class="absolute pointer-events-none z-50"
104
+ style="
105
+ top: {$top}px;
106
+ left: {$left}px;
107
+ max-width: {$width / 2}px;
108
+ "
109
+ transition:fade={{ duration: 100 }}
110
+ bind:clientWidth={tooltipWidth}
111
+ bind:clientHeight={tooltipHeight}
112
+ >
113
+ <slot data={tooltip?.data} />
114
+ </div>
115
+ </Html>
116
+
117
+ <Svg>
118
+ <slot name="highlight" data={tooltip?.data} />
119
+ </Svg>
120
+ {/if}
@@ -0,0 +1,33 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ snapToDataX?: boolean;
5
+ snapToDataY?: boolean;
6
+ findTooltipData?: 'closest' | 'left' | 'right';
7
+ topOffset?: number;
8
+ leftOffset?: number;
9
+ contained?: 'container' | false;
10
+ animate?: boolean;
11
+ };
12
+ events: {
13
+ click: CustomEvent<{
14
+ data: any;
15
+ }>;
16
+ } & {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {
20
+ default: {
21
+ data: any;
22
+ };
23
+ highlight: {
24
+ data: any;
25
+ };
26
+ };
27
+ };
28
+ export declare type TooltipProps = typeof __propDef.props;
29
+ export declare type TooltipEvents = typeof __propDef.events;
30
+ export declare type TooltipSlots = typeof __propDef.slots;
31
+ export default class Tooltip extends SvelteComponentTyped<TooltipProps, TooltipEvents, TooltipSlots> {
32
+ }
33
+ export {};
@@ -0,0 +1,7 @@
1
+ <script>
2
+ // console.log($$props, $$slots);
3
+ </script>
4
+
5
+ <div class="bg-black/5 border-l-4 border-blue-500 p-4 my-4 rounded">
6
+ <slot />
7
+ </div>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} BlockquoteProps */
2
+ /** @typedef {typeof __propDef.events} BlockquoteEvents */
3
+ /** @typedef {typeof __propDef.slots} BlockquoteSlots */
4
+ export default class Blockquote extends SvelteComponentTyped<{}, {
5
+ [evt: string]: CustomEvent<any>;
6
+ }, {
7
+ default: {};
8
+ }> {
9
+ }
10
+ export type BlockquoteProps = typeof __propDef.props;
11
+ export type BlockquoteEvents = typeof __propDef.events;
12
+ export type BlockquoteSlots = typeof __propDef.slots;
13
+ import { SvelteComponentTyped } from "svelte";
14
+ declare const __propDef: {
15
+ props: {};
16
+ events: {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {
20
+ default: {};
21
+ };
22
+ };
23
+ export {};
@@ -0,0 +1,6 @@
1
+ <script>
2
+ // TODO: Improve code highlighting, add quick copy buttons, support REPL, etc
3
+ // console.log($$props, $$slots);
4
+ </script>
5
+
6
+ <slot />
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} CodeProps */
2
+ /** @typedef {typeof __propDef.events} CodeEvents */
3
+ /** @typedef {typeof __propDef.slots} CodeSlots */
4
+ export default class Code extends SvelteComponentTyped<{}, {
5
+ [evt: string]: CustomEvent<any>;
6
+ }, {
7
+ default: {};
8
+ }> {
9
+ }
10
+ export type CodeProps = typeof __propDef.props;
11
+ export type CodeEvents = typeof __propDef.events;
12
+ export type CodeSlots = typeof __propDef.slots;
13
+ import { SvelteComponentTyped } from "svelte";
14
+ declare const __propDef: {
15
+ props: {};
16
+ events: {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {
20
+ default: {};
21
+ };
22
+ };
23
+ export {};
@@ -0,0 +1,20 @@
1
+ <script context="module">
2
+ // Custom components: https://mdsvex.com/docs#custom-components
3
+ import blockquote from './Blockquote.svelte';
4
+ import a from './Link.svelte';
5
+
6
+ export { a, blockquote };
7
+ </script>
8
+
9
+ <script>
10
+ import { AppBar } from 'svelte-ux';
11
+
12
+ // frontmatter: https://mdsvex.com/docs#frontmatter-1
13
+ export let title;
14
+ </script>
15
+
16
+ <AppBar {title} />
17
+
18
+ <main class="p-2">
19
+ <slot />
20
+ </main>
@@ -0,0 +1,29 @@
1
+ /** @typedef {typeof __propDef.props} LayoutProps */
2
+ /** @typedef {typeof __propDef.events} LayoutEvents */
3
+ /** @typedef {typeof __propDef.slots} LayoutSlots */
4
+ export default class Layout extends SvelteComponentTyped<{
5
+ title: any;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {
9
+ default: {};
10
+ }> {
11
+ }
12
+ export type LayoutProps = typeof __propDef.props;
13
+ export type LayoutEvents = typeof __propDef.events;
14
+ export type LayoutSlots = typeof __propDef.slots;
15
+ import a from "./Link.svelte";
16
+ import blockquote from "./Blockquote.svelte";
17
+ import { SvelteComponentTyped } from "svelte";
18
+ declare const __propDef: {
19
+ props: {
20
+ title: any;
21
+ };
22
+ events: {
23
+ [evt: string]: CustomEvent<any>;
24
+ };
25
+ slots: {
26
+ default: {};
27
+ };
28
+ };
29
+ export { a, blockquote };
@@ -0,0 +1,7 @@
1
+ <script>
2
+ // console.log($$props, $$slots);
3
+ </script>
4
+
5
+ <a class="text-blue-500 font-medium" {...$$restProps}>
6
+ <slot />
7
+ </a>
@@ -0,0 +1,27 @@
1
+ /** @typedef {typeof __propDef.props} LinkProps */
2
+ /** @typedef {typeof __propDef.events} LinkEvents */
3
+ /** @typedef {typeof __propDef.slots} LinkSlots */
4
+ export default class Link extends SvelteComponentTyped<{
5
+ [x: string]: any;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {
9
+ default: {};
10
+ }> {
11
+ }
12
+ export type LinkProps = typeof __propDef.props;
13
+ export type LinkEvents = typeof __propDef.events;
14
+ export type LinkSlots = typeof __propDef.slots;
15
+ import { SvelteComponentTyped } from "svelte";
16
+ declare const __propDef: {
17
+ props: {
18
+ [x: string]: any;
19
+ };
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {
24
+ default: {};
25
+ };
26
+ };
27
+ export {};
@@ -0,0 +1,19 @@
1
+ <script >export let code = null;
2
+ export let language = 'svelte';
3
+ </script>
4
+
5
+ <div class="border border-black/20 rounded bg-white">
6
+ <div class="p-4">
7
+ <slot />
8
+ </div>
9
+
10
+ {#if code}
11
+ <pre
12
+ class="language-{language} rounded"
13
+ style="margin: 0">
14
+ <code class="language-{language}">
15
+ {@html code}
16
+ </code>
17
+ </pre>
18
+ {/if}
19
+ </div>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ code?: any;
5
+ language?: string;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ default: {};
12
+ };
13
+ };
14
+ export declare type PreviewProps = typeof __propDef.props;
15
+ export declare type PreviewEvents = typeof __propDef.events;
16
+ export declare type PreviewSlots = typeof __propDef.slots;
17
+ export default class Preview extends SvelteComponentTyped<PreviewProps, PreviewEvents, PreviewSlots> {
18
+ }
19
+ export {};
package/package.json CHANGED
@@ -1,27 +1,74 @@
1
1
  {
2
- "name": "layerchart",
3
- "author": "Sean Lynch <techniq35@gmail.com>",
4
- "license": "MIT",
5
- "repository": "techniq/layerchart",
6
- "version": "0.0.1",
7
- "scripts": {
8
- "dev": "svelte-kit dev",
9
- "build": "svelte-kit build",
10
- "preview": "svelte-kit preview",
11
- "check": "svelte-check --tsconfig ./tsconfig.json",
12
- "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
13
- "lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
14
- "format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
15
- },
16
- "devDependencies": {
17
- "@sveltejs/kit": "next",
18
- "prettier": "~2.2.1",
19
- "prettier-plugin-svelte": "^2.2.0",
20
- "svelte": "^3.34.0",
21
- "svelte-check": "^2.0.0",
22
- "svelte-preprocess": "^4.0.0",
23
- "tslib": "^2.0.0",
24
- "typescript": "^4.0.0"
25
- },
26
- "type": "module"
27
- }
2
+ "name": "layerchart",
3
+ "author": "Sean Lynch <techniq35@gmail.com>",
4
+ "license": "MIT",
5
+ "repository": "techniq/layerchart",
6
+ "version": "0.0.2",
7
+ "devDependencies": {
8
+ "@sveltejs/adapter-static": "^1.0.0-next.21",
9
+ "@sveltejs/kit": "1.0.0-next.196",
10
+ "@types/d3-array": "^3.0.2",
11
+ "@types/d3-scale": "^4.0.2",
12
+ "@types/d3-shape": "^3.0.2",
13
+ "@types/lodash-es": "^4.17.5",
14
+ "autoprefixer": "^10.4.0",
15
+ "mdsvex": "^0.9.8",
16
+ "prettier": "^2.4.1",
17
+ "prettier-plugin-svelte": "^2.5.0",
18
+ "prism-themes": "^1.9.0",
19
+ "svelte": "^3.44.2",
20
+ "svelte-check": "^2.2.10",
21
+ "svelte-preprocess": "^4.9.4",
22
+ "svelte2tsx": "^0.4.10",
23
+ "tailwindcss": "^2.2.19",
24
+ "tailwindcss-elevation": "^1.0.1",
25
+ "tslib": "^2.3.1",
26
+ "typescript": "^4.5.2",
27
+ "unist-util-visit": "^4.1.0"
28
+ },
29
+ "type": "module",
30
+ "dependencies": {
31
+ "@mdi/js": "^6.5.95",
32
+ "d3-array": "^3.1.1",
33
+ "d3-scale": "^4.0.2",
34
+ "d3-shape": "^3.0.1",
35
+ "date-fns": "^2.26.0",
36
+ "layercake": "^5.0.0",
37
+ "lodash-es": "^4.17.21",
38
+ "svelte-ux": "^0.0.102"
39
+ },
40
+ "exports": {
41
+ "./package.json": "./package.json",
42
+ "./components/Area.svelte": "./components/Area.svelte",
43
+ "./components/AreaStack.svelte": "./components/AreaStack.svelte",
44
+ "./components/AxisX.svelte": "./components/AxisX.svelte",
45
+ "./components/AxisY.svelte": "./components/AxisY.svelte",
46
+ "./components/Bar.svelte": "./components/Bar.svelte",
47
+ "./components/Baseline.svelte": "./components/Baseline.svelte",
48
+ "./components/Chart.svelte": "./components/Chart.svelte",
49
+ "./components/Circle.svelte": "./components/Circle.svelte",
50
+ "./components/ClevelandDotPlot.svelte": "./components/ClevelandDotPlot.svelte",
51
+ "./components/HighlightBar.svelte": "./components/HighlightBar.svelte",
52
+ "./components/HighlightLine.svelte": "./components/HighlightLine.svelte",
53
+ "./components/Label.svelte": "./components/Label.svelte",
54
+ "./components/Line.svelte": "./components/Line.svelte",
55
+ "./components/Path.svelte": "./components/Path.svelte",
56
+ "./components/Rect.svelte": "./components/Rect.svelte",
57
+ "./components/Scatter.svelte": "./components/Scatter.svelte",
58
+ "./components/Text.svelte": "./components/Text.svelte",
59
+ "./components/Threshold.svelte": "./components/Threshold.svelte",
60
+ "./components/Tooltip.svelte": "./components/Tooltip.svelte",
61
+ "./docs/Blockquote.svelte": "./docs/Blockquote.svelte",
62
+ "./docs/Code.svelte": "./docs/Code.svelte",
63
+ "./docs/Layout.svelte": "./docs/Layout.svelte",
64
+ "./docs/Link.svelte": "./docs/Link.svelte",
65
+ "./docs/Preview.svelte": "./docs/Preview.svelte",
66
+ "./stores/motionStore": "./stores/motionStore.js",
67
+ "./utils/event": "./utils/event.js",
68
+ "./utils/genData": "./utils/genData.js",
69
+ "./utils/pivot": "./utils/pivot.js",
70
+ "./utils/scales": "./utils/scales.js",
71
+ "./utils/string": "./utils/string.js",
72
+ "./utils/ticks": "./utils/ticks.js"
73
+ }
74
+ }
@@ -0,0 +1,8 @@
1
+ import { spring, tweened } from 'svelte/motion';
2
+ /**
3
+ * Convenient wrapper to get motion store based on properties, or fall back to basic writable() store
4
+ */
5
+ export declare function getMotionStore(value: any, options: {
6
+ spring: boolean | Parameters<typeof spring>[1];
7
+ tweened: boolean | Parameters<typeof tweened>[1];
8
+ }): import("svelte/motion").Tweened<unknown> | import("svelte/motion").Spring<any> | import("svelte/store").Writable<any>;
@@ -0,0 +1,16 @@
1
+ import { writable } from 'svelte/store';
2
+ import { spring, tweened } from 'svelte/motion';
3
+ /**
4
+ * Convenient wrapper to get motion store based on properties, or fall back to basic writable() store
5
+ */
6
+ export function getMotionStore(value, options) {
7
+ if (options.spring) {
8
+ return spring(value, options.spring === true ? undefined : options.spring);
9
+ }
10
+ else if (options.tweened) {
11
+ return tweened(value, options.tweened === true ? undefined : options.tweened);
12
+ }
13
+ else {
14
+ return writable(value);
15
+ }
16
+ }
@@ -0,0 +1,4 @@
1
+ export declare function localPoint(node: Element, event: MouseEvent | TouchEvent): {
2
+ x: number;
3
+ y: number;
4
+ };
package/utils/event.js ADDED
@@ -0,0 +1,42 @@
1
+ import { isSVGElement, isSVGGraphicsElement, isSVGSVGElement, isTouchEvent } from 'svelte-ux/types/typeGuards';
2
+ // See: https://github.com/airbnb/visx/blob/master/packages/visx-event/src/localPointGeneric.ts
3
+ export function localPoint(node, event) {
4
+ if (!node || !event)
5
+ return null;
6
+ const coords = getPointFromEvent(event);
7
+ // find top-most SVG
8
+ const svg = isSVGElement(node) ? node.ownerSVGElement : node;
9
+ const screenCTM = isSVGGraphicsElement(svg) ? svg.getScreenCTM() : null;
10
+ if (isSVGSVGElement(svg) && screenCTM) {
11
+ let point = svg.createSVGPoint();
12
+ point.x = coords.x;
13
+ point.y = coords.y;
14
+ point = point.matrixTransform(screenCTM.inverse());
15
+ return {
16
+ x: point.x,
17
+ y: point.y
18
+ };
19
+ }
20
+ // fall back to bounding box
21
+ const rect = node.getBoundingClientRect();
22
+ return {
23
+ x: coords.x - rect.left - node.clientLeft,
24
+ y: coords.y - rect.top - node.clientTop
25
+ };
26
+ }
27
+ function getPointFromEvent(event) {
28
+ if (!event)
29
+ return { x: 0, y: 0 };
30
+ if (isTouchEvent(event)) {
31
+ return event.changedTouches.length > 0
32
+ ? {
33
+ x: event.changedTouches[0].clientX,
34
+ y: event.changedTouches[0].clientY
35
+ }
36
+ : { x: 0, y: 0 };
37
+ }
38
+ return {
39
+ x: event.clientX,
40
+ y: event.clientY
41
+ };
42
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Get random number between min (inclusive) and max (exclusive)
3
+ * see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_number_between_0_inclusive_and_1_exclusive
4
+ */
5
+ export declare function getRandomNumber(min: number, max: number): number;
6
+ /**
7
+ * Get random integer between min (inclusive) and max (inclusive by default)
8
+ * see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive
9
+ */
10
+ export declare function getRandomInteger(min: number, max: number, includeMax?: boolean): number;
11
+ export declare function createDateSeries(options: {
12
+ count?: number;
13
+ min: number;
14
+ max: number;
15
+ keys: Array<string>;
16
+ value: 'number' | 'integer';
17
+ }): {
18
+ date: Date;
19
+ }[];
@@ -0,0 +1,35 @@
1
+ import { subDays } from 'date-fns';
2
+ /**
3
+ * Get random number between min (inclusive) and max (exclusive)
4
+ * see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_number_between_0_inclusive_and_1_exclusive
5
+ */
6
+ export function getRandomNumber(min, max) {
7
+ return Math.random() * (max - min) + min;
8
+ }
9
+ /**
10
+ * Get random integer between min (inclusive) and max (inclusive by default)
11
+ * see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_integer_between_two_values_inclusive
12
+ */
13
+ export function getRandomInteger(min, max, includeMax = true) {
14
+ min = Math.ceil(min);
15
+ max = Math.floor(max);
16
+ return Math.floor(Math.random() * (max - min + (includeMax ? 1 : 0)) + min);
17
+ }
18
+ export function createDateSeries(options) {
19
+ const now = new Date();
20
+ const count = options.count ?? 10;
21
+ const min = options.min;
22
+ const max = options.max;
23
+ const keys = options.keys ?? ['value'];
24
+ return Array.from({ length: count }).map((_, i) => {
25
+ return {
26
+ date: subDays(now, count - i - 1),
27
+ ...Object.fromEntries(keys.map((key) => {
28
+ return [
29
+ key,
30
+ options.value === 'integer' ? getRandomInteger(min, max) : getRandomNumber(min, max)
31
+ ];
32
+ }))
33
+ };
34
+ });
35
+ }
@@ -0,0 +1,14 @@
1
+ export declare function getAccessor(key: any): any;
2
+ /**
3
+ * Pivot longer (columns to rows)
4
+ * - see: https://observablehq.com/d/3ea8d446f5ba96fe
5
+ * - see also: https://observablehq.com/d/ac2a320cf2b0adc4 as generator
6
+ */
7
+ export declare function pivotLonger(data: any, columns: any, name: any, value: any): any;
8
+ /**
9
+ * Pivot wider (rows to columns)
10
+ * - see: https://github.com/d3/d3-array/issues/142#issuecomment-761861983
11
+ */
12
+ export declare function pivotWider(data: any, column: any, name: any, value: any): any[];
13
+ export declare function first(items: any): any;
14
+ export declare function last(items: any): any;