nanoplot 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -50,6 +50,10 @@
50
50
  left: 0.5rem;
51
51
  }
52
52
 
53
+ .left-\[-1em\] {
54
+ left: -1em;
55
+ }
56
+
53
57
  .left-\[50\%\] {
54
58
  left: 50%;
55
59
  }
@@ -231,6 +235,10 @@
231
235
  display: inline-flex;
232
236
  }
233
237
 
238
+ .table {
239
+ display: table;
240
+ }
241
+
234
242
  .grid {
235
243
  display: grid;
236
244
  }
@@ -280,6 +288,10 @@
280
288
  height: 2rem;
281
289
  }
282
290
 
291
+ .h-\[0\.85em\] {
292
+ height: 0.85em;
293
+ }
294
+
283
295
  .h-\[1\.25em\] {
284
296
  height: 1.25em;
285
297
  }
@@ -348,6 +360,10 @@
348
360
  width: 2rem;
349
361
  }
350
362
 
363
+ .w-\[0\.85em\] {
364
+ width: 0.85em;
365
+ }
366
+
351
367
  .w-\[100\%\] {
352
368
  width: 100%;
353
369
  }
@@ -437,6 +453,11 @@
437
453
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
438
454
  }
439
455
 
456
+ .rotate-\[180deg\] {
457
+ --tw-rotate: 180deg;
458
+ transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
459
+ }
460
+
440
461
  .transform {
441
462
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
442
463
  }
@@ -523,6 +544,10 @@
523
544
  justify-content: space-between;
524
545
  }
525
546
 
547
+ .gap-1 {
548
+ gap: 0.25rem;
549
+ }
550
+
526
551
  .gap-2 {
527
552
  gap: 0.5rem;
528
553
  }
@@ -617,6 +642,10 @@
617
642
  border-bottom-width: 2px;
618
643
  }
619
644
 
645
+ .border-l-4 {
646
+ border-left-width: 4px;
647
+ }
648
+
620
649
  .border-r {
621
650
  border-right-width: 1px;
622
651
  }
@@ -639,6 +668,11 @@
639
668
  border-color: rgb(0 0 0 / var(--tw-border-opacity, 1));
640
669
  }
641
670
 
671
+ .border-emerald-500 {
672
+ --tw-border-opacity: 1;
673
+ border-color: rgb(16 185 129 / var(--tw-border-opacity, 1));
674
+ }
675
+
642
676
  .border-gray-100 {
643
677
  --tw-border-opacity: 1;
644
678
  border-color: rgb(243 244 246 / var(--tw-border-opacity, 1));
@@ -787,6 +821,10 @@
787
821
  fill: #efefef;
788
822
  }
789
823
 
824
+ .fill-blue-600 {
825
+ fill: #2563eb;
826
+ }
827
+
790
828
  .fill-gray-200 {
791
829
  fill: #e5e7eb;
792
830
  }
@@ -803,6 +841,10 @@
803
841
  stroke: #000;
804
842
  }
805
843
 
844
+ .stroke-blue-600 {
845
+ stroke: #2563eb;
846
+ }
847
+
806
848
  .stroke-dark-priority-100 {
807
849
  stroke: rgb(45, 45, 45);
808
850
  }
@@ -831,6 +873,10 @@
831
873
  stroke-width: 2;
832
874
  }
833
875
 
876
+ .stroke-\[0\] {
877
+ stroke-width: 0;
878
+ }
879
+
834
880
  .stroke-\[10\] {
835
881
  stroke-width: 10;
836
882
  }
@@ -965,6 +1011,11 @@
965
1011
  text-align: center;
966
1012
  }
967
1013
 
1014
+ .text-2xl {
1015
+ font-size: 1.5rem;
1016
+ line-height: 2rem;
1017
+ }
1018
+
968
1019
  .text-3xl {
969
1020
  font-size: 1.875rem;
970
1021
  line-height: 2.25rem;
@@ -1099,6 +1150,11 @@
1099
1150
  color: rgb(22 163 74 / var(--tw-text-opacity, 1));
1100
1151
  }
1101
1152
 
