@unovis/react 1.6.7 → 1.7.0-mcp.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 (115) hide show
  1. package/README.md +4 -0
  2. package/components/annotations/index.d.ts +12 -11
  3. package/components/annotations/index.js +30 -27
  4. package/components/annotations/index.js.map +1 -1
  5. package/components/area/index.d.ts +13 -12
  6. package/components/area/index.js +31 -29
  7. package/components/area/index.js.map +1 -1
  8. package/components/axis/index.d.ts +13 -12
  9. package/components/axis/index.js +31 -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 +33 -0
  13. package/components/boxplot/index.js.map +1 -0
  14. package/components/brush/index.d.ts +13 -12
  15. package/components/brush/index.js +31 -29
  16. package/components/brush/index.js.map +1 -1
  17. package/components/chord-diagram/index.d.ts +17 -16
  18. package/components/chord-diagram/index.js +31 -29
  19. package/components/chord-diagram/index.js.map +1 -1
  20. package/components/crosshair/index.d.ts +13 -12
  21. package/components/crosshair/index.js +31 -29
  22. package/components/crosshair/index.js.map +1 -1
  23. package/components/donut/index.d.ts +13 -12
  24. package/components/donut/index.js +31 -29
  25. package/components/donut/index.js.map +1 -1
  26. package/components/free-brush/index.d.ts +13 -12
  27. package/components/free-brush/index.js +31 -29
  28. package/components/free-brush/index.js.map +1 -1
  29. package/components/graph/index.d.ts +39 -38
  30. package/components/graph/index.js +31 -29
  31. package/components/graph/index.js.map +1 -1
  32. package/components/grouped-bar/index.d.ts +13 -12
  33. package/components/grouped-bar/index.js +31 -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 +33 -0
  37. package/components/heatmap/index.js.map +1 -0
  38. package/components/line/index.d.ts +13 -12
  39. package/components/line/index.js +31 -29
  40. package/components/line/index.js.map +1 -1
  41. package/components/nested-donut/index.d.ts +13 -12
  42. package/components/nested-donut/index.js +31 -29
  43. package/components/nested-donut/index.js.map +1 -1
  44. package/components/plotband/index.d.ts +12 -11
  45. package/components/plotband/index.js +30 -27
  46. package/components/plotband/index.js.map +1 -1
  47. package/components/plotline/index.d.ts +12 -11
  48. package/components/plotline/index.js +30 -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 +33 -0
  52. package/components/radial-bar/index.js.map +1 -0
  53. package/components/sankey/index.d.ts +17 -16
  54. package/components/sankey/index.js +31 -29
  55. package/components/sankey/index.js.map +1 -1
  56. package/components/scatter/index.d.ts +13 -12
  57. package/components/scatter/index.js +31 -29
  58. package/components/scatter/index.js.map +1 -1
  59. package/components/stacked-bar/index.d.ts +13 -12
  60. package/components/stacked-bar/index.js +31 -29
  61. package/components/stacked-bar/index.js.map +1 -1
  62. package/components/timeline/index.d.ts +13 -12
  63. package/components/timeline/index.js +31 -29
  64. package/components/timeline/index.js.map +1 -1
  65. package/components/tooltip/index.d.ts +12 -11
  66. package/components/tooltip/index.js +30 -27
  67. package/components/tooltip/index.js.map +1 -1
  68. package/components/topojson-map/index.d.ts +17 -16
  69. package/components/topojson-map/index.js +31 -29
  70. package/components/topojson-map/index.js.map +1 -1
  71. package/components/treemap/index.d.ts +13 -12
  72. package/components/treemap/index.js +31 -29
  73. package/components/treemap/index.js.map +1 -1
  74. package/components/xy-labels/index.d.ts +13 -12
  75. package/components/xy-labels/index.js +31 -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 -61
  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 +50 -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 +54 -59
  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 -12
  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 -12
  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 -17
  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 -14
  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 -12
  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 +15 -16
  110. package/types/dom.d.ts +3 -3
  111. package/utils/react.d.ts +5 -4
  112. package/utils/react.js +22 -29
  113. package/utils/react.js.map +1 -1
  114. package/external/.pnpm/style-inject@0.3.0/external/style-inject/dist/style-inject.es.js +0 -29
  115. package/external/.pnpm/style-inject@0.3.0/external/style-inject/dist/style-inject.es.js.map +0 -1
