@unovis/react 1.7.0-pre.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +4 -0
  2. package/components/annotations/index.d.ts +12 -10
  3. package/components/annotations/index.js +32 -27
  4. package/components/annotations/index.js.map +1 -1
  5. package/components/area/index.d.ts +13 -11
  6. package/components/area/index.js +33 -29
  7. package/components/area/index.js.map +1 -1
  8. package/components/axis/index.d.ts +13 -11
  9. package/components/axis/index.js +33 -29
  10. package/components/axis/index.js.map +1 -1
  11. package/components/boxplot/index.d.ts +13 -0
  12. package/components/boxplot/index.js +35 -0
  13. package/components/boxplot/index.js.map +1 -0
  14. package/components/brush/index.d.ts +13 -11
  15. package/components/brush/index.js +33 -29
  16. package/components/brush/index.js.map +1 -1
  17. package/components/chord-diagram/index.d.ts +17 -14
  18. package/components/chord-diagram/index.js +33 -29
  19. package/components/chord-diagram/index.js.map +1 -1
  20. package/components/crosshair/index.d.ts +13 -11
  21. package/components/crosshair/index.js +33 -29
  22. package/components/crosshair/index.js.map +1 -1
  23. package/components/donut/index.d.ts +13 -11
  24. package/components/donut/index.js +33 -29
  25. package/components/donut/index.js.map +1 -1
  26. package/components/free-brush/index.d.ts +13 -11
  27. package/components/free-brush/index.js +33 -29
  28. package/components/free-brush/index.js.map +1 -1
  29. package/components/graph/index.d.ts +39 -36
  30. package/components/graph/index.js +33 -29
  31. package/components/graph/index.js.map +1 -1
  32. package/components/grouped-bar/index.d.ts +13 -11
  33. package/components/grouped-bar/index.js +33 -29
  34. package/components/grouped-bar/index.js.map +1 -1
  35. package/components/heatmap/index.d.ts +13 -0
  36. package/components/heatmap/index.js +35 -0
  37. package/components/heatmap/index.js.map +1 -0
  38. package/components/line/index.d.ts +13 -11
  39. package/components/line/index.js +33 -29
  40. package/components/line/index.js.map +1 -1
  41. package/components/nested-donut/index.d.ts +13 -11
  42. package/components/nested-donut/index.js +33 -29
  43. package/components/nested-donut/index.js.map +1 -1
  44. package/components/plotband/index.d.ts +12 -10
  45. package/components/plotband/index.js +32 -27
  46. package/components/plotband/index.js.map +1 -1
  47. package/components/plotline/index.d.ts +12 -10
  48. package/components/plotline/index.js +32 -27
  49. package/components/plotline/index.js.map +1 -1
  50. package/components/radial-bar/index.d.ts +13 -0
  51. package/components/radial-bar/index.js +35 -0
  52. package/components/radial-bar/index.js.map +1 -0
  53. package/components/sankey/index.d.ts +17 -14
  54. package/components/sankey/index.js +33 -29
  55. package/components/sankey/index.js.map +1 -1
  56. package/components/scatter/index.d.ts +13 -11
  57. package/components/scatter/index.js +33 -29
  58. package/components/scatter/index.js.map +1 -1
  59. package/components/stacked-bar/index.d.ts +13 -11
  60. package/components/stacked-bar/index.js +33 -29
  61. package/components/stacked-bar/index.js.map +1 -1
  62. package/components/timeline/index.d.ts +13 -11
  63. package/components/timeline/index.js +33 -29
  64. package/components/timeline/index.js.map +1 -1
  65. package/components/tooltip/index.d.ts +12 -10
  66. package/components/tooltip/index.js +32 -27
  67. package/components/tooltip/index.js.map +1 -1
  68. package/components/topojson-map/index.d.ts +17 -15
  69. package/components/topojson-map/index.js +33 -29
  70. package/components/topojson-map/index.js.map +1 -1
  71. package/components/treemap/index.d.ts +13 -11
  72. package/components/treemap/index.js +33 -29
  73. package/components/treemap/index.js.map +1 -1
  74. package/components/xy-labels/index.d.ts +13 -11
  75. package/components/xy-labels/index.js +33 -29
  76. package/components/xy-labels/index.js.map +1 -1
  77. package/components.d.ts +30 -27
  78. package/composites/time-series/index.d.ts +55 -54
  79. package/composites/time-series/index.js +65 -60
  80. package/composites/time-series/index.js.map +1 -1
  81. package/composites/time-series/style.module.css.js +14 -7
  82. package/composites/time-series/style.module.css.js.map +1 -1
  83. package/composites.d.ts +1 -1
  84. package/containers/single-container/index.d.ts +9 -8
  85. package/containers/single-container/index.js +67 -49
  86. package/containers/single-container/index.js.map +1 -1
  87. package/containers/xy-container/index.d.ts +10 -9
  88. package/containers/xy-container/index.js +71 -57
  89. package/containers/xy-container/index.js.map +1 -1
  90. package/containers.d.ts +2 -2
  91. package/html-components/bullet-legend/index.d.ts +13 -11
  92. package/html-components/bullet-legend/index.js +30 -27
  93. package/html-components/bullet-legend/index.js.map +1 -1
  94. package/html-components/flow-legend/index.d.ts +13 -11
  95. package/html-components/flow-legend/index.js +30 -27
  96. package/html-components/flow-legend/index.js.map +1 -1
  97. package/html-components/leaflet-flow-map/index.d.ts +18 -15
  98. package/html-components/leaflet-flow-map/index.js +31 -29
  99. package/html-components/leaflet-flow-map/index.js.map +1 -1
  100. package/html-components/leaflet-map/index.d.ts +15 -12
  101. package/html-components/leaflet-map/index.js +31 -29
  102. package/html-components/leaflet-map/index.js.map +1 -1
  103. package/html-components/rolling-pin-legend/index.d.ts +13 -11
  104. package/html-components/rolling-pin-legend/index.js +30 -27
  105. package/html-components/rolling-pin-legend/index.js.map +1 -1
  106. package/index.d.ts +3 -3
  107. package/index.js +111 -30
  108. package/index.js.map +1 -1
  109. package/package.json +19 -19
  110. package/types/dom.d.ts +3 -3
  111. package/utils/container.d.ts +5 -0
  112. package/utils/container.js +18 -0
  113. package/utils/container.js.map +1 -0
  114. package/utils/react.d.ts +5 -4
  115. package/utils/react.js +22 -29
  116. package/utils/react.js.map +1 -1
  117. package/external/.pnpm/style-inject@0.3.0/external/style-inject/dist/style-inject.es.js +0 -29
  118. package/external/.pnpm/style-inject@0.3.0/external/style-inject/dist/style-inject.es.js.map +0 -1