1153
+ .text-neutral-700 {
1154
+ --tw-text-opacity: 1;
1155
+ color: rgb(64 64 64 / var(--tw-text-opacity, 1));
1156
+ }
1157
+
1102
1158
  .text-red-800 {
1103
1159
  --tw-text-opacity: 1;
1104
1160
  color: rgb(153 27 27 / var(--tw-text-opacity, 1));
@@ -1215,6 +1271,12 @@
1215
1271
  transition-duration: 150ms;
1216
1272
  }
1217
1273
 
1274
+ .transition-opacity {
1275
+ transition-property: opacity;
1276
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
1277
+ transition-duration: 150ms;
1278
+ }
1279
+
1218
1280
  .transition-transform {
1219
1281
  transition-property: transform;
1220
1282
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
@@ -1380,6 +1442,11 @@
1380
1442
  --tw-contain-style: ;
1381
1443
  }
1382
1444
 
1445
+ .odd\:bg-\[\#f6f8fa\]:nth-child(odd) {
1446
+ --tw-bg-opacity: 1;
1447
+ background-color: rgb(246 248 250 / var(--tw-bg-opacity, 1));
1448
+ }
1449
+
1383
1450
  .hover\:-translate-y-0\.5:hover {
1384
1451
  --tw-translate-y: -0.125rem;
1385
1452
  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
@@ -1439,6 +1506,10 @@
1439
1506
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
1440
1507
  }
1441
1508
 
1509
+ .hover\:\[fill-opacity\:0\.2\]:hover {
1510
+ fill-opacity: 0.2;
1511
+ }
1512
+
1442
1513
  .hover\:\[scale\:1\.02\]:hover {
1443
1514
  scale: 1.02;
1444
1515
  }
@@ -1723,6 +1794,11 @@
1723
1794
  border-color: hsl(210.5deg 68.97% 65.88% / 0.4);
1724
1795
  }
1725
1796
 
1797
+ .dark\:border-emerald-400:where(.dark, .dark *) {
1798
+ --tw-border-opacity: 1;
1799
+ border-color: rgb(52 211 153 / var(--tw-border-opacity, 1));
1800
+ }
1801
+
1726
1802
  .dark\:border-gray-700:where(.dark, .dark *) {
1727
1803
  --tw-border-opacity: 1;
1728
1804
  border-color: rgb(55 65 81 / var(--tw-border-opacity, 1));
@@ -1733,6 +1809,11 @@
1733
1809
  border-color: rgb(31 41 55 / var(--tw-border-opacity, 1));
1734
1810
  }
1735
1811
 
1812
+ .dark\:border-slate-600:where(.dark, .dark *) {
1813
+ --tw-border-opacity: 1;
1814
+ border-color: rgb(71 85 105 / var(--tw-border-opacity, 1));
1815
+ }
1816
+
1736
1817
  .dark\:border-white:where(.dark, .dark *) {
1737
1818
  --tw-border-opacity: 1;
1738
1819
  border-color: rgb(255 255 255 / var(--tw-border-opacity, 1));
@@ -1786,6 +1867,11 @@
1786
1867
  background-color: rgb(254 202 202 / var(--tw-bg-opacity, 1));
1787
1868
  }
1788
1869
 
1870
+ .dark\:bg-slate-800:where(.dark, .dark *) {
1871
+ --tw-bg-opacity: 1;
1872
+ background-color: rgb(30 41 59 / var(--tw-bg-opacity, 1));
1873
+ }
1874
+
1789
1875
  .dark\:from-\[hsl\(209\.65deg\2c 52\.15\%\2c 31\.96\%\)\]:where(.dark, .dark *) {
1790
1876
  --tw-gradient-from: hsl(209.65deg,52.15%,31.96%) var(--tw-gradient-from-position);
1791
1877
  --tw-gradient-to: hsl(209.65deg 52.15% 31.96% / 0) var(--tw-gradient-to-position);
@@ -1808,6 +1894,10 @@
1808
1894
  fill: #2d2d2d;
1809
1895
  }
1810
1896
 
1897
+ .dark\:fill-blue-400:where(.dark, .dark *) {
1898
+ fill: #60a5fa;
1899
+ }
1900
+
1811
1901
  .dark\:fill-dark-priority-100:where(.dark, .dark *) {
1812
1902
  fill: rgb(45, 45, 45);
1813
1903
  }
@@ -1824,6 +1914,10 @@
1824
1914
  stroke: #2d2d2d;
1825
1915
  }
1826
1916
 