@@ -1,63 +1,67 @@
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
-
12
- function VisTimeSeries(props) {
13
- var _a;
14
- const [selectedRange, setSelectedRange] = useState(undefined);
15
- const [animationDuration, setAnimationDuration] = useState(0);
16
- const xScale = useMemo(() => Scale.scaleTime(), []);
17
- const xScaleNav = useMemo(() => Scale.scaleTime(), []);
18
- const onBrushStart = useMemo(() => (selection, e, userDriven) => {
19
- var _a;
20
- if (userDriven)
21
- setAnimationDuration(0);
22
- (_a = props.onBrushStart) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
23
- }, []);
24
- const onBrushMove = useMemo(() => (selection, e, userDriven) => {
25
- var _a;
26
- if (userDriven && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[0]) !== selection[0] && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[1]) !== selection[1])
27
- setSelectedRange(selection);
28
- (_a = props.onBrushMove) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
29
- }, []);
30
- const onBrushEnd = useMemo(() => (selection, e, userDriven) => {
31
- var _a;
32
- if (userDriven && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[0]) !== selection[0] && (selectedRange === null || selectedRange === void 0 ? void 0 : selectedRange[1]) !== selection[1])
33
- setSelectedRange(selection);
34
- setAnimationDuration(undefined);
35
- (_a = props.onBrushEnd) === null || _a === void 0 ? void 0 : _a.call(props, selection, e, userDriven);
36
- }, []);
37
- return (React.createElement("div", { className: `${s.timeSeriesContainer}${props.className ? `.${props.className}` : ''}`, style: { height: props.height } },
38
- React.createElement(VisXYContainer, { className: s.timeSeriesModule, data: props.data, xScale: xScale, xDomain: selectedRange, duration: animationDuration, scaleByDomain: true },
39
- React.createElement(VisArea, { x: props.x, y: props.y, color: props.color }),
40
- React.createElement(VisAxis, { type: 'x', numTicks: 5, tickFormat: props.formatXTicks, tickTextAlign: TextAlign.Center }),
41
- React.createElement(VisAxis, { type: 'y', tickFormat: props.formatYTicks, label: props.yLabel }),
42
- React.createElement(VisTooltip, null),
43
- React.createElement(VisCrosshair, { template: props.crosshairTemplate })),
44
- React.createElement(VisXYContainer, { className: s.navigationModule, duration: 0, xScale: xScaleNav, data: props.data },
45
- React.createElement(VisArea, { x: props.x, y: props.y }),
46
- React.createElement(VisBrush, { draggable: true, onBrushStart: onBrushStart, onBrushMove: onBrushMove, onBrushEnd: onBrushEnd }),
47
- React.createElement(VisAxis, { type: 'x', numTicks: 5, tickFormat: (_a = props.formatXTicks) !== null && _a !== void 0 ? _a : props.formatNavXTicks, tickTextAlign: TextAlign.Right, label: props.xLabel }),
48
- React.createElement(VisAxis, { type: 'y', tickFormat: props.formatYTicks, minMaxTicksOnly: true, label: props.yLabel ? ' ' : undefined }))));
49
- }
50
- VisTimeSeries.defaultProps = {
51
- margin: { top: 10, bottom: 10, left: 10, right: 10 },
52
- autoMargin: true,
53
- padding: {},
54
- x: (d) => d.timestamp,
55
- y: (d) => d.value,
56
- id: (d) => d.id,
57
- color: (d) => null,
58
- formatYTicks: (d) => d.toFixed(1),
59
- 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
60
66
  };
