nanoplot 0.0.78 → 0.0.80

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 (44) hide show
  1. package/dist/src/components/Area/Area.d.ts +2 -2
  2. package/dist/src/components/Bars/Bars.d.ts +2 -2
  3. package/dist/src/components/Bars/components/HorizontalBars.d.ts +14 -10
  4. package/dist/src/components/Bars/components/HorizontalBars.js +6 -4
  5. package/dist/src/components/Bars/components/Rect.js +1 -1
  6. package/dist/src/components/Bars/components/VerticalBars.d.ts +14 -10
  7. package/dist/src/components/Bars/components/VerticalBars.js +7 -5
  8. package/dist/src/components/GradientLegend/GradientLegend.d.ts +4 -4
  9. package/dist/src/components/GradientLegend/GradientLegend.js +2 -0
  10. package/dist/src/components/Graph/Graph.js +5 -11
  11. package/dist/src/components/Legend/Legend.d.ts +8 -8
  12. package/dist/src/components/Lines/Lines.d.ts +3 -3
  13. package/dist/src/components/Lines/Lines.js +2 -2
  14. package/dist/src/components/Lines/components/LinesJoints.d.ts +2 -2
  15. package/dist/src/components/Lines/components/LinesJoints.js +6 -3
  16. package/dist/src/components/Pie/Pie.d.ts +9 -5
  17. package/dist/src/components/Pie/Pie.js +7 -6
  18. package/dist/src/components/Pie/components/PieTooltip.d.ts +2 -2
  19. package/dist/src/components/Worldmap/Worldmap.d.ts +4 -4
  20. package/dist/src/components/XAxis/XAxis.d.ts +2 -2
  21. package/dist/src/components/YAxis/YAxis.d.ts +2 -2
  22. package/dist/src/components/ZoomSlider/ZoomSlider.d.ts +4 -4
  23. package/dist/src/components/ZoomSlider/ZoomSliderX.d.ts +2 -2
  24. package/dist/src/components/ZoomSlider/ZoomSliderY.d.ts +2 -2
  25. package/dist/src/export/index.d.ts +1 -1
  26. package/dist/src/hooks/use-graph/use-client-graph.d.ts +4 -4
  27. package/dist/src/hooks/use-graph/use-graph.d.ts +31 -12
  28. package/dist/src/hooks/use-graph/use-server-graph.d.ts +3 -3
  29. package/dist/src/utils/children/children.d.ts +2 -2
  30. package/dist/src/utils/coordinates/coordinates.d.ts +14 -14
  31. package/dist/src/utils/coordinates/coordinates.js +4 -4
  32. package/dist/src/utils/domain/domain.d.ts +3 -3
  33. package/dist/src/utils/domain/utils/auto-minmax.d.ts +5 -1
  34. package/dist/src/utils/domain/utils/auto-minmax.js +18 -7
  35. package/dist/src/utils/domain/utils/range.d.ts +2 -2
  36. package/dist/src/utils/domain/utils/range.js +7 -7
  37. package/dist/src/utils/gradient/gradient.d.ts +9 -9
  38. package/dist/src/utils/gradient/gradient.js +4 -2
  39. package/dist/src/utils/math/math.d.ts +1 -1
  40. package/dist/src/utils/math/math.js +1 -10
  41. package/dist/src/utils/path/curve.js +28 -30
  42. package/dist/tsconfig.typings.tsbuildinfo +1 -1
  43. package/package.json +1 -1
  44. package/tailwind-container-queries.ts +0 -4
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  import { CurveUtils } from "../../utils/path/curve";
4
4
  interface Props extends React.SVGAttributes<SVGSVGElement> {
5
5
  children?: ReactNode;
@@ -8,7 +8,7 @@ interface Props extends React.SVGAttributes<SVGSVGElement> {
8
8
  }
9
9
  export declare const Area: {
10
10
  ({ className, curve, children, loading }: Props): React.JSX.Element | null;
11
- context(ctx: GraphContext): GraphContext;
11
+ context(ctx: InternalGraphContext): InternalGraphContext;
12
12
  Tooltip: React.ComponentType<Omit<React.HTMLAttributes<HTMLDivElement> & {
13
13
  tooltip?: ((points: Array<Omit<import("../../export").CartesianDataset[number], "data"> & {
14
14
  data: import("../../export").CartesianDataset[number]["data"][number];
@@ -1,7 +1,7 @@
1
1
  import React, { ComponentProps } from "react";
2
2
  import { HorizontalBars } from "./components/HorizontalBars";
3
3
  import { VerticalBars } from "./components/VerticalBars";
4
- import { GraphContext } from "../../hooks/use-graph/use-graph";
4
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
5
5
  type VerticalProps = {
6
6
  horizontal?: false;
7
7
  } & ComponentProps<typeof VerticalBars>;
@@ -10,6 +10,6 @@ type HorizontalProps = {
10
10
  } & ComponentProps<typeof HorizontalBars>;
11
11
  export declare const Bars: {
12
12
  ({ horizontal, ...props }: VerticalProps | HorizontalProps): React.JSX.Element;
13
- context(ctx: GraphContext): GraphContext;
13
+ context(ctx: InternalGraphContext): InternalGraphContext;
14
14
  };
15
15
  export {};
@@ -1,21 +1,25 @@
1
1
  import React, { MouseEvent } from "react";
2
- import { CartesianDatasetDefaulted } from "../../../hooks/use-graph/use-graph";
3
- import { Rect } from "./Rect";
4
- type Rect = Omit<CartesianDatasetDefaulted[number], "data"> & {
5
- data: CartesianDatasetDefaulted[number]["data"][number];
6
- };
7
- type Props = Omit<React.SVGAttributes<SVGSVGElement>, "onMouseEnter" | "onMouseLeave"> & {
2
+ import { InternalCartesianDataset, Simplify } from "../../../hooks/use-graph/use-graph";
3
+ type Segment = Simplify<Omit<InternalCartesianDataset[number], "data"> & {
4
+ data: InternalCartesianDataset[number]["data"][number];
5
+ }>;
6
+ type Props = Omit<React.SVGAttributes<SVGSVGElement>, "onMouseEnter" | "onMouseLeave" | "fill" | "stroke"> & {
8
7
  children?: React.ReactNode;
9
8
  size?: number;
10
9
  radius?: number;
11
10
  anchor?: number;
12
- labels?: boolean | ((value: string | number | Date) => string) | {
11
+ labels?: boolean | ((segment: Segment) => string) | {
13
12
  position: "above" | "center";
14
13
  collision?: boolean;
15
- display: (value: string | number | Date) => string;
14
+ display: (segment: Segment) => string;
16
15
  };
17
- onMouseEnter?: (event: MouseEvent, rect: Rect) => void;
16
+ /**
17
+ * Function that can change the 'fill' for individual segments based on some condition.
18
+ */
19
+ fill?: (segment: Segment) => string;
20
+ stroke?: (segment: Segment) => string;
21
+ onMouseEnter?: (rect: Segment, event: MouseEvent) => void;
18
22
  onMouseLeave?: (event: MouseEvent) => void;
19
23
  };
20
- export declare const HorizontalBars: ({ children, labels, size, radius, anchor, className }: Props) => React.JSX.Element | null;
24
+ export declare const HorizontalBars: ({ children, fill, stroke, labels, size, radius, anchor, onMouseEnter, onMouseLeave, className, }: Props) => React.JSX.Element | null;
21
25
  export {};
@@ -19,7 +19,7 @@ import { Rect } from "./Rect";
19
19
  import { scale } from "../../../utils/math/math";
20
20
  import { overlay } from "../../Overlay/Overlay";
21
21
  import { ColorUtils } from "../../../utils/color/color";
22
- export const HorizontalBars = ({ children, labels, size = 50, radius = 0, anchor = 0, className }) => {
22
+ export const HorizontalBars = ({ children, fill, stroke, labels, size = 50, radius = 0, anchor = 0, onMouseEnter, onMouseLeave, className, }) => {
23
23
  const context = useGraph();
24
24
  if (!GraphUtils.isXYData(context.data))
25
25
  return null;
@@ -47,7 +47,9 @@ export const HorizontalBars = ({ children, labels, size = 50, radius = 0, anchor
47
47
  React.createElement("svg", { viewBox: `0 0 ${context.viewbox.x} ${context.viewbox.y}`, className: cx("horizontal-bars [grid-area:graph] h-full w-full", className), preserveAspectRatio: "none" },
48
48
  dataset.map((_a, index) => {
49
49
  var { x1, x2, y1, y2 } = _a, bar = __rest(_a, ["x1", "x2", "y1", "y2"]);
50
- return (React.createElement(Rect, { key: index, x1: x1, x2: x2, y2: y2, y1: y1, fill: String(bar.fill), stroke: bar.stroke, radius: bar.radius, glow: false, horizontal: true, className: "bars__bar" }));
50
+ const fillColor = fill ? fill(bar) : bar.fill;
51
+ const strokeColor = stroke ? stroke(bar) : bar.stroke;
52
+ return (React.createElement(Rect, { key: index, x1: x1, x2: x2, y2: y2, y1: y1, fill: fillColor, stroke: strokeColor, radius: bar.radius, glow: false, horizontal: true, onMouseEnter: onMouseEnter ? (event) => onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(bar, event) : undefined, onMouseLeave: onMouseLeave, className: "bars__bar" }));
51
53
  }),
52
54
  children),
53
55
  labels &&
@@ -60,8 +62,8 @@ export const HorizontalBars = ({ children, labels, size = 50, radius = 0, anchor
60
62
  const label = (() => {
61
63
  var _a;
62
64
  if (typeof labels === "object" && "position" in labels)
63
- return labels.display(bar.data.x);
64
- return (_a = (labels === true ? bar.data.y : labels(bar.data.y))) !== null && _a !== void 0 ? _a : "";
65
+ return labels.display(bar);
66
+ return (_a = (labels === true ? bar.data.y : labels(bar))) !== null && _a !== void 0 ? _a : "";
65
67
  })();
66
68
  const breakpoint = [2, 4, 6, 8, 10, 15, 20].find((bp) => bp >= label.toString().length);
67
69
  return (React.createElement(overlay.div, { key: i, className: "bars__label @container-[size] absolute text-center", style: {
@@ -27,7 +27,7 @@ export const Rect = (_a) => {
27
27
  return (React.createElement(React.Fragment, null,
28
28
  isFillGradient && rest.fill && React.createElement(LinearGradient, { id: fillId, gradient: rest.fill }),
29
29
  isGradientStroke && rest.stroke && React.createElement(LinearGradient, { id: strokeId, gradient: rest.stroke }),
30
- React.createElement("path", { id: clipId, d: path }),
30
+ React.createElement("path", { id: clipId, d: path, fill: isFillGradient ? `url(#${fillId})` : rest.fill, stroke: isGradientStroke ? `url(#${strokeId})` : rest.stroke }),
31
31
  React.createElement("clipPath", { id: clip },
32
32
  React.createElement("use", { xlinkHref: "#" + clipId })),
33
33
  glow && (React.createElement(React.Fragment, null,
@@ -1,23 +1,27 @@
1
1
  import React, { MouseEvent, ReactNode } from "react";
2
- import { CartesianDatasetDefaulted } from "../../../hooks/use-graph/use-graph";
3
- import { Rect } from "./Rect";
4
- type Rect = Omit<CartesianDatasetDefaulted[number], "data"> & {
5
- data: CartesianDatasetDefaulted[number]["data"][number];
6
- };
7
- type Props = Omit<React.SVGAttributes<SVGSVGElement>, "onMouseEnter" | "onMouseLeave"> & {
2
+ import { InternalCartesianDataset, Simplify } from "../../../hooks/use-graph/use-graph";
3
+ type Segment = Simplify<Omit<InternalCartesianDataset[number], "data"> & {
4
+ data: InternalCartesianDataset[number]["data"][number];
5
+ }>;
6
+ type Props = Omit<React.SVGAttributes<SVGSVGElement>, "onMouseEnter" | "onMouseLeave" | "fill" | "stroke"> & {
8
7
  children?: ReactNode;
9
8
  loading?: boolean;
10
9
  glow?: boolean;
11
10
  size?: number;
12
11
  radius?: number;
13
12
  anchor?: number;
14
- labels?: boolean | ((value: string | number | Date) => string) | {
13
+ labels?: boolean | ((segment: Segment) => string) | {
15
14
  position: "above" | "center";
16
15
  collision?: boolean;
17
- display: (value: string | number | Date) => string;
16
+ display: (segment: Segment) => string;
18
17
  };
19
- onMouseEnter?: (event: MouseEvent, rect: Rect) => void;
18
+ /**
19
+ * Function that can change the 'fill' for individual segments based on some condition.
20
+ */
21
+ fill?: (segment: Segment) => string;
22
+ stroke?: (segment: Segment) => string;
23
+ onMouseEnter?: (rect: Segment, event: MouseEvent) => void;
20
24
  onMouseLeave?: (event: MouseEvent) => void;
21
25
  };
22
- export declare const VerticalBars: ({ children, size, anchor, labels, radius, glow, className, loading, onMouseEnter, onMouseLeave, ...rest }: Props) => React.JSX.Element | null;
26
+ export declare const VerticalBars: ({ children, fill, stroke, size, anchor, labels, radius, glow, className, loading, onMouseEnter, onMouseLeave, ...rest }: Props) => React.JSX.Element | null;
23
27
  export {};
@@ -21,7 +21,7 @@ import { scale } from "../../../utils/math/math";
21
21
  import { overlay } from "../../Overlay/Overlay";
22
22
  import { ColorUtils } from "../../../utils/color/color";
23
23
  export const VerticalBars = (_a) => {
24
- var { children, size = 50, anchor = 0, labels = true, radius = 0, glow, className, loading, onMouseEnter, onMouseLeave } = _a, rest = __rest(_a, ["children", "size", "anchor", "labels", "radius", "glow", "className", "loading", "onMouseEnter", "onMouseLeave"]);
24
+ var { children, fill, stroke, size = 50, anchor = 0, labels, radius = 0, glow, className, loading, onMouseEnter, onMouseLeave } = _a, rest = __rest(_a, ["children", "fill", "stroke", "size", "anchor", "labels", "radius", "glow", "className", "loading", "onMouseEnter", "onMouseLeave"]);
25
25
  const context = useGraph();
26
26
  if (!GraphUtils.isXYData(context.data))
27
27
  return null;
@@ -56,10 +56,12 @@ export const VerticalBars = (_a) => {
56
56
  .filter((x) => !!x);
57
57
  const isBelowAnchor = bars.some((bar) => +bar.data.y < anchor); /* is any bar below the anchor */
58
58
  return (React.createElement(React.Fragment, null,
59
- React.createElement("svg", Object.assign({}, rest, { viewBox: `0 0 ${context.viewbox.x} ${context.viewbox.y}`, className: cx("horizontal-bars [grid-area:graph] h-full w-full bars", className), preserveAspectRatio: "none" }),
59
+ React.createElement("svg", Object.assign({}, rest, { viewBox: `0 0 ${context.viewbox.x} ${context.viewbox.y}`, className: cx("vertical-bars [grid-area:graph] h-full w-full bars", className), preserveAspectRatio: "none" }),
60
60
  dataset.map((_a, index) => {
61
61
  var { x1, x2, y1, y2 } = _a, bar = __rest(_a, ["x1", "x2", "y1", "y2"]);
62
- return (React.createElement(Rect, { key: index, x1: x1, x2: x2, y2: y2, y1: y1, fill: String(bar.fill), stroke: bar.stroke, radius: bar.radius, glow: glow, onMouseEnter: (event) => onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(event, bar), onMouseLeave: onMouseLeave, className: "bars__bar" }));
62
+ const fillColor = fill ? fill(bar) : bar.fill;
63
+ const strokeColor = stroke ? stroke(bar) : bar.stroke;
64
+ return (React.createElement(Rect, { key: index, x1: x1, x2: x2, y2: y2, y1: y1, fill: fillColor, stroke: strokeColor, radius: bar.radius, glow: glow, onMouseEnter: onMouseEnter ? (event) => onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(bar, event) : undefined, onMouseLeave: onMouseLeave, className: "bars__bar" }));
63
65
  }),
64
66
  isBelowAnchor && (React.createElement("path", { strokeWidth: 2, vectorEffect: "non-scaling-stroke", stroke: "red", className: "stroke-dark-priority-100", d: `M 0 ${yForValue(anchor)} L ${context.viewbox.x} ${yForValue(anchor)}` })),
65
67
  children),
@@ -73,8 +75,8 @@ export const VerticalBars = (_a) => {
73
75
  const label = (() => {
74
76
  var _a;
75
77
  if (typeof labels === "object" && "position" in labels)
76
- return labels.display(bar.data.y);
77
- return (_a = (labels === true ? bar.data.y : labels(bar.data.y))) !== null && _a !== void 0 ? _a : "";
78
+ return labels.display(bar);
79
+ return (_a = (labels === true ? bar.data.y : labels(bar))) !== null && _a !== void 0 ? _a : "";
78
80
  })();
79
81
  const breakpoint = [2, 4, 5, 6, 8, 10, 15, 20].find((bp) => bp >= label.toString().replace(".", "").length);
80
82
  return (React.createElement(overlay.div, { key: i, className: "bars__label @container-[size] absolute text-center", style: {
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  type Props = React.HTMLAttributes<HTMLDivElement> & {
4
4
  position: "top" | "bottom";
5
5
  alignment?: "start" | "center" | "end";
@@ -12,7 +12,7 @@ type Props = React.HTMLAttributes<HTMLDivElement> & {
12
12
  };
13
13
  export declare const GradientLegend: {
14
14
  ({ position, alignment, gradient, scalars, labels, ...rest }: Props): React.JSX.Element;
15
- context(ctx: GraphContext, props: Props): {
15
+ context(ctx: InternalGraphContext, props: Props): {
16
16
  layout: {
17
17
  rows: string;
18
18
  columns: string;
@@ -29,7 +29,7 @@ export declare const GradientLegend: {
29
29
  x: number;
30
30
  y: number;
31
31
  };
32
- data: import("../../hooks/use-graph/use-graph").CartesianDatasetDefaulted | import("../../hooks/use-graph/use-graph").SegmentDatasetDefaulted;
32
+ data: import("../../hooks/use-graph/use-graph").InternalSegmentDataset | import("../../hooks/use-graph/use-graph").InternalCartesianDataset;
33
33
  zoom: {
34
34
  x: [number, number];
35
35
  y: [number, number];
@@ -49,7 +49,7 @@ export declare const GradientLegend: {
49
49
  hovered: string[];
50
50
  pinned: string[];
51
51
  };
52
- datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
52
+ datasets: Record<string, Pick<InternalGraphContext, "domain" | "colors" | "data">>;
53
53
  };
54
54
  };
55
55
  export {};
@@ -21,6 +21,8 @@ export const GradientLegend = (_a) => {
21
21
  return { label: tick, left: scale(i, ticks.length - 1, 100) + "%" };
22
22
  return { label: tick.tick, left: tick.percent + "%" };
23
23
  });
24
+ // linear-gradient(to right, red 1590, blue 120000);
25
+ // gradient`linear-gradient(to right, red 1590, blue ${new Date()})`
24
26
  return (React.createElement("div", Object.assign({}, rest, { className: cx("gradient-legend w-[100%] px-[20px]", alignment === "center" && "mx-auto", alignment === "start" && "mr-auto", alignment === "end" && "ml-auto", rest.className), style: Object.assign({ gridColumn: column }, rest.style) }),
25
27
  React.createElement("div", { className: "relative mb-[40px]" },
26
28
  React.createElement("div", { className: "text-xs text-gray-500" }, "Value \u2192"),
@@ -31,7 +31,7 @@ const GraphComponent = ({ data = [], gap, children, interactions, datasets = {},
31
31
  data: data,
32
32
  gap: { top: (_c = gap === null || gap === void 0 ? void 0 : gap.top) !== null && _c !== void 0 ? _c : 0, left: (_d = gap === null || gap === void 0 ? void 0 : gap.left) !== null && _d !== void 0 ? _d : 0, right: (_e = gap === null || gap === void 0 ? void 0 : gap.right) !== null && _e !== void 0 ? _e : 0, bottom: (_f = gap === null || gap === void 0 ? void 0 : gap.bottom) !== null && _f !== void 0 ? _f : 0 },
33
33
  attributes: {
34
- className: "@container/graph [container-type:size_!important] nanoplot relative grid h-full w-full isolate",
34
+ className: "@container/graph relative grid h-full w-full isolate",
35
35
  },
36
36
  domain: {
37
37
  x: [],
@@ -84,20 +84,14 @@ const GraphComponent = ({ data = [], gap, children, interactions, datasets = {},
84
84
  y: yDomainZoomed,
85
85
  }, data: GraphUtils.isXYData(dataset.data)
86
86
  ? dataset.data.map((dp, i) => {
87
- var _a, _b, _c;
88
- /* if there's a fill and no stroke, use fill as the stroke, otherwise use stroke color, or default color */
89
- return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke
90
- ? dp.fill
91
- : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dataset.colors[i]) !== null && _c !== void 0 ? _c : dataset.colors.at(-1)) }, dp);
87
+ var _a, _b, _c, _d, _e, _f, _g;
88
+ return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: (_d = (_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dp.fill) !== null && _c !== void 0 ? _c : dataset.colors[i]) !== null && _d !== void 0 ? _d : dataset.colors.at(-1), fill: (_g = (_f = (_e = dp.fill) !== null && _e !== void 0 ? _e : dp.stroke) !== null && _f !== void 0 ? _f : dataset.colors[i]) !== null && _g !== void 0 ? _g : dataset.colors.at(-1) }, dp);
92
89
  })
93
90
  : dataset.data
94
91
  .toSorted((a, b) => Number(b.value) - Number(a.value))
95
92
  .map((dp, i) => {
96
- var _a, _b, _c;
97
- /* if there's a fill and no stroke, use fill as the stroke, otherwise use stroke color, or default color */
98
- return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: typeof dp.fill === "string" && !dp.stroke
99
- ? dp.fill
100
- : ((_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dataset.colors[i]) !== null && _c !== void 0 ? _c : dataset.colors.at(-1)) }, dp);
93
+ var _a, _b, _c, _d, _e, _f, _g;
94
+ return Object.assign({ id: (_a = dp.id) !== null && _a !== void 0 ? _a : dp.name, stroke: (_d = (_c = (_b = dp.stroke) !== null && _b !== void 0 ? _b : dp.fill) !== null && _c !== void 0 ? _c : dataset.colors[i]) !== null && _d !== void 0 ? _d : dataset.colors.at(-1), fill: (_g = (_f = (_e = dp.fill) !== null && _e !== void 0 ? _e : dp.stroke) !== null && _f !== void 0 ? _f : dataset.colors[i]) !== null && _g !== void 0 ? _g : dataset.colors.at(-1) }, dp);
101
95
  }), datasets: Object.fromEntries(Object.entries("datasets" in dataset ? dataset["datasets"] : {}).map(([datasetId, dctx]) => {
102
96
  return [datasetId, setDefaults(dctx /* Will return to this after zoom */)];
103
97
  })) });
@@ -1,18 +1,18 @@
1
1
  import React, { JSX, ReactNode } from "react";
2
- import { CartesianDatasetDefaulted, GraphContext, SegmentDatasetDefaulted } from "../../hooks/use-graph/use-graph";
2
+ import { InternalCartesianDataset, InternalGraphContext, InternalSegmentDataset } from "../../hooks/use-graph/use-graph";
3
3
  type Props = Omit<JSX.IntrinsicElements["div"], "onClick" | "onMouseEnter" | "onMouseLeave"> & {
4
4
  position?: "top" | "bottom" | "left" | "right";
5
5
  alignment?: "center" | "start" | "end";
6
- onClick?: (datapoint: CartesianDatasetDefaulted[number] | SegmentDatasetDefaulted[number]) => void;
7
- onMouseEnter?: (datapoint: CartesianDatasetDefaulted[number] | SegmentDatasetDefaulted[number]) => void;
8
- onMouseLeave?: (datapoint: CartesianDatasetDefaulted[number] | SegmentDatasetDefaulted[number]) => void;
9
- onMouseMove?: (datapoint: CartesianDatasetDefaulted[number] | SegmentDatasetDefaulted[number]) => void;
6
+ onClick?: (datapoint: InternalCartesianDataset[number] | InternalSegmentDataset[number]) => void;
7
+ onMouseEnter?: (datapoint: InternalCartesianDataset[number] | InternalSegmentDataset[number]) => void;
8
+ onMouseLeave?: (datapoint: InternalCartesianDataset[number] | InternalSegmentDataset[number]) => void;
9
+ onMouseMove?: (datapoint: InternalCartesianDataset[number] | InternalSegmentDataset[number]) => void;
10
10
  children?: ReactNode;
11
11
  datasets?: string[];
12
12
  };
13
13
  export declare const Legend: {
14
14
  ({ position, alignment, onClick, onMouseEnter, onMouseMove, onMouseLeave, datasets, ...rest }: Props): JSX.Element;
15
- context(ctx: GraphContext, { position }: Props): {
15
+ context(ctx: InternalGraphContext, { position }: Props): {
16
16
  layout: {
17
17
  rows: string;
18
18
  columns: string;
@@ -29,7 +29,7 @@ export declare const Legend: {
29
29
  x: number;
30
30
  y: number;
31
31
  };
32
- data: CartesianDatasetDefaulted | SegmentDatasetDefaulted;
32
+ data: InternalSegmentDataset | InternalCartesianDataset;
33
33
  zoom: {
34
34
  x: [number, number];
35
35
  y: [number, number];
@@ -49,7 +49,7 @@ export declare const Legend: {
49
49
  hovered: string[];
50
50
  pinned: string[];
51
51
  };
52
- datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
52
+ datasets: Record<string, Pick<InternalGraphContext, "domain" | "colors" | "data">>;
53
53
  };
54
54
  };
55
55
  export {};
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  import { CurveUtils } from "../../utils/path/curve";
4
4
  interface Props extends React.SVGAttributes<SVGSVGElement> {
5
5
  children?: ReactNode;
@@ -9,7 +9,7 @@ interface Props extends React.SVGAttributes<SVGSVGElement> {
9
9
  };
10
10
  loading?: boolean;
11
11
  datasets?: string[];
12
- context?: GraphContext;
12
+ context?: InternalGraphContext;
13
13
  }
14
14
  export declare const Lines: {
15
15
  (props: Props): React.JSX.Element | null;
@@ -43,7 +43,7 @@ export declare const Lines: {
43
43
  };
44
44
  border?: string;
45
45
  strokeWidth?: number;
46
- context: GraphContext;
46
+ context: InternalGraphContext;
47
47
  }) => (React.JSX.Element | null)[] | null;
48
48
  Reference: ({ x, y, ...rest }: React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement> & {
49
49
  x: number | string | Date;
@@ -47,7 +47,7 @@ export const Lines = (props) => {
47
47
  const isChunkingCandidate = !stroke.includes("linear-gradient") && points.length > 5000 && curve === "linear";
48
48
  const path = isChunkingCandidate ? "" : CurveUtils[curve](points);
49
49
  const disabled = pinned.length && !pinned.includes(id) && !hovered.includes(id);
50
- const isInteractiveFill = hovered.includes(id) || (pinned.includes(id) && !disabled) || fill;
50
+ const isInteractiveFill = hovered.includes(id) || (pinned.includes(id) && !disabled);
51
51
  const identifier = id.replace(/[^a-zA-Z0-9]/g, "");
52
52
  return (React.createElement(React.Fragment, { key: i },
53
53
  isInteractiveFill && !disabled && (React.createElement("linearGradient", { id: identifier, x1: "0", y1: "0", x2: "0", y2: "1" },
@@ -59,7 +59,7 @@ export const Lines = (props) => {
59
59
  })) : (React.createElement(React.Fragment, null,
60
60
  React.createElement(Line, { d: path, stroke: stroke, fill: "transparent", className: cx("lines__stroke", disabled && "stroke-black dark:stroke-white [stroke-opacity:0.1]") }),
61
61
  isInteractiveFill && points[0] && (React.createElement(Line, { d: path +
62
- `L ${(_b = (_a = points.at(-1)) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 0} ${viewbox.y} L 0 ${viewbox.y} L ${points[0].x} ${viewbox.y} Z`, stroke: "transparent", fill: fill || `linear-gradient(to bottom, ${toRgb(stroke, 0.5)}, ${toRgb(stroke, 0)})`, strokeOpacity: 0, className: "lines__fill" })))),
62
+ `L ${(_b = (_a = points.at(-1)) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 0} ${viewbox.y} L 0 ${viewbox.y} L ${points[0].x} ${viewbox.y} Z`, stroke: "transparent", fill: `linear-gradient(to bottom, ${toRgb(stroke, 0.5)}, ${toRgb(stroke, 0)})`, strokeOpacity: 0, className: "lines__fill" })))),
63
63
  joints && (React.createElement(Lines.Joints, { context: context, border: typeof joints === "object" ? joints["border"] : undefined }))));
64
64
  }),
65
65
  children)));
@@ -1,4 +1,4 @@
1
- import { GraphContext } from "../../../hooks/use-graph/use-graph";
1
+ import { InternalGraphContext } from "../../../hooks/use-graph/use-graph";
2
2
  import * as React from "react";
3
3
  type Props = {
4
4
  at?: {
@@ -6,7 +6,7 @@ type Props = {
6
6
  };
7
7
  border?: string;
8
8
  strokeWidth?: number;
9
- context: GraphContext;
9
+ context: InternalGraphContext;
10
10
  };
11
11
  export declare const LinesJoints: ({ context, border, at, strokeWidth }: Props) => (React.JSX.Element | null)[] | null;
12
12
  export {};
@@ -3,11 +3,13 @@ import { GraphUtils } from "../../../utils/graph/graph";
3
3
  import { GradientUtils } from "../../../utils/gradient/gradient";
4
4
  import { equals } from "../../../utils/equals/equals";
5
5
  import { CoordinatesUtils } from "../../../utils/coordinates/coordinates";
6
+ import { cx } from "../../../utils/cx/cx";
6
7
  export const LinesJoints = ({ context, border, at, strokeWidth = 8 }) => {
8
+ const { interactions: { pinned, hovered }, } = context;
7
9
  if (!GraphUtils.isXYData(context.data))
8
10
  return null;
9
11
  const xyForPoints = CoordinatesUtils.xyCoordinatesForDataset(context);
10
- return context.data.flatMap(({ data, stroke }, i) => {
12
+ return context.data.flatMap(({ data, stroke, id }, i) => {
11
13
  const points = xyForPoints(data);
12
14
  const isLinearGradient = stroke === null || stroke === void 0 ? void 0 : stroke.includes("linear-gradient");
13
15
  if (isLinearGradient && stroke) {
@@ -33,8 +35,9 @@ export const LinesJoints = ({ context, border, at, strokeWidth = 8 }) => {
33
35
  continue; /* Skip if at.x is set and data[i].x !== at.x */
34
36
  path += `M ${points[i].x} ${points[i].y} h 0.001 `; /* += for perf; see V8 and other engine string types. */
35
37
  }
38
+ const disabled = pinned.length && !pinned.includes(id) && !hovered.includes(id);
36
39
  return (React.createElement(React.Fragment, { key: i },
37
- border && (React.createElement("path", { stroke: border, fill: border, d: path, strokeWidth: strokeWidth + 1, strokeLinecap: "round", vectorEffect: "non-scaling-stroke" })),
38
- React.createElement("path", { stroke: stroke, fill: stroke, d: path, strokeWidth: strokeWidth, strokeLinecap: "round", vectorEffect: "non-scaling-stroke" })));
40
+ border && (React.createElement("path", { stroke: border, fill: border, d: path, strokeWidth: strokeWidth + 1, strokeLinecap: "round", vectorEffect: "non-scaling-stroke", className: cx(disabled && "stroke-black dark:stroke-white [stroke-opacity:0.1]") })),
41
+ React.createElement("path", { stroke: stroke, fill: stroke, d: path, strokeWidth: strokeWidth, strokeLinecap: "round", vectorEffect: "non-scaling-stroke", className: cx(disabled && "stroke-black dark:stroke-white [stroke-opacity:0.1]") })));
39
42
  });
40
43
  };
@@ -1,23 +1,27 @@
1
1
  import React, { ReactNode } from "react";
2
- import { GraphContext, SegmentDatasetDefaulted } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext, InternalSegmentDataset } from "../../hooks/use-graph/use-graph";
3
3
  type Props = {
4
4
  loading?: boolean;
5
5
  donut?: boolean | number;
6
6
  radius?: number;
7
7
  labels?: boolean | {
8
8
  position: "outside" | "center";
9
- display: (value: SegmentDatasetDefaulted[number]) => ReactNode;
9
+ display: (value: InternalSegmentDataset[number]) => ReactNode;
10
10
  };
11
11
  glow?: boolean;
12
12
  total?: number;
13
13
  className?: string;
14
+ onMouseEnter?: (segment: InternalSegmentDataset[number] & {
15
+ degrees: number;
16
+ }, event: React.MouseEvent<SVGPathElement>) => void;
17
+ onMouseLeave?: (event: React.MouseEvent<SVGPathElement>) => void;
14
18
  children?: ReactNode;
15
19
  };
16
20
  export declare const Pie: {
17
- ({ glow, donut, labels, radius, total, loading, className, children }: Props): React.JSX.Element | null;
21
+ ({ glow, donut, labels, radius, total, loading, className, onMouseEnter, onMouseLeave, children }: Props): React.JSX.Element | null;
18
22
  Tooltip: React.ComponentType<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "children"> & {
19
- children: (segment: SegmentDatasetDefaulted[number]) => ReactNode;
23
+ children: (segment: InternalSegmentDataset[number]) => ReactNode;
20
24
  }>;
21
- context(ctx: GraphContext, props: Props): GraphContext;
25
+ context(ctx: InternalGraphContext, props: Props): InternalGraphContext;
22
26
  };
23
27
  export {};
@@ -9,7 +9,7 @@ import { cx } from "../../utils/cx/cx";
9
9
  import { overlay } from "../Overlay/Overlay";
10
10
  import { ColorUtils } from "../../utils/color/color";
11
11
  import { PieTooltip } from "./components/PieTooltip";
12
- export const Pie = ({ glow, donut, labels, radius, total, loading, className, children }) => {
12
+ export const Pie = ({ glow, donut, labels, radius, total, loading, className, onMouseEnter, onMouseLeave, children }) => {
13
13
  const glowId = useId();
14
14
  const maskId = useId();
15
15
  const { data, viewbox, colors } = useGraph();
@@ -37,7 +37,7 @@ export const Pie = ({ glow, donut, labels, radius, total, loading, className, ch
37
37
  return React.createElement(PieEmpty, { donut: Boolean(donut), center: DONUT_RADIUS, className: className });
38
38
  }
39
39
  return (React.createElement(React.Fragment, null,
40
- donut && React.createElement(overlay.div, { className: "pie__children absolute inset-0 flex items-center justify-center" }, children),
40
+ donut && children && (React.createElement(overlay.div, { className: "pie__children absolute inset-0 flex items-center justify-center" }, children)),
41
41
  total !== undefined && (React.createElement("svg", { viewBox: `0 0 ${viewbox.x} ${viewbox.y}`, className: cx("pie__track h-full w-full [grid-area:graph]", className) },
42
42
  donut && (React.createElement("mask", { id: maskId },
43
43
  React.createElement("rect", { width: "80%", height: "80%", fill: "white" }),
@@ -92,13 +92,13 @@ export const Pie = ({ glow, donut, labels, radius, total, loading, className, ch
92
92
  })();
93
93
  return (React.createElement(React.Fragment, { key: i },
94
94
  isLabelsCentered && (React.createElement(overlay.div, { x: { coordinate: center.x }, y: { coordinate: center.y }, className: "z-[2] [transform:translate(-50%,-50%)]" }, label)),
95
- React.createElement("svg", { viewBox: `0 0 ${viewbox.x} ${viewbox.y}`, role: "img", className: cx("pie__segment-group group absolute overflow-visible transition-all duration-200 ease-in-out [grid-area:graph] pointer-events-none h-auto w-full brightness-100 has-[path:hover]:z-[1] has-[path:hover]:[&_.label-path]:stroke-current has-[path:hover]:brightness-110", isLabelsCentered && "aspect-square", className), preserveAspectRatio: isLabelsCentered ? "none" : undefined },
95
+ React.createElement("svg", { viewBox: `0 0 ${viewbox.x} ${viewbox.y}`, role: "img", className: cx("pie__segment-group group absolute overflow-visible transition-all duration-200 ease-in-out [grid-area:graph] pointer-events-none h-full w-full brightness-100 has-[path:hover]:z-[1] has-[path:hover]:[&_.label-path]:stroke-current has-[path:hover]:brightness-110", isLabelsCentered && "aspect-square h-auto", className), preserveAspectRatio: isLabelsCentered ? "none" : undefined },
96
96
  glow && React.createElement("use", { xlinkHref: `#${glowId + segment.id}`, filter: "blur(150px)", opacity: 0.5, scale: 0.9 }),
97
97
  React.createElement("g", { className: "transform origin-center", id: glowId + segment.id, mask: donut ? `url(#${maskId})` : undefined },
98
- React.createElement("path", { "data-pie-id": segment.id /* used for client component tooltip to hook into */, className: cx(`pie__segment transition-all duration-200 ease-in-out [scale:1] origin-center pointer-events-auto`, !donut && `group-hover:[filter:drop-shadow(0_0_50px_rgba(0,0,0,0.5))] hover:[scale:1.02]`), d: PathUtils.describeArc(CX, CX, PIE_RADIUS, segment.previousTotalDegrees + ROTATION_DEGREES, segment.previousTotalDegrees + ROTATION_DEGREES + segment.degrees) + ` L ${CX} ${CX} Z`, fill: String(segment.fill), "data-degrees": segment.degrees })),
98
+ React.createElement("path", { "data-pie-id": segment.id /* used for client component tooltip to hook into */, className: cx(`pie__segment transition-all duration-200 ease-in-out [scale:1] origin-center pointer-events-auto`, !donut && `group-hover:[filter:drop-shadow(0_0_50px_rgba(0,0,0,0.5))] hover:[scale:1.02]`), d: PathUtils.describeArc(CX, CX, PIE_RADIUS, segment.previousTotalDegrees + ROTATION_DEGREES, segment.previousTotalDegrees + ROTATION_DEGREES + segment.degrees) + ` L ${CX} ${CX} Z`, fill: segment.fill, "data-degrees": segment.degrees, onMouseEnter: onMouseEnter ? (event) => onMouseEnter(segment, event) : undefined, onMouseLeave: onMouseLeave })),
99
99
  isLabelsOutside && (React.createElement("g", { className: "invisible @[width:400px]:!visible" },
100
100
  React.createElement(React.Fragment, null,
101
- React.createElement("path", { className: "pie__label-connector stroke-[5] fill-transparent group-hover:stroke-[15]", key: segment.name, d: `M ${startLabelLine.x} ${startLabelLine.y} L ${endLabelLine.x} ${endLabelLine.y} ${isRightAligned ? "l 100 0" : "l -100 0"}`, stroke: String(segment.fill) }),
101
+ React.createElement("path", { className: "pie__label-connector stroke-[5] fill-transparent group-hover:stroke-[15]", key: segment.name, d: `M ${startLabelLine.x} ${startLabelLine.y} L ${endLabelLine.x} ${endLabelLine.y} ${isRightAligned ? "l 100 0" : "l -100 0"}`, stroke: segment.fill }),
102
102
  React.createElement("g", { className: "pie__label text-7xl font-bold pointer-events-auto" },
103
103
  React.createElement("text", { "aria-label": `${segment.name}-label`, y: endLabelLine.y, x: endLabelLine.x, stroke: segment.stroke, fill: String(segment.fill), dx: isRightAligned ? 140 : -140, className: cx("[--hundred-cqh:100cqh] [font-size:calc((13.5px_/_tan(atan2(var(--hundred-cqh),_1px)))*_3000)]", isRightAligned ? "[text-anchor:start]" : "[text-anchor:end]") }, label))))),
104
104
  donut && (React.createElement("mask", { id: maskId },
@@ -109,7 +109,8 @@ export const Pie = ({ glow, donut, labels, radius, total, loading, className, ch
109
109
  Pie.Tooltip = PieTooltip;
110
110
  Pie.context = (ctx, props) => {
111
111
  const isLabelsCentered = props.labels && typeof props.labels === "object" && props.labels.position === "center";
112
+ const isLabelsOutside = props.labels === true || (typeof props.labels === "object" && props.labels.position === "outside");
112
113
  return Object.assign(Object.assign({}, ctx), { attributes: {
113
- className: isLabelsCentered ? cx(ctx.attributes.className, "aspect-square w-full h-auto") : ctx.attributes.className,
114
+ className: cx(ctx.attributes.className, isLabelsCentered && "aspect-square w-full h-auto", isLabelsOutside && "[container-type:size_!important]"),
114
115
  }, colors: ColorUtils.scheme.contrast });
115
116
  };
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  import { ComponentProps, ReactNode } from "react";
3
- import { SegmentDatasetDefaulted } from "../../../hooks/use-graph/use-graph";
3
+ import { InternalSegmentDataset } from "../../../hooks/use-graph/use-graph";
4
4
  type Props = Omit<ComponentProps<"div">, "children"> & {
5
- children: (segment: SegmentDatasetDefaulted[number]) => ReactNode;
5
+ children: (segment: InternalSegmentDataset[number]) => ReactNode;
6
6
  };
7
7
  export declare const PieTooltip: React.ComponentType<Props>;
8
8
  export {};
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  type Props = {
4
4
  translate?: {
5
5
  x: number;
@@ -15,7 +15,7 @@ export declare const Worldmap: {
15
15
  Tooltip: React.ComponentType<{
16
16
  tooltip: (datapoint: import("../../export").SegmentDataset[number]) => ReactNode;
17
17
  }>;
18
- context(ctx: GraphContext): {
18
+ context(ctx: InternalGraphContext): {
19
19
  attributes: {
20
20
  className: string;
21
21
  defaultChecked?: boolean | undefined;
@@ -307,7 +307,7 @@ export declare const Worldmap: {
307
307
  x: number;
308
308
  y: number;
309
309
  };
310
- data: import("../../hooks/use-graph/use-graph").CartesianDatasetDefaulted | import("../../hooks/use-graph/use-graph").SegmentDatasetDefaulted;
310
+ data: import("../../hooks/use-graph/use-graph").InternalSegmentDataset | import("../../hooks/use-graph/use-graph").InternalCartesianDataset;
311
311
  layout: {
312
312
  rows: string;
313
313
  columns: string;
@@ -331,7 +331,7 @@ export declare const Worldmap: {
331
331
  hovered: string[];
332
332
  pinned: string[];
333
333
  };
334
- datasets: Record<string, Pick<GraphContext, "domain" | "colors" | "data">>;
334
+ datasets: Record<string, Pick<InternalGraphContext, "domain" | "colors" | "data">>;
335
335
  };
336
336
  };
337
337
  export {};
@@ -1,5 +1,5 @@
1
1
  import React, { ComponentProps, ReactNode } from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  import { FromToJumps } from "../../models/domain/domain";
4
4
  type Props = Omit<ComponentProps<"div">, "title"> & {
5
5
  ticks?: FromToJumps;
@@ -10,6 +10,6 @@ type Props = Omit<ComponentProps<"div">, "title"> & {
10
10
  };
11
11
  export declare const XAxis: {
12
12
  ({ display, title, ticks, description, dataset, ...rest }: Props): React.JSX.Element;
13
- context(ctx: GraphContext, props: Props): GraphContext;
13
+ context(ctx: InternalGraphContext, props: Props): InternalGraphContext;
14
14
  };
15
15
  export {};
@@ -1,5 +1,5 @@
1
1
  import React, { ComponentProps, ReactNode } from "react";
2
- import { GraphContext } from "../../hooks/use-graph/use-graph";
2
+ import { InternalGraphContext } from "../../hooks/use-graph/use-graph";
3
3
  import { FromToJumps } from "../../models/domain/domain";
4
4
  type Props = Omit<ComponentProps<"div">, "title"> & {
5
5
  ticks?: FromToJumps;
@@ -11,6 +11,6 @@ type Props = Omit<ComponentProps<"div">, "title"> & {
11
11
  };
12
12
  export declare const YAxis: {
13
13
  ({ title, description, display, dataset, position, ...rest }: Props): React.JSX.Element;
14
- context(ctx: GraphContext, props: Props): GraphContext;
14
+ context(ctx: InternalGraphContext, props: Props): InternalGraphContext;
15
15
  };
16
16
  export {};
@@ -9,7 +9,7 @@ export declare const ZoomSlider: {
9
9
  minimum?: number;
10
10
  };
11
11
  }): import("react").JSX.Element;
12
- context(ctx: import("../../export").GraphContext, props: {
12
+ context(ctx: import("../../export").InternalGraphContext, props: {
13
13
  onChange: (zoom: {
14
14
  x: [number, number];
15
15
  y: [number, number];
@@ -17,7 +17,7 @@ export declare const ZoomSlider: {
17
17
  distance?: {
18
18
  minimum?: number;
19
19
  };
20
- }): import("../../export").GraphContext;
20
+ }): import("../../export").InternalGraphContext;
21
21
  };
22
22
  Y: {
23
23
  ({ onChange, distance }: {
@@ -29,7 +29,7 @@ export declare const ZoomSlider: {
29
29
  minimum?: number;
30
30
  };
31
31
  }): import("react").JSX.Element;
32
- context(ctx: import("../../export").GraphContext, props: {
32
+ context(ctx: import("../../export").InternalGraphContext, props: {
33
33
  onChange: (zoom: {
34
34
  x: [number, number];
35
35
  y: [number, number];
@@ -37,6 +37,6 @@ export declare const ZoomSlider: {
37
37
  distance?: {
38
38
  minimum?: number;
39
39
  };
40
- }): import("../../export").GraphContext;
40
+ }): import("../../export").InternalGraphContext;
41
41
  };
42
42
  };