@exegia/corpora-ui 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist-lib/components/composed/chat/chart/chart-atom.d.ts +30 -0
  2. package/dist-lib/components/composed/chat/chart/chart-context.d.ts +2 -0
  3. package/dist-lib/components/composed/chat/chart/chart-legend.d.ts +4 -0
  4. package/dist-lib/components/composed/chat/chart/chart-plot.d.ts +3 -0
  5. package/dist-lib/components/composed/chat/chart/chart-root.d.ts +3 -0
  6. package/dist-lib/components/composed/chat/chart/chart-tooltip.d.ts +4 -0
  7. package/dist-lib/components/composed/chat/chart/constants.d.ts +3 -0
  8. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-area-chart.d.ts +93 -0
  9. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-bar-chart.d.ts +86 -0
  10. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-brush.d.ts +65 -0
  11. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-chart.d.ts +44 -0
  12. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-dot.d.ts +16 -0
  13. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-legend.d.ts +24 -0
  14. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-line-chart.d.ts +90 -0
  15. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-pie-chart.d.ts +73 -0
  16. package/dist-lib/components/composed/chat/chart/evilcharts/echarts-tooltip.d.ts +29 -0
  17. package/dist-lib/components/composed/chat/chart/index.d.ts +6 -0
  18. package/dist-lib/components/composed/chat/chart/type.d.ts +80 -0
  19. package/dist-lib/components/composed/chat/chart/use-chart-state.d.ts +3 -0
  20. package/dist-lib/components/composed/chat/chart/use-chart.d.ts +6 -0
  21. package/dist-lib/components/composed/chat/chart/utils.d.ts +5 -0
  22. package/dist-lib/components/composed/chat/chart.d.ts +1 -44
  23. package/dist-lib/components/composed/chat/index.d.ts +1 -1
  24. package/dist-lib/components/stories/chart.story.d.ts +39 -2
  25. package/dist-lib/components/stories/insight-cards.story.d.ts +30 -1
  26. package/dist-lib/index.js +10020 -5549
  27. package/dist-lib/index.js.map +1 -1
  28. package/package.json +2 -1
  29. package/src/components/composed/chat/__tests__/chart.test.tsx +255 -1
  30. package/src/components/composed/chat/chart/chart-atom.ts +55 -0
  31. package/src/components/composed/chat/chart/chart-context.ts +9 -0
  32. package/src/components/composed/chat/chart/chart-legend.tsx +75 -0
  33. package/src/components/composed/chat/chart/chart-plot.tsx +233 -0
  34. package/src/components/composed/chat/chart/chart-root.tsx +229 -0
  35. package/src/components/composed/chat/chart/chart-tooltip.tsx +74 -0
  36. package/src/components/composed/chat/chart/constants.ts +8 -0
  37. package/src/components/composed/chat/chart/evilcharts/LICENSE +21 -0
  38. package/src/components/composed/chat/chart/evilcharts/README.md +8 -0
  39. package/src/components/composed/chat/chart/evilcharts/echarts-area-chart.tsx +2358 -0
  40. package/src/components/composed/chat/chart/evilcharts/echarts-bar-chart.tsx +2261 -0
  41. package/src/components/composed/chat/chart/evilcharts/echarts-brush.tsx +233 -0
  42. package/src/components/composed/chat/chart/evilcharts/echarts-chart.tsx +214 -0
  43. package/src/components/composed/chat/chart/evilcharts/echarts-dot.tsx +111 -0
  44. package/src/components/composed/chat/chart/evilcharts/echarts-legend.tsx +131 -0
  45. package/src/components/composed/chat/chart/evilcharts/echarts-line-chart.tsx +2112 -0
  46. package/src/components/composed/chat/chart/evilcharts/echarts-pie-chart.tsx +1235 -0
  47. package/src/components/composed/chat/chart/evilcharts/echarts-tooltip.tsx +125 -0
  48. package/src/components/composed/chat/chart/index.ts +13 -0
  49. package/src/components/composed/chat/chart/type.ts +88 -0
  50. package/src/components/composed/chat/chart/use-chart-state.ts +22 -0
  51. package/src/components/composed/chat/chart/use-chart.ts +70 -0
  52. package/src/components/composed/chat/chart/utils.ts +47 -0
  53. package/src/components/composed/chat/chart.tsx +2 -400
  54. package/src/components/composed/chat/index.ts +1 -7
  55. package/src/components/stories/chart.story.tsx +16 -1