61
-
62
- export { VisTimeSeries };
63
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 } 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":";;;;;;;;;;;AAiDM,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;AAC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o } 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,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CAAU,CACjH,CACF;AAEJ;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/containers/single-container/config';
3
- export declare type VisSingleContainerProps<Data> = SingleContainerConfigInterface<Data> & {
4
- data?: Data;
5
- className?: string;
6
- style?: React.CSSProperties | Record<`--${string}`, string | number>;
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,52 @@
1
- import React, { useRef, useEffect } from 'react';
2
- import { SingleContainer } from '@unovis/ts/containers/single-container';
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, useEffect } from "react";
2
+ import { SingleContainer } from "@unovis/ts/containers/single-container";
3
+ import { arePropsEqual } from "../../utils/react.js";
4
+ function VisSingleContainerFC(props) {
5
+ const container = useRef(null);
6
+ const prevPropsRef = useRef({});
7
+ const chartRef = useRef(void 0);
8
+ const dataRef = useRef(void 0);
9
+ const animationFrameRef = useRef(null);
10
+ const getConfig = () => ({
11
+ ...props,
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
13
+ component: container.current?.querySelector("vis-component")?.__component__,
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention
15
+ tooltip: container.current?.querySelector("vis-tooltip")?.__component__,
16
+ annotations: container.current?.querySelector("vis-annotations")?.__component__
17
+ });
18
+ useEffect(() => {
19
+ const c = new SingleContainer(container.current, getConfig(), props.data);
20
+ chartRef.current = c;
21
+ prevPropsRef.current = props;
22
+ dataRef.current = props.data;
23
+ return () => {
24
+ if (animationFrameRef.current) {
25
+ cancelAnimationFrame(animationFrameRef.current);
26
+ animationFrameRef.current = null;
27
+ prevPropsRef.current = {};
28
+ }
29
+ c.destroy();
30
+ };
31
+ }, []);
32
+ useEffect(() => {
33
+ const preventRender = true;
34
+ if (props.data && props.data !== dataRef.current) {
35
+ chartRef.current?.setData(props.data, preventRender);
36
+ dataRef.current = props.data;
37
+ }
38
+ if (!arePropsEqual(prevPropsRef.current, props)) {
39
+ prevPropsRef.current = props;
40
+ if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
41
+ animationFrameRef.current = requestAnimationFrame(() => {
42
+ chartRef.current?.updateContainer(getConfig());
43
+ });
44
+ }
45
+ });
46
+ return /* @__PURE__ */ React.createElement("div", { ref: container, className: props.className, style: props.style }, props.children);
47
+ }
48
48
  const VisSingleContainer = React.memo(VisSingleContainerFC, arePropsEqual);
