@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.
- package/dist-lib/components/composed/chat/chart/chart-atom.d.ts +30 -0
- package/dist-lib/components/composed/chat/chart/chart-context.d.ts +2 -0
- package/dist-lib/components/composed/chat/chart/chart-legend.d.ts +4 -0
- package/dist-lib/components/composed/chat/chart/chart-plot.d.ts +3 -0
- package/dist-lib/components/composed/chat/chart/chart-root.d.ts +3 -0
- package/dist-lib/components/composed/chat/chart/chart-tooltip.d.ts +4 -0
- package/dist-lib/components/composed/chat/chart/constants.d.ts +3 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-area-chart.d.ts +93 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-bar-chart.d.ts +86 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-brush.d.ts +65 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-chart.d.ts +44 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-dot.d.ts +16 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-legend.d.ts +24 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-line-chart.d.ts +90 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-pie-chart.d.ts +73 -0
- package/dist-lib/components/composed/chat/chart/evilcharts/echarts-tooltip.d.ts +29 -0
- package/dist-lib/components/composed/chat/chart/index.d.ts +6 -0
- package/dist-lib/components/composed/chat/chart/type.d.ts +80 -0
- package/dist-lib/components/composed/chat/chart/use-chart-state.d.ts +3 -0
- package/dist-lib/components/composed/chat/chart/use-chart.d.ts +6 -0
- package/dist-lib/components/composed/chat/chart/utils.d.ts +5 -0
- package/dist-lib/components/composed/chat/chart.d.ts +1 -44
- package/dist-lib/components/composed/chat/index.d.ts +1 -1
- package/dist-lib/components/stories/chart.story.d.ts +39 -2
- package/dist-lib/components/stories/insight-cards.story.d.ts +30 -1
- package/dist-lib/index.js +10020 -5549
- package/dist-lib/index.js.map +1 -1
- package/package.json +2 -1
- package/src/components/composed/chat/__tests__/chart.test.tsx +255 -1
- package/src/components/composed/chat/chart/chart-atom.ts +55 -0
- package/src/components/composed/chat/chart/chart-context.ts +9 -0
- package/src/components/composed/chat/chart/chart-legend.tsx +75 -0
- package/src/components/composed/chat/chart/chart-plot.tsx +233 -0
- package/src/components/composed/chat/chart/chart-root.tsx +229 -0
- package/src/components/composed/chat/chart/chart-tooltip.tsx +74 -0
- package/src/components/composed/chat/chart/constants.ts +8 -0
- package/src/components/composed/chat/chart/evilcharts/LICENSE +21 -0
- package/src/components/composed/chat/chart/evilcharts/README.md +8 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-area-chart.tsx +2358 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-bar-chart.tsx +2261 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-brush.tsx +233 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-chart.tsx +214 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-dot.tsx +111 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-legend.tsx +131 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-line-chart.tsx +2112 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-pie-chart.tsx +1235 -0
- package/src/components/composed/chat/chart/evilcharts/echarts-tooltip.tsx +125 -0
- package/src/components/composed/chat/chart/index.ts +13 -0
- package/src/components/composed/chat/chart/type.ts +88 -0
- package/src/components/composed/chat/chart/use-chart-state.ts +22 -0
- package/src/components/composed/chat/chart/use-chart.ts +70 -0
- package/src/components/composed/chat/chart/utils.ts +47 -0
- package/src/components/composed/chat/chart.tsx +2 -400
- package/src/components/composed/chat/index.ts +1 -7
- package/src/components/stories/chart.story.tsx +16 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import { useRender } from "@base-ui/react/use-render"
|
|
3
|
+
import { useImperativeHandle } from "react"
|
|
4
|
+
import type * as React from "react"
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardFrame,
|
|
9
|
+
CardFrameHeader,
|
|
10
|
+
CardPanel,
|
|
11
|
+
} from "@/components/ui/card"
|
|
12
|
+
import { Pill } from "@/components/ui/chat"
|
|
13
|
+
import { Reference } from "@/components/atoms/reference"
|
|
14
|
+
import { ChartContext } from "./chart-context"
|
|
15
|
+
import { ChartPlot } from "./chart-plot"
|
|
16
|
+
import { ChartLegend } from "./chart-legend"
|
|
17
|
+
import { CHART_DEFAULT_HEIGHT, CHART_TYPE_LABEL } from "./constants"
|
|
18
|
+
import { useChart } from "./use-chart"
|
|
19
|
+
import type { IChartProps } from "./type"
|
|
20
|
+
|
|
21
|
+
export function ChartRoot({
|
|
22
|
+
ref,
|
|
23
|
+
...allProps
|
|
24
|
+
}: IChartProps): React.ReactElement {
|
|
25
|
+
const { id, selectedKey, actions } = useChart(allProps)
|
|
26
|
+
useImperativeHandle(ref, () => actions, [actions])
|
|
27
|
+
return (
|
|
28
|
+
<ChartContext value={id}>
|
|
29
|
+
<ChartCard
|
|
30
|
+
{...allProps}
|
|
31
|
+
selectedKey={selectedKey}
|
|
32
|
+
onSelectionChange={actions.select}
|
|
33
|
+
/>
|
|
34
|
+
</ChartContext>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
function ChartCard({
|
|
38
|
+
type,
|
|
39
|
+
title,
|
|
40
|
+
subtitle,
|
|
41
|
+
badge,
|
|
42
|
+
reference,
|
|
43
|
+
data,
|
|
44
|
+
series,
|
|
45
|
+
center,
|
|
46
|
+
headerless = false,
|
|
47
|
+
plotHeight,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
render,
|
|
51
|
+
style,
|
|
52
|
+
className,
|
|
53
|
+
chartId: _chartId,
|
|
54
|
+
ref: _ref,
|
|
55
|
+
defaultSelectedKey: _defaultSelectedKey,
|
|
56
|
+
variant = "default",
|
|
57
|
+
renderer,
|
|
58
|
+
animation,
|
|
59
|
+
loading = false,
|
|
60
|
+
emptyContent = "No data",
|
|
61
|
+
showLegend = true,
|
|
62
|
+
interactive = false,
|
|
63
|
+
selectedKey,
|
|
64
|
+
onSelectionChange,
|
|
65
|
+
curveType,
|
|
66
|
+
grid,
|
|
67
|
+
xAxis,
|
|
68
|
+
yAxis,
|
|
69
|
+
tooltip,
|
|
70
|
+
brush,
|
|
71
|
+
pie,
|
|
72
|
+
chartOptions,
|
|
73
|
+
children,
|
|
74
|
+
...props
|
|
75
|
+
}: IChartProps): React.ReactElement {
|
|
76
|
+
const fillHeight =
|
|
77
|
+
(height !== undefined || style?.height !== undefined) &&
|
|
78
|
+
plotHeight === undefined
|
|
79
|
+
const plotSize = fillHeight
|
|
80
|
+
? "100%"
|
|
81
|
+
: (plotHeight ?? (type === "pie" ? 140 : CHART_DEFAULT_HEIGHT))
|
|
82
|
+
const rootStyle = { width, height, ...style }
|
|
83
|
+
const empty = data.length === 0 || series.length === 0
|
|
84
|
+
const legend =
|
|
85
|
+
!empty && !loading && showLegend ? (
|
|
86
|
+
<ChartLegend
|
|
87
|
+
type={type}
|
|
88
|
+
data={data}
|
|
89
|
+
series={series}
|
|
90
|
+
selectedKey={selectedKey}
|
|
91
|
+
interactive={interactive}
|
|
92
|
+
onSelect={(key) =>
|
|
93
|
+
onSelectionChange?.(selectedKey === key ? null : key)
|
|
94
|
+
}
|
|
95
|
+
/>
|
|
96
|
+
) : null
|
|
97
|
+
const plot = (
|
|
98
|
+
<>
|
|
99
|
+
<div
|
|
100
|
+
className={cn(
|
|
101
|
+
"min-w-0",
|
|
102
|
+
fillHeight && "min-h-0 flex flex-1 flex-col",
|
|
103
|
+
type === "pie" &&
|
|
104
|
+
"gap-6 flex flex-row flex-wrap items-center justify-center"
|
|
105
|
+
)}
|
|
106
|
+
aria-busy={loading}
|
|
107
|
+
>
|
|
108
|
+
<div
|
|
109
|
+
className={cn(
|
|
110
|
+
"min-w-0 relative",
|
|
111
|
+
type === "pie" ? "shrink-0" : "w-full"
|
|
112
|
+
)}
|
|
113
|
+
style={{
|
|
114
|
+
height: plotSize,
|
|
115
|
+
width:
|
|
116
|
+
type === "pie" ? (fillHeight ? "auto" : plotSize) : undefined,
|
|
117
|
+
maxWidth: "100%",
|
|
118
|
+
aspectRatio: type === "pie" ? "1" : undefined,
|
|
119
|
+
}}
|
|
120
|
+
role="group"
|
|
121
|
+
aria-label={
|
|
122
|
+
typeof title === "string"
|
|
123
|
+
? title
|
|
124
|
+
: `${CHART_TYPE_LABEL[type]} chart`
|
|
125
|
+
}
|
|
126
|
+
>
|
|
127
|
+
{empty && !loading ? (
|
|
128
|
+
<div
|
|
129
|
+
role="status"
|
|
130
|
+
className="text-xs flex h-full items-center justify-center text-text-secondary"
|
|
131
|
+
>
|
|
132
|
+
{emptyContent}
|
|
133
|
+
</div>
|
|
134
|
+
) : (
|
|
135
|
+
<ChartPlot
|
|
136
|
+
type={type}
|
|
137
|
+
data={data}
|
|
138
|
+
series={series}
|
|
139
|
+
variant={variant}
|
|
140
|
+
renderer={renderer}
|
|
141
|
+
animation={animation}
|
|
142
|
+
loading={loading}
|
|
143
|
+
interactive={interactive}
|
|
144
|
+
selectedKey={selectedKey}
|
|
145
|
+
onSelectionChange={onSelectionChange}
|
|
146
|
+
curveType={curveType}
|
|
147
|
+
grid={grid}
|
|
148
|
+
xAxis={xAxis}
|
|
149
|
+
yAxis={yAxis}
|
|
150
|
+
tooltip={tooltip}
|
|
151
|
+
brush={brush}
|
|
152
|
+
pie={pie}
|
|
153
|
+
chartOptions={chartOptions}
|
|
154
|
+
/>
|
|
155
|
+
)}
|
|
156
|
+
{type === "pie" && center && !loading ? (
|
|
157
|
+
<div className="inset-0 pointer-events-none absolute flex flex-col items-center justify-center">
|
|
158
|
+
<span className="font-semibold text-[17px] text-text-primary">
|
|
159
|
+
{center.value}
|
|
160
|
+
</span>
|
|
161
|
+
{center.label && (
|
|
162
|
+
<span className="text-[11px] text-text-secondary">
|
|
163
|
+
{center.label}
|
|
164
|
+
</span>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
) : null}
|
|
168
|
+
</div>
|
|
169
|
+
{type === "pie" && legend}
|
|
170
|
+
</div>
|
|
171
|
+
{type !== "pie" && legend}
|
|
172
|
+
{children}
|
|
173
|
+
</>
|
|
174
|
+
)
|
|
175
|
+
const bareRoot = useRender({
|
|
176
|
+
defaultTagName: "div",
|
|
177
|
+
render: headerless ? render : undefined,
|
|
178
|
+
props: {
|
|
179
|
+
...props,
|
|
180
|
+
"data-slot": "chart",
|
|
181
|
+
"data-type": type,
|
|
182
|
+
className: cn("w-80 gap-2 flex max-w-full flex-col", className),
|
|
183
|
+
style: rootStyle,
|
|
184
|
+
children: plot,
|
|
185
|
+
},
|
|
186
|
+
})
|
|
187
|
+
if (headerless) return bareRoot
|
|
188
|
+
return (
|
|
189
|
+
<CardFrame
|
|
190
|
+
render={render}
|
|
191
|
+
style={rootStyle}
|
|
192
|
+
data-slot="chart"
|
|
193
|
+
data-type={type}
|
|
194
|
+
className={cn(
|
|
195
|
+
"w-80 max-w-full [--frame-radius:var(--radius-md)]",
|
|
196
|
+
className
|
|
197
|
+
)}
|
|
198
|
+
{...props}
|
|
199
|
+
>
|
|
200
|
+
<CardFrameHeader className="gap-x-3 gap-y-2 px-3.5 py-3 flex flex-row flex-wrap items-start justify-between">
|
|
201
|
+
<div className="min-w-0 basis-36 gap-0.5 flex flex-1 flex-col">
|
|
202
|
+
<span className="font-semibold leading-4 text-[13px] text-text-primary">
|
|
203
|
+
{title}
|
|
204
|
+
</span>
|
|
205
|
+
{subtitle ? (
|
|
206
|
+
<span className="leading-3 text-[11px] text-text-secondary">
|
|
207
|
+
{subtitle}
|
|
208
|
+
</span>
|
|
209
|
+
) : null}
|
|
210
|
+
</div>
|
|
211
|
+
{reference ? (
|
|
212
|
+
<Reference
|
|
213
|
+
{...reference}
|
|
214
|
+
className={cn("max-w-full shrink-0", reference.className)}
|
|
215
|
+
/>
|
|
216
|
+
) : (
|
|
217
|
+
<Pill>{badge ?? CHART_TYPE_LABEL[type]}</Pill>
|
|
218
|
+
)}
|
|
219
|
+
</CardFrameHeader>
|
|
220
|
+
<Card className={cn(fillHeight && "min-h-0 flex-1")}>
|
|
221
|
+
<CardPanel
|
|
222
|
+
className={cn("gap-3 p-3.5 flex flex-col", fillHeight && "min-h-0")}
|
|
223
|
+
>
|
|
224
|
+
{plot}
|
|
225
|
+
</CardPanel>
|
|
226
|
+
</Card>
|
|
227
|
+
</CardFrame>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from "react-dom/server"
|
|
2
|
+
import type { TooltipProps } from "./evilcharts/echarts-area-chart"
|
|
3
|
+
import {
|
|
4
|
+
roundnessClass,
|
|
5
|
+
tooltipVariantClass,
|
|
6
|
+
} from "./evilcharts/echarts-tooltip"
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
import { chartSeriesColor, formatChartValue } from "./utils"
|
|
9
|
+
import type { IChartSeries, TChartDatum, TChartType } from "./type"
|
|
10
|
+
/** React escapes labels and formatted nodes before they enter ECharts' HTML tooltip. */
|
|
11
|
+
export function createChartTooltip(
|
|
12
|
+
type: TChartType,
|
|
13
|
+
data: TChartDatum[],
|
|
14
|
+
series: IChartSeries[],
|
|
15
|
+
options: TooltipProps = {}
|
|
16
|
+
) {
|
|
17
|
+
return (params: unknown) => {
|
|
18
|
+
const rows = (Array.isArray(params) ? params : [params]).filter(
|
|
19
|
+
(row): row is Record<string, unknown> =>
|
|
20
|
+
typeof row === "object" && row !== null
|
|
21
|
+
)
|
|
22
|
+
return renderToStaticMarkup(
|
|
23
|
+
<div
|
|
24
|
+
data-slot="chart-tooltip"
|
|
25
|
+
style={{ boxShadow: "0 4px 12px rgb(0 0 0 / 0.12)" }}
|
|
26
|
+
className={cn(
|
|
27
|
+
"p-2.5 text-xs border border-border-default text-text-primary",
|
|
28
|
+
roundnessClass[options.roundness ?? "md"],
|
|
29
|
+
tooltipVariantClass[options.variant ?? "frosted-glass"]
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
{type !== "pie" && (
|
|
33
|
+
<div className="mb-1 font-medium">
|
|
34
|
+
{data[Number(rows[0]?.dataIndex)]?.label}
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
{rows
|
|
38
|
+
.filter((row) => !String(row.seriesId ?? "").startsWith("__"))
|
|
39
|
+
.map((row, i) => {
|
|
40
|
+
const item =
|
|
41
|
+
type === "pie"
|
|
42
|
+
? series[0]
|
|
43
|
+
: (series.find(
|
|
44
|
+
(s) => s.key === row.seriesId || s.key === row.seriesName
|
|
45
|
+
) ?? series[Number(row.seriesIndex)])
|
|
46
|
+
const datum = data[Number(row.dataIndex)]
|
|
47
|
+
return (
|
|
48
|
+
<div key={i} className="gap-3 flex items-center">
|
|
49
|
+
<span
|
|
50
|
+
aria-hidden="true"
|
|
51
|
+
className="size-2 shrink-0 rounded-full"
|
|
52
|
+
style={{
|
|
53
|
+
background:
|
|
54
|
+
type === "pie"
|
|
55
|
+
? `var(--chart-series-${(Number(row.dataIndex) % 5) + 1})`
|
|
56
|
+
: item
|
|
57
|
+
? chartSeriesColor(item, series.indexOf(item))
|
|
58
|
+
: undefined,
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
<span>{type === "pie" ? datum?.label : item?.label}</span>
|
|
62
|
+
<span className="font-medium ml-auto">
|
|
63
|
+
{formatChartValue(
|
|
64
|
+
item,
|
|
65
|
+
datum && item ? datum[item.key] : row.value
|
|
66
|
+
)}
|
|
67
|
+
</span>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
})}
|
|
71
|
+
</div>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gurbinder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# EvilCharts source
|
|
2
|
+
|
|
3
|
+
Vendored from https://github.com/legions-developer/evilcharts at `500ecd44c1fdcf319ba83ea68f3771bc76125974`.
|
|
4
|
+
MIT license in LICENSE. Only shared module import paths are adapted.
|
|
5
|
+
|
|
6
|
+
Local patches: line/bar accept controlled selectedDataKey; selection callbacks run outside React state updaters.
|
|
7
|
+
|
|
8
|
+
CSS variable declarations escape category/series keys so labels with spaces retain their colors.
|