@@ -1,62 +1,67 @@
1
- import React, { useState, useMemo } from 'react';
2
- import { Scale, TextAlign } from '@unovis/ts';
3
- import { VisXYContainer } from '../../containers/xy-container/index.js';
4
- import { VisArea } from '../../components/area/index.js';
5
- import { VisAxis } from '../../components/axis/index.js';
6
- import { VisCrosshair } from '../../components/crosshair/index.js';
7
- import { VisTooltip } from '../../components/tooltip/index.js';
8
- import { VisBrush } from '../../components/brush/index.js';
9
- import s from './style.module.css.js';
10
-
11
- function VisTimeSeries(props) {
12
- var _a;
13
- const [selectedRange, setSelectedRange] = useState(undefined);
14
- const [animationDuration, setAnimationDuration] = useState(0);
15
- const xScale = useMemo(() => Scale.scaleTime(), []);
16
- const xScaleNav = useMemo(() => Scale.scaleTime(), []);
17
- const onBrushStart = useMemo(() => (selection, e, userDriven) => {
18
- var _a;
19
- if (userDriven)
20
- setAnimationDuration(0);
21
- (_a = props.onBrushStart) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
22
- }, []);
23
- const onBrushMove = useMemo(() => (selection, e, userDriven) => {
24
- var _a;
25
- if (userDriven && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[0]) !== selection[0] && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[1]) !== selection[1])
26
- setSelectedRange(selection);
27
- (_a = props.onBrushMove) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
28
- }, []);
29
- const onBrushEnd = useMemo(() => (selection, e, userDriven) => {
30
- var _a;
31
- if (userDriven && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[0]) !== selection[0] && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[1]) !== selection[1])
32
- setSelectedRange(selection);
33
- setAnimationDuration(undefined);
34
- (_a = props.onBrushEnd) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
35
- }, []);
36
- return (React.createElement("div", { className: `${s.timeSeriesContainer}${props.className ? `.${props.className}` : ''}`, style: { height: props.height } },
37
- React.createElement(VisXYContainer, { className: s.timeSeriesModule, data: props.data, xScale: xScale, xDomain: selectedRange, duration: animationDuration, scaleByDomain: true },
38
- React.createElement(VisArea, { x: props.x, y: props.y, color: props.color }),
39
- React.createElement(VisAxis, { type: 'x', numTicks: 5, tickFormat: props.formatXTicks, tickTextAlign: TextAlign.Center }),
40
- React.createElement(VisAxis, { type: 'y', tickFormat: props.formatYTicks, label: props.yLabel }),
41
- React.createElement(VisTooltip, null),
42
- React.createElement(VisCrosshair, { template: props.crosshairTemplate })),
43
- React.createElement(VisXYContainer, { className: s.navigationModule, duration: 0, xScale: xScaleNav, data: props.data },
44
- React.createElement(VisArea, { x: props.x, y: props.y }),
45
- React.createElement(VisBrush, { draggable: true, onBrushStart: onBrushStart, onBrushMove: onBrushMove, onBrushEnd: onBrushEnd }),
46
- React.createElement(VisAxis, { type: 'x', numTicks: 5, tickFormat: (_a = props.formatXTicks) !== null && _a !== void 0 ? _a : props.formatNavXTicks, tickTextAlign: TextAlign.Right, label: props.xLabel }),
47
- React.createElement(VisAxis, { type: 'y', tickFormat: props.formatYTicks, minMaxTicksOnly: true, label: props.yLabel ? ' ' : undefined }))));
48
- }
49
- VisTimeSeries.defaultProps = {
50
- margin: { top: 10, bottom: 10, left: 10, right: 10 },
51
- autoMargin: true,
52
- padding: {},
53
- x: (d) => d.timestamp,
54
- y: (d) => d.value,
55
- id: (d) => d.id,
56
- color: (d) => null,
57
- formatYTicks: (d) => d.toFixed(1),
58
- crosshairTemplate: (d) => { var _a; return `<div>Date: ${new Date(d.timestamp).toLocaleDateString()}</div><div>Value: ${(_a = d.value) === null || _a === void 0 ? void 0 : _a.toFixed(1)}</div>`; },
1
+ import React, { useState, useMemo } from "react";
2
+ import { TextAlign } from "@unovis/ts/types/text";
3
+ import { Scale } from "@unovis/ts/types/scale";
4
+ import { VisXYContainer } from "../../containers/xy-container/index.js";
5
+ import { VisArea } from "../../components/area/index.js";
6
+ import { VisAxis } from "../../components/axis/index.js";
7
+ import { VisCrosshair } from "../../components/crosshair/index.js";
8
+ import { VisTooltip } from "../../components/tooltip/index.js";
9
+ import { VisBrush } from "../../components/brush/index.js";
10
+ import s from "./style.module.css.js";
11
+ function VisTimeSeries(props) {
12
+ const [selectedRange, setSelectedRange] = useState(void 0);
13
+ const [animationDuration, setAnimationDuration] = useState(0);
14
+ const xScale = useMemo(() => Scale.scaleTime(), []);
15
+ const xScaleNav = useMemo(() => Scale.scaleTime(), []);
16
+ const onBrushStart = useMemo(() => (selection, e, userDriven) => {
17
+ if (userDriven) setAnimationDuration(0);
18
+ props.onBrushStart?.(selection, e, userDriven);
19
+ }, []);
20
+ const onBrushMove = useMemo(() => (selection, e, userDriven) => {
21
+ if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection);
22
+ props.onBrushMove?.(selection, e, userDriven);
23
+ }, []);
24
+ const onBrushEnd = useMemo(() => (selection, e, userDriven) => {
25
+ if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection);
26
+ setAnimationDuration(void 0);
27
+ props.onBrushEnd?.(selection, e, userDriven);
28
+ }, []);
29
+ return /* @__PURE__ */ React.createElement("div", { className: `${s.timeSeriesContainer}${props.className ? `.${props.className}` : ""}`, style: { height: props.height } }, /* @__PURE__ */ React.createElement(
30
+ VisXYContainer,
31
+ {
32
+ className: s.timeSeriesModule,
33
+ data: props.data,
34
+ xScale,
35
+ xDomain: selectedRange,
36
+ duration: animationDuration,
37
+ scaleByDomain: true
38
+ },
39
+ /* @__PURE__ */ React.createElement(
40
+ VisArea,
41
+ {
42
+ x: props.x,
43
+ y: props.y,
44
+ color: props.color
45
+ }
46
+ ),
47
+ /* @__PURE__ */ React.createElement(VisAxis, { type: "x", numTicks: 5, tickFormat: props.formatXTicks, tickTextAlign: TextAlign.Center }),
48
+ /* @__PURE__ */ React.createElement(VisAxis, { type: "y", tickFormat: props.formatYTicks, label: props.yLabel }),
49
+ /* @__PURE__ */ React.createElement(VisTooltip, null),
50
+ /* @__PURE__ */ React.createElement(VisCrosshair, { template: props.crosshairTemplate })
51
+ ), /* @__PURE__ */ React.createElement(VisXYContainer, { className: s.navigationModule, duration: 0, xScale: xScaleNav, data: props.data }, /* @__PURE__ */ React.createElement(VisArea, { x: props.x, y: props.y }), /* @__PURE__ */ React.createElement(VisBrush, { draggable: true, onBrushStart, onBrushMove, onBrushEnd }), /* @__PURE__ */ React.createElement(VisAxis, { type: "x", numTicks: 5, tickFormat: props.formatXTicks ?? props.formatNavXTicks, tickTextAlign: TextAlign.Right, label: props.xLabel }), /* @__PURE__ */ React.createElement(VisAxis, { type: "y", tickFormat: props.formatYTicks, minMaxTicksOnly: true, label: props.yLabel ? " " : void 0 })));
52
+ }
53
+ VisTimeSeries.defaultProps = {
54
+ margin: { top: 10, bottom: 10, left: 10, right: 10 },
55
+ autoMargin: true,
56
+ padding: {},
57
+ x: (d) => d.timestamp,
58
+ y: (d) => d.value,
59
+ id: (d) => d.id,
60
+ color: (d) => null,
61
+ formatYTicks: (d) => d.toFixed(1),
62
+ crosshairTemplate: (d) => `<div>Date: ${new Date(d.timestamp).toLocaleDateString()}</div><div>Value: ${d.value?.toFixed(1)}</div>`
63
+ };
64
+ export {
65
+ VisTimeSeries
59
66
  };