49
-
50
- export { VisSingleContainer };
49
+ export {
50
+ VisSingleContainer
51
+ };
51
52
  //# 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 } 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'\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\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":";;;;AAqBA,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,aAAa,CAA2C,eAAe,CAAC,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,aAAa,EAErH,OAAO,EAAE,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,SAAS,CAAC,OAAO,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,G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,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, 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'\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\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":";;;AAqBA,SAAS,qBAA4B,OAAsE;AACzG,QAAM,YAAY,OAAuB,IAAI;AAC7C,QAAM,eAAe,OAAyD,EAAE;AAChF,QAAM,WAAW,OAA0C,MAAS;AACpE,QAAM,UAAU,OAAyB,MAAS;AAClD,QAAM,oBAAoB,OAAsB,IAAI;AAEpD,QAAM,YAAY,OAA6C;AAAA,IAC7D,GAAG;AAAA;AAAA,IAEH,WAAW,UAAU,SAAS,cAAwD,eAAe,GAAG;AAAA;AAAA,IAExG,SAAS,UAAU,SAAS,cAA4C,aAAa,GAAG;AAAA,IACxF,aAAa,UAAU,SAAS,cAAgD,iBAAiB,GAAG;AAAA,EAAA;AAItG,YAAU,MAAM;AACd,UAAM,IAAI,IAAI,gBAAsB,UAAU,SAA2B,UAAA,GAAa,MAAM,IAAI;AAChG,aAAS,UAAU;AACnB,iBAAa,UAAU;AACvB,YAAQ,UAAU,MAAM;AAExB,WAAO,MAAM;AACX,UAAI,kBAAkB,SAAS;AAC7B,6BAAqB,kBAAkB,OAAO;AAC9C,0BAAkB,UAAU;AAC5B,qBAAa,UAAU,CAAA;AAAA,MACzB;AACA,QAAE,QAAA;AAAA,IACJ;AAAA,EACF,GAAG,CAAA,CAAE;AAGL,YAAU,MAAM;AACd,UAAM,gBAAgB;AAGtB,QAAI,MAAM,QAAS,MAAM,SAAS,QAAQ,SAAU;AAClD,eAAS,SAAS,QAAQ,MAAM,MAAM,aAAa;AACnD,cAAQ,UAAU,MAAM;AAAA,IAC1B;AASA,QAAI,CAAC,cAAc,aAAa,SAAS,KAAK,GAAG;AAC/C,mBAAa,UAAU;AACvB,UAAI,kBAAkB,QAAS,sBAAqB,kBAAkB,OAAO;AAC7E,wBAAkB,UAAU,sBAAsB,MAAM;AACtD,iBAAS,SAAS,gBAAgB,WAAW;AAAA,MAC/C,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SACE,sBAAA,cAAC,OAAA,EAAI,KAAK,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAA,GAC3D,MAAM,QACT;AAEJ;AAIO,MAAM,qBACX,MAAM,KAAK,sBAAsB,aAAa;"}
