@matthieumordrel/chart-studio 0.3.0 → 0.5.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/README.md +10 -378
- package/dist/_internal.d.mts +9 -0
- package/dist/_internal.mjs +9 -0
- package/dist/core/chart-builder-controls.mjs +141 -0
- package/dist/core/chart-capabilities.d.mts +5 -0
- package/dist/core/chart-capabilities.mjs +9 -0
- package/dist/core/config-utils.mjs +2 -1
- package/dist/core/dashboard.types.d.mts +220 -0
- package/dist/core/data-label-defaults.d.mts +92 -0
- package/dist/core/data-label-defaults.mjs +78 -0
- package/dist/core/data-model.types.d.mts +196 -0
- package/dist/core/dataset-builder.types.d.mts +51 -0
- package/dist/core/dataset-chart-metadata.d.mts +8 -0
- package/dist/core/dataset-chart-metadata.mjs +4 -0
- package/dist/core/date-range-presets.d.mts +43 -1
- package/dist/core/date-range-presets.mjs +2 -2
- package/dist/core/date-utils.d.mts +26 -0
- package/dist/core/define-dashboard.d.mts +8 -0
- package/dist/core/define-dashboard.mjs +156 -0
- package/dist/core/define-data-model.d.mts +11 -0
- package/dist/core/define-data-model.mjs +327 -0
- package/dist/core/define-dataset.d.mts +13 -0
- package/dist/core/define-dataset.mjs +111 -0
- package/dist/core/formatting.d.mts +49 -0
- package/dist/core/formatting.mjs +32 -10
- package/dist/core/index.d.mts +19 -0
- package/dist/core/infer-columns.mjs +28 -2
- package/dist/core/materialized-view.mjs +580 -0
- package/dist/core/materialized-view.types.d.mts +223 -0
- package/dist/core/metric-utils.d.mts +18 -2
- package/dist/core/metric-utils.mjs +1 -1
- package/dist/core/model-chart.mjs +242 -0
- package/dist/core/model-chart.types.d.mts +199 -0
- package/dist/core/model-inference.mjs +169 -0
- package/dist/core/model-inference.types.d.mts +71 -0
- package/dist/core/pipeline.mjs +32 -1
- package/dist/core/schema-builder.mjs +28 -158
- package/dist/core/schema-builder.types.d.mts +2 -49
- package/dist/core/types.d.mts +61 -10
- package/dist/core/use-chart-options.d.mts +35 -8
- package/dist/core/use-chart-resolvers.mjs +13 -3
- package/dist/core/use-chart.d.mts +16 -12
- package/dist/core/use-chart.mjs +137 -35
- package/dist/core/use-dashboard.d.mts +190 -0
- package/dist/core/use-dashboard.mjs +551 -0
- package/dist/index.d.mts +14 -4
- package/dist/index.mjs +8 -2
- package/package.json +10 -41
- package/LICENSE +0 -21
- package/dist/core/define-chart-schema.d.mts +0 -38
- package/dist/core/define-chart-schema.mjs +0 -39
- package/dist/ui/chart-axis-ticks.mjs +0 -65
- package/dist/ui/chart-canvas.d.mts +0 -33
- package/dist/ui/chart-canvas.mjs +0 -779
- package/dist/ui/chart-context.d.mts +0 -99
- package/dist/ui/chart-context.mjs +0 -115
- package/dist/ui/chart-date-range-badge.d.mts +0 -20
- package/dist/ui/chart-date-range-badge.mjs +0 -49
- package/dist/ui/chart-date-range-panel.d.mts +0 -18
- package/dist/ui/chart-date-range-panel.mjs +0 -126
- package/dist/ui/chart-date-range.d.mts +0 -20
- package/dist/ui/chart-date-range.mjs +0 -67
- package/dist/ui/chart-debug.d.mts +0 -21
- package/dist/ui/chart-debug.mjs +0 -173
- package/dist/ui/chart-dropdown.mjs +0 -92
- package/dist/ui/chart-filters-panel.d.mts +0 -26
- package/dist/ui/chart-filters-panel.mjs +0 -132
- package/dist/ui/chart-filters.d.mts +0 -18
- package/dist/ui/chart-filters.mjs +0 -48
- package/dist/ui/chart-group-by-selector.d.mts +0 -16
- package/dist/ui/chart-group-by-selector.mjs +0 -32
- package/dist/ui/chart-metric-panel.d.mts +0 -25
- package/dist/ui/chart-metric-panel.mjs +0 -172
- package/dist/ui/chart-metric-selector.d.mts +0 -16
- package/dist/ui/chart-metric-selector.mjs +0 -50
- package/dist/ui/chart-select.mjs +0 -61
- package/dist/ui/chart-source-switcher.d.mts +0 -24
- package/dist/ui/chart-source-switcher.mjs +0 -56
- package/dist/ui/chart-time-bucket-selector.d.mts +0 -17
- package/dist/ui/chart-time-bucket-selector.mjs +0 -37
- package/dist/ui/chart-toolbar-overflow.d.mts +0 -28
- package/dist/ui/chart-toolbar-overflow.mjs +0 -231
- package/dist/ui/chart-toolbar.d.mts +0 -33
- package/dist/ui/chart-toolbar.mjs +0 -60
- package/dist/ui/chart-type-selector.d.mts +0 -19
- package/dist/ui/chart-type-selector.mjs +0 -168
- package/dist/ui/chart-x-axis-selector.d.mts +0 -16
- package/dist/ui/chart-x-axis-selector.mjs +0 -28
- package/dist/ui/index.d.mts +0 -19
- package/dist/ui/index.mjs +0 -18
- package/dist/ui/percent-stacked.mjs +0 -36
- package/dist/ui/theme.css +0 -67
- package/dist/ui/toolbar-types.d.mts +0 -7
- package/dist/ui/toolbar-types.mjs +0 -83
package/dist/ui/chart-debug.mjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { applyFilters } from "../core/pipeline.mjs";
|
|
2
|
-
import { computeDateRange, filterByDateRange } from "../core/date-utils.mjs";
|
|
3
|
-
import { useChartContext } from "./chart-context.mjs";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
//#region src/ui/chart-debug.tsx
|
|
7
|
-
/**
|
|
8
|
-
* Debug panel — shows raw data, transformed data, series, and current state.
|
|
9
|
-
* Drop `<ChartDebug />` inside a `<Chart>` to inspect what's happening.
|
|
10
|
-
*/
|
|
11
|
-
const TABS = [
|
|
12
|
-
{
|
|
13
|
-
id: "raw",
|
|
14
|
-
label: "Raw"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: "transformed",
|
|
18
|
-
label: "Transformed"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
id: "series",
|
|
22
|
-
label: "Series"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: "state",
|
|
26
|
-
label: "State"
|
|
27
|
-
}
|
|
28
|
-
];
|
|
29
|
-
/**
|
|
30
|
-
* Format a date as a full calendar label to avoid ambiguous numeric dates.
|
|
31
|
-
*/
|
|
32
|
-
function formatFullDay(date) {
|
|
33
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
34
|
-
month: "long",
|
|
35
|
-
day: "numeric",
|
|
36
|
-
year: "numeric",
|
|
37
|
-
timeZone: "UTC"
|
|
38
|
-
}).format(date);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get the exact earliest and latest visible dates for the active date X-axis.
|
|
42
|
-
*/
|
|
43
|
-
function getVisibleDateRange(chart) {
|
|
44
|
-
if (!chart.isTimeSeries || !chart.xAxisId) return null;
|
|
45
|
-
const xAxisColumn = chart.columns.find((column) => column.id === chart.xAxisId);
|
|
46
|
-
if (!xAxisColumn || xAxisColumn.type !== "date") return null;
|
|
47
|
-
let visibleData = chart.rawData;
|
|
48
|
-
if (chart.dateRangeFilter && chart.referenceDateId) {
|
|
49
|
-
const referenceDateColumn = chart.columns.find((column) => column.id === chart.referenceDateId);
|
|
50
|
-
if (referenceDateColumn?.type === "date") visibleData = filterByDateRange(visibleData, referenceDateColumn, chart.dateRangeFilter);
|
|
51
|
-
}
|
|
52
|
-
visibleData = applyFilters(visibleData, chart.columns, chart.filters);
|
|
53
|
-
const { min, max } = computeDateRange(visibleData, xAxisColumn);
|
|
54
|
-
if (!min || !max) return null;
|
|
55
|
-
return {
|
|
56
|
-
columnId: xAxisColumn.id,
|
|
57
|
-
columnLabel: xAxisColumn.label,
|
|
58
|
-
earliest: { label: formatFullDay(min) },
|
|
59
|
-
latest: { label: formatFullDay(max) },
|
|
60
|
-
rule: "Uses exact dates from visible rows on the active X-axis date column."
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Build a compact UI label for the visible time range.
|
|
65
|
-
*/
|
|
66
|
-
function getVisibleDateRangeLabel(range) {
|
|
67
|
-
if (!range) return null;
|
|
68
|
-
const columnLabel = `${range.columnLabel} (${range.columnId})`;
|
|
69
|
-
if (range.earliest.label === range.latest.label) return `Visible exact date: ${range.earliest.label} via ${columnLabel}`;
|
|
70
|
-
return `Visible exact date range: ${range.earliest.label} -> ${range.latest.label} via ${columnLabel}`;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Resolve the currently selected debug payload.
|
|
74
|
-
*/
|
|
75
|
-
function getDebugContent(chart, activeTab) {
|
|
76
|
-
switch (activeTab) {
|
|
77
|
-
case "raw": return chart.rawData;
|
|
78
|
-
case "transformed": return chart.transformedData;
|
|
79
|
-
case "series": return chart.series;
|
|
80
|
-
case "state": return {
|
|
81
|
-
activeSourceId: chart.activeSourceId,
|
|
82
|
-
chartType: chart.chartType,
|
|
83
|
-
xAxisId: chart.xAxisId,
|
|
84
|
-
groupById: chart.groupById,
|
|
85
|
-
metric: chart.metric,
|
|
86
|
-
timeBucket: chart.timeBucket,
|
|
87
|
-
availableTimeBuckets: chart.availableTimeBuckets,
|
|
88
|
-
isTimeSeries: chart.isTimeSeries,
|
|
89
|
-
filters: Object.fromEntries([...chart.filters.entries()].map(([k, v]) => [k, [...v]])),
|
|
90
|
-
sorting: chart.sorting,
|
|
91
|
-
availableChartTypes: chart.availableChartTypes,
|
|
92
|
-
availableGroupBys: chart.availableGroupBys,
|
|
93
|
-
availableMetrics: chart.availableMetrics,
|
|
94
|
-
columns: chart.columns,
|
|
95
|
-
availableFilters: chart.availableFilters.map((filter) => ({
|
|
96
|
-
...filter,
|
|
97
|
-
options: filter.options.length > 5 ? [...filter.options.slice(0, 5), {
|
|
98
|
-
value: "...",
|
|
99
|
-
label: `+${filter.options.length - 5} more`,
|
|
100
|
-
count: 0
|
|
101
|
-
}] : filter.options
|
|
102
|
-
})),
|
|
103
|
-
visibleDateRange: getVisibleDateRange(chart)
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/** Tab bar button. */
|
|
108
|
-
function TabButton({ tab, isActive, onClick }) {
|
|
109
|
-
return /* @__PURE__ */ jsx("button", {
|
|
110
|
-
onClick,
|
|
111
|
-
className: `border-b-2 px-3 py-1.5 text-[11px] font-mono transition-colors ${isActive ? "border-primary bg-primary/10 text-primary" : "border-transparent text-muted-foreground hover:text-foreground"}`,
|
|
112
|
-
children: tab.label
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/** Debug panel that renders chart internals as formatted JSON.
|
|
116
|
-
*
|
|
117
|
-
* @param className - Additional CSS classes for the debug panel.
|
|
118
|
-
* @param defaultOpen - Whether the debug panel should be open by default. (default: false)
|
|
119
|
-
*/
|
|
120
|
-
function ChartDebug({ className, defaultOpen = false }) {
|
|
121
|
-
const chart = useChartContext();
|
|
122
|
-
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
123
|
-
const [activeTab, setActiveTab] = useState("raw");
|
|
124
|
-
const content = getDebugContent(chart, activeTab);
|
|
125
|
-
const visibleDateRangeLabel = getVisibleDateRangeLabel(getVisibleDateRange(chart));
|
|
126
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
127
|
-
className: `overflow-hidden rounded-lg border border-dashed border-border bg-background ${className ?? ""}`,
|
|
128
|
-
children: [/* @__PURE__ */ jsx("button", {
|
|
129
|
-
onClick: () => setIsOpen(!isOpen),
|
|
130
|
-
className: "flex w-full items-center gap-2 px-3 py-2 text-left text-xs font-mono text-foreground transition-colors hover:bg-muted/50",
|
|
131
|
-
children: /* @__PURE__ */ jsxs("span", {
|
|
132
|
-
className: "flex items-center gap-2",
|
|
133
|
-
children: [
|
|
134
|
-
/* @__PURE__ */ jsx("span", { children: isOpen ? "▼" : "▶" }),
|
|
135
|
-
/* @__PURE__ */ jsx("span", { children: "chart-studio debug" }),
|
|
136
|
-
/* @__PURE__ */ jsxs("span", {
|
|
137
|
-
className: "text-muted-foreground",
|
|
138
|
-
children: [
|
|
139
|
-
"(",
|
|
140
|
-
chart.rawData.length,
|
|
141
|
-
" raw, ",
|
|
142
|
-
chart.transformedData.length,
|
|
143
|
-
" points, ",
|
|
144
|
-
chart.series.length,
|
|
145
|
-
" ",
|
|
146
|
-
"series)"
|
|
147
|
-
]
|
|
148
|
-
}),
|
|
149
|
-
visibleDateRangeLabel ? /* @__PURE__ */ jsxs("span", {
|
|
150
|
-
className: "text-[11px] text-muted-foreground",
|
|
151
|
-
children: ["• ", visibleDateRangeLabel]
|
|
152
|
-
}) : null
|
|
153
|
-
]
|
|
154
|
-
})
|
|
155
|
-
}), isOpen && /* @__PURE__ */ jsxs("div", {
|
|
156
|
-
className: "border-t border-dashed border-border",
|
|
157
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
158
|
-
className: "flex gap-0 border-b border-border bg-muted/20",
|
|
159
|
-
children: TABS.map((tab) => /* @__PURE__ */ jsx(TabButton, {
|
|
160
|
-
tab,
|
|
161
|
-
isActive: activeTab === tab.id,
|
|
162
|
-
onClick: () => setActiveTab(tab.id)
|
|
163
|
-
}, tab.id))
|
|
164
|
-
}), /* @__PURE__ */ jsx("pre", {
|
|
165
|
-
className: "max-h-64 overflow-auto bg-muted/20 p-3 font-mono text-[11px] leading-relaxed text-foreground",
|
|
166
|
-
onWheel: (e) => e.stopPropagation(),
|
|
167
|
-
children: JSON.stringify(content, null, 2)
|
|
168
|
-
})]
|
|
169
|
-
})]
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
//#endregion
|
|
173
|
-
export { ChartDebug };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createPortal } from "react-dom";
|
|
4
|
-
//#region src/ui/chart-dropdown.tsx
|
|
5
|
-
/**
|
|
6
|
-
* Shared dropdown panel primitive for chart-studio popover controls.
|
|
7
|
-
* Provides a positioned floating panel with backdrop, premium layered
|
|
8
|
-
* shadows, and close-on-click-outside.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Positioned dropdown panel with premium styling.
|
|
12
|
-
* Renders a transparent backdrop overlay and a fixed-position content panel
|
|
13
|
-
* anchored to a trigger element.
|
|
14
|
-
*
|
|
15
|
-
* @property isOpen - Whether the panel is visible
|
|
16
|
-
* @property onClose - Callback to close the panel
|
|
17
|
-
* @property triggerRef - Ref to the button or element that anchors the panel
|
|
18
|
-
* @property align - Horizontal alignment relative to trigger ('left' | 'right')
|
|
19
|
-
* @property width - Fixed panel width in pixels
|
|
20
|
-
* @property minWidth - Minimum panel width in pixels or equal to trigger width
|
|
21
|
-
* @property offset - Gap between trigger and panel
|
|
22
|
-
* @property repositionKey - Value that forces re-measurement when panel content changes
|
|
23
|
-
* @property className - Additional CSS classes for the content area
|
|
24
|
-
* @property children - Panel content
|
|
25
|
-
*/
|
|
26
|
-
function ChartDropdownPanel({ isOpen, onClose, triggerRef, align = "left", width, minWidth, offset = 6, repositionKey, className, children }) {
|
|
27
|
-
const panelRef = useRef(null);
|
|
28
|
-
const [position, setPosition] = useState(null);
|
|
29
|
-
useLayoutEffect(() => {
|
|
30
|
-
if (!isOpen) {
|
|
31
|
-
setPosition(null);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Measure the trigger and panel, then place the panel in the best
|
|
36
|
-
* available viewport position.
|
|
37
|
-
*/
|
|
38
|
-
function updatePosition() {
|
|
39
|
-
const trigger = triggerRef.current;
|
|
40
|
-
const panel = panelRef.current;
|
|
41
|
-
if (!trigger || !panel) return;
|
|
42
|
-
const triggerRect = trigger.getBoundingClientRect();
|
|
43
|
-
const measuredPanelWidth = width ?? panel.offsetWidth;
|
|
44
|
-
const resolvedMinWidth = minWidth === "trigger" ? triggerRect.width : minWidth;
|
|
45
|
-
const panelWidth = Math.max(measuredPanelWidth, resolvedMinWidth ?? 0);
|
|
46
|
-
const panelHeight = panel.offsetHeight;
|
|
47
|
-
let left = align === "right" ? triggerRect.right - panelWidth : triggerRect.left;
|
|
48
|
-
left = Math.min(Math.max(left, 8), window.innerWidth - panelWidth - 8);
|
|
49
|
-
let top = window.innerHeight - triggerRect.bottom < panelHeight + offset && triggerRect.top >= panelHeight + offset ? triggerRect.top - panelHeight - offset : triggerRect.bottom + offset;
|
|
50
|
-
top = Math.max(8, Math.min(top, window.innerHeight - panelHeight - 8));
|
|
51
|
-
setPosition({
|
|
52
|
-
top,
|
|
53
|
-
left
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
updatePosition();
|
|
57
|
-
window.addEventListener("resize", updatePosition);
|
|
58
|
-
window.addEventListener("scroll", updatePosition, true);
|
|
59
|
-
return () => {
|
|
60
|
-
window.removeEventListener("resize", updatePosition);
|
|
61
|
-
window.removeEventListener("scroll", updatePosition, true);
|
|
62
|
-
};
|
|
63
|
-
}, [
|
|
64
|
-
align,
|
|
65
|
-
isOpen,
|
|
66
|
-
minWidth,
|
|
67
|
-
offset,
|
|
68
|
-
repositionKey,
|
|
69
|
-
triggerRef,
|
|
70
|
-
width
|
|
71
|
-
]);
|
|
72
|
-
if (!isOpen) return null;
|
|
73
|
-
if (typeof document === "undefined") return null;
|
|
74
|
-
return createPortal(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
75
|
-
className: "fixed inset-0 z-40",
|
|
76
|
-
onClick: onClose
|
|
77
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
78
|
-
ref: panelRef,
|
|
79
|
-
className: `fixed z-50 overflow-hidden rounded-xl border border-border/50 bg-popover text-popover-foreground shadow-[0_8px_30px_-6px_rgba(0,0,0,0.12),0_2px_8px_-2px_rgba(0,0,0,0.05)] ${className ?? ""}`,
|
|
80
|
-
style: {
|
|
81
|
-
top: position?.top ?? 0,
|
|
82
|
-
left: position?.left ?? 0,
|
|
83
|
-
width,
|
|
84
|
-
minWidth: minWidth === "trigger" ? triggerRef.current?.getBoundingClientRect().width : minWidth,
|
|
85
|
-
visibility: position ? "visible" : "hidden"
|
|
86
|
-
},
|
|
87
|
-
onWheel: (e) => e.stopPropagation(),
|
|
88
|
-
children
|
|
89
|
-
})] }), document.body);
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
export { ChartDropdownPanel };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/ui/chart-filters-panel.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Filters panel content — reusable by both ChartFilters (inside a popover)
|
|
6
|
-
* and ChartToolbarOverflow (rendered inline).
|
|
7
|
-
*
|
|
8
|
-
* Shows filterable columns as collapsible sections with checkbox options.
|
|
9
|
-
* Each column section can be expanded/collapsed independently.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Filters panel content (no popover wrapper).
|
|
13
|
-
*
|
|
14
|
-
* @property className - Additional CSS classes
|
|
15
|
-
* @property showHeader - When true (default), shows "X filter(s) active · Filters" + clear icon.
|
|
16
|
-
* Set false when the header is rendered by the parent (e.g. overflow DetailPage).
|
|
17
|
-
*/
|
|
18
|
-
declare function ChartFiltersPanel({
|
|
19
|
-
className,
|
|
20
|
-
showHeader
|
|
21
|
-
}: {
|
|
22
|
-
className?: string;
|
|
23
|
-
showHeader?: boolean;
|
|
24
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { ChartFiltersPanel };
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { useChartContext } from "./chart-context.mjs";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
import { ChevronDown, Eraser } from "lucide-react";
|
|
5
|
-
//#region src/ui/chart-filters-panel.tsx
|
|
6
|
-
/**
|
|
7
|
-
* Filters panel content — reusable by both ChartFilters (inside a popover)
|
|
8
|
-
* and ChartToolbarOverflow (rendered inline).
|
|
9
|
-
*
|
|
10
|
-
* Shows filterable columns as collapsible sections with checkbox options.
|
|
11
|
-
* Each column section can be expanded/collapsed independently.
|
|
12
|
-
*/
|
|
13
|
-
/** Maximum number of options to show per column before collapsing. */
|
|
14
|
-
const MAX_VISIBLE_OPTIONS = 6;
|
|
15
|
-
/**
|
|
16
|
-
* Filters panel content (no popover wrapper).
|
|
17
|
-
*
|
|
18
|
-
* @property className - Additional CSS classes
|
|
19
|
-
* @property showHeader - When true (default), shows "X filter(s) active · Filters" + clear icon.
|
|
20
|
-
* Set false when the header is rendered by the parent (e.g. overflow DetailPage).
|
|
21
|
-
*/
|
|
22
|
-
function ChartFiltersPanel({ className, showHeader = true }) {
|
|
23
|
-
const { availableFilters, filters, toggleFilter, clearAllFilters } = useChartContext();
|
|
24
|
-
const activeCount = [...filters.values()].reduce((sum, set) => sum + set.size, 0);
|
|
25
|
-
if (availableFilters.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
26
|
-
className,
|
|
27
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
28
|
-
className: "py-6 text-center text-xs text-muted-foreground",
|
|
29
|
-
children: "No filterable columns"
|
|
30
|
-
})
|
|
31
|
-
});
|
|
32
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
33
|
-
className,
|
|
34
|
-
children: [showHeader && /* @__PURE__ */ jsxs("div", {
|
|
35
|
-
className: "mb-3 flex items-center justify-between gap-2",
|
|
36
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
37
|
-
className: "truncate text-xs font-semibold text-foreground",
|
|
38
|
-
children: [activeCount > 0 && /* @__PURE__ */ jsxs("span", {
|
|
39
|
-
className: "text-muted-foreground",
|
|
40
|
-
children: [
|
|
41
|
-
activeCount,
|
|
42
|
-
" filter",
|
|
43
|
-
activeCount !== 1 ? "s" : "",
|
|
44
|
-
" active ·",
|
|
45
|
-
" "
|
|
46
|
-
]
|
|
47
|
-
}), "Filters"]
|
|
48
|
-
}), activeCount > 0 && /* @__PURE__ */ jsx("button", {
|
|
49
|
-
onClick: () => clearAllFilters(),
|
|
50
|
-
className: "shrink-0 rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
|
|
51
|
-
"aria-label": "Clear all filters",
|
|
52
|
-
children: /* @__PURE__ */ jsx(Eraser, { className: "h-3.5 w-3.5" })
|
|
53
|
-
})]
|
|
54
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
55
|
-
className: "space-y-1",
|
|
56
|
-
children: availableFilters.map((filter) => /* @__PURE__ */ jsx(FilterSection, {
|
|
57
|
-
filter,
|
|
58
|
-
activeValues: filters.get(filter.columnId),
|
|
59
|
-
onToggle: (value) => toggleFilter(filter.columnId, value)
|
|
60
|
-
}, filter.columnId))
|
|
61
|
-
})]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
/** A collapsible filter column section with checkable options. */
|
|
65
|
-
function FilterSection({ filter, activeValues, onToggle }) {
|
|
66
|
-
const [isOpen, setIsOpen] = useState(true);
|
|
67
|
-
const [expanded, setExpanded] = useState(false);
|
|
68
|
-
const visibleOptions = expanded ? filter.options : filter.options.slice(0, MAX_VISIBLE_OPTIONS);
|
|
69
|
-
const hasMore = filter.options.length > MAX_VISIBLE_OPTIONS;
|
|
70
|
-
const activeCount = activeValues?.size ?? 0;
|
|
71
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
72
|
-
className: "rounded-lg",
|
|
73
|
-
children: [/* @__PURE__ */ jsxs("button", {
|
|
74
|
-
onClick: () => setIsOpen(!isOpen),
|
|
75
|
-
className: "flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-muted/50",
|
|
76
|
-
children: [
|
|
77
|
-
/* @__PURE__ */ jsx(ChevronDown, { className: `h-3 w-3 shrink-0 text-muted-foreground transition-transform ${isOpen ? "" : "-rotate-90"}` }),
|
|
78
|
-
/* @__PURE__ */ jsx("span", {
|
|
79
|
-
className: "text-[11px] font-semibold text-foreground",
|
|
80
|
-
children: filter.label
|
|
81
|
-
}),
|
|
82
|
-
activeCount > 0 && /* @__PURE__ */ jsx("span", {
|
|
83
|
-
className: "ml-auto flex h-4 min-w-4 items-center justify-center rounded-full bg-primary/10 px-1.5 text-[9px] font-semibold text-primary",
|
|
84
|
-
children: activeCount
|
|
85
|
-
})
|
|
86
|
-
]
|
|
87
|
-
}), isOpen && /* @__PURE__ */ jsxs("div", {
|
|
88
|
-
className: "pb-1 pl-2 pr-1 pt-0.5",
|
|
89
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
90
|
-
className: "space-y-px",
|
|
91
|
-
children: visibleOptions.map((option) => {
|
|
92
|
-
const isActive = activeValues?.has(option.value) ?? false;
|
|
93
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
94
|
-
onClick: () => onToggle(option.value),
|
|
95
|
-
className: `flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-xs transition-colors ${isActive ? "bg-primary/8 text-primary" : "text-foreground hover:bg-muted/60"}`,
|
|
96
|
-
children: [
|
|
97
|
-
/* @__PURE__ */ jsx("div", {
|
|
98
|
-
className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-colors ${isActive ? "border-primary bg-primary" : "border-muted-foreground/30 bg-background"}`,
|
|
99
|
-
children: isActive && /* @__PURE__ */ jsx("svg", {
|
|
100
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
101
|
-
width: "10",
|
|
102
|
-
height: "10",
|
|
103
|
-
viewBox: "0 0 24 24",
|
|
104
|
-
fill: "none",
|
|
105
|
-
stroke: "white",
|
|
106
|
-
strokeWidth: "3",
|
|
107
|
-
strokeLinecap: "round",
|
|
108
|
-
strokeLinejoin: "round",
|
|
109
|
-
children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" })
|
|
110
|
-
})
|
|
111
|
-
}),
|
|
112
|
-
/* @__PURE__ */ jsx("span", {
|
|
113
|
-
className: "flex-1 truncate",
|
|
114
|
-
children: option.label
|
|
115
|
-
}),
|
|
116
|
-
/* @__PURE__ */ jsx("span", {
|
|
117
|
-
className: "shrink-0 tabular-nums text-[10px] text-muted-foreground/70",
|
|
118
|
-
children: option.count
|
|
119
|
-
})
|
|
120
|
-
]
|
|
121
|
-
}, option.value);
|
|
122
|
-
})
|
|
123
|
-
}), hasMore && /* @__PURE__ */ jsx("button", {
|
|
124
|
-
onClick: () => setExpanded(!expanded),
|
|
125
|
-
className: "mt-1 w-full rounded-md px-2 py-1 text-left text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground",
|
|
126
|
-
children: expanded ? "Show less" : `Show ${filter.options.length - MAX_VISIBLE_OPTIONS} more…`
|
|
127
|
-
})]
|
|
128
|
-
})]
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
export { ChartFiltersPanel };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/ui/chart-filters.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Chart filters — compact button that shows active filter count.
|
|
6
|
-
* Clicking reveals a popover wrapping ChartFiltersPanel.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Compact filter button + dropdown for all filterable columns.
|
|
10
|
-
* Shows a count badge when filters are active.
|
|
11
|
-
*/
|
|
12
|
-
declare function ChartFilters({
|
|
13
|
-
className
|
|
14
|
-
}: {
|
|
15
|
-
className?: string;
|
|
16
|
-
}): react_jsx_runtime0.JSX.Element | null;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { ChartFilters };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useChartContext } from "./chart-context.mjs";
|
|
2
|
-
import { ChartDropdownPanel } from "./chart-dropdown.mjs";
|
|
3
|
-
import { ChartFiltersPanel } from "./chart-filters-panel.mjs";
|
|
4
|
-
import { useRef, useState } from "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { Filter } from "lucide-react";
|
|
7
|
-
//#region src/ui/chart-filters.tsx
|
|
8
|
-
/**
|
|
9
|
-
* Chart filters — compact button that shows active filter count.
|
|
10
|
-
* Clicking reveals a popover wrapping ChartFiltersPanel.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Compact filter button + dropdown for all filterable columns.
|
|
14
|
-
* Shows a count badge when filters are active.
|
|
15
|
-
*/
|
|
16
|
-
function ChartFilters({ className }) {
|
|
17
|
-
const { availableFilters, filters } = useChartContext();
|
|
18
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
19
|
-
const triggerRef = useRef(null);
|
|
20
|
-
if (availableFilters.length === 0) return null;
|
|
21
|
-
const activeCount = [...filters.values()].reduce((sum, set) => sum + set.size, 0);
|
|
22
|
-
const isActive = activeCount > 0;
|
|
23
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
24
|
-
className,
|
|
25
|
-
children: [/* @__PURE__ */ jsxs("button", {
|
|
26
|
-
ref: triggerRef,
|
|
27
|
-
onClick: () => setIsOpen(!isOpen),
|
|
28
|
-
className: `inline-flex h-7 items-center gap-1.5 rounded-lg border px-2.5 text-xs font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/20 ${isActive ? "border-primary/30 bg-primary/5 text-primary shadow-sm shadow-primary/5 hover:bg-primary/8" : "border-border/50 bg-background text-muted-foreground shadow-sm hover:border-border hover:bg-muted/30 hover:shadow hover:text-foreground"}`,
|
|
29
|
-
children: [
|
|
30
|
-
/* @__PURE__ */ jsx(Filter, { className: "h-3 w-3" }),
|
|
31
|
-
"Filters",
|
|
32
|
-
isActive && /* @__PURE__ */ jsx("span", {
|
|
33
|
-
className: "flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold text-primary-foreground",
|
|
34
|
-
children: activeCount
|
|
35
|
-
})
|
|
36
|
-
]
|
|
37
|
-
}), /* @__PURE__ */ jsx(ChartDropdownPanel, {
|
|
38
|
-
isOpen,
|
|
39
|
-
onClose: () => setIsOpen(false),
|
|
40
|
-
triggerRef,
|
|
41
|
-
width: 288,
|
|
42
|
-
className: "max-h-[420px] overflow-y-auto overscroll-contain p-3",
|
|
43
|
-
children: /* @__PURE__ */ jsx(ChartFiltersPanel, {})
|
|
44
|
-
})]
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
export { ChartFilters };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/ui/chart-group-by-selector.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* GroupBy selector — premium custom dropdown replacing native <select>.
|
|
6
|
-
*/
|
|
7
|
-
/** Custom dropdown to select the groupBy column. */
|
|
8
|
-
declare function ChartGroupBySelector({
|
|
9
|
-
className,
|
|
10
|
-
hideIcon
|
|
11
|
-
}: {
|
|
12
|
-
className?: string;
|
|
13
|
-
hideIcon?: boolean;
|
|
14
|
-
}): react_jsx_runtime0.JSX.Element | null;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { ChartGroupBySelector };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { CHART_TYPE_CONFIG } from "../core/chart-capabilities.mjs";
|
|
2
|
-
import { useChartContext } from "./chart-context.mjs";
|
|
3
|
-
import { ChartSelect } from "./chart-select.mjs";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { Layers } from "lucide-react";
|
|
6
|
-
//#region src/ui/chart-group-by-selector.tsx
|
|
7
|
-
/**
|
|
8
|
-
* GroupBy selector — premium custom dropdown replacing native <select>.
|
|
9
|
-
*/
|
|
10
|
-
/** Custom dropdown to select the groupBy column. */
|
|
11
|
-
function ChartGroupBySelector({ className, hideIcon }) {
|
|
12
|
-
const { chartType, groupById, setGroupBy, availableGroupBys } = useChartContext();
|
|
13
|
-
if (!CHART_TYPE_CONFIG[chartType].supportsGrouping || availableGroupBys.length === 0) return null;
|
|
14
|
-
const options = [{
|
|
15
|
-
value: "",
|
|
16
|
-
label: "No grouping"
|
|
17
|
-
}, ...availableGroupBys.map((col) => ({
|
|
18
|
-
value: col.id,
|
|
19
|
-
label: col.label
|
|
20
|
-
}))];
|
|
21
|
-
return /* @__PURE__ */ jsx(ChartSelect, {
|
|
22
|
-
value: groupById ?? "",
|
|
23
|
-
options,
|
|
24
|
-
onChange: (v) => setGroupBy(v || null),
|
|
25
|
-
ariaLabel: "Group by",
|
|
26
|
-
icon: Layers,
|
|
27
|
-
hideIcon,
|
|
28
|
-
className
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { ChartGroupBySelector };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/ui/chart-metric-panel.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Metric panel content — reusable by both ChartMetricSelector (inside a popover)
|
|
6
|
-
* and ChartToolbarOverflow (rendered inline).
|
|
7
|
-
*
|
|
8
|
-
* Shows a "Count" option plus grouped number columns with aggregate buttons
|
|
9
|
-
* (Sum, Avg, Min, Max) and an "Exclude zeros" toggle per column.
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Metric panel content (no popover wrapper).
|
|
13
|
-
*
|
|
14
|
-
* @property onClose - Optional callback when user makes a definitive selection (e.g. "Count")
|
|
15
|
-
* @property className - Additional CSS classes
|
|
16
|
-
*/
|
|
17
|
-
declare function ChartMetricPanel({
|
|
18
|
-
onClose,
|
|
19
|
-
className
|
|
20
|
-
}: {
|
|
21
|
-
onClose?: () => void;
|
|
22
|
-
className?: string;
|
|
23
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
24
|
-
//#endregion
|
|
25
|
-
export { ChartMetricPanel };
|