@altertable/data-app-react 0.73.0 → 0.74.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/chunks/{SectionHeading-CVenpddF.js → SectionHeading-DYRGGLUr.js} +455 -281
- package/dist/chunks/SectionHeading-DYRGGLUr.js.map +1 -0
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/types/chunks/date-formatting.d.ts +2 -1
- package/dist/types/index.d.ts +8 -4
- package/dist/types/ui/index.d.ts +22 -3
- package/dist/ui/index.js +92 -18
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/SectionHeading-CVenpddF.js.map +0 -1
package/dist/ui/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as FilterBar, $t as PressButton, A as LiveControl, B as isPlainKeyEvent, Bt as useViewTab, E as DataAppFrame, F as MenuSeparator, Ft as Tab, G as FilterActions, Gt as TooltipSurface, Ht as GradientScroll, I as MenuTrigger, It as TabList, J as NumberFilterPicker, K as SearchTypeahead, Lt as TabPanel, M as MenuItem, Mt as DataAppProvider, N as MenuPopover, Ot as ShimmerText, P as MenuSection, Pt as AboutData, Q as Select, Qt as Button$1, Rt as TabPanels, S as withWidgetBoundary, St as HelpPopover, T as DataValue, U as useDeclaredResult, Ut as Tooltip, V as createDataHooks, Vt as Sheet, W as VariableBar, Wt as TooltipProvider, X as NumberRangeField, Xt as AppIcon, Y as NumberField, Z as DimensionPicker, _ as explorationMenuEvents, a as TextWidget$1, at as SearchMatch, b as useChartActions, bt as DateDisplay, c as DataTableEmptyRow, ct as searchItems, d as MetricWidget$1, en as classNames, et as DateRangePicker, f as VisualizationWidget$1, g as ExplorationActionMenu, h as ExplorationActionControl, in as injectDataAppStyles, j as Menu, k as PresentStory, l as DataTableShare, n as createDataContext, nn as useDateFormatting, nt as CheckboxGroupContext, o as TableWidget$1, pt as useAppVariables, q as SearchField, r as chartBarFill, rt as ChoicePicker, s as DataTable, st as matchSearchText, t as SectionHeading, tt as Checkbox, u as DataTableTimestamp, v as getPrimaryExplorationAction, x as DataWidget, y as openExplorationMenu, zt as Tabs } from "../chunks/SectionHeading-DYRGGLUr.js";
|
|
2
2
|
import { createDataClient } from "@altertable/data-app/client";
|
|
3
3
|
import { KEY_SEPARATOR, invariant, validateChoiceOptions } from "@altertable/data-app/internal";
|
|
4
4
|
import { Children, Fragment, createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { Label, Radio as Radio$1, RadioGroup as RadioGroup$1 } from "react-aria-components";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { formatDate, formatDateTime, formatNumber, formatPercent, parseDateTime } from "@altertable/data-app/format";
|
|
8
|
-
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, usePlotArea } from "recharts";
|
|
7
|
+
import { formatDate, formatDateTime, formatMetric, formatNumber, formatPercent, parseDateTime } from "@altertable/data-app/format";
|
|
8
|
+
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, usePlotArea, useYAxisTicks } from "recharts";
|
|
9
9
|
//#region src/ui/StaticDataApp.tsx
|
|
10
10
|
/** Setup and static screens; fetched data uses the declared-view DataApp. */
|
|
11
11
|
function DataApp(props) {
|
|
@@ -753,15 +753,32 @@ function ChartDateAxes({ data, children }) {
|
|
|
753
753
|
return next;
|
|
754
754
|
});
|
|
755
755
|
}, []);
|
|
756
|
+
const [barAxes, setBarAxes] = useState(() => /* @__PURE__ */ new Map());
|
|
757
|
+
const registerBar = useCallback((id) => {
|
|
758
|
+
setBarAxes((current) => new Map(current).set(id, (current.get(id) ?? 0) + 1));
|
|
759
|
+
return () => setBarAxes((current) => {
|
|
760
|
+
const next = new Map(current);
|
|
761
|
+
const count = (next.get(id) ?? 1) - 1;
|
|
762
|
+
if (count) next.set(id, count);
|
|
763
|
+
else next.delete(id);
|
|
764
|
+
return next;
|
|
765
|
+
});
|
|
766
|
+
}, []);
|
|
756
767
|
return /* @__PURE__ */ jsx(ChartDateAxesContext.Provider, {
|
|
757
768
|
value: {
|
|
758
769
|
data,
|
|
759
770
|
formatters,
|
|
760
|
-
register
|
|
771
|
+
register,
|
|
772
|
+
barAxes,
|
|
773
|
+
registerBar
|
|
761
774
|
},
|
|
762
775
|
children
|
|
763
776
|
});
|
|
764
777
|
}
|
|
778
|
+
function useDateAxisBar(id = 0) {
|
|
779
|
+
const registerBar = useContext(ChartDateAxesContext)?.registerBar;
|
|
780
|
+
useLayoutEffect(() => registerBar?.(id), [registerBar, id]);
|
|
781
|
+
}
|
|
765
782
|
function useDateAxisLabel(id = 0) {
|
|
766
783
|
return useContext(ChartDateAxesContext)?.formatters.get(id);
|
|
767
784
|
}
|
|
@@ -771,6 +788,7 @@ function field(row, key) {
|
|
|
771
788
|
return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : void 0, row);
|
|
772
789
|
}
|
|
773
790
|
const xAxisDefaults = {
|
|
791
|
+
interval: "preserveStartEnd",
|
|
774
792
|
stroke: "var(--atbl-muted)",
|
|
775
793
|
tickFormatter: (value) => typeof value === "number" ? formatNumber(value) : String(value),
|
|
776
794
|
tickLine: false,
|
|
@@ -813,7 +831,7 @@ function ChartXAxis(props) {
|
|
|
813
831
|
return /* @__PURE__ */ jsx(XAxis, {
|
|
814
832
|
...xAxisDefaults,
|
|
815
833
|
scale: "utc",
|
|
816
|
-
domain: model.start === model.end ? [model.start - model.minimumInterval / 2, model.end + model.minimumInterval / 2] : [model.start, model.end],
|
|
834
|
+
domain: model.start === model.end || context?.barAxes.has(id) ? [model.start - model.minimumInterval / 2, model.end + model.minimumInterval / 2] : [model.start, model.end],
|
|
817
835
|
ticks: automaticTicks?.ticks,
|
|
818
836
|
interval: automaticTicks ? 0 : void 0,
|
|
819
837
|
height: 48,
|
|
@@ -868,6 +886,43 @@ function ChartSeries({ id, children }) {
|
|
|
868
886
|
});
|
|
869
887
|
}
|
|
870
888
|
//#endregion
|
|
889
|
+
//#region src/ui/chart-value-format.ts
|
|
890
|
+
const ChartValueFormat = createContext(void 0);
|
|
891
|
+
/** Use one magnitude for every tick, and enough precision to distinguish them. */
|
|
892
|
+
function axisValueFormatter(values, format) {
|
|
893
|
+
const magnitude = Math.max(0, ...values.map(Math.abs));
|
|
894
|
+
const exponent = format?.kind !== "ratio" && !(format?.kind === "count" && format.compact === false) && magnitude >= 1e3 ? Math.min(12, Math.floor(Math.log10(magnitude) / 3) * 3) : 0;
|
|
895
|
+
const divisor = 10 ** exponent;
|
|
896
|
+
const sorted = [...new Set(values)].sort((a, b) => a - b);
|
|
897
|
+
const displayStep = sorted.slice(1).reduce((minimum, value, index) => Math.min(minimum, value - sorted[index]), Infinity) / divisor * (format?.kind === "ratio" ? 100 : 1);
|
|
898
|
+
const digits = Number.isFinite(displayStep) && displayStep > 0 ? Math.min(20, Math.max(0, -Math.floor(Math.log10(displayStep)) + 1)) : 2;
|
|
899
|
+
const locale = format?.locale ?? "en-US";
|
|
900
|
+
const options = {
|
|
901
|
+
maximumFractionDigits: digits,
|
|
902
|
+
minimumFractionDigits: 0,
|
|
903
|
+
...format?.kind === "currency" ? {
|
|
904
|
+
style: "currency",
|
|
905
|
+
currency: format.currency
|
|
906
|
+
} : {},
|
|
907
|
+
...format?.kind === "ratio" ? { style: "percent" } : {}
|
|
908
|
+
};
|
|
909
|
+
const suffix = [
|
|
910
|
+
"",
|
|
911
|
+
"k",
|
|
912
|
+
"M",
|
|
913
|
+
"B",
|
|
914
|
+
"T"
|
|
915
|
+
][exponent / 3];
|
|
916
|
+
const formatter = new Intl.NumberFormat(locale, options);
|
|
917
|
+
return (value) => {
|
|
918
|
+
if (typeof value !== "number") return String(value);
|
|
919
|
+
if (!Number.isFinite(value)) return formatNumber(value);
|
|
920
|
+
const parts = formatter.formatToParts(value === 0 ? 0 : value / divisor);
|
|
921
|
+
const index = parts.findLastIndex((part) => part.type === "integer" || part.type === "fraction");
|
|
922
|
+
return parts.map((part, i) => part.value + (i === index && value !== 0 ? suffix : "")).join("");
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
//#endregion
|
|
871
926
|
//#region src/ui/ChartLegend.tsx
|
|
872
927
|
/** Optional chart key, placed beside any chart with the app's layout components.
|
|
873
928
|
* Items describe displayed series or categories; the caller owns series visibility and interactions. */
|
|
@@ -1044,6 +1099,7 @@ function NearestChartDot({ seriesId, cx, cy, stroke }) {
|
|
|
1044
1099
|
}
|
|
1045
1100
|
/** Shared series defaults; native props override every authored choice. */
|
|
1046
1101
|
function ChartBar(props) {
|
|
1102
|
+
useDateAxisBar(props.xAxisId);
|
|
1047
1103
|
const series = useChartSeries(props.id);
|
|
1048
1104
|
return /* @__PURE__ */ jsx(ChartSeries, {
|
|
1049
1105
|
id: series.id,
|
|
@@ -1136,9 +1192,12 @@ function ChartScatter(props) {
|
|
|
1136
1192
|
});
|
|
1137
1193
|
}
|
|
1138
1194
|
function ChartYAxis(props) {
|
|
1195
|
+
const format = useContext(ChartValueFormat);
|
|
1196
|
+
const formatter = axisValueFormatter((useYAxisTicks(props.yAxisId) ?? []).map((tick) => tick.value).filter((value) => typeof value === "number"), format);
|
|
1139
1197
|
return /* @__PURE__ */ jsx(YAxis, {
|
|
1198
|
+
width: "auto",
|
|
1140
1199
|
stroke: "var(--atbl-muted)",
|
|
1141
|
-
tickFormatter:
|
|
1200
|
+
tickFormatter: formatter,
|
|
1142
1201
|
tickLine: false,
|
|
1143
1202
|
axisLine: false,
|
|
1144
1203
|
tick: { fontSize: "var(--atbl-type-meta-size)" },
|
|
@@ -1153,6 +1212,10 @@ function ChartGrid(props) {
|
|
|
1153
1212
|
});
|
|
1154
1213
|
}
|
|
1155
1214
|
function ChartTooltipContent(props) {
|
|
1215
|
+
const valueFormat = useContext(ChartValueFormat);
|
|
1216
|
+
function formatValue(value) {
|
|
1217
|
+
return valueFormat ? formatMetric(value, valueFormat) : formatNumber(value);
|
|
1218
|
+
}
|
|
1156
1219
|
if (!props.active || !props.payload?.length) return null;
|
|
1157
1220
|
return /* @__PURE__ */ jsx(TooltipSurface, {
|
|
1158
1221
|
"data-variant": "chart",
|
|
@@ -1165,7 +1228,7 @@ function ChartTooltipContent(props) {
|
|
|
1165
1228
|
unit: void 0,
|
|
1166
1229
|
formatter: (value, name, _item, index, payload) => {
|
|
1167
1230
|
const formatter = entry.formatter ?? props.formatter;
|
|
1168
|
-
const formatted = formatter ? formatter(value, name, entry, index, props.payload ?? payload) : Array.isArray(value) ? value.map((item) => typeof item === "number" ?
|
|
1231
|
+
const formatted = formatter ? formatter(value, name, entry, index, props.payload ?? payload) : Array.isArray(value) ? value.map((item) => typeof item === "number" ? formatValue(item) : item).join(" ~ ") : typeof value === "number" ? formatValue(value) : value;
|
|
1169
1232
|
if (formatted == null) return null;
|
|
1170
1233
|
const [displayValue, displayName] = Array.isArray(formatted) ? formatted : [formatted, name];
|
|
1171
1234
|
return [/* @__PURE__ */ jsxs("span", {
|
|
@@ -2059,7 +2122,7 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
|
|
|
2059
2122
|
* for stacks. Preserve missing measures as null and choose connectNulls deliberately.
|
|
2060
2123
|
* Use public chart tokens for series colors. Dataset bindings own
|
|
2061
2124
|
* loading, empty results, evidence, and CSV; this primitive owns only the plot. */
|
|
2062
|
-
function ComposedChartRoot({ data, ariaLabel, width = "100%", height = 300, responsive = true, className, ...props }) {
|
|
2125
|
+
function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", height = 300, responsive = true, className, ...props }) {
|
|
2063
2126
|
const [hasPointerFocus, setHasPointerFocus] = useState(false);
|
|
2064
2127
|
const [isPointerInspection, setIsPointerInspection] = useState(false);
|
|
2065
2128
|
const [hoveredSeriesId, setHoveredSeriesId] = useState(null);
|
|
@@ -2145,16 +2208,19 @@ function ComposedChartRoot({ data, ariaLabel, width = "100%", height = 300, resp
|
|
|
2145
2208
|
resetPointerInspection();
|
|
2146
2209
|
}
|
|
2147
2210
|
},
|
|
2148
|
-
children: /* @__PURE__ */ jsx(
|
|
2149
|
-
|
|
2150
|
-
children: /* @__PURE__ */ jsx(
|
|
2151
|
-
"data-atbl-focus": "inset",
|
|
2152
|
-
...props,
|
|
2211
|
+
children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
|
|
2212
|
+
value: valueFormat,
|
|
2213
|
+
children: /* @__PURE__ */ jsx(ChartDateAxes, {
|
|
2153
2214
|
data,
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2215
|
+
children: /* @__PURE__ */ jsx(ComposedChart$1, {
|
|
2216
|
+
"data-atbl-focus": "inset",
|
|
2217
|
+
...props,
|
|
2218
|
+
data,
|
|
2219
|
+
width,
|
|
2220
|
+
height,
|
|
2221
|
+
responsive,
|
|
2222
|
+
"aria-label": ariaLabel
|
|
2223
|
+
})
|
|
2158
2224
|
})
|
|
2159
2225
|
})
|
|
2160
2226
|
})
|
|
@@ -2891,6 +2957,14 @@ function JourneyFlow({ paths, unit, formatValue }) {
|
|
|
2891
2957
|
});
|
|
2892
2958
|
}
|
|
2893
2959
|
//#endregion
|
|
2894
|
-
|
|
2960
|
+
//#region src/ui/index.ts
|
|
2961
|
+
/** Direct UI composition and static screens. Requests use declared views from /react. */
|
|
2962
|
+
const TextWidget = withWidgetBoundary(TextWidget$1);
|
|
2963
|
+
/** Compose an unframed visual with the shared heading and inspection. */
|
|
2964
|
+
const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
|
|
2965
|
+
const TableWidget = withWidgetBoundary(TableWidget$1);
|
|
2966
|
+
const MetricWidget = withWidgetBoundary(MetricWidget$1);
|
|
2967
|
+
//#endregion
|
|
2968
|
+
export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, DataApp, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, DataValue, DataWidget, DateDisplay, DateRangePicker, DimensionPicker, ExplorationActionControl, FilterActions, FilterBar, FunnelChart, GettingStarted, GlossaryDefinition, GlossaryExplanation, GradientScroll, HelpPopover, JourneyChart, LineChart, LiveControl, Menu, PressButton as MenuButton, MenuItem, MenuPopover, MenuSection, MenuSeparator, MenuTrigger, MetricWidget, NumberField, NumberFilterPicker, NumberRangeField, PieChart, PresentStory, Radio, RadioGroup, RetentionChart, ScatterChart, SearchField, SearchMatch, SearchTypeahead, SectionHeading, SegmentedControl, Select, Sheet, ShimmerText, Tab, TabList, TabPanel, TabPanels, TableWidget, Tabs, TextWidget, Tooltip, TooltipProvider, VariableBar, VisualizationWidget, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppVariables, useDateFormatting, useSvgId, useViewTab };
|
|
2895
2969
|
|
|
2896
2970
|
//# sourceMappingURL=index.js.map
|