@@ -1,9 +1,10 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { XYContainerConfigInterface } from '@unovis/ts/containers/xy-container/config';
3
- export declare type VisXYContainerProps<Datum> = XYContainerConfigInterface<Datum> & {
4
- data?: Datum[];
5
- className?: string;
6
- style?: React.CSSProperties | Record<`--${string}`, string | number>;
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,61 +1,56 @@
1
- import React, { useRef, 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
-
6
- function VisXYContainerFC(props) {
7
- const container = useRef(null);
8
- const prevPropsRef = useRef({});
9
- const chartRef = useRef(undefined);
10
- const dataRef = useRef(undefined);
11
- const animationFrameRef = useRef(null);
12
- const getConfig = () => {
13
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
14
- return (Object.assign({ components: Array
15
- .from((_b = (_a = container.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('vis-component')) !== null && _b !== void 0 ? _b : [])
16
- .map(c => c.__component__)
17
- .filter(Boolean), 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
18
- .from((_k = (_j = container.current) === null || _j === void 0 ? void 0 : _j.querySelectorAll('vis-axis')) !== null && _k !== void 0 ? _k : [])
19
- .map(c => c.__component__)
20
- .find(c => c.config.type === AxisType.X), yAxis: Array
21
- .from((_m = (_l = container.current) === null || _l === void 0 ? void 0 : _l.querySelectorAll('vis-axis')) !== null && _m !== void 0 ? _m : [])
22
- .map(c => c.__component__)
23
- .find(c => c.config.type === AxisType.Y), margin: { top: 5, left: 5, right: 5, bottom: 5 } }, props));
24
- };
25
- useEffect(() => {
26
- const c = new XYContainer(container.current, getConfig(), props.data);
27
- chartRef.current = c;
28
- prevPropsRef.current = props;
29
- dataRef.current = props.data;
30
- return () => {
31
- if (animationFrameRef.current) {
32
- cancelAnimationFrame(animationFrameRef.current);
33
- animationFrameRef.current = null;
34
- prevPropsRef.current = {};
35
- }
36
- c.destroy();
37
- };
38
- }, []);
39
- useEffect(() => {
40
- var _a;
41
- const preventRender = true;
42
- if (props.data && (props.data !== dataRef.current)) {
43
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.setData(props.data, preventRender);
44
- dataRef.current = props.data;
45
- }
46
- if (!arePropsEqual(prevPropsRef.current, props)) {
47
- prevPropsRef.current = props;
48
- if (animationFrameRef.current)
49
- cancelAnimationFrame(animationFrameRef.current);
50
- animationFrameRef.current = requestAnimationFrame(() => {
51
- var _a;
52
- (_a = chartRef.current) === null || _a === void 0 ? void 0 : _a.updateContainer(getConfig());
53
- });
54
- }
55
- });
56
- return (React.createElement("div", { ref: container, className: props.className, style: props.style }, props.children));
57
- }
1
+ import React, { useRef, 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
+ function VisXYContainerFC(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 getConfig = () => ({
12
+ components: Array.from(container.current?.querySelectorAll("vis-component") ?? []).map((c) => c.__component__).filter(Boolean),
13
+ tooltip: container.current?.querySelector("vis-tooltip")?.__component__,
14
+ crosshair: container.current?.querySelector("vis-crosshair")?.__component__,
15
+ annotations: container.current?.querySelector("vis-annotations")?.__component__,
16
+ xAxis: Array.from(container.current?.querySelectorAll("vis-axis") ?? []).map((c) => c.__component__).find((c) => c.config.type === AxisType.X),
17
+ yAxis: Array.from(container.current?.querySelectorAll("vis-axis") ?? []).map((c) => c.__component__).find((c) => c.config.type === AxisType.Y),
18
+ margin: { top: 5, left: 5, right: 5, bottom: 5 },
19
+ ...props
20
+ });
21
+ useEffect(() => {
22
+ const c = new XYContainer(container.current, getConfig(), props.data);
23
+ chartRef.current = c;
24
+ prevPropsRef.current = props;
25
+ dataRef.current = props.data;
26
+ return () => {
27
+ if (animationFrameRef.current) {
28
+ cancelAnimationFrame(animationFrameRef.current);
29
+ animationFrameRef.current = null;
30
+ prevPropsRef.current = {};
31
+ }
32
+ c.destroy();
33
+ };
34
+ }, []);
35
+ useEffect(() => {
36
+ const preventRender = true;
37
+ if (props.data && props.data !== dataRef.current) {
38
+ chartRef.current?.setData(props.data, preventRender);
39
+ dataRef.current = props.data;
40
+ }
41
+ if (!arePropsEqual(prevPropsRef.current, props)) {
42
+ prevPropsRef.current = props;
43
+ if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
44
+ animationFrameRef.current = requestAnimationFrame(() => {
45
+ chartRef.current?.updateContainer(getConfig());
46
+ });
47
+ }
48
+ });
49
+ return /* @__PURE__ */ React.createElement("div", { ref: container, className: props.className, style: props.style }, props.children);
50
+ }
58
51
  const VisXYContainer = React.memo(VisXYContainerFC, arePropsEqual);
59
-
60
- export { VisXYContainer, VisXYContainerFC };
52
+ export {
53
+ VisXYContainer,
54
+ VisXYContainerFC
55
+ };
61
56
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/containers/xy-container/index.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport React, { ReactNode, useEffect, useRef, useState, PropsWithChildren } from 'react'\nimport { XYContainer } from '@unovis/ts/containers/xy-container'\nimport { XYContainerConfigInterface } from '@unovis/ts/containers/xy-container/config'\nimport { XYComponentCore } from '@unovis/ts/core/xy-component'\nimport { Tooltip } from '@unovis/ts/components/tooltip'\nimport { Crosshair } from '@unovis/ts/components/crosshair'\nimport { Axis } from '@unovis/ts/components/axis'\nimport { AxisType } from '@unovis/ts/components/axis/types'\nimport { Annotations } from '@unovis/ts/components/annotations'\n\n// Utils\nimport { arePropsEqual } from 'src/utils/react'\n\n// Types\nimport { VisComponentElement } from 'src/types/dom'\n\nexport type VisXYContainerProps<Datum> = XYContainerConfigInterface<Datum> & {\n data?: Datum[];\n className?: string;\n style?: React.CSSProperties | Record<`--${string}`, string | number>;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function VisXYContainerFC<Datum> (props: PropsWithChildren<VisXYContainerProps<Datum>>): JSX.Element {\n const container = useRef<HTMLDivElement>(null)\n const prevPropsRef = useRef<PropsWithChildren<VisXYContainerProps<Datum>>>({})\n const chartRef = useRef<XYContainer<Datum> | undefined>(undefined)\n const dataRef = useRef<Datum[] | undefined>(undefined)\n const animationFrameRef = useRef<number | null>(null)\n\n const getConfig = (): XYContainerConfigInterface<Datum> => ({\n components: Array\n .from(container.current?.querySelectorAll<VisComponentElement<XYComponentCore<Datum>>>('vis-component') ?? [])\n .map(c => c.__component__)\n .filter(Boolean) as XYComponentCore<Datum>[],\n tooltip: container.current?.querySelector<VisComponentElement<Tooltip>>('vis-tooltip')?.__component__,\n crosshair: container.current?.querySelector<VisComponentElement<Crosshair<Datum>>>('vis-crosshair')?.__component__,\n annotations: container.current?.querySelector<VisComponentElement<Annotations>>('vis-annotations')?.__component__,\n xAxis: Array\n .from(container.current?.querySelectorAll<VisComponentElement<Axis<Datum>>>('vis-axis') ?? [])\n .map(c => c.__component__)\n .find(c => c.config.type === AxisType.X),\n yAxis: Array\n .from(container.current?.querySelectorAll<VisComponentElement<Axis<Datum>>>('vis-axis') ?? [])\n .map(c => c.__component__)\n .find(c => c.config.type === AxisType.Y),\n margin: { top: 5, left: 5, right: 5, bottom: 5 },\n ...props,\n })\n\n // On Mount\n useEffect(() => {\n const c = new XYContainer<Datum>(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 (VisLine, VisArea, ...) 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 VisXYContainer: (<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>) => JSX.Element | null) =\n React.memo(VisXYContainerFC, arePropsEqual)\n"],"names":[],"mappings":";;;;;AAwBM,SAAU,gBAAgB,CAAS,KAAoD,EAAA;AAC3F,IAAA,MAAM,SAAS,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAA;AAC9C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAgD,EAAE,CAAC,CAAA;AAC9E,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAiC,SAAS,CAAC,CAAA;AAClE,IAAA,MAAM,OAAO,GAAG,MAAM,CAAsB,SAAS,CAAC,CAAA;AACtD,IAAA,MAAM,iBAAiB,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAA;IAErD,MAAM,SAAS,GAAG,MAAwC;;QAAC,QAAA,MAAA,CAAA,MAAA,CAAA,EACzD,UAAU,EAAE,KAAK;AACd,iBAAA,IAAI,CAAC,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,SAAS,CAAC,OAAO,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,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../../src/containers/xy-container/index.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport React, { ReactNode, useEffect, useRef, useState, PropsWithChildren } from 'react'\nimport { XYContainer } from '@unovis/ts/containers/xy-container'\nimport { XYContainerConfigInterface } from '@unovis/ts/containers/xy-container/config'\nimport { XYComponentCore } from '@unovis/ts/core/xy-component'\nimport { Tooltip } from '@unovis/ts/components/tooltip'\nimport { Crosshair } from '@unovis/ts/components/crosshair'\nimport { Axis } from '@unovis/ts/components/axis'\nimport { AxisType } from '@unovis/ts/components/axis/types'\nimport { Annotations } from '@unovis/ts/components/annotations'\n\n// Utils\nimport { arePropsEqual } from 'src/utils/react'\n\n// Types\nimport { VisComponentElement } from 'src/types/dom'\n\nexport type VisXYContainerProps<Datum> = XYContainerConfigInterface<Datum> & {\n data?: Datum[];\n className?: string;\n style?: React.CSSProperties | Record<`--${string}`, string | number>;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function VisXYContainerFC<Datum> (props: PropsWithChildren<VisXYContainerProps<Datum>>): JSX.Element {\n const container = useRef<HTMLDivElement>(null)\n const prevPropsRef = useRef<PropsWithChildren<VisXYContainerProps<Datum>>>({})\n const chartRef = useRef<XYContainer<Datum> | undefined>(undefined)\n const dataRef = useRef<Datum[] | undefined>(undefined)\n const animationFrameRef = useRef<number | null>(null)\n\n const getConfig = (): XYContainerConfigInterface<Datum> => ({\n components: Array\n .from(container.current?.querySelectorAll<VisComponentElement<XYComponentCore<Datum>>>('vis-component') ?? [])\n .map(c => c.__component__)\n .filter(Boolean) as XYComponentCore<Datum>[],\n tooltip: container.current?.querySelector<VisComponentElement<Tooltip>>('vis-tooltip')?.__component__,\n crosshair: container.current?.querySelector<VisComponentElement<Crosshair<Datum>>>('vis-crosshair')?.__component__,\n annotations: container.current?.querySelector<VisComponentElement<Annotations>>('vis-annotations')?.__component__,\n xAxis: Array\n .from(container.current?.querySelectorAll<VisComponentElement<Axis<Datum>>>('vis-axis') ?? [])\n .map(c => c.__component__)\n .find(c => c.config.type === AxisType.X),\n yAxis: Array\n .from(container.current?.querySelectorAll<VisComponentElement<Axis<Datum>>>('vis-axis') ?? [])\n .map(c => c.__component__)\n .find(c => c.config.type === AxisType.Y),\n margin: { top: 5, left: 5, right: 5, bottom: 5 },\n ...props,\n })\n\n // On Mount\n useEffect(() => {\n const c = new XYContainer<Datum>(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 (VisLine, VisArea, ...) 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 VisXYContainer: (<Datum>(props: PropsWithChildren<VisXYContainerProps<Datum>>) => JSX.Element | null) =\n React.memo(VisXYContainerFC, arePropsEqual)\n"],"names":[],"mappings":";;;;AAwBO,SAAS,iBAAyB,OAA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,YAAU,MAAM;AACd,UAAM,gBAAgB;AAGtB,QAAI,MAAM,QAAS,MAAM,SAAS,QAAQ,SAAU;AAClD,eAAS,SAAS,QAAQ,MAAM,MAAM,aAAa;AACnD,cAAQ,UAAU,MAAM;AAAA,IAC1B;AASA,QAAI,CAAC,cAAc,aAAa,SAAS,KAAK,GAAG;AAC/C,mBAAa,UAAU;AACvB,UAAI,kBAAkB,QAAS,sBAAqB,kBAAkB,OAAO;AAC7E,wBAAkB,UAAU,sBAAsB,MAAM;AACtD,iBAAS,SAAS,gBAAgB,WAAW;AAAA,MAC/C,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SACE,sBAAA,cAAC,OAAA,EAAI,KAAK,WAAW,WAAW,MAAM,WAAW,OAAO,MAAM,MAAA,GAC3D,MAAM,QACT;AAEJ;AAIO,MAAM,iBACX,MAAM,KAAK,kBAAkB,aAAa;"}
package/containers.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './containers/xy-container';
2
- export * from './containers/single-container';
1
+ export * from './containers/xy-container';
2
+ export * from './containers/single-container';