@databricks/appkit-ui 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +3 -0
- package/DCO +25 -0
- package/LICENSE +203 -0
- package/NOTICE.md +73 -0
- package/README.md +35 -0
- package/bin/setup-claude.js +190 -0
- package/dist/js/arrow/arrow-client.d.ts +64 -0
- package/dist/js/arrow/arrow-client.d.ts.map +1 -0
- package/dist/js/arrow/arrow-client.js +181 -0
- package/dist/js/arrow/arrow-client.js.map +1 -0
- package/dist/js/arrow/index.js +3 -0
- package/dist/js/arrow/lazy-arrow.d.ts +23 -0
- package/dist/js/arrow/lazy-arrow.d.ts.map +1 -0
- package/dist/js/arrow/lazy-arrow.js +86 -0
- package/dist/js/arrow/lazy-arrow.js.map +1 -0
- package/dist/js/constants.d.ts +10 -0
- package/dist/js/constants.d.ts.map +1 -0
- package/dist/js/constants.js +30 -0
- package/dist/js/constants.js.map +1 -0
- package/dist/js/index.d.ts +8 -0
- package/dist/js/index.js +8 -0
- package/dist/js/sse/connect-sse.d.ts +14 -0
- package/dist/js/sse/connect-sse.d.ts.map +1 -0
- package/dist/js/sse/connect-sse.js +128 -0
- package/dist/js/sse/connect-sse.js.map +1 -0
- package/dist/js/sse/types.d.ts +34 -0
- package/dist/js/sse/types.d.ts.map +1 -0
- package/dist/react/charts/area/index.d.ts +33 -0
- package/dist/react/charts/area/index.d.ts.map +1 -0
- package/dist/react/charts/area/index.js +29 -0
- package/dist/react/charts/area/index.js.map +1 -0
- package/dist/react/charts/bar/index.d.ts +43 -0
- package/dist/react/charts/bar/index.d.ts.map +1 -0
- package/dist/react/charts/bar/index.js +39 -0
- package/dist/react/charts/bar/index.js.map +1 -0
- package/dist/react/charts/base.d.ts +89 -0
- package/dist/react/charts/base.d.ts.map +1 -0
- package/dist/react/charts/base.js +123 -0
- package/dist/react/charts/base.js.map +1 -0
- package/dist/react/charts/chart-error-boundary.js +37 -0
- package/dist/react/charts/chart-error-boundary.js.map +1 -0
- package/dist/react/charts/constants.d.ts +22 -0
- package/dist/react/charts/constants.d.ts.map +1 -0
- package/dist/react/charts/constants.js +86 -0
- package/dist/react/charts/constants.js.map +1 -0
- package/dist/react/charts/create-chart.d.ts +26 -0
- package/dist/react/charts/create-chart.d.ts.map +1 -0
- package/dist/react/charts/create-chart.js +55 -0
- package/dist/react/charts/create-chart.js.map +1 -0
- package/dist/react/charts/empty.js +16 -0
- package/dist/react/charts/empty.js.map +1 -0
- package/dist/react/charts/error.js +16 -0
- package/dist/react/charts/error.js.map +1 -0
- package/dist/react/charts/heatmap/index.d.ts +42 -0
- package/dist/react/charts/heatmap/index.d.ts.map +1 -0
- package/dist/react/charts/heatmap/index.js +38 -0
- package/dist/react/charts/heatmap/index.js.map +1 -0
- package/dist/react/charts/index.js +18 -0
- package/dist/react/charts/line/index.d.ts +34 -0
- package/dist/react/charts/line/index.d.ts.map +1 -0
- package/dist/react/charts/line/index.js +30 -0
- package/dist/react/charts/line/index.js.map +1 -0
- package/dist/react/charts/loading.js +13 -0
- package/dist/react/charts/loading.js.map +1 -0
- package/dist/react/charts/normalize.d.ts +37 -0
- package/dist/react/charts/normalize.d.ts.map +1 -0
- package/dist/react/charts/normalize.js +256 -0
- package/dist/react/charts/normalize.js.map +1 -0
- package/dist/react/charts/options.d.ts +39 -0
- package/dist/react/charts/options.d.ts.map +1 -0
- package/dist/react/charts/options.js +212 -0
- package/dist/react/charts/options.js.map +1 -0
- package/dist/react/charts/pie/index.d.ts +57 -0
- package/dist/react/charts/pie/index.d.ts.map +1 -0
- package/dist/react/charts/pie/index.js +50 -0
- package/dist/react/charts/pie/index.js.map +1 -0
- package/dist/react/charts/radar/index.d.ts +32 -0
- package/dist/react/charts/radar/index.d.ts.map +1 -0
- package/dist/react/charts/radar/index.js +28 -0
- package/dist/react/charts/radar/index.js.map +1 -0
- package/dist/react/charts/scatter/index.d.ts +32 -0
- package/dist/react/charts/scatter/index.d.ts.map +1 -0
- package/dist/react/charts/scatter/index.js +28 -0
- package/dist/react/charts/scatter/index.js.map +1 -0
- package/dist/react/charts/theme.d.ts +23 -0
- package/dist/react/charts/theme.d.ts.map +1 -0
- package/dist/react/charts/theme.js +96 -0
- package/dist/react/charts/theme.js.map +1 -0
- package/dist/react/charts/types.d.ts +160 -0
- package/dist/react/charts/types.d.ts.map +1 -0
- package/dist/react/charts/types.js +17 -0
- package/dist/react/charts/types.js.map +1 -0
- package/dist/react/charts/utils.d.ts +36 -0
- package/dist/react/charts/utils.d.ts.map +1 -0
- package/dist/react/charts/utils.js +77 -0
- package/dist/react/charts/utils.js.map +1 -0
- package/dist/react/charts/wrapper.d.ts +65 -0
- package/dist/react/charts/wrapper.d.ts.map +1 -0
- package/dist/react/charts/wrapper.js +94 -0
- package/dist/react/charts/wrapper.js.map +1 -0
- package/dist/react/hooks/index.js +2 -0
- package/dist/react/hooks/types.d.ts +101 -0
- package/dist/react/hooks/types.d.ts.map +1 -0
- package/dist/react/hooks/use-analytics-query.d.ts +33 -0
- package/dist/react/hooks/use-analytics-query.d.ts.map +1 -0
- package/dist/react/hooks/use-analytics-query.js +146 -0
- package/dist/react/hooks/use-analytics-query.js.map +1 -0
- package/dist/react/hooks/use-chart-data.d.ts +54 -0
- package/dist/react/hooks/use-chart-data.d.ts.map +1 -0
- package/dist/react/hooks/use-chart-data.js +80 -0
- package/dist/react/hooks/use-chart-data.js.map +1 -0
- package/dist/react/hooks/use-mobile.js +21 -0
- package/dist/react/hooks/use-mobile.js.map +1 -0
- package/dist/react/hooks/use-query-hmr.js +19 -0
- package/dist/react/hooks/use-query-hmr.js.map +1 -0
- package/dist/react/index.d.ts +75 -0
- package/dist/react/index.js +79 -0
- package/dist/react/lib/format.js +42 -0
- package/dist/react/lib/format.js.map +1 -0
- package/dist/react/lib/utils.js +11 -0
- package/dist/react/lib/utils.js.map +1 -0
- package/dist/react/table/data-table.d.ts +47 -0
- package/dist/react/table/data-table.d.ts.map +1 -0
- package/dist/react/table/data-table.js +205 -0
- package/dist/react/table/data-table.js.map +1 -0
- package/dist/react/table/empty.js +16 -0
- package/dist/react/table/empty.js.map +1 -0
- package/dist/react/table/error.js +16 -0
- package/dist/react/table/error.js.map +1 -0
- package/dist/react/table/index.js +1 -0
- package/dist/react/table/loading.js +50 -0
- package/dist/react/table/loading.js.map +1 -0
- package/dist/react/table/table-wrapper.js +143 -0
- package/dist/react/table/table-wrapper.js.map +1 -0
- package/dist/react/table/types.d.ts +55 -0
- package/dist/react/table/types.d.ts.map +1 -0
- package/dist/react/ui/accordion.d.ts +25 -0
- package/dist/react/ui/accordion.d.ts.map +1 -0
- package/dist/react/ui/accordion.js +45 -0
- package/dist/react/ui/accordion.js.map +1 -0
- package/dist/react/ui/alert-dialog.d.ts +49 -0
- package/dist/react/ui/alert-dialog.d.ts.map +1 -0
- package/dist/react/ui/alert-dialog.js +82 -0
- package/dist/react/ui/alert-dialog.js.map +1 -0
- package/dist/react/ui/alert.d.ts +25 -0
- package/dist/react/ui/alert.d.ts.map +1 -0
- package/dist/react/ui/alert.js +38 -0
- package/dist/react/ui/alert.js.map +1 -0
- package/dist/react/ui/aspect-ratio.d.ts +10 -0
- package/dist/react/ui/aspect-ratio.d.ts.map +1 -0
- package/dist/react/ui/aspect-ratio.js +16 -0
- package/dist/react/ui/aspect-ratio.js.map +1 -0
- package/dist/react/ui/avatar.d.ts +20 -0
- package/dist/react/ui/avatar.d.ts.map +1 -0
- package/dist/react/ui/avatar.js +30 -0
- package/dist/react/ui/avatar.js.map +1 -0
- package/dist/react/ui/badge.d.ts +20 -0
- package/dist/react/ui/badge.d.ts.map +1 -0
- package/dist/react/ui/badge.js +26 -0
- package/dist/react/ui/badge.js.map +1 -0
- package/dist/react/ui/breadcrumb.d.ts +38 -0
- package/dist/react/ui/breadcrumb.d.ts.map +1 -0
- package/dist/react/ui/breadcrumb.js +71 -0
- package/dist/react/ui/breadcrumb.js.map +1 -0
- package/dist/react/ui/button-group.d.ts +29 -0
- package/dist/react/ui/button-group.d.ts.map +1 -0
- package/dist/react/ui/button-group.js +41 -0
- package/dist/react/ui/button-group.js.map +1 -0
- package/dist/react/ui/button.d.ts +22 -0
- package/dist/react/ui/button.d.ts.map +1 -0
- package/dist/react/ui/button.js +45 -0
- package/dist/react/ui/button.js.map +1 -0
- package/dist/react/ui/calendar.d.ts +27 -0
- package/dist/react/ui/calendar.d.ts.map +1 -0
- package/dist/react/ui/calendar.js +109 -0
- package/dist/react/ui/calendar.js.map +1 -0
- package/dist/react/ui/card.d.ts +35 -0
- package/dist/react/ui/card.d.ts.map +1 -0
- package/dist/react/ui/card.js +57 -0
- package/dist/react/ui/card.js.map +1 -0
- package/dist/react/ui/carousel.d.ts +48 -0
- package/dist/react/ui/carousel.d.ts.map +1 -0
- package/dist/react/ui/carousel.js +134 -0
- package/dist/react/ui/carousel.js.map +1 -0
- package/dist/react/ui/chart.d.ts +80 -0
- package/dist/react/ui/chart.d.ts.map +1 -0
- package/dist/react/ui/chart.js +143 -0
- package/dist/react/ui/chart.js.map +1 -0
- package/dist/react/ui/checkbox.d.ts +12 -0
- package/dist/react/ui/checkbox.d.ts.map +1 -0
- package/dist/react/ui/checkbox.js +24 -0
- package/dist/react/ui/checkbox.js.map +1 -0
- package/dist/react/ui/collapsible.d.ts +16 -0
- package/dist/react/ui/collapsible.d.ts.map +1 -0
- package/dist/react/ui/collapsible.js +26 -0
- package/dist/react/ui/collapsible.js.map +1 -0
- package/dist/react/ui/command.d.ts +53 -0
- package/dist/react/ui/command.d.ts.map +1 -0
- package/dist/react/ui/command.js +87 -0
- package/dist/react/ui/command.js.map +1 -0
- package/dist/react/ui/context-menu.d.ts +77 -0
- package/dist/react/ui/context-menu.d.ts.map +1 -0
- package/dist/react/ui/context-menu.js +125 -0
- package/dist/react/ui/context-menu.js.map +1 -0
- package/dist/react/ui/dialog.d.ts +48 -0
- package/dist/react/ui/dialog.d.ts.map +1 -0
- package/dist/react/ui/dialog.js +87 -0
- package/dist/react/ui/dialog.js.map +1 -0
- package/dist/react/ui/drawer.d.ts +45 -0
- package/dist/react/ui/drawer.d.ts.map +1 -0
- package/dist/react/ui/drawer.js +81 -0
- package/dist/react/ui/drawer.js.map +1 -0
- package/dist/react/ui/dropdown-menu.d.ts +78 -0
- package/dist/react/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/react/ui/dropdown-menu.js +124 -0
- package/dist/react/ui/dropdown-menu.js.map +1 -0
- package/dist/react/ui/empty.d.ts +36 -0
- package/dist/react/ui/empty.d.ts.map +1 -0
- package/dist/react/ui/empty.js +62 -0
- package/dist/react/ui/empty.js.map +1 -0
- package/dist/react/ui/field.d.ts +65 -0
- package/dist/react/ui/field.d.ts.map +1 -0
- package/dist/react/ui/field.js +120 -0
- package/dist/react/ui/field.js.map +1 -0
- package/dist/react/ui/form.d.ts +46 -0
- package/dist/react/ui/form.d.ts.map +1 -0
- package/dist/react/ui/form.js +92 -0
- package/dist/react/ui/form.js.map +1 -0
- package/dist/react/ui/hover-card.d.ts +20 -0
- package/dist/react/ui/hover-card.d.ts.map +1 -0
- package/dist/react/ui/hover-card.js +35 -0
- package/dist/react/ui/hover-card.js.map +1 -0
- package/dist/react/ui/index.js +53 -0
- package/dist/react/ui/input-group.d.ts +44 -0
- package/dist/react/ui/input-group.d.ts.map +1 -0
- package/dist/react/ui/input-group.js +82 -0
- package/dist/react/ui/input-group.js.map +1 -0
- package/dist/react/ui/input-otp.d.ts +29 -0
- package/dist/react/ui/input-otp.d.ts.map +1 -0
- package/dist/react/ui/input-otp.js +47 -0
- package/dist/react/ui/input-otp.js.map +1 -0
- package/dist/react/ui/input.d.ts +12 -0
- package/dist/react/ui/input.d.ts.map +1 -0
- package/dist/react/ui/input.js +16 -0
- package/dist/react/ui/input.js.map +1 -0
- package/dist/react/ui/item.d.ts +63 -0
- package/dist/react/ui/item.d.ts.map +1 -0
- package/dist/react/ui/item.js +118 -0
- package/dist/react/ui/item.js.map +1 -0
- package/dist/react/ui/kbd.d.ts +14 -0
- package/dist/react/ui/kbd.d.ts.map +1 -0
- package/dist/react/ui/kbd.js +22 -0
- package/dist/react/ui/kbd.js.map +1 -0
- package/dist/react/ui/label.d.ts +12 -0
- package/dist/react/ui/label.d.ts.map +1 -0
- package/dist/react/ui/label.js +18 -0
- package/dist/react/ui/label.js.map +1 -0
- package/dist/react/ui/menubar.d.ts +85 -0
- package/dist/react/ui/menubar.d.ts.map +1 -0
- package/dist/react/ui/menubar.js +134 -0
- package/dist/react/ui/menubar.js.map +1 -0
- package/dist/react/ui/navigation-menu.d.ts +47 -0
- package/dist/react/ui/navigation-menu.d.ts.map +1 -0
- package/dist/react/ui/navigation-menu.js +82 -0
- package/dist/react/ui/navigation-menu.js.map +1 -0
- package/dist/react/ui/pagination.d.ts +40 -0
- package/dist/react/ui/pagination.d.ts.map +1 -0
- package/dist/react/ui/pagination.js +80 -0
- package/dist/react/ui/pagination.js.map +1 -0
- package/dist/react/ui/popover.d.ts +23 -0
- package/dist/react/ui/popover.d.ts.map +1 -0
- package/dist/react/ui/popover.js +38 -0
- package/dist/react/ui/popover.js.map +1 -0
- package/dist/react/ui/progress.d.ts +13 -0
- package/dist/react/ui/progress.d.ts.map +1 -0
- package/dist/react/ui/progress.js +21 -0
- package/dist/react/ui/progress.js.map +1 -0
- package/dist/react/ui/radio-group.d.ts +16 -0
- package/dist/react/ui/radio-group.d.ts.map +1 -0
- package/dist/react/ui/radio-group.js +31 -0
- package/dist/react/ui/radio-group.js.map +1 -0
- package/dist/react/ui/resizable.d.ts +22 -0
- package/dist/react/ui/resizable.d.ts.map +1 -0
- package/dist/react/ui/resizable.js +34 -0
- package/dist/react/ui/resizable.js.map +1 -0
- package/dist/react/ui/scroll-area.d.ts +18 -0
- package/dist/react/ui/scroll-area.d.ts.map +1 -0
- package/dist/react/ui/scroll-area.js +39 -0
- package/dist/react/ui/scroll-area.js.map +1 -0
- package/dist/react/ui/select.d.ts +53 -0
- package/dist/react/ui/select.d.ts.map +1 -0
- package/dist/react/ui/select.js +98 -0
- package/dist/react/ui/select.js.map +1 -0
- package/dist/react/ui/separator.d.ts +14 -0
- package/dist/react/ui/separator.d.ts.map +1 -0
- package/dist/react/ui/separator.js +20 -0
- package/dist/react/ui/separator.js.map +1 -0
- package/dist/react/ui/sheet.d.ts +41 -0
- package/dist/react/ui/sheet.d.ts.map +1 -0
- package/dist/react/ui/sheet.js +83 -0
- package/dist/react/ui/sheet.js.map +1 -0
- package/dist/react/ui/sidebar.d.ts +167 -0
- package/dist/react/ui/sidebar.d.ts.map +1 -0
- package/dist/react/ui/sidebar.js +379 -0
- package/dist/react/ui/sidebar.js.map +1 -0
- package/dist/react/ui/skeleton.d.ts +10 -0
- package/dist/react/ui/skeleton.d.ts.map +1 -0
- package/dist/react/ui/skeleton.js +15 -0
- package/dist/react/ui/skeleton.js.map +1 -0
- package/dist/react/ui/slider.d.ts +16 -0
- package/dist/react/ui/slider.d.ts.map +1 -0
- package/dist/react/ui/slider.js +40 -0
- package/dist/react/ui/slider.js.map +1 -0
- package/dist/react/ui/sonner.d.ts +10 -0
- package/dist/react/ui/sonner.d.ts.map +1 -0
- package/dist/react/ui/sonner.js +31 -0
- package/dist/react/ui/sonner.js.map +1 -0
- package/dist/react/ui/spinner.d.ts +10 -0
- package/dist/react/ui/spinner.d.ts.map +1 -0
- package/dist/react/ui/spinner.js +17 -0
- package/dist/react/ui/spinner.js.map +1 -0
- package/dist/react/ui/switch.d.ts +12 -0
- package/dist/react/ui/switch.d.ts.map +1 -0
- package/dist/react/ui/switch.js +22 -0
- package/dist/react/ui/switch.js.map +1 -0
- package/dist/react/ui/table.d.ts +39 -0
- package/dist/react/ui/table.d.ts.map +1 -0
- package/dist/react/ui/table.js +68 -0
- package/dist/react/ui/table.js.map +1 -0
- package/dist/react/ui/tabs.d.ts +24 -0
- package/dist/react/ui/tabs.d.ts.map +1 -0
- package/dist/react/ui/tabs.js +39 -0
- package/dist/react/ui/tabs.js.map +1 -0
- package/dist/react/ui/textarea.d.ts +11 -0
- package/dist/react/ui/textarea.d.ts.map +1 -0
- package/dist/react/ui/textarea.js +15 -0
- package/dist/react/ui/textarea.js.map +1 -0
- package/dist/react/ui/toggle-group.d.ts +27 -0
- package/dist/react/ui/toggle-group.d.ts.map +1 -0
- package/dist/react/ui/toggle-group.js +50 -0
- package/dist/react/ui/toggle-group.js.map +1 -0
- package/dist/react/ui/toggle.d.ts +20 -0
- package/dist/react/ui/toggle.d.ts.map +1 -0
- package/dist/react/ui/toggle.js +38 -0
- package/dist/react/ui/toggle.js.map +1 -0
- package/dist/react/ui/tooltip.d.ts +24 -0
- package/dist/react/ui/tooltip.d.ts.map +1 -0
- package/dist/react/ui/tooltip.js +39 -0
- package/dist/react/ui/tooltip.js.map +1 -0
- package/dist/shared/src/sql/helpers.d.ts +160 -0
- package/dist/shared/src/sql/helpers.d.ts.map +1 -0
- package/dist/shared/src/sql/helpers.js +103 -0
- package/dist/shared/src/sql/helpers.js.map +1 -0
- package/dist/shared/src/sql/types.d.ts +34 -0
- package/dist/shared/src/sql/types.d.ts.map +1 -0
- package/dist/styles.css +425 -0
- package/llms.txt +193 -0
- package/package.json +98 -0
- package/scripts/postinstall.js +6 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { createTimeSeriesData, formatLabel, truncateLabel } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/charts/options.ts
|
|
4
|
+
function buildBaseOption(ctx) {
|
|
5
|
+
return {
|
|
6
|
+
title: ctx.title ? {
|
|
7
|
+
text: ctx.title,
|
|
8
|
+
left: "center"
|
|
9
|
+
} : void 0,
|
|
10
|
+
color: ctx.colors
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function buildRadarOption(ctx, showArea = true) {
|
|
14
|
+
const maxValue = Math.max(...ctx.yFields.flatMap((f) => ctx.yDataMap[f].map((v) => Number(v) || 0)));
|
|
15
|
+
return {
|
|
16
|
+
...buildBaseOption(ctx),
|
|
17
|
+
tooltip: { trigger: "item" },
|
|
18
|
+
legend: ctx.showLegend && ctx.yFields.length > 1 ? { top: "bottom" } : void 0,
|
|
19
|
+
radar: {
|
|
20
|
+
indicator: ctx.xData.map((name) => ({
|
|
21
|
+
name: String(name),
|
|
22
|
+
max: maxValue * 1.2
|
|
23
|
+
})),
|
|
24
|
+
shape: "polygon"
|
|
25
|
+
},
|
|
26
|
+
series: [{
|
|
27
|
+
type: "radar",
|
|
28
|
+
data: ctx.yFields.map((key, idx) => ({
|
|
29
|
+
name: formatLabel(key),
|
|
30
|
+
value: ctx.yDataMap[key],
|
|
31
|
+
itemStyle: { color: ctx.colors[idx % ctx.colors.length] },
|
|
32
|
+
areaStyle: showArea ? { opacity: .3 } : void 0
|
|
33
|
+
}))
|
|
34
|
+
}]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function buildPieOption(ctx, chartType, innerRadius, showLabels, labelPosition) {
|
|
38
|
+
const pieData = ctx.xData.map((name, i) => ({
|
|
39
|
+
name: String(name),
|
|
40
|
+
value: ctx.yDataMap[ctx.yFields[0]]?.[i] ?? 0
|
|
41
|
+
}));
|
|
42
|
+
const isDonut = chartType === "donut" || innerRadius > 0;
|
|
43
|
+
return {
|
|
44
|
+
...buildBaseOption(ctx),
|
|
45
|
+
tooltip: {
|
|
46
|
+
trigger: "item",
|
|
47
|
+
formatter: "{b}: {c} ({d}%)"
|
|
48
|
+
},
|
|
49
|
+
legend: ctx.showLegend ? {
|
|
50
|
+
orient: "vertical",
|
|
51
|
+
left: "left",
|
|
52
|
+
top: "middle"
|
|
53
|
+
} : void 0,
|
|
54
|
+
series: [{
|
|
55
|
+
type: "pie",
|
|
56
|
+
radius: isDonut ? [`${innerRadius || 40}%`, "70%"] : "70%",
|
|
57
|
+
center: ["60%", "50%"],
|
|
58
|
+
data: pieData,
|
|
59
|
+
label: {
|
|
60
|
+
show: showLabels,
|
|
61
|
+
position: labelPosition,
|
|
62
|
+
formatter: "{b}: {d}%"
|
|
63
|
+
},
|
|
64
|
+
emphasis: { itemStyle: {
|
|
65
|
+
shadowBlur: 10,
|
|
66
|
+
shadowOffsetX: 0,
|
|
67
|
+
shadowColor: "rgba(0, 0, 0, 0.5)"
|
|
68
|
+
} }
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function buildHorizontalBarOption(ctx, stacked) {
|
|
73
|
+
const hasMultipleSeries = ctx.yFields.length > 1;
|
|
74
|
+
return {
|
|
75
|
+
...buildBaseOption(ctx),
|
|
76
|
+
tooltip: {
|
|
77
|
+
trigger: "axis",
|
|
78
|
+
axisPointer: { type: "shadow" }
|
|
79
|
+
},
|
|
80
|
+
legend: ctx.showLegend && hasMultipleSeries ? { top: "bottom" } : void 0,
|
|
81
|
+
grid: {
|
|
82
|
+
left: "20%",
|
|
83
|
+
right: "10%",
|
|
84
|
+
top: ctx.title ? "15%" : "5%",
|
|
85
|
+
bottom: ctx.showLegend && hasMultipleSeries ? "15%" : "5%"
|
|
86
|
+
},
|
|
87
|
+
xAxis: { type: "value" },
|
|
88
|
+
yAxis: {
|
|
89
|
+
type: "category",
|
|
90
|
+
data: ctx.xData,
|
|
91
|
+
axisLabel: {
|
|
92
|
+
width: 100,
|
|
93
|
+
overflow: "truncate",
|
|
94
|
+
formatter: (value) => truncateLabel(String(value))
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
series: ctx.yFields.map((key, idx) => ({
|
|
98
|
+
name: formatLabel(key),
|
|
99
|
+
type: "bar",
|
|
100
|
+
data: ctx.yDataMap[key],
|
|
101
|
+
stack: stacked ? "total" : void 0,
|
|
102
|
+
itemStyle: { borderRadius: [
|
|
103
|
+
0,
|
|
104
|
+
4,
|
|
105
|
+
4,
|
|
106
|
+
0
|
|
107
|
+
] },
|
|
108
|
+
color: ctx.colors[idx % ctx.colors.length]
|
|
109
|
+
}))
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function buildHeatmapOption(ctx) {
|
|
113
|
+
return {
|
|
114
|
+
...buildBaseOption(ctx),
|
|
115
|
+
tooltip: {
|
|
116
|
+
trigger: "item",
|
|
117
|
+
formatter: (params) => {
|
|
118
|
+
const [xIdx, yIdx, value] = params.data;
|
|
119
|
+
return `${ctx.xData[xIdx] ?? xIdx}, ${ctx.yAxisData[yIdx] ?? yIdx}: ${value}`;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
grid: {
|
|
123
|
+
left: "15%",
|
|
124
|
+
right: "15%",
|
|
125
|
+
top: ctx.title ? "15%" : "10%",
|
|
126
|
+
bottom: "15%"
|
|
127
|
+
},
|
|
128
|
+
xAxis: {
|
|
129
|
+
type: "category",
|
|
130
|
+
data: ctx.xData,
|
|
131
|
+
splitArea: { show: true },
|
|
132
|
+
axisLabel: {
|
|
133
|
+
rotate: ctx.xData.length > 10 ? 45 : 0,
|
|
134
|
+
formatter: (v) => truncateLabel(String(v), 10)
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
yAxis: {
|
|
138
|
+
type: "category",
|
|
139
|
+
data: ctx.yAxisData,
|
|
140
|
+
splitArea: { show: true },
|
|
141
|
+
axisLabel: { formatter: (v) => truncateLabel(String(v), 12) }
|
|
142
|
+
},
|
|
143
|
+
visualMap: {
|
|
144
|
+
min: ctx.min,
|
|
145
|
+
max: ctx.max,
|
|
146
|
+
calculable: true,
|
|
147
|
+
orient: "vertical",
|
|
148
|
+
right: "2%",
|
|
149
|
+
top: "center",
|
|
150
|
+
inRange: { color: ctx.colors.length >= 2 ? ctx.colors : ["#f0f0f0", ctx.colors[0]] }
|
|
151
|
+
},
|
|
152
|
+
series: [{
|
|
153
|
+
type: "heatmap",
|
|
154
|
+
data: ctx.heatmapData,
|
|
155
|
+
label: {
|
|
156
|
+
show: ctx.showLabels,
|
|
157
|
+
formatter: (params) => String(params.data[2])
|
|
158
|
+
},
|
|
159
|
+
emphasis: { itemStyle: {
|
|
160
|
+
shadowBlur: 10,
|
|
161
|
+
shadowColor: "rgba(0, 0, 0, 0.5)"
|
|
162
|
+
} }
|
|
163
|
+
}]
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function buildCartesianOption(ctx) {
|
|
167
|
+
const { chartType, isTimeSeries, stacked, smooth, showSymbol, symbolSize } = ctx;
|
|
168
|
+
const hasMultipleSeries = ctx.yFields.length > 1;
|
|
169
|
+
const seriesType = chartType === "area" ? "line" : chartType;
|
|
170
|
+
return {
|
|
171
|
+
...buildBaseOption(ctx),
|
|
172
|
+
tooltip: { trigger: "axis" },
|
|
173
|
+
legend: ctx.showLegend && hasMultipleSeries ? { top: "bottom" } : void 0,
|
|
174
|
+
grid: {
|
|
175
|
+
left: "10%",
|
|
176
|
+
right: "10%",
|
|
177
|
+
top: ctx.title ? "15%" : "10%",
|
|
178
|
+
bottom: ctx.showLegend && hasMultipleSeries ? "20%" : "15%"
|
|
179
|
+
},
|
|
180
|
+
xAxis: {
|
|
181
|
+
type: isTimeSeries ? "time" : "category",
|
|
182
|
+
data: isTimeSeries ? void 0 : ctx.xData,
|
|
183
|
+
axisLabel: isTimeSeries ? void 0 : {
|
|
184
|
+
rotate: ctx.xData.length > 10 ? 45 : 0,
|
|
185
|
+
formatter: (v) => truncateLabel(String(v), 10)
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
yAxis: { type: "value" },
|
|
189
|
+
series: ctx.yFields.map((key, idx) => ({
|
|
190
|
+
name: formatLabel(key),
|
|
191
|
+
type: seriesType,
|
|
192
|
+
data: isTimeSeries ? createTimeSeriesData(ctx.xData, ctx.yDataMap[key]) : ctx.yDataMap[key],
|
|
193
|
+
smooth: chartType === "line" || chartType === "area" ? smooth : void 0,
|
|
194
|
+
showSymbol: chartType === "line" || chartType === "area" ? showSymbol : void 0,
|
|
195
|
+
symbol: chartType === "scatter" ? "circle" : void 0,
|
|
196
|
+
symbolSize: chartType === "scatter" ? symbolSize : void 0,
|
|
197
|
+
areaStyle: chartType === "area" ? { opacity: .3 } : void 0,
|
|
198
|
+
stack: stacked && chartType === "area" ? "total" : void 0,
|
|
199
|
+
itemStyle: chartType === "bar" ? { borderRadius: [
|
|
200
|
+
4,
|
|
201
|
+
4,
|
|
202
|
+
0,
|
|
203
|
+
0
|
|
204
|
+
] } : void 0,
|
|
205
|
+
color: ctx.colors[idx % ctx.colors.length]
|
|
206
|
+
}))
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
export { buildCartesianOption, buildHeatmapOption, buildHorizontalBarOption, buildPieOption, buildRadarOption };
|
|
212
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","names":[],"sources":["../../../src/react/charts/options.ts"],"sourcesContent":["import type { ChartType } from \"./types\";\nimport { createTimeSeriesData, formatLabel, truncateLabel } from \"./utils\";\n\n// ============================================================================\n// Option Builder Types\n// ============================================================================\n\nexport interface OptionBuilderContext {\n xData: (string | number)[];\n yDataMap: Record<string, (string | number)[]>;\n yFields: string[];\n colors: string[];\n title?: string;\n showLegend: boolean;\n}\n\nexport interface CartesianContext extends OptionBuilderContext {\n chartType: ChartType;\n isTimeSeries: boolean;\n stacked: boolean;\n smooth: boolean;\n showSymbol: boolean;\n symbolSize: number;\n}\n\n// ============================================================================\n// Base Option Builder\n// ============================================================================\n\nfunction buildBaseOption(ctx: OptionBuilderContext): Record<string, unknown> {\n return {\n title: ctx.title ? { text: ctx.title, left: \"center\" } : undefined,\n color: ctx.colors,\n };\n}\n\n// ============================================================================\n// Radar Chart Option\n// ============================================================================\n\nexport function buildRadarOption(\n ctx: OptionBuilderContext,\n showArea = true,\n): Record<string, unknown> {\n const maxValue = Math.max(\n ...ctx.yFields.flatMap((f) => ctx.yDataMap[f].map((v) => Number(v) || 0)),\n );\n\n return {\n ...buildBaseOption(ctx),\n tooltip: { trigger: \"item\" },\n legend:\n ctx.showLegend && ctx.yFields.length > 1 ? { top: \"bottom\" } : undefined,\n radar: {\n indicator: ctx.xData.map((name) => ({\n name: String(name),\n max: maxValue * 1.2,\n })),\n shape: \"polygon\",\n },\n series: [\n {\n type: \"radar\",\n data: ctx.yFields.map((key, idx) => ({\n name: formatLabel(key),\n value: ctx.yDataMap[key],\n itemStyle: { color: ctx.colors[idx % ctx.colors.length] },\n areaStyle: showArea ? { opacity: 0.3 } : undefined,\n })),\n },\n ],\n };\n}\n\n// ============================================================================\n// Pie/Donut Chart Option\n// ============================================================================\n\nexport function buildPieOption(\n ctx: OptionBuilderContext,\n chartType: \"pie\" | \"donut\",\n innerRadius: number,\n showLabels: boolean,\n labelPosition: string,\n): Record<string, unknown> {\n const pieData = ctx.xData.map((name, i) => ({\n name: String(name),\n value: ctx.yDataMap[ctx.yFields[0]]?.[i] ?? 0,\n }));\n\n const isDonut = chartType === \"donut\" || innerRadius > 0;\n\n return {\n ...buildBaseOption(ctx),\n tooltip: { trigger: \"item\", formatter: \"{b}: {c} ({d}%)\" },\n legend: ctx.showLegend\n ? { orient: \"vertical\", left: \"left\", top: \"middle\" }\n : undefined,\n series: [\n {\n type: \"pie\",\n radius: isDonut ? [`${innerRadius || 40}%`, \"70%\"] : \"70%\",\n center: [\"60%\", \"50%\"],\n data: pieData,\n label: {\n show: showLabels,\n position: labelPosition,\n formatter: \"{b}: {d}%\",\n },\n emphasis: {\n itemStyle: {\n shadowBlur: 10,\n shadowOffsetX: 0,\n shadowColor: \"rgba(0, 0, 0, 0.5)\",\n },\n },\n },\n ],\n };\n}\n\n// ============================================================================\n// Horizontal Bar Chart Option\n// ============================================================================\n\nexport function buildHorizontalBarOption(\n ctx: OptionBuilderContext,\n stacked: boolean,\n): Record<string, unknown> {\n const hasMultipleSeries = ctx.yFields.length > 1;\n\n return {\n ...buildBaseOption(ctx),\n tooltip: { trigger: \"axis\", axisPointer: { type: \"shadow\" } },\n legend: ctx.showLegend && hasMultipleSeries ? { top: \"bottom\" } : undefined,\n grid: {\n left: \"20%\",\n right: \"10%\",\n top: ctx.title ? \"15%\" : \"5%\",\n bottom: ctx.showLegend && hasMultipleSeries ? \"15%\" : \"5%\",\n },\n xAxis: { type: \"value\" },\n yAxis: {\n type: \"category\",\n data: ctx.xData,\n axisLabel: {\n width: 100,\n overflow: \"truncate\",\n formatter: (value: string) => truncateLabel(String(value)),\n },\n },\n series: ctx.yFields.map((key, idx) => ({\n name: formatLabel(key),\n type: \"bar\",\n data: ctx.yDataMap[key],\n stack: stacked ? \"total\" : undefined,\n itemStyle: { borderRadius: [0, 4, 4, 0] },\n color: ctx.colors[idx % ctx.colors.length],\n })),\n };\n}\n\n// ============================================================================\n// Heatmap Chart Option\n// ============================================================================\n\nexport interface HeatmapContext extends OptionBuilderContext {\n /** Y-axis categories (rows) */\n yAxisData: (string | number)[];\n /** Heatmap data as [xIndex, yIndex, value] tuples */\n heatmapData: [number, number, number][];\n /** Min value for color scale */\n min: number;\n /** Max value for color scale */\n max: number;\n /** Show value labels on cells */\n showLabels: boolean;\n}\n\nexport function buildHeatmapOption(\n ctx: HeatmapContext,\n): Record<string, unknown> {\n return {\n ...buildBaseOption(ctx),\n tooltip: {\n trigger: \"item\",\n formatter: (params: { data: [number, number, number] }) => {\n const [xIdx, yIdx, value] = params.data;\n const xLabel = ctx.xData[xIdx] ?? xIdx;\n const yLabel = ctx.yAxisData[yIdx] ?? yIdx;\n return `${xLabel}, ${yLabel}: ${value}`;\n },\n },\n grid: {\n left: \"15%\",\n right: \"15%\",\n top: ctx.title ? \"15%\" : \"10%\",\n bottom: \"15%\",\n },\n xAxis: {\n type: \"category\",\n data: ctx.xData,\n splitArea: { show: true },\n axisLabel: {\n rotate: ctx.xData.length > 10 ? 45 : 0,\n formatter: (v: string) => truncateLabel(String(v), 10),\n },\n },\n yAxis: {\n type: \"category\",\n data: ctx.yAxisData,\n splitArea: { show: true },\n axisLabel: {\n formatter: (v: string) => truncateLabel(String(v), 12),\n },\n },\n visualMap: {\n min: ctx.min,\n max: ctx.max,\n calculable: true,\n orient: \"vertical\",\n right: \"2%\",\n top: \"center\",\n inRange: {\n color: ctx.colors.length >= 2 ? ctx.colors : [\"#f0f0f0\", ctx.colors[0]],\n },\n },\n series: [\n {\n type: \"heatmap\",\n data: ctx.heatmapData,\n label: {\n show: ctx.showLabels,\n formatter: (params: { data: [number, number, number] }) =>\n String(params.data[2]),\n },\n emphasis: {\n itemStyle: {\n shadowBlur: 10,\n shadowColor: \"rgba(0, 0, 0, 0.5)\",\n },\n },\n },\n ],\n };\n}\n\n// ============================================================================\n// Cartesian Chart Option (line, bar, area, scatter)\n// ============================================================================\n\nexport function buildCartesianOption(\n ctx: CartesianContext,\n): Record<string, unknown> {\n const { chartType, isTimeSeries, stacked, smooth, showSymbol, symbolSize } =\n ctx;\n const hasMultipleSeries = ctx.yFields.length > 1;\n const seriesType = chartType === \"area\" ? \"line\" : chartType;\n\n return {\n ...buildBaseOption(ctx),\n tooltip: { trigger: \"axis\" },\n legend: ctx.showLegend && hasMultipleSeries ? { top: \"bottom\" } : undefined,\n grid: {\n left: \"10%\",\n right: \"10%\",\n top: ctx.title ? \"15%\" : \"10%\",\n bottom: ctx.showLegend && hasMultipleSeries ? \"20%\" : \"15%\",\n },\n xAxis: {\n type: isTimeSeries ? \"time\" : \"category\",\n data: isTimeSeries ? undefined : ctx.xData,\n axisLabel: isTimeSeries\n ? undefined\n : {\n rotate: ctx.xData.length > 10 ? 45 : 0,\n formatter: (v: string) => truncateLabel(String(v), 10),\n },\n },\n yAxis: { type: \"value\" },\n series: ctx.yFields.map((key, idx) => ({\n name: formatLabel(key),\n type: seriesType,\n data: isTimeSeries\n ? createTimeSeriesData(ctx.xData, ctx.yDataMap[key])\n : ctx.yDataMap[key],\n smooth: chartType === \"line\" || chartType === \"area\" ? smooth : undefined,\n showSymbol:\n chartType === \"line\" || chartType === \"area\" ? showSymbol : undefined,\n symbol: chartType === \"scatter\" ? \"circle\" : undefined,\n symbolSize: chartType === \"scatter\" ? symbolSize : undefined,\n areaStyle: chartType === \"area\" ? { opacity: 0.3 } : undefined,\n stack: stacked && chartType === \"area\" ? \"total\" : undefined,\n itemStyle:\n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;EACD,OAAO;GACL,MAAM,eAAe,SAAS;GAC9B,MAAM,eAAe,SAAY,IAAI;GACrC,WAAW,eACP,SACA;IACE,QAAQ,IAAI,MAAM,SAAS,KAAK,KAAK;IACrC,YAAY,MAAc,cAAc,OAAO,EAAE,EAAE,GAAG;IACvD;GACN;EACD,OAAO,EAAE,MAAM,SAAS;EACxB,QAAQ,IAAI,QAAQ,KAAK,KAAK,SAAS;GACrC,MAAM,YAAY,IAAI;GACtB,MAAM;GACN,MAAM,eACF,qBAAqB,IAAI,OAAO,IAAI,SAAS,KAAK,GAClD,IAAI,SAAS;GACjB,QAAQ,cAAc,UAAU,cAAc,SAAS,SAAS;GAChE,YACE,cAAc,UAAU,cAAc,SAAS,aAAa;GAC9D,QAAQ,cAAc,YAAY,WAAW;GAC7C,YAAY,cAAc,YAAY,aAAa;GACnD,WAAW,cAAc,SAAS,EAAE,SAAS,IAAK,GAAG;GACrD,OAAO,WAAW,cAAc,SAAS,UAAU;GACnD,WACE,cAAc,QAAQ,EAAE,cAAc;IAAC;IAAG;IAAG;IAAG;IAAE,EAAE,GAAG;GACzD,OAAO,IAAI,OAAO,MAAM,IAAI,OAAO;GACpC,EAAE;EACJ"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DonutChartProps, PieChartProps } from "../types.js";
|
|
2
|
+
import * as react_jsx_runtime278 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/charts/pie/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Pie Chart component.
|
|
8
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
9
|
+
*
|
|
10
|
+
* @example Simple usage
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PieChart
|
|
13
|
+
* queryKey="market_share"
|
|
14
|
+
* parameters={{ category: "tech" }}
|
|
15
|
+
* />
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example With custom labels
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <PieChart
|
|
21
|
+
* queryKey="distribution"
|
|
22
|
+
* showLabels={true}
|
|
23
|
+
* labelPosition="inside"
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const PieChart: {
|
|
28
|
+
(props: PieChartProps): react_jsx_runtime278.JSX.Element;
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Donut Chart component (Pie chart with inner radius).
|
|
33
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
34
|
+
*
|
|
35
|
+
* @example Simple usage
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <DonutChart
|
|
38
|
+
* queryKey="budget_allocation"
|
|
39
|
+
* parameters={{ year: 2024 }}
|
|
40
|
+
* />
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Custom inner radius
|
|
44
|
+
* ```tsx
|
|
45
|
+
* <DonutChart
|
|
46
|
+
* queryKey="progress"
|
|
47
|
+
* innerRadius={60}
|
|
48
|
+
* />
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare const DonutChart: {
|
|
52
|
+
(props: DonutChartProps): react_jsx_runtime278.JSX.Element;
|
|
53
|
+
displayName: string;
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { DonutChart, PieChart };
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/react/charts/pie/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAwBA;;;;;AAsBA;;;;;;;;;;;;;cAtBa;;;;;;;;;;;;;;;;;;;;;;;;cAsBA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createChart } from "../create-chart.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/charts/pie/index.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Pie Chart component.
|
|
6
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
7
|
+
*
|
|
8
|
+
* @example Simple usage
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <PieChart
|
|
11
|
+
* queryKey="market_share"
|
|
12
|
+
* parameters={{ category: "tech" }}
|
|
13
|
+
* />
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With custom labels
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <PieChart
|
|
19
|
+
* queryKey="distribution"
|
|
20
|
+
* showLabels={true}
|
|
21
|
+
* labelPosition="inside"
|
|
22
|
+
* />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const PieChart = createChart("pie", "PieChart");
|
|
26
|
+
/**
|
|
27
|
+
* Donut Chart component (Pie chart with inner radius).
|
|
28
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
29
|
+
*
|
|
30
|
+
* @example Simple usage
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <DonutChart
|
|
33
|
+
* queryKey="budget_allocation"
|
|
34
|
+
* parameters={{ year: 2024 }}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Custom inner radius
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <DonutChart
|
|
41
|
+
* queryKey="progress"
|
|
42
|
+
* innerRadius={60}
|
|
43
|
+
* />
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const DonutChart = createChart("donut", "DonutChart");
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { DonutChart, PieChart };
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/react/charts/pie/index.tsx"],"sourcesContent":["import { createChart } from \"../create-chart\";\nimport type { DonutChartProps, PieChartProps } from \"../types\";\n\n/**\n * Pie Chart component.\n * Supports both JSON and Arrow data formats with automatic format selection.\n *\n * @example Simple usage\n * ```tsx\n * <PieChart\n * queryKey=\"market_share\"\n * parameters={{ category: \"tech\" }}\n * />\n * ```\n *\n * @example With custom labels\n * ```tsx\n * <PieChart\n * queryKey=\"distribution\"\n * showLabels={true}\n * labelPosition=\"inside\"\n * />\n * ```\n */\nexport const PieChart = createChart<PieChartProps>(\"pie\", \"PieChart\");\n\n/**\n * Donut Chart component (Pie chart with inner radius).\n * Supports both JSON and Arrow data formats with automatic format selection.\n *\n * @example Simple usage\n * ```tsx\n * <DonutChart\n * queryKey=\"budget_allocation\"\n * parameters={{ year: 2024 }}\n * />\n * ```\n *\n * @example Custom inner radius\n * ```tsx\n * <DonutChart\n * queryKey=\"progress\"\n * innerRadius={60}\n * />\n * ```\n */\nexport const DonutChart = createChart<DonutChartProps>(\"donut\", \"DonutChart\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,WAAW,YAA2B,OAAO,WAAW;;;;;;;;;;;;;;;;;;;;;AAsBrE,MAAa,aAAa,YAA6B,SAAS,aAAa"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RadarChartProps } from "../types.js";
|
|
2
|
+
import * as react_jsx_runtime280 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/charts/radar/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Radar Chart component.
|
|
8
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
9
|
+
*
|
|
10
|
+
* @example Simple usage
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <RadarChart
|
|
13
|
+
* queryKey="skills_assessment"
|
|
14
|
+
* parameters={{ userId: "123" }}
|
|
15
|
+
* />
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example With custom styling
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <RadarChart
|
|
21
|
+
* queryKey="performance_metrics"
|
|
22
|
+
* showArea={true}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const RadarChart: {
|
|
27
|
+
(props: RadarChartProps): react_jsx_runtime280.JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { RadarChart };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/react/charts/radar/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAuBA;;;;;;;;;;;;;;;;;cAAa"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createChart } from "../create-chart.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/charts/radar/index.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Radar Chart component.
|
|
6
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
7
|
+
*
|
|
8
|
+
* @example Simple usage
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <RadarChart
|
|
11
|
+
* queryKey="skills_assessment"
|
|
12
|
+
* parameters={{ userId: "123" }}
|
|
13
|
+
* />
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With custom styling
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <RadarChart
|
|
19
|
+
* queryKey="performance_metrics"
|
|
20
|
+
* showArea={true}
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const RadarChart = createChart("radar", "RadarChart");
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { RadarChart };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/react/charts/radar/index.tsx"],"sourcesContent":["import { createChart } from \"../create-chart\";\nimport type { RadarChartProps } from \"../types\";\n\n/**\n * Radar Chart component.\n * Supports both JSON and Arrow data formats with automatic format selection.\n *\n * @example Simple usage\n * ```tsx\n * <RadarChart\n * queryKey=\"skills_assessment\"\n * parameters={{ userId: \"123\" }}\n * />\n * ```\n *\n * @example With custom styling\n * ```tsx\n * <RadarChart\n * queryKey=\"performance_metrics\"\n * showArea={true}\n * />\n * ```\n */\nexport const RadarChart = createChart<RadarChartProps>(\"radar\", \"RadarChart\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,aAAa,YAA6B,SAAS,aAAa"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ScatterChartProps } from "../types.js";
|
|
2
|
+
import * as react_jsx_runtime281 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/charts/scatter/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scatter Chart component.
|
|
8
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
9
|
+
*
|
|
10
|
+
* @example Simple usage
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <ScatterChart
|
|
13
|
+
* queryKey="correlation_data"
|
|
14
|
+
* parameters={{ metrics: ["revenue", "growth"] }}
|
|
15
|
+
* />
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example With custom symbol size
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <ScatterChart
|
|
21
|
+
* queryKey="data_points"
|
|
22
|
+
* symbolSize={12}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const ScatterChart: {
|
|
27
|
+
(props: ScatterChartProps): react_jsx_runtime281.JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ScatterChart };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/react/charts/scatter/index.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAuBA;;;;;;;;;;;;;;;;;cAAa"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createChart } from "../create-chart.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/charts/scatter/index.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Scatter Chart component.
|
|
6
|
+
* Supports both JSON and Arrow data formats with automatic format selection.
|
|
7
|
+
*
|
|
8
|
+
* @example Simple usage
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <ScatterChart
|
|
11
|
+
* queryKey="correlation_data"
|
|
12
|
+
* parameters={{ metrics: ["revenue", "growth"] }}
|
|
13
|
+
* />
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example With custom symbol size
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <ScatterChart
|
|
19
|
+
* queryKey="data_points"
|
|
20
|
+
* symbolSize={12}
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const ScatterChart = createChart("scatter", "ScatterChart");
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ScatterChart };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/react/charts/scatter/index.tsx"],"sourcesContent":["import { createChart } from \"../create-chart\";\nimport type { ScatterChartProps } from \"../types\";\n\n/**\n * Scatter Chart component.\n * Supports both JSON and Arrow data formats with automatic format selection.\n *\n * @example Simple usage\n * ```tsx\n * <ScatterChart\n * queryKey=\"correlation_data\"\n * parameters={{ metrics: [\"revenue\", \"growth\"] }}\n * />\n * ```\n *\n * @example With custom symbol size\n * ```tsx\n * <ScatterChart\n * queryKey=\"data_points\"\n * symbolSize={12}\n * />\n * ```\n */\nexport const ScatterChart = createChart<ScatterChartProps>(\n \"scatter\",\n \"ScatterChart\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,eAAe,YAC1B,WACA,eACD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChartColorPalette } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/react/charts/theme.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook to get theme colors with automatic updates on theme change.
|
|
7
|
+
* Re-resolves CSS variables when color scheme or theme attributes change.
|
|
8
|
+
*
|
|
9
|
+
* @param palette - Color palette type: "categorical" (default), "sequential", or "diverging"
|
|
10
|
+
*/
|
|
11
|
+
declare function useThemeColors(palette?: ChartColorPalette): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Hook to get all three color palettes at once.
|
|
14
|
+
* Useful when a component needs access to multiple palette types.
|
|
15
|
+
*/
|
|
16
|
+
declare function useAllThemeColors(): {
|
|
17
|
+
categorical: string[];
|
|
18
|
+
sequential: string[];
|
|
19
|
+
diverging: string[];
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { useAllThemeColors, useThemeColors };
|
|
23
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","names":[],"sources":["../../../src/react/charts/theme.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;iBA0FgB,cAAA,WACL;;;;;iBAuCK,iBAAA,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { CHART_COLOR_VARS_CATEGORICAL, CHART_COLOR_VARS_DIVERGING, CHART_COLOR_VARS_SEQUENTIAL, FALLBACK_COLORS_CATEGORICAL, FALLBACK_COLORS_DIVERGING, FALLBACK_COLORS_SEQUENTIAL } from "./constants.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/react/charts/theme.ts
|
|
5
|
+
const PALETTE_CONFIG = {
|
|
6
|
+
categorical: {
|
|
7
|
+
vars: CHART_COLOR_VARS_CATEGORICAL,
|
|
8
|
+
fallback: FALLBACK_COLORS_CATEGORICAL
|
|
9
|
+
},
|
|
10
|
+
sequential: {
|
|
11
|
+
vars: CHART_COLOR_VARS_SEQUENTIAL,
|
|
12
|
+
fallback: FALLBACK_COLORS_SEQUENTIAL
|
|
13
|
+
},
|
|
14
|
+
diverging: {
|
|
15
|
+
vars: CHART_COLOR_VARS_DIVERGING,
|
|
16
|
+
fallback: FALLBACK_COLORS_DIVERGING
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Cache for computed theme colors to avoid repeated CSS variable lookups.
|
|
21
|
+
* Cache is cleared when theme change events fire (MutationObserver/matchMedia).
|
|
22
|
+
*/
|
|
23
|
+
const colorCache = /* @__PURE__ */ new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Clears the theme color cache.
|
|
26
|
+
* Called when theme change events fire, or for testing when mocks change.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function resetThemeColorCache() {
|
|
30
|
+
colorCache.clear();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets theme colors with module-level caching.
|
|
34
|
+
* Avoids repeated CSS variable lookups for the same palette within a theme.
|
|
35
|
+
*/
|
|
36
|
+
function getThemeColors(palette = "categorical") {
|
|
37
|
+
const config = PALETTE_CONFIG[palette];
|
|
38
|
+
if (typeof window === "undefined") return config.fallback;
|
|
39
|
+
const cached = colorCache.get(palette);
|
|
40
|
+
if (cached) return cached;
|
|
41
|
+
const styles = getComputedStyle(document.documentElement);
|
|
42
|
+
const colors = [];
|
|
43
|
+
for (const varName of config.vars) {
|
|
44
|
+
const value = styles.getPropertyValue(varName).trim();
|
|
45
|
+
if (value) colors.push(value);
|
|
46
|
+
}
|
|
47
|
+
const result = colors.length > 0 ? colors : config.fallback;
|
|
48
|
+
colorCache.set(palette, result);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Hook to get theme colors with automatic updates on theme change.
|
|
53
|
+
* Re-resolves CSS variables when color scheme or theme attributes change.
|
|
54
|
+
*
|
|
55
|
+
* @param palette - Color palette type: "categorical" (default), "sequential", or "diverging"
|
|
56
|
+
*/
|
|
57
|
+
function useThemeColors(palette = "categorical") {
|
|
58
|
+
const [colors, setColors] = useState(() => typeof window === "undefined" ? PALETTE_CONFIG[palette].fallback : getThemeColors(palette));
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const updateColors = () => {
|
|
61
|
+
resetThemeColorCache();
|
|
62
|
+
setColors(getThemeColors(palette));
|
|
63
|
+
};
|
|
64
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
65
|
+
mediaQuery.addEventListener("change", updateColors);
|
|
66
|
+
const observer = new MutationObserver(updateColors);
|
|
67
|
+
observer.observe(document.documentElement, {
|
|
68
|
+
attributes: true,
|
|
69
|
+
attributeFilter: [
|
|
70
|
+
"class",
|
|
71
|
+
"data-theme",
|
|
72
|
+
"data-mode"
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
return () => {
|
|
76
|
+
mediaQuery.removeEventListener("change", updateColors);
|
|
77
|
+
observer.disconnect();
|
|
78
|
+
};
|
|
79
|
+
}, [palette]);
|
|
80
|
+
return colors;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Hook to get all three color palettes at once.
|
|
84
|
+
* Useful when a component needs access to multiple palette types.
|
|
85
|
+
*/
|
|
86
|
+
function useAllThemeColors() {
|
|
87
|
+
return {
|
|
88
|
+
categorical: useThemeColors("categorical"),
|
|
89
|
+
sequential: useThemeColors("sequential"),
|
|
90
|
+
diverging: useThemeColors("diverging")
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { useAllThemeColors, useThemeColors };
|
|
96
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","names":["PALETTE_CONFIG: Record<\n ChartColorPalette,\n { vars: readonly string[]; fallback: string[] }\n>","colors: string[]"],"sources":["../../../src/react/charts/theme.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport {\n CHART_COLOR_VARS_CATEGORICAL,\n CHART_COLOR_VARS_DIVERGING,\n CHART_COLOR_VARS_SEQUENTIAL,\n FALLBACK_COLORS_CATEGORICAL,\n FALLBACK_COLORS_DIVERGING,\n FALLBACK_COLORS_SEQUENTIAL,\n} from \"./constants\";\nimport type { ChartColorPalette } from \"./types\";\n\n// ============================================================================\n// Theme Colors (resolved from CSS variables)\n// ============================================================================\n\nconst PALETTE_CONFIG: Record<\n ChartColorPalette,\n { vars: readonly string[]; fallback: string[] }\n> = {\n categorical: {\n vars: CHART_COLOR_VARS_CATEGORICAL,\n fallback: FALLBACK_COLORS_CATEGORICAL,\n },\n sequential: {\n vars: CHART_COLOR_VARS_SEQUENTIAL,\n fallback: FALLBACK_COLORS_SEQUENTIAL,\n },\n diverging: {\n vars: CHART_COLOR_VARS_DIVERGING,\n fallback: FALLBACK_COLORS_DIVERGING,\n },\n};\n\n// ============================================================================\n// Module-Level Caching\n// ============================================================================\n\n/**\n * Cache for computed theme colors to avoid repeated CSS variable lookups.\n * Cache is cleared when theme change events fire (MutationObserver/matchMedia).\n */\nconst colorCache = new Map<string, string[]>();\n\n/**\n * Clears the theme color cache.\n * Called when theme change events fire, or for testing when mocks change.\n * @internal\n */\nexport function resetThemeColorCache(): void {\n colorCache.clear();\n}\n\n/**\n * Gets theme colors with module-level caching.\n * Avoids repeated CSS variable lookups for the same palette within a theme.\n */\nfunction getThemeColors(palette: ChartColorPalette = \"categorical\"): string[] {\n const config = PALETTE_CONFIG[palette];\n\n if (typeof window === \"undefined\") return config.fallback;\n\n // Return cached colors if available\n const cached = colorCache.get(palette);\n if (cached) {\n return cached;\n }\n\n // Compute colors from CSS variables\n const styles = getComputedStyle(document.documentElement);\n const colors: string[] = [];\n\n for (const varName of config.vars) {\n const value = styles.getPropertyValue(varName).trim();\n if (value) colors.push(value);\n }\n\n const result = colors.length > 0 ? colors : config.fallback;\n\n // Cache the result\n colorCache.set(palette, result);\n\n return result;\n}\n\n/**\n * Hook to get theme colors with automatic updates on theme change.\n * Re-resolves CSS variables when color scheme or theme attributes change.\n *\n * @param palette - Color palette type: \"categorical\" (default), \"sequential\", or \"diverging\"\n */\nexport function useThemeColors(\n palette: ChartColorPalette = \"categorical\",\n): string[] {\n const [colors, setColors] = useState<string[]>(() =>\n typeof window === \"undefined\"\n ? PALETTE_CONFIG[palette].fallback\n : getThemeColors(palette),\n );\n\n useEffect(() => {\n // Clear cache and re-fetch colors when theme changes\n const updateColors = () => {\n resetThemeColorCache();\n setColors(getThemeColors(palette));\n };\n\n // Listen for system color scheme changes\n const mediaQuery = window.matchMedia(\"(prefers-color-scheme: dark)\");\n mediaQuery.addEventListener(\"change\", updateColors);\n\n // Listen for theme attribute changes (e.g., class=\"dark\", data-theme=\"dark\")\n const observer = new MutationObserver(updateColors);\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\", \"data-theme\", \"data-mode\"],\n });\n\n return () => {\n mediaQuery.removeEventListener(\"change\", updateColors);\n observer.disconnect();\n };\n }, [palette]);\n\n return colors;\n}\n\n/**\n * Hook to get all three color palettes at once.\n * Useful when a component needs access to multiple palette types.\n */\nexport function useAllThemeColors(): {\n categorical: string[];\n sequential: string[];\n diverging: string[];\n} {\n const categorical = useThemeColors(\"categorical\");\n const sequential = useThemeColors(\"sequential\");\n const diverging = useThemeColors(\"diverging\");\n\n return { categorical, sequential, diverging };\n}\n"],"mappings":";;;;AAeA,MAAMA,iBAGF;CACF,aAAa;EACX,MAAM;EACN,UAAU;EACX;CACD,YAAY;EACV,MAAM;EACN,UAAU;EACX;CACD,WAAW;EACT,MAAM;EACN,UAAU;EACX;CACF;;;;;AAUD,MAAM,6BAAa,IAAI,KAAuB;;;;;;AAO9C,SAAgB,uBAA6B;AAC3C,YAAW,OAAO;;;;;;AAOpB,SAAS,eAAe,UAA6B,eAAyB;CAC5E,MAAM,SAAS,eAAe;AAE9B,KAAI,OAAO,WAAW,YAAa,QAA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