@@ -0,0 +1,131 @@
1
+ "use client";
2
+
3
+ import { getColorsCount, indicatorBackground, type ChartConfig } from "./echarts-chart";
4
+ import type { CSSProperties } from "react";
5
+
6
+ // ─────────────────────────────────────────────────────────────────────────────
7
+ // Legend overlay (React) — replicates ChartLegendContent + its 7 indicators.
8
+ // The legend is HTML inside `[data-chart={id}]`, so it uses the injected
9
+ // `--color-*` vars directly. Shared by every ECharts chart.
10
+ // ─────────────────────────────────────────────────────────────────────────────
11
+
12
+ export type LegendVariant =
13
+ | "square"
14
+ | "circle"
15
+ | "circle-outline"
16
+ | "rounded-square"
17
+ | "rounded-square-outline"
18
+ | "vertical-bar"
19
+ | "horizontal-bar";
20
+
21
+ export function legendFillStyle(key: string, colorsCount: number): CSSProperties {
22
+ if (colorsCount <= 1) return { backgroundColor: `var(--color-${key}-0)` };
23
+ return { background: indicatorBackground(key, colorsCount) };
24
+ }
25
+
26
+ // Punches out the centre with a mask-composite so only the "border" shows —
27
+ // works with gradients and border-radius, unlike plain border-color.
28
+ export function legendOutlineStyle(key: string, colorsCount: number): CSSProperties {
29
+ const mask: CSSProperties = {
30
+ WebkitMask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
31
+ WebkitMaskComposite: "xor",
32
+ mask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
33
+ maskComposite: "exclude",
34
+ };
35
+ return { ...legendFillStyle(key, colorsCount), ...mask };
36
+ }
37
+
38
+ export function LegendIndicator({
39
+ variant,
40
+ dataKey,
41
+ colorsCount,
42
+ }: {
43
+ variant: LegendVariant;
44
+ dataKey: string;
45
+ colorsCount: number;
46
+ }) {
47
+ const fill = legendFillStyle(dataKey, colorsCount);
48
+ const outline = legendOutlineStyle(dataKey, colorsCount);
49
+
50
+ switch (variant) {
51
+ case "square":
52
+ return <div className="h-2 w-2 shrink-0" style={fill} />;
53
+ case "circle":
54
+ return <div className="h-2 w-2 shrink-0 rounded-full" style={fill} />;
55
+ case "circle-outline":
56
+ return <div className="h-2.5 w-2.5 shrink-0 rounded-full p-[1.5px]" style={outline} />;
57
+ case "vertical-bar":
58
+ return <div className="h-3 w-1 shrink-0 rounded-[2px]" style={fill} />;
59
+ case "horizontal-bar":
60
+ return <div className="h-1 w-3 shrink-0 rounded-[2px]" style={fill} />;
61
+ case "rounded-square-outline":
62
+ return <div className="h-2.5 w-2.5 shrink-0 rounded-[3px] p-[1.5px]" style={outline} />;
63
+ case "rounded-square":
64
+ default:
65
+ return <div className="h-2 w-2 shrink-0 rounded-[2px]" style={fill} />;
66
+ }
67
+ }
68
+
69
+ // ─────────────────────────────────────────────────────────────────────────────
70
+ // LegendOverlay — the positioned HTML legend row. The chart computes the
71
+ // absolute-positioned `style` (it owns the brush/verticalAlign layout math) and
72
+ // passes it in; this renders the entries, their indicators, and the
73
+ // selection/hover dim. `verticalAlign` is carried on the props for parity with
74
+ // the chart's LegendSlot even though positioning arrives fully via `style`.
75
+ // ─────────────────────────────────────────────────────────────────────────────
76
+
77
+ type LegendOverlayProps = {
78
+ seriesKeys: string[];
79
+ config: ChartConfig;
80
+ variant: LegendVariant;
81
+ align: "left" | "center" | "right";
82
+ verticalAlign: "top" | "middle" | "bottom";
83
+ selectedKey: string | null;
84
+ hoveredKey: string | null;
85
+ isClickable: boolean;
86
+ onToggle: (key: string) => void;
87
+ style: CSSProperties;
88
+ };
89
+
90
+ export function LegendOverlay({
91
+ seriesKeys,
92
+ config,
93
+ variant,
94
+ align,
95
+ selectedKey,
96
+ hoveredKey,
97
+ isClickable,
98
+ onToggle,
99
+ style,
100
+ }: LegendOverlayProps) {
101
+ const legendJustify =
102
+ align === "left" ? "justify-start" : align === "center" ? "justify-center" : "justify-end";
103
+
104
+ return (
105
+ <div style={style} className={`flex items-center gap-4 select-none ${legendJustify}`}>
106
+ {seriesKeys.map((key) => {
107
+ const item = config[key];
108
+ const colorsCount = item ? getColorsCount(item) : 1;
109
+ const isSelected =
110
+ (selectedKey === null || selectedKey === key) &&
111
+ (hoveredKey === null || hoveredKey === key);
112
+ return (
113
+ // No entrance here — the Recharts legend appears instantly, and a
114
+ // fade-in reads as disconnected from the canvas draw-in.
115
+ <div
116
+ key={key}
117
+ className={`flex items-center gap-1.5 transition-opacity ${
118
+ !isSelected ? "opacity-30" : ""
119
+ } ${isClickable ? "cursor-pointer" : ""}`}
120
+ onClick={() => {
121
+ if (isClickable) onToggle(key);
122
+ }}
123
+ >
124
+ <LegendIndicator variant={variant} dataKey={key} colorsCount={colorsCount} />
125
+ {item?.label}
126
+ </div>
127
+ );
128
+ })}
129
+ </div>
130
+ );
131
+ }