1917
+ .dark\:stroke-blue-400:where(.dark, .dark *) {
1918
+ stroke: #60a5fa;
1919
+ }
1920
+
1827
1921
  .dark\:stroke-dark-priority-100:where(.dark, .dark *) {
1828
1922
  stroke: rgb(45, 45, 45);
1829
1923
  }
@@ -1882,6 +1976,11 @@
1882
1976
  color: rgb(74 222 128 / var(--tw-text-opacity, 1));
1883
1977
  }
1884
1978
 
1979
+ .dark\:text-neutral-300:where(.dark, .dark *) {
1980
+ --tw-text-opacity: 1;
1981
+ color: rgb(212 212 212 / var(--tw-text-opacity, 1));
1982
+ }
1983
+
1885
1984
  .dark\:text-red-900:where(.dark, .dark *) {
1886
1985
  --tw-text-opacity: 1;
1887
1986
  color: rgb(127 29 29 / var(--tw-text-opacity, 1));
@@ -1905,6 +2004,11 @@
1905
2004
  filter: invert(0);
1906
2005
  }
1907
2006
 
2007
+ .odd\:dark\:bg-slate-700:where(.dark, .dark *):nth-child(odd) {
2008
+ --tw-bg-opacity: 1;
2009
+ background-color: rgb(51 65 85 / var(--tw-bg-opacity, 1));
2010
+ }
2011
+
1908
2012
  .dark\:hover\:border-gray-600:hover:where(.dark, .dark *) {
1909
2013
  --tw-border-opacity: 1;
1910
2014
  border-color: rgb(75 85 99 / var(--tw-border-opacity, 1));
@@ -13,7 +13,6 @@ import React, { useId } from "react";
13
13
  import { LinearGradient } from "../../LinearGradient/LinearGradient";
14
14
  import { PathUtils } from "../../../utils/path/path";
15
15
  import { useGraph } from "../../../hooks/use-graph/use-graph";
16
- import { MathUtils } from "../../../utils/math/math";
17
16
  export const Rect = (_a) => {
18
17
  var _b, _c, _d;
19
18
  var { x1, y1, x2, y2, radius, glow, horizontal = false } = _a, rest = __rest(_a, ["x1", "y1", "x2", "y2", "radius", "glow", "horizontal"]);
@@ -27,7 +26,6 @@ export const Rect = (_a) => {
27
26
  const isFillMasked = (_c = rest.fill) === null || _c === void 0 ? void 0 : _c.includes("mask");
28
27
  const isGradientStroke = (_d = rest.stroke) === null || _d === void 0 ? void 0 : _d.includes("gradient");
29
28
  const path = PathUtils.borderRadius({ x: x1, y: y1 }, { x: x2, y: y2 }, radius !== null && radius !== void 0 ? radius : 0, horizontal);
30
- const height = MathUtils.scale(y2 - y1, viewbox.y, 100);
31
29
  return (React.createElement(React.Fragment, null,
32
30
  isFillGradient && rest.fill && React.createElement(LinearGradient, { id: fillId, gradient: rest.fill }),
33
31
  isGradientStroke && rest.stroke && React.createElement(LinearGradient, { id: strokeId, gradient: rest.stroke }),
@@ -2,6 +2,7 @@ import React, { CSSProperties, HTMLAttributes, ReactNode } from "react";
2
2
  import { GraphContext } from "../../hooks/use-graph/use-graph";
3
3
  type Props = {
4
4
  data?: GraphContext["data"];
5
+ datasets?: Record<string, GraphContext["data"]>;
5
6
  gap?: {
6
7
  top?: number;
7
8
  right?: number;
@@ -16,7 +17,7 @@ type Props = {
16
17
  style?: CSSProperties;
17
18
  className?: string;
18
19
  };
19
- export declare const Graph: (({ data, gap, children, interactions, style, className }: Props) => React.JSX.Element) & {
20
+ export declare const Graph: (({ data, gap, children, interactions, datasets, style, className }: Props) => React.JSX.Element) & {
20
21
  Row: ({ children, ...rest }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
21
22
  Column: ({ children, ...rest }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
22
23
  };
@@ -10,22 +10,22 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import React, { useId } from "react";
13
- import { GraphContextProvider } from "../../hooks/use-graph/use-graph";
13
+ import { GraphContextProvider, useGraphColumn } from "../../hooks/use-graph/use-graph";
14
14
  import { ChildrenUtils } from "../../utils/children/children";
15
15
  import { GraphUtils } from "../../utils/graph/graph";
16
16
  import { ColorUtils } from "../../utils/color/color";
17
17
  import { DomainUtils } from "../../utils/domain/domain";
18
- import { cx, tw } from "../../utils/cx/cx";
18
+ import { tw } from "../../utils/cx/cx";
19
19
  import { useIsServerComponent } from "../../hooks/use-is-server-component";
20
- const GraphComponent = ({ data = [], gap, children, interactions, style, className }) => {
21
- var _a, _b, _c, _d, _e, _f, _g, _h;
20
+ const GraphComponent = ({ data = [], gap, children, interactions, datasets = {}, style, className }) => {
21
+ var _a, _b, _c, _d, _e, _f;
22
22
  const id = useId();
23
23
  const X_SCALE = 3000;
24
24
  const Y_SCALE = 3000;
25
25
  const isServerComponent = useIsServerComponent();
26
26
  const ctx = ChildrenUtils.context(children, {
27
27
  id,
28
- layout: { rows: "[graph] auto", columns: "[graph] auto" },
28
+ layout: { rows: "[graph]auto", columns: "[graph]auto" },
29
29
  viewbox: { x: X_SCALE, y: Y_SCALE },
30
30
  data: data,
31
31
  gap: { top: (_a = gap === null || gap === void 0 ? void 0 : gap.top) !== null && _a !== void 0 ? _a : 0, left: (_b = gap === null || gap === void 0 ? void 0 : gap.left) !== null && _b !== void 0 ? _b : 0, right: (_c = gap === null || gap === void 0 ? void 0 : gap.right) !== null && _c !== void 0 ? _c : 0, bottom: (_d = gap === null || gap === void 0 ? void 0 : gap.bottom) !== null && _d !== void 0 ? _d : 0 },
@@ -38,31 +38,65 @@ const GraphComponent = ({ data = [], gap, children, interactions, style, classNa
38
38
  },
39
39
  colors: ColorUtils.scheme.contrast,
40
40
  interactions: { hovered: (_e = interactions === null || interactions === void 0 ? void 0 : interactions.hovered) !== null && _e !== void 0 ? _e : [], pinned: (_f = interactions === null || interactions === void 0 ? void 0 : interactions.pinned) !== null && _f !== void 0 ? _f : [] },
41
+ datasets: Object.fromEntries(Object.entries(datasets).map(([datasetId, dataset]) => {
42
+ return [
43
+ datasetId,
44
+ {
45
+ colors: ColorUtils.scheme.contrast,
46
+ domain: {
47
+ x: [],
48
+ y: [],
49
+ },
50
+ data: dataset,
51
+ },
52
+ ];
53
+ })),
41
54
  });
42
- const colorized = Object.assign(Object.assign({}, ctx), { domain: {
43
- x: (_g = ctx.domain.x) !== null && _g !== void 0 ? _g : DomainUtils.x.ticks({ data, viewbox: { x: X_SCALE, y: Y_SCALE } }),
44
- y: (_h = ctx.domain.y) !== null && _h !== void 0 ? _h : DomainUtils.y.ticks({ data, viewbox: { x: X_SCALE, y: Y_SCALE } }),
45
- }, data: GraphUtils.isXYData(data)
46
- ? data.map((dp, i) => {
47
- var _a, _b, _c;
48
- return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke ? dp.fill : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : ctx.colors[i]) !== null && _c !== void 0 ? _c : ctx.colors.at(-1)) }, dp);
49
- })
50
- : [...data]
51
- .sort((a, b) => Number(b.value) - Number(a.value))
52
- .map((dp, i) => {
53
- var _a, _b, _c;
54
- return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke ? dp.fill : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : ctx.colors[i]) !== null && _c !== void 0 ? _c : ctx.colors.at(-1)) }, dp);
55
- }) });
55
+ const setDefaults = (dataset) => {
56
+ console.log("Y", dataset.domain.y.length === 0, DomainUtils.y.ticks({ data: dataset.data, viewbox: { x: X_SCALE, y: Y_SCALE } }), dataset.domain.y);
57
+ return Object.assign(Object.assign({}, dataset), { domain: {
58
+ x: dataset.domain.x.length === 0
59
+ ? DomainUtils.x.ticks({ data: dataset.data, viewbox: { x: X_SCALE, y: Y_SCALE } })
60
+ : dataset.domain.x,
61
+ y: dataset.domain.y.length === 0
62
+ ? DomainUtils.y.ticks({ data: dataset.data, viewbox: { x: X_SCALE, y: Y_SCALE } })
63
+ : dataset.domain.y,
64
+ }, data: GraphUtils.isXYData(dataset.data)
65
+ ? dataset.data.map((dp, i) => {
66
+ var _a, _b, _c;
67
+ /* if there's a fill and no stroke, use fill as the stroke, otherwise use stroke color, or default color */
68
+ return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke
69
+ ? dp.fill
70
+ : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dataset.colors[i]) !== null && _c !== void 0 ? _c : dataset.colors.at(-1)) }, dp);
71
+ })
72
+ : [...dataset.data]
73
+ .sort((a, b) => Number(b.value) - Number(a.value))
74
+ .map((dp, i) => {
75
+ var _a, _b, _c;
76
+ /* if there's a fill and no stroke, use fill as the stroke, otherwise use stroke color, or default color */
77
+ return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke
78
+ ? dp.fill
79
+ : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dataset.colors[i]) !== null && _c !== void 0 ? _c : dataset.colors.at(-1)) }, dp);
80
+ }), datasets: Object.fromEntries(Object.entries("datasets" in dataset ? dataset["datasets"] : {}).map(([datasetId, dctx]) => {
81
+ console.log(setDefaults(dctx));
82
+ return [datasetId, setDefaults(dctx)];
83
+ })) });
84
+ };
85
+ const colorized = setDefaults(ctx);
56
86
  return (React.createElement("div", Object.assign({ id: id, "data-ctx": "graph" }, ctx.attributes, { style: Object.assign(Object.assign(Object.assign({}, style), ctx.attributes.style), { gridTemplateColumns: ctx.layout.columns, gridTemplateRows: ctx.layout.rows, padding: `${ctx.gap.top}px ${ctx.gap.right}px ${ctx.gap.bottom}px ${ctx.gap.left}px` }), className: tw(ctx.attributes.className, className) }),
57
87
  isServerComponent && (
58
- /* Server components */
88
+ /* CTX for server components. */
59
89
  React.createElement("script", { id: id + "-context", type: "application/json", dangerouslySetInnerHTML: { __html: JSON.stringify(colorized) } })),
60
90
  React.createElement(GraphContextProvider, { value: colorized }, children)));