60
-
61
- export { VisTimeSeries };
62
67
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/composites/time-series/index.tsx"],"sourcesContent":["import React, { useState, useMemo } from 'react'\nimport { Spacing, TextAlign, Scale } from '@unovis/ts'\nimport { VisXYContainer } from '@unovis/react/containers/xy-container'\nimport { VisArea } from '@unovis/react/components/area'\nimport { VisAxis } from '@unovis/react/components/axis'\nimport { VisCrosshair } from '@unovis/react/components/crosshair'\nimport { VisTooltip } from '@unovis/react/components/tooltip'\nimport { VisBrush } from '@unovis/react/components/brush'\n\nimport s from './style.module.css'\n\nexport type VisTimeSeriesDatum = {\n timestamp: number;\n value: number;\n id?: string;\n color?: string;\n}\n\nexport type VisTimeSeriesProps<Datum> = {\n data: Datum[];\n margin: Spacing;\n autoMargin: boolean;\n\n x: (d: Datum, i: number) => number;\n y: (d: Datum, i: number) => number;\n id: (d: Datum, i: number) => string;\n color: (d: Datum[], i: number) => string | null;\n cursor: string | ((d: Datum, i: number) => string);\n formatXTicks?: (timestamp: number) => string;\n formatYTicks?: (timestamp: number) => string;\n\n selectionMinLength: number;\n onBrushStart?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n onBrushMove?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n onBrushEnd?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n formatNavXTicks?: (timestamp: number) => string;\n\n xLabel?: string;\n yLabel?: string;\n\n crosshairTemplate?: (d: Datum) => string | HTMLElement;\n\n className?: string;\n height?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function VisTimeSeries<Datum> (props: VisTimeSeriesProps<Datum>): JSX.Element {\n const [selectedRange, setSelectedRange] = useState<[number, number] | undefined>(undefined)\n const [animationDuration, setAnimationDuration] = useState<number | undefined>(0)\n const xScale = useMemo(() => Scale.scaleTime(), [])\n const xScaleNav = useMemo(() => Scale.scaleTime(), [])\n\n // On Mount\n // useEffect(() => {}, [])\n\n // On Props Update\n // useEffect(() => {})\n\n // Brush callbacks\n const onBrushStart = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven) setAnimationDuration(0)\n props.onBrushStart?.(selection, e, userDriven)\n }, [])\n\n const onBrushMove = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection)\n props.onBrushMove?.(selection, e, userDriven)\n }, [])\n\n const onBrushEnd = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection)\n setAnimationDuration(undefined)\n props.onBrushEnd?.(selection, e, userDriven)\n }, [])\n\n return (\n <div className={`${s.timeSeriesContainer}${props.className ? `.${props.className}` : ''}`} style={{ height: props.height }}>\n <VisXYContainer\n className={s.timeSeriesModule}\n data={props.data}\n xScale={xScale}\n xDomain={selectedRange}\n duration={animationDuration}\n scaleByDomain={true}\n >\n <VisArea\n x={props.x}\n y={props.y}\n color={props.color}\n />\n <VisAxis type='x' numTicks={5} tickFormat={props.formatXTicks} tickTextAlign={TextAlign.Center}/>\n <VisAxis type='y' tickFormat={props.formatYTicks} label={props.yLabel}/>\n <VisTooltip />\n <VisCrosshair template={props.crosshairTemplate}/>\n </VisXYContainer>\n <VisXYContainer className={s.navigationModule} duration={0} xScale={xScaleNav} data={props.data}>\n <VisArea x={props.x} y={props.y} />\n <VisBrush draggable={true} onBrushStart={onBrushStart} onBrushMove={onBrushMove} onBrushEnd={onBrushEnd} />\n <VisAxis type='x' numTicks={5} tickFormat={props.formatXTicks ?? props.formatNavXTicks} tickTextAlign={TextAlign.Right} label={props.xLabel}/>\n <VisAxis type='y' tickFormat={props.formatYTicks} minMaxTicksOnly={true} label={props.yLabel ? ' ' : undefined}/>\n </VisXYContainer>\n </div>\n )\n}\n\nVisTimeSeries.defaultProps = {\n margin: { top: 10, bottom: 10, left: 10, right: 10 },\n autoMargin: true,\n padding: {},\n\n x: (d: VisTimeSeriesDatum) => d.timestamp,\n y: (d: VisTimeSeriesDatum) => d.value,\n id: (d: VisTimeSeriesDatum) => d.id,\n color: (d: VisTimeSeriesDatum[]) => null,\n\n formatYTicks: (d: number) => d.toFixed(1),\n\n crosshairTemplate: (d: VisTimeSeriesDatum) =>\n `<div>Date: ${new Date(d.timestamp).toLocaleDateString()}</div><div>Value: ${d.value?.toFixed(1)}</div>`,\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+CM,SAAU,aAAa,CAAS,KAAgC,EAAA;;IACpE,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAA+B,SAAS,CAAC,CAAA;IAC3F,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CAAqB,CAAC,CAAC,CAAA;AACjF,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,CAAA;AACnD,IAAA,MAAM,SAA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AAE,KAAK,CAAC,MAAM,EAAG,CAAA;AAC9I,YAAA,KAAA,CAAA,aAAA,CAAC,OAAO,EAAA,EAAC,IAAI,EAAC,GAAG,EAAC,UAAU,EAAE,KAAK,CAAC,YAAY,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,GAAG,GAAG,SAAS,EAAA,CAAG,CAClG,CACb,EACP;AACH,CAAC;AAED,aAAa,CAAC,YAAY,GAAG;AAC3B,IAAA,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;AACpD,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,OAAO,EAAE,EAAE;IAEX,CAAC,EAAE,CAAC,CAAqB,KAAK,CAAC,CAAC,SAAS;IACzC,CAAC,EAAE,CAAC,CAAqB,KAAK,CAAC,CAAC,KAAK;IACrC,EAAE,EAAE,CAAC,CAAqB,KAAK,CAAC,CAAC,EAAE;AACnC,IAAA,KAAK,EAAE,CAAC,CAAuB,KAAK,IAAI;IAExC,YAAY,EAAE,CAAC,CAAS,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzC,IAAA,iBAAiB,EAAE,CAAC,CAAqB,KAAI,EAAA,IAAA,EAAA,CAAA,CAC3C,OAAA,CAAA,WAAA,EAAc,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,CAAA,kBAAA,EAAqB,CAAA,EAAA,GAAA,CAAC,CAAC,KAAK,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAO,CAAC,CAAC,CAAC,CAAA,MAAA,CAAQ,CAAA,EAAA;CAC3G;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/composites/time-series/index.tsx"],"sourcesContent":["import React, { useState, useMemo } from 'react'\nimport { Spacing } from '@unovis/ts/types/spacing'\nimport { TextAlign } from '@unovis/ts/types/text'\nimport { Scale } from '@unovis/ts/types/scale'\nimport { VisXYContainer } from '@unovis/react/containers/xy-container'\nimport { VisArea } from '@unovis/react/components/area'\nimport { VisAxis } from '@unovis/react/components/axis'\nimport { VisCrosshair } from '@unovis/react/components/crosshair'\nimport { VisTooltip } from '@unovis/react/components/tooltip'\nimport { VisBrush } from '@unovis/react/components/brush'\n\nimport s from './style.module.css'\n\nexport type VisTimeSeriesDatum = {\n timestamp: number;\n value: number;\n id?: string;\n color?: string;\n}\n\nexport type VisTimeSeriesProps<Datum> = {\n data: Datum[];\n margin: Spacing;\n autoMargin: boolean;\n\n x: (d: Datum, i: number) => number;\n y: (d: Datum, i: number) => number;\n id: (d: Datum, i: number) => string;\n color: (d: Datum[], i: number) => string | null;\n cursor: string | ((d: Datum, i: number) => string);\n formatXTicks?: (timestamp: number) => string;\n formatYTicks?: (timestamp: number) => string;\n\n selectionMinLength: number;\n onBrushStart?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n onBrushMove?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n onBrushEnd?: (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean) => void;\n formatNavXTicks?: (timestamp: number) => string;\n\n xLabel?: string;\n yLabel?: string;\n\n crosshairTemplate?: (d: Datum) => string | HTMLElement;\n\n className?: string;\n height?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function VisTimeSeries<Datum> (props: VisTimeSeriesProps<Datum>): JSX.Element {\n const [selectedRange, setSelectedRange] = useState<[number, number] | undefined>(undefined)\n const [animationDuration, setAnimationDuration] = useState<number | undefined>(0)\n const xScale = useMemo(() => Scale.scaleTime(), [])\n const xScaleNav = useMemo(() => Scale.scaleTime(), [])\n\n // On Mount\n // useEffect(() => {}, [])\n\n // On Props Update\n // useEffect(() => {})\n\n // Brush callbacks\n const onBrushStart = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven) setAnimationDuration(0)\n props.onBrushStart?.(selection, e, userDriven)\n }, [])\n\n const onBrushMove = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection)\n props.onBrushMove?.(selection, e, userDriven)\n }, [])\n\n const onBrushEnd = useMemo(() => (selection: [number, number], e?: { sourceEvent: MouseEvent }, userDriven?: boolean): void => {\n if (userDriven && selectedRange?.[0] !== selection[0] && selectedRange?.[1] !== selection[1]) setSelectedRange(selection)\n setAnimationDuration(undefined)\n props.onBrushEnd?.(selection, e, userDriven)\n }, [])\n\n return (\n <div className={`${s.timeSeriesContainer}${props.className ? `.${props.className}` : ''}`} style={{ height: props.height }}>\n <VisXYContainer\n className={s.timeSeriesModule}\n data={props.data}\n xScale={xScale}\n xDomain={selectedRange}\n duration={animationDuration}\n scaleByDomain={true}\n >\n <VisArea\n x={props.x}\n y={props.y}\n color={props.color}\n />\n <VisAxis type='x' numTicks={5} tickFormat={props.formatXTicks} tickTextAlign={TextAlign.Center}/>\n <VisAxis type='y' tickFormat={props.formatYTicks} label={props.yLabel}/>\n <VisTooltip />\n <VisCrosshair template={props.crosshairTemplate}/>\n </VisXYContainer>\n <VisXYContainer className={s.navigationModule} duration={0} xScale={xScaleNav} data={props.data}>\n <VisArea x={props.x} y={props.y} />\n <VisBrush draggable={true} onBrushStart={onBrushStart} onBrushMove={onBrushMove} onBrushEnd={onBrushEnd} />\n <VisAxis type='x' numTicks={5} tickFormat={props.formatXTicks ?? props.formatNavXTicks} tickTextAlign={TextAlign.Right} label={props.xLabel}/>\n <VisAxis type='y' tickFormat={props.formatYTicks} minMaxTicksOnly={true} label={props.yLabel ? ' ' : undefined}/>\n </VisXYContainer>\n </div>\n )\n}\n\nVisTimeSeries.defaultProps = {\n margin: { top: 10, bottom: 10, left: 10, right: 10 },\n autoMargin: true,\n padding: {},\n\n x: (d: VisTimeSeriesDatum) => d.timestamp,\n y: (d: VisTimeSeriesDatum) => d.value,\n id: (d: VisTimeSeriesDatum) => d.id,\n color: (d: VisTimeSeriesDatum[]) => null,\n\n formatYTicks: (d: number) => d.toFixed(1),\n\n crosshairTemplate: (d: VisTimeSeriesDatum) =>\n `<div>Date: ${new Date(d.timestamp).toLocaleDateString()}</div><div>Value: ${d.value?.toFixed(1)}</div>`,\n}\n"],"names":[],"mappings":";;;;;;;;;;AAiDO,SAAS,cAAsB,OAA+C;AACnF,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAuC,MAAS;AAC1F,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAA6B,CAAC;AAChF,QAAM,SAAS,QAAQ,MAAM,MAAM,UAAA,GAAa,CAAA,CAAE;AAClD,QAAM,YAAY,QAAQ,MAAM,MAAM,UAAA,GAAa,CAAA,CAAE;AASrD,QAAM,eAAe,QAAQ,MAAM,CAAC,WAA6B,GAAiC,eAA+B;AAC/H,QAAI,iCAAiC,CAAC;AACtC,UAAM,eAAe,WAAW,GAAG,UAAU;AAAA,EAC/C,GAAG,CAAA,CAAE;AAEL,QAAM,cAAc,QAAQ,MAAM,CAAC,WAA6B,GAAiC,eAA+B;AAC9H,QAAI,cAAc,gBAAgB,CAAC,MAAM,UAAU,CAAC,KAAK,gBAAgB,CAAC,MAAM,UAAU,CAAC,oBAAoB,SAAS;AACxH,UAAM,cAAc,WAAW,GAAG,UAAU;AAAA,EAC9C,GAAG,CAAA,CAAE;AAEL,QAAM,aAAa,QAAQ,MAAM,CAAC,WAA6B,GAAiC,eAA+B;AAC7H,QAAI,cAAc,gBAAgB,CAAC,MAAM,UAAU,CAAC,KAAK,gBAAgB,CAAC,MAAM,UAAU,CAAC,oBAAoB,SAAS;AACxH,yBAAqB,MAAS;AAC9B,UAAM,aAAa,WAAW,GAAG,UAAU;AAAA,EAC7C,GAAG,CAAA,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EJ;AAEA,cAAc,eAAe;AAAA,EAC3B,QAAQ,EAAE,KAAK,IAAI,QAAQ,IAAI,MAAM,IAAI,OAAO,GAAA;AAAA,EAChD,YAAY;AAAA,EACZ,SAAS,CAAA;AAAA,EAET,GAAG,CAAC,MAA0B,EAAE;AAAA,EAChC,GAAG,CAAC,MAA0B,EAAE;AAAA,EAChC,IAAI,CAAC,MAA0B,EAAE;AAAA,EACjC,OAAO,CAAC,MAA4B;AAAA,EAEpC,cAAc,CAAC,MAAc,EAAE,QAAQ,CAAC;AAAA,EAExC,mBAAmB,CAAC,MAClB,cAAc,IAAI,KAAK,EAAE,SAAS,EAAE,mBAAA,CAAoB,qBAAqB,EAAE,OAAO,QAAQ,CAAC,CAAC;AACpG;"}
@@ -1,8 +1,15 @@
1
- import styleInject from './../../external/.pnpm/style-inject@0.3.0/external/style-inject/dist/style-inject.es.js';
2
-
3
- var css_248z = ".style-module_timeSeriesContainer__Qu3sl {\n position: relative;\n height: 400px;\n width: 100%;\n font-family: sans-serif;\n}\n\n.style-module_timeSeriesModule__7qbsL {\n width: 100%;\n height: 70%;\n position: relative;\n}\n\n.style-module_navigationModule__S7Q4i {\n width: 100%;\n height: 30%;\n position: relative;\n}\n";
4
- var s = {"timeSeriesContainer":"style-module_timeSeriesContainer__Qu3sl","timeSeriesModule":"style-module_timeSeriesModule__7qbsL","navigationModule":"style-module_navigationModule__S7Q4i"};
5
- styleInject(css_248z);
6
-
7
- export { s as default };
1
+ const timeSeriesContainer = "_timeSeriesContainer_1ayv5_1";
2
+ const timeSeriesModule = "_timeSeriesModule_1ayv5_8";
3
+ const navigationModule = "_navigationModule_1ayv5_14";
4
+ const s = {
5
+ timeSeriesContainer,
6
+ timeSeriesModule,
7
+ navigationModule
8
+ };
9
+ export {
10
+ s as default,
11
+ navigationModule,
12
+ timeSeriesContainer,
13
+ timeSeriesModule
14
+ };
8
15
  //# sourceMappingURL=style.module.css.js.map
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,wBAAwB,yFAA+F;AACvH;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":"style.module.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/composites.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './composites/time-series';
1
+ export * from './composites/time-series';
@@ -1,8 +1,9 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { SingleContainerConfigInterface } from '@unovis/ts';
3
- export declare type VisSingleContainerProps<Data> = SingleContainerConfigInterface<Data> & {
4
- data?: Data;
5
- className?: string;
6
- style?: React.CSSProperties;
7
- };
8
- export declare const VisSingleContainer: (<Data>(props: PropsWithChildren<VisSingleContainerProps<Data>>) => JSX.Element | null);
1
+ import { default as React, PropsWithChildren } from 'react';
2
+ import { SingleContainerConfigInterface } from '@unovis/ts/containers/single-container/config';
3
+
4
+ export type VisSingleContainerProps<Data> = SingleContainerConfigInterface<Data> & {
5
+ data?: Data;
6
+ className?: string;
7
+ style?: React.CSSProperties | Record<`--${string}`, string | number>;
8
+ };
9
+ export declare const VisSingleContainer: (<Data>(props: PropsWithChildren<VisSingleContainerProps<Data>>) => JSX.Element | null);
@@ -1,51 +1,69 @@
1
- import React, { useRef, useEffect } from 'react';
2
- import { SingleContainer } from '@unovis/ts';
3
- import { arePropsEqual } from '../../utils/react.js';
4
-
5
- function VisSingleContainerFC(props) {
6
- const container = useRef(null);
7
- const prevPropsRef = useRef({});
8
- const chartRef = useRef(undefined);
9
- const dataRef = useRef(undefined);
10
- const animationFrameRef = useRef(null);
11
- const getConfig = () => {
12
- var _a, _b, _c, _d, _e, _f;
13
- return (Object.assign(Object.assign({}, props), { component: (_b = (_a = container.current) === null || _a === void 0 ? void 0 : _a.querySelector('vis-component')) === null || _b === void 0 ? void 0 : _b.__component__, tooltip: (_d = (_c = container.current) === null || _c === void 0 ? void 0 : _c.querySelector('vis-tooltip')) === null || _d === void 0 ? void 0 : _d.__component__, annotations: (_f = (_e = container.current) === null || _e === void 0 ? void 0 : _e.querySelector('vis-annotations')) === null || _f === void 0 ? void 0 : _f.__component__ }));
14
- };
15
- useEffect(() => {
16
- const c = new SingleContainer(container.current, getConfig(), props.data);
17
- chartRef.current = c;
18
- prevPropsRef.current = props;
19
- dataRef.current = props.data;
20
- return () => {
21
- if (animationFrameRef.current) {
22
- cancelAnimationFrame(animationFrameRef.current);
23
- animationFrameRef.current = null;
24
- prevPropsRef.current = {};
25
- }
26
- c.destroy();
27
- };
28
- }, []);
29
- useEffect(() => {
30
- var _a;
31
- const preventRender = true;
32
- if (props.data && (props.data !== dataRef.current)) {
33
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.setData(props.data, preventRender);
34
- dataRef.current = props.data;
35
- }
36
- if (!arePropsEqual(prevPropsRef.current, props)) {
37
- prevPropsRef.current = props;
38
- if (animationFrameRef.current)
39
- cancelAnimationFrame(animationFrameRef.current);
40
- animationFrameRef.current = requestAnimationFrame(() => {
41
- var _a;
42
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.updateContainer(getConfig());
43
- });
44
- }
45
- });
46
- return (React.createElement("div", { ref: container, className: props.className, style: props.style }, props.children));
47
- }
1
+ import React, { useRef, useMemo, useEffect } from "react";
2
+ import { SingleContainer } from "@unovis/ts/containers/single-container";
3
+ import { arePropsEqual } from "../../utils/react.js";
4
+ import { VisContainerContext } from "../../utils/container.js";
5
+ function VisSingleContainerFC(props) {
6
+ const container = useRef(null);
7
+ const prevPropsRef = useRef({});
8
+ const chartRef = useRef(void 0);
9
+ const dataRef = useRef(void 0);
10
+ const animationFrameRef = useRef(null);
11
+ const renderRequestFrameRef = useRef(null);
12
+ const containerContext = useMemo(() => ({
13
+ requestRender: () => {
14
+ if (renderRequestFrameRef.current !== null) return;
15
+ renderRequestFrameRef.current = requestAnimationFrame(() => {
16
+ renderRequestFrameRef.current = null;
17
+ if (animationFrameRef.current !== null) return;
18
+ chartRef.current?.render();
19
+ });
20
+ }
21
+ }), []);
22
+ const getConfig = () => ({
23
+ ...props,
24
+ // eslint-disable-next-line @typescript-eslint/naming-convention
25
+ component: container.current?.querySelector("vis-component")?.__component__,
26
+ // eslint-disable-next-line @typescript-eslint/naming-convention
27
+ tooltip: container.current?.querySelector("vis-tooltip")?.__component__,
28
+ annotations: container.current?.querySelector("vis-annotations")?.__component__
29
+ });
30
+ useEffect(() => {
31
+ const c = new SingleContainer(container.current, getConfig(), props.data);
32
+ chartRef.current = c;
33
+ prevPropsRef.current = props;
34
+ dataRef.current = props.data;
35
+ return () => {
36
+ if (animationFrameRef.current) {
37
+ cancelAnimationFrame(animationFrameRef.current);
38
+ animationFrameRef.current = null;
39
+ prevPropsRef.current = {};
40
+ }
41
+ if (renderRequestFrameRef.current !== null) {
42
+ cancelAnimationFrame(renderRequestFrameRef.current);
43
+ renderRequestFrameRef.current = null;
44
+ }
45
+ c.destroy();
46
+ };
47
+ }, []);
48
+ useEffect(() => {
49
+ const preventRender = true;
50
+ if (props.data && props.data !== dataRef.current) {
51
+ chartRef.current?.setData(props.data, preventRender);
52
+ dataRef.current = props.data;
53
+ }
54
+ if (!arePropsEqual(prevPropsRef.current, props)) {
55
+ prevPropsRef.current = props;
56
+ if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
57
+ animationFrameRef.current = requestAnimationFrame(() => {
58
+ animationFrameRef.current = null;
59
+ chartRef.current?.updateContainer(getConfig());
60
+ });
61
+ }
62
+ });
63
+ return /* @__PURE__ */ React.createElement("div", { ref: container, className: props.className, style: props.style }, /* @__PURE__ */ React.createElement(VisContainerContext.Provider, { value: containerContext }, props.children));
64
+ }
48
65
  const VisSingleContainer = React.memo(VisSingleContainerFC, arePropsEqual);
49
-
50
- export { VisSingleContainer };
66
+ export {
67
+ VisSingleContainer
68
+ };
51
69
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/containers/single-container/index.tsx"],"sourcesContent":["// eslint-disable-next-line no-use-before-define\nimport React, { ReactNode, useEffect, useRef, useState, PropsWithChildren } from 'react'\nimport { SingleContainer, SingleContainerConfigInterface, ComponentCore, Tooltip, Annotations } from '@unovis/ts'\n\n// Utils\nimport { arePropsEqual } from 'src/utils/react'\n\n// Types\nimport { VisComponentElement } from 'src/types/dom'\n\nexport type VisSingleContainerProps<Data> = SingleContainerConfigInterface<Data> & {\n data?: Data;\n className?: string;\n style?: React.CSSProperties;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction VisSingleContainerFC<Data> (props: PropsWithChildren<VisSingleContainerProps<Data>>): JSX.Element {\n const container = useRef<HTMLDivElement>(null)\n const prevPropsRef = useRef<PropsWithChildren<VisSingleContainerProps<Data>>>({})\n const chartRef = useRef<SingleContainer<Data> | undefined>(undefined)\n const dataRef = useRef<Data | undefined>(undefined)\n const animationFrameRef = useRef<number | null>(null)\n\n const getConfig = (): SingleContainerConfigInterface<Data> => ({\n ...props,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n component: container.current?.querySelector<VisComponentElement<ComponentCore<Data>>>('vis-component')?.__component__,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n tooltip: container.current?.querySelector<VisComponentElement<Tooltip>>('vis-tooltip')?.__component__,\n annotations: container.current?.querySelector<VisComponentElement<Annotations>>('vis-annotations')?.__component__,\n })\n\n // On Mount\n useEffect(() => {\n const c = new SingleContainer<Data>(container.current as HTMLDivElement, getConfig(), props.data)\n chartRef.current = c\n prevPropsRef.current = props\n dataRef.current = props.data\n\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current)\n animationFrameRef.current = null\n prevPropsRef.current = {}\n }\n c.destroy()\n }\n }, [])\n\n // On Props Update\n useEffect(() => {\n const preventRender = true\n\n // Set new Data without re-render\n if (props.data && (props.data !== dataRef.current)) {\n chartRef.current?.setData(props.data, preventRender)\n dataRef.current = props.data\n }\n\n // Update and render\n // ! Experimental: we use `requestAnimationFrame` to make the wrapper compatible with React 18 Strict Mode.\n // React 18 in Strict Mode renders components twice. At the same time, this container will get updated only after\n // the first render of its children (VisSankey, VisGraph, ...) meaning that their wrong instances (the ones\n // that will be destroyed soon) are stored in the `__component__` property of their elements at that moment.\n // So we delay the container update with `requestAnimationFrame` to wait till the new instances of children\n // components are available at `__component__`.\n if (!arePropsEqual(prevPropsRef.current, props)) { // Checking whether the props have changed do avoid multiple renders\n prevPropsRef.current = props\n if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current)\n animationFrameRef.current = requestAnimationFrame(() => {\n chartRef.current?.updateContainer(getConfig())\n })\n }\n })\n\n return (\n <div ref={container} className={props.className} style={props.style}>\n {props.children}\n </div>\n )\n}\n\n// We export a memoized component to avoid unnecessary re-renders\n// and define its type explicitly to help react-docgen-typescript to extract information about props\nexport const VisSingleContainer: (<Data>(props: PropsWithChildren<VisSingleContainerProps<Data>>) => JSX.Element | null) =\n React.memo(VisSingleContainerFC, arePropsEqual)\n"],"names":[],"mappings":";;;;AAiBA,SAAS,oBAAoB,CAAQ,KAAuD,EAAA;AAC1F,IAAA,MAAM,SAAS,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;AAC9C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAmD,EAAE,CAAC,CAAA;AACjF,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAoC,SAAS,CAAC,CAAA;AACrE,IAAA,MAAM,OAAO,GAAG,MAAM,CAAmB,SAAS,CAAC,CAAA;AACnD,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAA;IAErD,MAAM,SAAS,GAAG,MAA2C;;QAAC,QAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EACzD,KAAK,CAER,EAAA,EAAA,SAAS,EAAE,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,SAAS,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,aA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IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,EAAE;AAClD,YAAA,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;AACpD,YAAA,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAA;AAC7B,SAAA;QASD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE;AAC/C,YAAA,YAAY,CAAC,OAAO,GAAG,KAAK,CAAA;YAC5B,IAAI,iBAAiB,CAAC,OAAO;AAAE,gBAAA,oBAAoB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;AAC9E,YAAA,iBAAiB,CAAC,OAAO,GAAG,qBAAqB,CAAC,MAAK;;gBACrD,CAAA,EAAA,GAAA,QAAQ,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,eAAe,CAAC,SAAS,EAAE,CAAC,CAAA;AAChD,aAAC,CAAC,CAAA;AACH,SAAA;AACH,KAAC,CAAC,CAAA;IAEF,QACE,6BAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAA,EAChE,KAAK,CAAC,QAAQ,CACX,EACP;AACH,CAAC;AAIM,MAAM,kBAAkB,GAC7B,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,aAAa;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/containers/single-container/index.tsx"],"sourcesContent":["// eslint-disable-next-line no-use-before-define\nimport React, { ReactNode, useEffect, useMemo, useRef, useState, PropsWithChildren } from 'react'\nimport { SingleContainer } from '@unovis/ts/containers/single-container'\nimport { SingleContainerConfigInterface } from '@unovis/ts/containers/single-container/config'\nimport { ComponentCore } from '@unovis/ts/core/component'\nimport { Tooltip } from '@unovis/ts/components/tooltip'\nimport { Annotations } from '@unovis/ts/components/annotations'\n\n// Utils\nimport { arePropsEqual } from 'src/utils/react'\nimport { VisContainerContext, VisContainerContextValue } from 'src/utils/container'\n\n// Types\nimport { VisComponentElement } from 'src/types/dom'\n\nexport type VisSingleContainerProps<Data> = SingleContainerConfigInterface<Data> & {\n data?: Data;\n className?: string;\n style?: React.CSSProperties | Record<`--${string}`, string | number>;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction VisSingleContainerFC<Data> (props: PropsWithChildren<VisSingleContainerProps<Data>>): JSX.Element {\n const container = useRef<HTMLDivElement>(null)\n const prevPropsRef = useRef<PropsWithChildren<VisSingleContainerProps<Data>>>({})\n const chartRef = useRef<SingleContainer<Data> | undefined>(undefined)\n const dataRef = useRef<Data | undefined>(undefined)\n const animationFrameRef = useRef<number | null>(null)\n const renderRequestFrameRef = useRef<number | null>(null)\n\n // Children ask for a re-render when their own config changes. We coalesce the requests into a single\n // frame, and skip them when this container's props changed too, because the `updateContainer` call\n // scheduled below renders on its own.\n const containerContext = useMemo<VisContainerContextValue>(() => ({\n requestRender: () => {\n if (renderRequestFrameRef.current !== null) return\n renderRequestFrameRef.current = requestAnimationFrame(() => {\n renderRequestFrameRef.current = null\n if (animationFrameRef.current !== null) return\n chartRef.current?.render()\n })\n },\n }), [])\n\n const getConfig = (): SingleContainerConfigInterface<Data> => ({\n ...props,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n component: container.current?.querySelector<VisComponentElement<ComponentCore<Data>>>('vis-component')?.__component__,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n tooltip: container.current?.querySelector<VisComponentElement<Tooltip>>('vis-tooltip')?.__component__,\n annotations: container.current?.querySelector<VisComponentElement<Annotations>>('vis-annotations')?.__component__,\n })\n\n // On Mount\n useEffect(() => {\n const c = new SingleContainer<Data>(container.current as HTMLDivElement, getConfig(), props.data)\n chartRef.current = c\n prevPropsRef.current = props\n dataRef.current = props.data\n\n return () => {\n if (animationFrameRef.current) {\n cancelAnimationFrame(animationFrameRef.current)\n animationFrameRef.current = null\n prevPropsRef.current = {}\n }\n if (renderRequestFrameRef.current !== null) {\n cancelAnimationFrame(renderRequestFrameRef.current)\n renderRequestFrameRef.current = null\n }\n c.destroy()\n }\n }, [])\n\n // On Props Update\n useEffect(() => {\n const preventRender = true\n\n // Set new Data without re-render\n if (props.data && (props.data !== dataRef.current)) {\n chartRef.current?.setData(props.data, preventRender)\n dataRef.current = props.data\n }\n\n // Update and render\n // ! Experimental: we use `requestAnimationFrame` to make the wrapper compatible with React 18 Strict Mode.\n // React 18 in Strict Mode renders components twice. At the same time, this container will get updated only after\n // the first render of its children (VisSankey, VisGraph, ...) meaning that their wrong instances (the ones\n // that will be destroyed soon) are stored in the `__component__` property of their elements at that moment.\n // So we delay the container update with `requestAnimationFrame` to wait till the new instances of children\n // components are available at `__component__`.\n if (!arePropsEqual(prevPropsRef.current, props)) { // Checking whether the props have changed do avoid multiple renders\n prevPropsRef.current = props\n if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current)\n animationFrameRef.current = requestAnimationFrame(() => {\n animationFrameRef.current = null\n chartRef.current?.updateContainer(getConfig())\n })\n }\n })\n\n return (\n <div ref={container} className={props.className} style={props.style}>\n <VisContainerContext.Provider value={containerContext}>\n {props.children}\n </VisContainerContext.Provider>\n </div>\n )\n}\n\n// We export a memoized component to avoid unnecessary re-renders\n// and define its type explicitly to help react-docgen-typescript to extract information about props\nexport const VisSingleContainer: (<Data>(props: PropsWithChildren<VisSingleContainerProps<Data>>) => JSX.Element | null) =\n React.memo(VisSingleContainerFC, arePropsEqual)\n"],"names":[],"mappings":";;;;AAsBA,SAAS,qBAA4B,OAAsE;AACzG,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,eAAe,OAAyD,EAAE;AAChF,QAAM,WAAW,OAA0C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K,GAAG;AAC/C,mBAAa,UAAU;AACvB,UAAI,kBAAkB,QAAS,sBAAqB,kBAAkB,OAAO;AAC7E,wBAAkB,UAAU,sBAAsB,MAAM;AACtD,0BAAkB,UAAU;AAC5B,iBAAS,SAAS,gBAAgB,WAAW;AAAA,MAC/C,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,6CACG,OAAA,EAAI,KAAK,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAA,GAC5D,sBAAA,cAAC,oBAAoB,UAApB,EAA6B,OAAO,iBAAA,GAClC,MAAM,QACT,CACF;AAEJ;AAIO,MAAM,qBACX,MAAM,KAAK,sBAAsB,aAAa;"}
@@ -1,9 +1,10 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { XYContainerConfigInterface } from '@unovis/ts';
3
- export declare type VisXYContainerProps<Datum> = XYContainerConfigInterface<Datum> & {
4
- data?: Datum[];
5
- className?: string;
6
- style?: React.CSSProperties;
7
- };
8
- export declare function VisXYContainerFC<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>): JSX.Element;
9
- export declare const VisXYContainer: (<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>) => JSX.Element | null);
1
+ import { default as React, PropsWithChildren } from 'react';
2
+ import { XYContainerConfigInterface } from '@unovis/ts/containers/xy-container/config';
3
+
4
+ export type VisXYContainerProps<Datum> = XYContainerConfigInterface<Datum> & {
5
+ data?: Datum[];
6
+ className?: string;
7
+ style?: React.CSSProperties | Record<`--${string}`, string | number>;
8
+ };
9
+ export declare function VisXYContainerFC<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>): JSX.Element;
10
+ export declare const VisXYContainer: (<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>) => JSX.Element | null);
@@ -1,59 +1,73 @@
1
- import React, { useRef, useEffect } from 'react';
2
- import { XYContainer, AxisType } from '@unovis/ts';
3
- import { arePropsEqual } from '../../utils/react.js';
4
-
5
- function VisXYContainerFC(props) {
6
- const container = useRef(null);
7
- const prevPropsRef = useRef({});
8
- const chartRef = useRef(undefined);
9
- const dataRef = useRef(undefined);
10
- const animationFrameRef = useRef(null);
11
- const getConfig = () => {
12
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
13
- return (Object.assign({ components: Array
14
- .from((_b = (_a = container.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('vis-component')) !== null && _b !== void 0 ? _b : [])
15
- .map(c => c.__component__), tooltip: (_d = (_c = container.current) === null || _c === void 0 ? void 0 : _c.querySelector('vis-tooltip')) === null || _d === void 0 ? void 0 : _d.__component__, crosshair: (_f = (_e = container.current) === null || _e === void 0 ? void 0 : _e.querySelector('vis-crosshair')) === null || _f === void 0 ? void 0 : _f.__component__, annotations: (_h = (_g = container.current) === null || _g === void 0 ? void 0 : _g.querySelector('vis-annotations')) === null || _h === void 0 ? void 0 : _h.__component__, xAxis: Array
16
- .from((_k = (_j = container.current) === null || _j === void 0 ? void 0 : _j.querySelectorAll('vis-axis')) !== null && _k !== void 0 ? _k : [])
17
- .map(c => c.__component__)
18
- .find(c => c.config.type === AxisType.X), yAxis: Array
19
- .from((_m = (_l = container.current) === null || _l === void 0 ? void 0 : _l.querySelectorAll('vis-axis')) !== null && _m !== void 0 ? _m : [])
20
- .map(c => c.__component__)
21
- .find(c => c.config.type === AxisType.Y), margin: { top: 5, left: 5, right: 5, bottom: 5 } }, props));
22
- };
23
- useEffect(() => {
24
- const c = new XYContainer(container.current, getConfig(), props.data);
25
- chartRef.current = c;
26
- prevPropsRef.current = props;
27
- dataRef.current = props.data;
28
- return () => {
29
- if (animationFrameRef.current) {
30
- cancelAnimationFrame(animationFrameRef.current);
31
- animationFrameRef.current = null;
32
- prevPropsRef.current = {};
33
- }
34
- c.destroy();
35
- };
36
- }, []);
37
- useEffect(() => {
38
- var _a;
39
- const preventRender = true;
40
- if (props.data && (props.data !== dataRef.current)) {
41
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.setData(props.data, preventRender);
42
- dataRef.current = props.data;
43
- }
44
- if (!arePropsEqual(prevPropsRef.current, props)) {
45
- prevPropsRef.current = props;
46
- if (animationFrameRef.current)
47
- cancelAnimationFrame(animationFrameRef.current);
48
- animationFrameRef.current = requestAnimationFrame(() => {
49
- var _a;
50
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.updateContainer(getConfig());
51
- });
52
- }
53
- });
54
- return (React.createElement("div", { ref: container, className: props.className, style: props.style }, props.children));
55
- }
1
+ import React, { useRef, useMemo, useEffect } from "react";
2
+ import { XYContainer } from "@unovis/ts/containers/xy-container";
3
+ import { AxisType } from "@unovis/ts/components/axis/types";
4
+ import { arePropsEqual } from "../../utils/react.js";
5
+ import { VisContainerContext } from "../../utils/container.js";
6
+ function VisXYContainerFC(props) {
7
+ const container = useRef(null);
8
+ const prevPropsRef = useRef({});
9
+ const chartRef = useRef(void 0);
10
+ const dataRef = useRef(void 0);
11
+ const animationFrameRef = useRef(null);
12
+ const renderRequestFrameRef = useRef(null);
13
+ const containerContext = useMemo(() => ({
14
+ requestRender: () => {
15
+ if (renderRequestFrameRef.current !== null) return;
16
+ renderRequestFrameRef.current = requestAnimationFrame(() => {
17
+ renderRequestFrameRef.current = null;
18
+ if (animationFrameRef.current !== null) return;
19
+ chartRef.current?.render();
20
+ });
21
+ }
22
+ }), []);
23
+ const getConfig = () => ({
24
+ components: Array.from(container.current?.querySelectorAll("vis-component") ?? []).map((c) => c.__component__).filter(Boolean),
25
+ tooltip: container.current?.querySelector("vis-tooltip")?.__component__,
26
+ crosshair: container.current?.querySelector("vis-crosshair")?.__component__,
27
+ annotations: container.current?.querySelector("vis-annotations")?.__component__,
28
+ xAxis: Array.from(container.current?.querySelectorAll("vis-axis") ?? []).map((c) => c.__component__).find((c) => c.config.type === AxisType.X),
29
+ yAxis: Array.from(container.current?.querySelectorAll("vis-axis") ?? []).map((c) => c.__component__).find((c) => c.config.type === AxisType.Y),
30
+ margin: { top: 5, left: 5, right: 5, bottom: 5 },
31
+ ...props
32
+ });
33
+ useEffect(() => {
34
+ const c = new XYContainer(container.current, getConfig(), props.data);
35
+ chartRef.current = c;
36
+ prevPropsRef.current = props;
37
+ dataRef.current = props.data;
38
+ return () => {
39
+ if (animationFrameRef.current) {
40
+ cancelAnimationFrame(animationFrameRef.current);
41
+ animationFrameRef.current = null;
42
+ prevPropsRef.current = {};
43
+ }
44
+ if (renderRequestFrameRef.current !== null) {
45
+ cancelAnimationFrame(renderRequestFrameRef.current);
46
+ renderRequestFrameRef.current = null;
47
+ }
48
+ c.destroy();
49
+ };
50
+ }, []);
51
+ useEffect(() => {
52
+ const preventRender = true;
53
+ if (props.data && props.data !== dataRef.current) {
54
+ chartRef.current?.setData(props.data, preventRender);
55
+ dataRef.current = props.data;
56
+ }
57
+ if (!arePropsEqual(prevPropsRef.current, props)) {
58
+ prevPropsRef.current = props;
59
+ if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
60
+ animationFrameRef.current = requestAnimationFrame(() => {
61
+ animationFrameRef.current = null;
62
+ chartRef.current?.updateContainer(getConfig());
63
+ });
64
+ }
65
+ });
66
+ return /* @__PURE__ */ React.createElement("div", { ref: container, className: props.className, style: props.style }, /* @__PURE__ */ React.createElement(VisContainerContext.Provider, { value: containerContext }, props.children));
67
+ }
56
68
  const VisXYContainer = React.memo(VisXYContainerFC, arePropsEqual);
57
-
58
- export { VisXYContainer, VisXYContainerFC };
69
+ export {
70
+ VisXYContainer,
71
+ VisXYContainerFC
72
+ };
59
73
  //# sourceMappingURL=index.js.map