61
91
  };
62
92
  export const Graph = Object.assign(GraphComponent, {
63
93
  Row: (_a) => {
64
94
  var { children } = _a, rest = __rest(_a, ["children"]);
65
- return (React.createElement("div", Object.assign({}, rest, { className: cx("col-span-full", rest.className) }), children));
95
+ const column = useGraphColumn();
96
+ return (React.createElement(React.Fragment, null,
97
+ new Array(column.left).fill(null).map((_, i) => (React.createElement("div", { key: i }))),
98
+ React.createElement("div", Object.assign({}, rest), children),
99
+ new Array(column.right).fill(null).map((_, i) => (React.createElement("div", { key: i })))));
66
100
  },
67
101
  Column: (_a) => {
68
102
  var { children } = _a, rest = __rest(_a, ["children"]);
@@ -40,6 +40,7 @@ export declare const Legend: {
40
40
  hovered: string[];
41
41
  pinned: string[];
42
42
  };
43
+ datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
43
44
  };
44
45
  };
45
46
  export {};
@@ -11,15 +11,14 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import React from "react";
13
13
  import { Graph } from "../Graph/Graph";
14
- import { useGraph, useGraphColumn } from "../../hooks/use-graph/use-graph";
14
+ import { useGraph } from "../../hooks/use-graph/use-graph";
15
15
  import { cx } from "../../utils/cx/cx";
16
16
  import { GradientUtils } from "../../utils/gradient/gradient";
17
17
  export const Legend = ({ position = "top", alignment = "center" }) => {
18
18
  const context = useGraph();
19
19
  const Element = position === "top" || position === "bottom" ? Graph.Row : Graph.Column;
20
- const column = useGraphColumn(context);
21
20
  const { viewbox, domain, interactions: { pinned, hovered }, } = context;
22
- return (React.createElement(Element, { className: cx("flex gap-3", (position === "left" || position === "right") && "flex-col", position === "right" && "pl-4", position === "left" && "pr-4", position === "top" && "pb-3 pt-2", position === "bottom" && "pt-3 pb-2", alignment === "start" && "justify-start", alignment === "end" && "justify-end", alignment === "center" && "justify-center"), style: position === "top" || position === "bottom" ? { gridColumn: column } : undefined }, context.data
21
+ return (React.createElement(Element, { className: cx("flex gap-3", (position === "left" || position === "right") && "flex-col", position === "right" && "pl-4", position === "left" && "pr-4", position === "top" && "pb-3 pt-2", position === "bottom" && "pt-3 pb-2", alignment === "start" && "justify-start", alignment === "end" && "justify-end", alignment === "center" && "justify-center") }, context.data
23
22
  .map((dp) => { var _a; return (Object.assign(Object.assign({}, dp), { group: (_a = dp.group) !== null && _a !== void 0 ? _a : "" })); })
24
23
  .sort((a, b) => a.group.localeCompare(b.group))
25
24
  .map((_a, i, datapoints) => {
@@ -5,9 +5,10 @@ interface Props extends React.SVGAttributes<SVGSVGElement> {
5
5
  curve?: keyof typeof CurveUtils;
6
6
  joints?: boolean;
7
7
  loading?: boolean;
8
+ dataset?: string;
8
9
  }
9
10
  export declare const Lines: {
10
- ({ className, curve, joints, children, loading }: Props): React.JSX.Element | null;
11
+ ({ className, curve, joints, children, loading, dataset }: Props): React.JSX.Element | null;
11
12
  Tooltip: React.ComponentType<React.HTMLAttributes<HTMLDivElement> & {
12
13
  tooltip?: ((points: Array<Omit<import("../../export").CartesianDataset[number], "data"> & {
13
14
  data: import("../../export").CartesianDataset[number]["data"][number];
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { GraphUtils } from "../../utils/graph/graph";
3
- import { useGraph } from "../../hooks/use-graph/use-graph";
3
+ import { useDataset, useGraph } from "../../hooks/use-graph/use-graph";
4
4
  import { CurveUtils } from "../../utils/path/curve";
5
5
  import { CoordinatesUtils } from "../../utils/coordinates/coordinates";
6
6
  import { LinesLoading } from "./components/LinesLoading";
@@ -16,8 +16,9 @@ const chunk = (points, size) => {
16
16
  }
17
17
  return chunks;
18
18
  };
19
- export const Lines = ({ className, curve = "linear", joints, children, loading }) => {
20
- const { interactions: { pinned, hovered }, data, viewbox, domain, colors, } = useGraph();
19
+ export const Lines = ({ className, curve = "linear", joints, children, loading, dataset }) => {
20
+ const { interactions: { pinned, hovered }, viewbox, } = useGraph();
21
+ const { data, domain, colors } = useDataset(dataset);
21
22
  if (!GraphUtils.isXYData(data))
22
23
  return null;
23
24
  const xForValue = CoordinatesUtils.xCoordinateFor({ domain, viewbox });
@@ -42,6 +42,8 @@ const LinesTooltipComponent = (_a) => {
42
42
  const { width, height } = (_f = (_e = ref.current) === null || _e === void 0 ? void 0 : _e.getBoundingClientRect()) !== null && _f !== void 0 ? _f : { width: 0, height: 0 };
43
43
  const isDateTimeAxis = ((_g = domain.x[0]) === null || _g === void 0 ? void 0 : _g.tick) instanceof Date;
44
44
  const datapoints = useMemo(() => {
45
+ if (!mouse)
46
+ return [];
45
47
  /* data wont change while mouse is moving, but will change when parent re-renders with new object identity */
46
48
  const max = data.reduce((max, { data }) => Math.max(max, data.length), 0);
47
49
  let values = new Float64Array(data.length * max);
@@ -52,7 +54,7 @@ const LinesTooltipComponent = (_a) => {
52
54
  }
53
55
  }
54
56
  return values;
55
- }, [data]);
57
+ }, [data, Boolean(mouse)]);
56
58
  const closest = (() => {
57
59
  var _a, _b;
58
60
  /*
@@ -158,7 +160,7 @@ const LinesTooltipComponent = (_a) => {
158
160
  closest != null && (React.createElement("line", { x1: xForValue(+closest), x2: xForValue(+closest), y1: 0, y2: viewbox.y, className: "stroke-black dark:stroke-white", strokeWidth: 4 })),
159
161
  joints &&
160
162
  (jointPoints === null || jointPoints === void 0 ? void 0 : jointPoints.map(({ data: { x, y }, stroke }, i) => {
161
- return (React.createElement("path", { key: i, stroke: stroke, fill: stroke, d: `M ${x} ${y} A 0 0 0 0 1 ${x} ${y}`, strokeWidth: "10", strokeLinecap: "round", vectorEffect: "non-scaling-stroke" }));
163
+ return (React.createElement("path", { key: i, stroke: stroke, fill: stroke, d: `M ${x} ${y} A 0 0 0 0 1 ${x} ${y}`, strokeWidth: "8", strokeLinecap: "round", vectorEffect: "non-scaling-stroke" }));
162
164
  }))),
163
165
  ordered && closest != null && mouse && (React.createElement(overlay.div, Object.assign({}, rest, { ref: setTooltipRef, className: tw("lines-tooltip__tooltip absolute pointer-events-none", rest.className), style: { left: left + rect.left, top: top + rect.top } }), typeof tooltip === "function" ? (tooltip(ordered, closest)) : (React.createElement("div", Object.assign({}, rest, { className: "text-[14px] leading-[14px] rounded border bg-opacity-60 shadow-md backdrop-blur-sm w-[250px] pb-1.5 border-gray-200 dark-border-[#454545]" }),
164
166
  React.createElement("div", { className: "font-medium bg-gradient-to-b from-transparent to-[#CFCFCF] dark:to-[#3C3C3C] pl-2 pr-2 pt-1.5 pb-1 mb-1.5" }, (() => {
@@ -49,10 +49,10 @@ export const overlay = new Proxy(Overlay, {
49
49
  if (cache[prop])
50
50
  return cache[prop];
51
51
  /*
52
- Ensures this component identity is only created once, this is important because react's remount logic
53
- will check element.type === lastrender.type, if this is not the same, it will remount the component.
54
- because overlay.div will run this function every time 'component' will recieve a new function identity
55
- */
52
+ Ensures this component identity is only created once, this is important because react's remount logic
53
+ will check element.type === lastrender.type, if this is not the same, it will remount the component.
54
+ because overlay.div will run this function every time 'component' will recieve a new function identity
55
+ */
56
56
  const component = (_a) => {
57
57
  var { children } = _a, rest = __rest(_a, ["children"]);
58
58
  return (React.createElement(Overlay, Object.assign({}, rest, { tag: prop }), children));
@@ -87,7 +87,7 @@ export const Pie = ({ glow = true, donut, labels = true, total, loading, classNa
87
87
  glow && React.createElement("use", { xlinkHref: `#${glowId + id}`, filter: "blur(150px)", opacity: 0.5, scale: 0.9 }),
88
88
  React.createElement("g", { className: "pie__slice group" },
89
89
  React.createElement("g", { className: `pie__segment-${id}`, id: glowId + id, mask: donut ? `url(#${maskId})` : undefined }, path),
90
- React.createElement("g", { className: "transform origin-center rotate-180 invisible @[width:400px]:!visible " }, label)),
90
+ React.createElement("g", { className: "transform origin-center rotate-[180deg] invisible @[width:400px]:!visible " }, label)),
91
91
  donut && (React.createElement("mask", { id: maskId },
92
92
  React.createElement("rect", { width: "80%", height: "80%", fill: "white" }),
93
93
  React.createElement("circle", { cx: CX, cy: CY, r: DONUT_RADIUS, fill: "black" })))));
@@ -136,6 +136,6 @@ export const Radar = ({ scalars = [0, 20, 40, 60, 80, 100], labels = true, loadi
136
136
  React.createElement("circle", { cx: x1, cy: y1, r: viewbox.x * 0.005, className: "fill-gray-500 dark:fill-white" })));
137
137
  }),
138
138
  angles.map((point, i) => {
139
- return (React.createElement("path", { key: i, className: "[vector-effect:non-scaling-stroke] dark:fill-white [fill-opacity:0] [stroke-opacity:0]", d: PathUtils.describeArc(viewbox.x / 2, viewbox.y / 2, radius, point - arcDegrees / 2, point + arcDegrees / 2) + ` L ${viewbox.x / 2} ${viewbox.x / 2} Z` }));
139
+ return (React.createElement("path", { key: i, className: "[vector-effect:non-scaling-stroke] dark:fill-white [fill-opacity:0] [stroke-opacity:0] hover:[fill-opacity:0.2] ", d: PathUtils.describeArc(viewbox.x / 2, viewbox.y / 2, radius, point - arcDegrees / 2, point + arcDegrees / 2) + ` L ${viewbox.x / 2} ${viewbox.x / 2} Z` }));
140
140
  }))));
141
141
  };
@@ -325,6 +325,7 @@ export declare const Worldmap: {
325
325
  hovered: string[];
326
326
  pinned: string[];
327
327
  };
328
+ datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
328
329
  };
329
330
  };
330
331
  export {};
@@ -42,6 +42,7 @@ export declare const XAxis: {
42
42
  hovered: string[];
43
43
  pinned: string[];
44
44
  };
45
+ datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
45
46
  };
46
47
  };
47
48
  export {};
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
- import { useGraph, useGraphColumn } from "../../hooks/use-graph/use-graph";
2
+ import { useGraph } from "../../hooks/use-graph/use-graph";
3
3
  import { Graph } from "../Graph/Graph";
4
4
  import { DomainUtils } from "../../utils/domain/domain";
5
5
  import { MathUtils } from "../../utils/math/math";
6
6
  import { cx } from "../../utils/cx/cx";
7
7
  export const XAxis = ({ display, title, description }) => {
8
8
  const context = useGraph();
9
- const column = useGraphColumn(context);
10
9
  const formatter = new Intl.NumberFormat("en-US", { minimumFractionDigits: 0, maximumFractionDigits: 2 });
11
10
  const labels = context.domain.x.map(({ tick, coordinate }) => {
12
11
  const label = (() => {
@@ -20,7 +19,7 @@ export const XAxis = ({ display, title, description }) => {
20
19
  });
21
20
  const characters = labels.reduce((acc, { label }) => acc + (typeof label === "string" ? label.length : 0), 0);
22
21
  const breakpoint = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100].find((bp) => bp >= characters);
23
- return (React.createElement(Graph.Row, { className: "xaxis items-center relative pt-2 text-xs font-normal select-none", style: { gridColumn: column } },
22
+ return (React.createElement(Graph.Row, { className: "xaxis items-center relative pt-2 text-xs font-normal select-none" },
24
23
  React.createElement("div", { className: "xaxis__ticks flex relative" },
25
24
  labels.map(({ label }, i) => {
26
25
  return (React.createElement("div", { className: "xaxis__tick opacity-0 text-nowrap", key: i }, label));
@@ -12,42 +12,11 @@ type Props = {
12
12
  title?: ReactNode;
13
13
  display?: (tick: string | number | Date) => ReactNode;
14
14
  description?: ReactNode;
15
+ position?: "top" | "bottom" | "left" | "right";
16
+ dataset?: string;
15
17
  };
16
18
  export declare const YAxis: {
17
- ({ title, description, display }: Props): React.JSX.Element;
18
- context(ctx: GraphContext, props: Props): {
19
- layout: {
20
- rows: string;
21
- columns: string;
22
- };
23
- domain: {
24
- x: {
25
- coordinate: number;
26
- tick: string | number | Date;
27
- }[];
28
- y: {
29
- coordinate: number;
30
- tick: string | number | Date;
31
- }[];
32
- };
33
- id: string;
34
- attributes: React.HTMLAttributes<HTMLDivElement>;
35
- gap: {
36
- top: number;
37
- right: number;
38
- bottom: number;
39
- left: number;
40
- };
41
- viewbox: {
42
- x: number;
43
- y: number;
44
- };
45
- data: import("../../export").CartesianDataset | import("../../export").SegmentDataset;
46
- colors: string[];
47
- interactions: {
48
- hovered: string[];
49
- pinned: string[];
50
- };
51
- };
19
+ ({ title, description, display, dataset, position }: Props): React.JSX.Element;
20
+ context(ctx: GraphContext, props: Props): GraphContext;
52
21
  };
53
22
  export {};