@altertable/data-app 0.70.0 → 0.72.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/AGENTS.md +7 -1
- package/CONTRIBUTING.md +73 -33
- package/README.md +23 -26
- package/REFERENCE.md +1904 -0
- package/dist/chunks/index-5a27erdg.js +54 -0
- package/dist/chunks/index-5a27erdg.js.map +10 -0
- package/dist/chunks/{index-58kks6a8.js → index-9yxr7nmm.js} +330 -21
- package/dist/chunks/index-9yxr7nmm.js.map +17 -0
- package/dist/chunks/{index-wjt6cavj.js → index-j5q5n3ra.js} +5 -5
- package/dist/chunks/index-j5q5n3ra.js.map +10 -0
- package/dist/chunks/{index-22d576sn.js → index-q75zm3a7.js} +3 -3
- package/dist/chunks/{index-22d576sn.js.map → index-q75zm3a7.js.map} +3 -3
- package/dist/chunks/{index-9zqbrv2z.js → index-vhaec7m5.js} +4 -6
- package/dist/chunks/index-vhaec7m5.js.map +10 -0
- package/dist/chunks/{index-q1w84fv9.js → index-zp78caex.js} +345 -84
- package/dist/chunks/index-zp78caex.js.map +19 -0
- package/dist/client/index.js +284 -16
- package/dist/client/index.js.map +7 -3
- package/dist/core/appearance.js +181 -11
- package/dist/core/appearance.js.map +4 -3
- package/dist/core/config.js +3 -3
- package/dist/core/contract.js +10 -12
- package/dist/core/contract.js.map +1 -1
- package/dist/core/format.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.js +418 -0
- package/dist/internal.js.map +15 -0
- package/dist/server/index.js +102 -0
- package/dist/server/index.js.map +10 -0
- package/dist/types/client/annotations.d.ts +1 -1
- package/dist/types/client/iframe.d.ts +6 -6
- package/dist/types/client/index.d.ts +3 -4
- package/dist/types/client/location.d.ts +2 -2
- package/dist/types/client/logger.d.ts +1 -1
- package/dist/types/client/navigation.d.ts +1 -1
- package/dist/types/client/transport.d.ts +1 -1
- package/dist/types/core/bridge.d.ts +1 -1
- package/dist/types/core/config.d.ts +8 -9
- package/dist/types/core/filters.d.ts +1 -1
- package/dist/types/core/format.d.ts +1 -2
- package/dist/types/core/messages.d.ts +3 -3
- package/dist/types/core/operation-types.d.ts +1 -1
- package/dist/types/core/presentation.d.ts +1 -1
- package/dist/types/core/reading.d.ts +1 -1
- package/dist/types/internal.d.ts +22 -0
- package/dist/types/server/index.d.ts +1 -2
- package/docs/app-authoring.md +18 -1
- package/docs/client.md +1 -1
- package/docs/contract.md +1 -1
- package/docs/data-context.md +3 -3
- package/docs/embed.md +4 -4
- package/docs/formatting-and-appearance.md +1 -1
- package/docs/hosted-apps.md +16 -8
- package/docs/local-data-apps.md +1 -1
- package/docs/react-embed.md +7 -6
- package/docs/react.md +6 -6
- package/docs/server-bun.md +6 -6
- package/docs/stories-and-export.md +3 -3
- package/docs/styling.md +2 -2
- package/docs/ui.md +6 -6
- package/docs/views.md +2 -2
- package/docs/widgets.md +4 -4
- package/docs/worker.md +4 -4
- package/package.json +15 -92
- package/THIRD_PARTY_NOTICES +0 -18
- package/dist/chunks/index-2ajhmsc4.js +0 -355
- package/dist/chunks/index-2ajhmsc4.js.map +0 -13
- package/dist/chunks/index-58kks6a8.js.map +0 -13
- package/dist/chunks/index-7q99hf1z.js +0 -87
- package/dist/chunks/index-7q99hf1z.js.map +0 -10
- package/dist/chunks/index-9zqbrv2z.js.map +0 -10
- package/dist/chunks/index-cv36cyna.js +0 -180
- package/dist/chunks/index-cv36cyna.js.map +0 -10
- package/dist/chunks/index-q1w84fv9.js.map +0 -15
- package/dist/chunks/index-rew95tbg.js +0 -272
- package/dist/chunks/index-rew95tbg.js.map +0 -13
- package/dist/chunks/index-vtpygsbq.js +0 -17270
- package/dist/chunks/index-vtpygsbq.js.map +0 -126
- package/dist/chunks/index-wjt6cavj.js.map +0 -10
- package/dist/chunks/index-wss3gd3h.js +0 -319
- package/dist/chunks/index-wss3gd3h.js.map +0 -13
- package/dist/chunks/index-xzb7sx6g.js +0 -221
- package/dist/chunks/index-xzb7sx6g.js.map +0 -12
- package/dist/embed/index.js +0 -138
- package/dist/embed/index.js.map +0 -12
- package/dist/local.js +0 -465
- package/dist/local.js.map +0 -16
- package/dist/preview.js +0 -1456
- package/dist/preview.js.map +0 -17
- package/dist/react/embed/index.js +0 -117
- package/dist/react/embed/index.js.map +0 -10
- package/dist/react/index.js +0 -2890
- package/dist/react/index.js.map +0 -23
- package/dist/react/ui/index.js +0 -3514
- package/dist/react/ui/index.js.map +0 -36
- package/dist/server.js +0 -334
- package/dist/server.js.map +0 -15
- package/dist/types/core/time-interval.d.ts +0 -96
- package/dist/types/embed/bootstrap.d.ts +0 -5
- package/dist/types/embed/bridge.d.ts +0 -12
- package/dist/types/embed/host.d.ts +0 -36
- package/dist/types/embed/index.d.ts +0 -14
- package/dist/types/embed/navigation.d.ts +0 -6
- package/dist/types/embed/runtime-html.d.ts +0 -2
- package/dist/types/embed/source.d.ts +0 -16
- package/dist/types/embed/sql.d.ts +0 -4
- package/dist/types/react/actions.d.ts +0 -53
- package/dist/types/react/annotations/AnnotationBar.d.ts +0 -30
- package/dist/types/react/annotations/AnnotationControls.d.ts +0 -10
- package/dist/types/react/annotations/AnnotationEditor.d.ts +0 -16
- package/dist/types/react/annotations/AnnotationMarkers.d.ts +0 -19
- package/dist/types/react/annotations/AnnotationSelectionLayer.d.ts +0 -12
- package/dist/types/react/annotations/AnnotationTarget.d.ts +0 -9
- package/dist/types/react/annotations/AnnotationTooltip.d.ts +0 -9
- package/dist/types/react/annotations/AnnotationTrigger.d.ts +0 -10
- package/dist/types/react/annotations/annotation-editor-state.d.ts +0 -58
- package/dist/types/react/annotations/annotation-screenshot.d.ts +0 -4
- package/dist/types/react/annotations/annotation-targets.d.ts +0 -34
- package/dist/types/react/annotations/getAnnotationProps.d.ts +0 -17
- package/dist/types/react/annotations/styles.d.ts +0 -3
- package/dist/types/react/annotations/useAnnotationGeometry.d.ts +0 -22
- package/dist/types/react/annotations/useDataAppAnnotations.d.ts +0 -22
- package/dist/types/react/app-context.d.ts +0 -3
- package/dist/types/react/bindings.d.ts +0 -169
- package/dist/types/react/content.d.ts +0 -36
- package/dist/types/react/date-formatting.d.ts +0 -12
- package/dist/types/react/details.d.ts +0 -46
- package/dist/types/react/embed/bridge.d.ts +0 -21
- package/dist/types/react/embed/index.d.ts +0 -7
- package/dist/types/react/exploration.d.ts +0 -44
- package/dist/types/react/hooks.d.ts +0 -113
- package/dist/types/react/index.d.ts +0 -78
- package/dist/types/react/injectStyles.d.ts +0 -7
- package/dist/types/react/mount.d.ts +0 -13
- package/dist/types/react/search-suggestions.d.ts +0 -8
- package/dist/types/react/source-owner.d.ts +0 -2
- package/dist/types/react/style-contract.d.ts +0 -88
- package/dist/types/react/style-validation.d.ts +0 -2
- package/dist/types/react/styles.d.ts +0 -8
- package/dist/types/react/ui/AboutData.d.ts +0 -73
- package/dist/types/react/ui/AltertableLogo.d.ts +0 -3
- package/dist/types/react/ui/AppFooter.d.ts +0 -6
- package/dist/types/react/ui/AppHeader.d.ts +0 -10
- package/dist/types/react/ui/AppLayout.d.ts +0 -10
- package/dist/types/react/ui/AppScope.d.ts +0 -7
- package/dist/types/react/ui/AppToolbar.d.ts +0 -30
- package/dist/types/react/ui/AreaChart.d.ts +0 -7
- package/dist/types/react/ui/BarChart.d.ts +0 -6
- package/dist/types/react/ui/Breakdown.d.ts +0 -13
- package/dist/types/react/ui/Button.d.ts +0 -12
- package/dist/types/react/ui/ChartLegend.d.ts +0 -32
- package/dist/types/react/ui/Checkbox.d.ts +0 -21
- package/dist/types/react/ui/CheckboxGroup.d.ts +0 -7
- package/dist/types/react/ui/ChoicePicker.d.ts +0 -39
- package/dist/types/react/ui/Comparison.d.ts +0 -14
- package/dist/types/react/ui/ComposedChart.d.ts +0 -41
- package/dist/types/react/ui/ComposedChartLegend.d.ts +0 -9
- package/dist/types/react/ui/ContentSkeleton.d.ts +0 -7
- package/dist/types/react/ui/DataApp.d.ts +0 -24
- package/dist/types/react/ui/DataAppFrame.d.ts +0 -52
- package/dist/types/react/ui/DataBoundary.d.ts +0 -14
- package/dist/types/react/ui/DataSection.d.ts +0 -14
- package/dist/types/react/ui/DataSectionBoundary.d.ts +0 -30
- package/dist/types/react/ui/DataTable.d.ts +0 -29
- package/dist/types/react/ui/DataValue.d.ts +0 -9
- package/dist/types/react/ui/DataViewToast.d.ts +0 -11
- package/dist/types/react/ui/DataWidget.d.ts +0 -37
- package/dist/types/react/ui/DateDisplay.d.ts +0 -9
- package/dist/types/react/ui/DateRangePicker.d.ts +0 -30
- package/dist/types/react/ui/DateTimeTooltip.d.ts +0 -10
- package/dist/types/react/ui/DimensionPicker.d.ts +0 -13
- package/dist/types/react/ui/EmptyState.d.ts +0 -6
- package/dist/types/react/ui/ExplorationActionControl.d.ts +0 -60
- package/dist/types/react/ui/ExportControl.d.ts +0 -4
- package/dist/types/react/ui/FilterActions.d.ts +0 -10
- package/dist/types/react/ui/FilterBar.d.ts +0 -3
- package/dist/types/react/ui/FunnelChart.d.ts +0 -20
- package/dist/types/react/ui/GettingStarted.d.ts +0 -6
- package/dist/types/react/ui/GlossaryDefinition.d.ts +0 -7
- package/dist/types/react/ui/GlossaryExplanation.d.ts +0 -16
- package/dist/types/react/ui/GradientScroll.d.ts +0 -23
- package/dist/types/react/ui/Grid.d.ts +0 -12
- package/dist/types/react/ui/GridItem.d.ts +0 -7
- package/dist/types/react/ui/HelpPopover.d.ts +0 -21
- package/dist/types/react/ui/IconButton.d.ts +0 -19
- package/dist/types/react/ui/InspectionContext.d.ts +0 -12
- package/dist/types/react/ui/InspectionProvider.d.ts +0 -29
- package/dist/types/react/ui/JourneyChart.d.ts +0 -10
- package/dist/types/react/ui/Kbd.d.ts +0 -7
- package/dist/types/react/ui/LineChart.d.ts +0 -7
- package/dist/types/react/ui/LiveControl.d.ts +0 -10
- package/dist/types/react/ui/Menu.d.ts +0 -13
- package/dist/types/react/ui/MetricWidget.d.ts +0 -51
- package/dist/types/react/ui/NumberField.d.ts +0 -27
- package/dist/types/react/ui/NumberFilterPicker.d.ts +0 -11
- package/dist/types/react/ui/PeriodSummary.d.ts +0 -17
- package/dist/types/react/ui/PickerField.d.ts +0 -23
- package/dist/types/react/ui/PieChart.d.ts +0 -11
- package/dist/types/react/ui/PopoverSurface.d.ts +0 -5
- package/dist/types/react/ui/PresentStory.d.ts +0 -30
- package/dist/types/react/ui/QueryList.d.ts +0 -14
- package/dist/types/react/ui/RadioGroup.d.ts +0 -18
- package/dist/types/react/ui/Ranking.d.ts +0 -13
- package/dist/types/react/ui/RefreshControl.d.ts +0 -9
- package/dist/types/react/ui/RequestHint.d.ts +0 -20
- package/dist/types/react/ui/RetentionChart.d.ts +0 -27
- package/dist/types/react/ui/ScatterChart.d.ts +0 -17
- package/dist/types/react/ui/SearchField.d.ts +0 -23
- package/dist/types/react/ui/SearchInput.d.ts +0 -10
- package/dist/types/react/ui/SearchMatch.d.ts +0 -6
- package/dist/types/react/ui/SearchTypeahead.d.ts +0 -15
- package/dist/types/react/ui/SectionHeading.d.ts +0 -8
- package/dist/types/react/ui/Select.d.ts +0 -22
- package/dist/types/react/ui/SelectionMark.d.ts +0 -5
- package/dist/types/react/ui/Sheet.d.ts +0 -21
- package/dist/types/react/ui/Skeleton.d.ts +0 -8
- package/dist/types/react/ui/Stack.d.ts +0 -7
- package/dist/types/react/ui/StaticDataApp.d.ts +0 -4
- package/dist/types/react/ui/StatusPanel.d.ts +0 -10
- package/dist/types/react/ui/TableWidget.d.ts +0 -67
- package/dist/types/react/ui/Tabs.d.ts +0 -10
- package/dist/types/react/ui/TextContent.d.ts +0 -4
- package/dist/types/react/ui/TextWidget.d.ts +0 -20
- package/dist/types/react/ui/ThemeSelector.d.ts +0 -12
- package/dist/types/react/ui/Toast.d.ts +0 -8
- package/dist/types/react/ui/Tooltip.d.ts +0 -23
- package/dist/types/react/ui/TooltipSurface.d.ts +0 -3
- package/dist/types/react/ui/TrendChart.d.ts +0 -5
- package/dist/types/react/ui/UpdatedAt.d.ts +0 -9
- package/dist/types/react/ui/VariableBar.d.ts +0 -6
- package/dist/types/react/ui/VisualizationWidget.d.ts +0 -43
- package/dist/types/react/ui/WidgetDisclosure.d.ts +0 -6
- package/dist/types/react/ui/WidgetEvidence.d.ts +0 -12
- package/dist/types/react/ui/WidgetViewTabs.d.ts +0 -16
- package/dist/types/react/ui/chart-data.d.ts +0 -36
- package/dist/types/react/ui/chart-date-axis.d.ts +0 -15
- package/dist/types/react/ui/chart-interaction.d.ts +0 -27
- package/dist/types/react/ui/chart-primitives.d.ts +0 -22
- package/dist/types/react/ui/chart-time.d.ts +0 -19
- package/dist/types/react/ui/chartColor.d.ts +0 -2
- package/dist/types/react/ui/classNames.d.ts +0 -1
- package/dist/types/react/ui/csv-export.d.ts +0 -19
- package/dist/types/react/ui/data-context.d.ts +0 -76
- package/dist/types/react/ui/data-identifiers.d.ts +0 -32
- package/dist/types/react/ui/icons.d.ts +0 -49
- package/dist/types/react/ui/index.d.ts +0 -111
- package/dist/types/react/ui/journey-flow.d.ts +0 -49
- package/dist/types/react/ui/keyboard.d.ts +0 -6
- package/dist/types/react/ui/metric-comparison.d.ts +0 -30
- package/dist/types/react/ui/metric.d.ts +0 -11
- package/dist/types/react/ui/presentation.d.ts +0 -25
- package/dist/types/react/ui/search.d.ts +0 -6
- package/dist/types/react/ui/searchItems.d.ts +0 -36
- package/dist/types/react/ui/shortcuts.d.ts +0 -45
- package/dist/types/react/ui/story.d.ts +0 -20
- package/dist/types/react/ui/use-chart-scroll-to-end.d.ts +0 -2
- package/dist/types/react/ui/useAppAppearance.d.ts +0 -3
- package/dist/types/react/ui/useDataAppPresentation.d.ts +0 -3
- package/dist/types/react/ui/useSvgId.d.ts +0 -2
- package/dist/types/react/ui/variables.d.ts +0 -38
- package/dist/types/react/ui/widget-views.d.ts +0 -3
- package/dist/types/react/view-control-bar.d.ts +0 -18
- package/dist/types/react/view-controls.d.ts +0 -20
- package/dist/types/react/view-runtime.d.ts +0 -34
- package/dist/types/react/view.d.ts +0 -87
- package/dist/types/react/widgets.d.ts +0 -90
- package/dist/types/server/local.d.ts +0 -19
- package/dist/types/server/preview/host.d.ts +0 -1
- package/dist/types/server/preview/index.d.ts +0 -16
- package/dist/types/server/reload-channel.d.ts +0 -6
- package/dist/worker.js +0 -106
- package/examples/starter-data-app/index.tsx +0 -193
- package/examples/starter-local-data-app/.bun-version +0 -1
- package/examples/starter-local-data-app/.node-version +0 -1
- package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
- package/examples/starter-local-data-app/.oxlintrc.json +0 -33
- package/examples/starter-local-data-app/AGENTS.md +0 -22
- package/examples/starter-local-data-app/README.md +0 -54
- package/examples/starter-local-data-app/app.ts +0 -28
- package/examples/starter-local-data-app/bunfig.toml +0 -2
- package/examples/starter-local-data-app/package.json +0 -33
- package/examples/starter-local-data-app/src/App.tsx +0 -8
- package/examples/starter-local-data-app/src/assets.d.ts +0 -1
- package/examples/starter-local-data-app/src/data-context.ts +0 -21
- package/examples/starter-local-data-app/src/favicon.svg +0 -13
- package/examples/starter-local-data-app/src/index.html +0 -14
- package/examples/starter-local-data-app/src/main.tsx +0 -7
- package/examples/starter-local-data-app/src/operations.ts +0 -6
- package/examples/starter-local-data-app/src/server.ts +0 -6
- package/examples/starter-local-data-app/tsconfig.json +0 -21
package/dist/react/ui/index.js
DELETED
|
@@ -1,3514 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
injectDataAppStyles2,
|
|
3
|
-
useDateFormatting2,
|
|
4
|
-
AppIcon2,
|
|
5
|
-
classNames,
|
|
6
|
-
Button2,
|
|
7
|
-
PressButton,
|
|
8
|
-
TooltipSurface,
|
|
9
|
-
TooltipProvider2,
|
|
10
|
-
Tooltip2,
|
|
11
|
-
GradientScroll2,
|
|
12
|
-
Sheet2,
|
|
13
|
-
TabPanels2,
|
|
14
|
-
TabList2,
|
|
15
|
-
Tab2,
|
|
16
|
-
TabPanel2,
|
|
17
|
-
Tabs2,
|
|
18
|
-
useViewTab2,
|
|
19
|
-
AboutData2,
|
|
20
|
-
DataAppProvider2,
|
|
21
|
-
useDeclaredResult,
|
|
22
|
-
HelpPopover2,
|
|
23
|
-
DateDisplay2,
|
|
24
|
-
validateChoiceOptions,
|
|
25
|
-
useAppVariables2,
|
|
26
|
-
SearchField2,
|
|
27
|
-
SearchMatch2,
|
|
28
|
-
matchSearchText2,
|
|
29
|
-
searchItems2,
|
|
30
|
-
SearchTypeahead2,
|
|
31
|
-
Select2,
|
|
32
|
-
FilterActions2,
|
|
33
|
-
VariableBar2,
|
|
34
|
-
NumberField2,
|
|
35
|
-
NumberRangeField2,
|
|
36
|
-
NumberFilterPicker2,
|
|
37
|
-
ChoicePicker2,
|
|
38
|
-
CheckboxGroupContext,
|
|
39
|
-
Checkbox2,
|
|
40
|
-
DateRangePicker2,
|
|
41
|
-
FilterBar2,
|
|
42
|
-
DimensionPicker2,
|
|
43
|
-
createDataHooks2,
|
|
44
|
-
isPlainKeyEvent2,
|
|
45
|
-
MenuTrigger2,
|
|
46
|
-
MenuSection2,
|
|
47
|
-
MenuPopover2,
|
|
48
|
-
Menu2,
|
|
49
|
-
MenuItem2,
|
|
50
|
-
MenuSeparator2,
|
|
51
|
-
LiveControl2,
|
|
52
|
-
PresentStory2,
|
|
53
|
-
DataAppFrame,
|
|
54
|
-
ExplorationActionControl2,
|
|
55
|
-
ExplorationActionMenu,
|
|
56
|
-
useChartActions,
|
|
57
|
-
openExplorationMenu,
|
|
58
|
-
explorationMenuEvents,
|
|
59
|
-
getPrimaryExplorationAction,
|
|
60
|
-
DataWidget2,
|
|
61
|
-
VisualizationWidget2,
|
|
62
|
-
MetricWidget2,
|
|
63
|
-
DataTable2,
|
|
64
|
-
DataTableShare2,
|
|
65
|
-
DataTableEmptyRow2,
|
|
66
|
-
DataTableTimestamp2,
|
|
67
|
-
TableWidget2,
|
|
68
|
-
TextWidget2,
|
|
69
|
-
DataValue2,
|
|
70
|
-
chartBarFill,
|
|
71
|
-
createDataContext2,
|
|
72
|
-
SectionHeading2
|
|
73
|
-
} from "../../chunks/index-vtpygsbq.js";
|
|
74
|
-
import {
|
|
75
|
-
formatDate2,
|
|
76
|
-
parseDateTime2,
|
|
77
|
-
formatDateTime2,
|
|
78
|
-
formatNumber2,
|
|
79
|
-
formatPercent2
|
|
80
|
-
} from "../../chunks/index-22d576sn.js";
|
|
81
|
-
import {
|
|
82
|
-
KEY_SEPARATOR
|
|
83
|
-
} from "../../chunks/index-q1w84fv9.js";
|
|
84
|
-
import"../../chunks/index-9zqbrv2z.js";
|
|
85
|
-
import"../../chunks/index-cv36cyna.js";
|
|
86
|
-
import {
|
|
87
|
-
createDataClient2
|
|
88
|
-
} from "../../chunks/index-7q99hf1z.js";
|
|
89
|
-
import"../../chunks/index-wjt6cavj.js";
|
|
90
|
-
import"../../chunks/index-xzb7sx6g.js";
|
|
91
|
-
import {
|
|
92
|
-
invariant
|
|
93
|
-
} from "../../chunks/index-rew95tbg.js";
|
|
94
|
-
// src/react/ui/StaticDataApp.tsx
|
|
95
|
-
import { jsx } from "react/jsx-runtime";
|
|
96
|
-
function DataApp(props) {
|
|
97
|
-
return /* @__PURE__ */ jsx(DataAppFrame, {
|
|
98
|
-
...props
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/react/ui/GettingStarted.tsx
|
|
103
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
104
|
-
var connectionContext = createDataContext2({})({
|
|
105
|
-
description: "Connection setup",
|
|
106
|
-
glossary: {}
|
|
107
|
-
});
|
|
108
|
-
var client = /* @__PURE__ */ createDataClient2();
|
|
109
|
-
var { defineDataView } = /* @__PURE__ */ createDataHooks2(client);
|
|
110
|
-
var connectionView = defineDataView({
|
|
111
|
-
dataContext: connectionContext,
|
|
112
|
-
operation: "connection",
|
|
113
|
-
describeInput: () => "the connection",
|
|
114
|
-
isEmpty: () => false,
|
|
115
|
-
emptyFallback: { title: "No connection" }
|
|
116
|
-
});
|
|
117
|
-
function GettingStarted({ dataContext }) {
|
|
118
|
-
const connection = useDeclaredResult(connectionView);
|
|
119
|
-
const state = connection.view.kind === "error" || connection.view.kind === "stale-error" ? "error" : connection.refreshing || !connection.snapshot ? "checking" : "connected";
|
|
120
|
-
return /* @__PURE__ */ jsxs(DataApp, {
|
|
121
|
-
dataContext,
|
|
122
|
-
description: "Check your lakehouse connection, then build a view around a real question.",
|
|
123
|
-
queries: connection.queries,
|
|
124
|
-
toolbarActions: /* @__PURE__ */ jsx2(Button2, {
|
|
125
|
-
disabled: connection.refreshing,
|
|
126
|
-
onClick: () => connection.refetch(),
|
|
127
|
-
children: "Check connection"
|
|
128
|
-
}),
|
|
129
|
-
children: [
|
|
130
|
-
/* @__PURE__ */ jsxs("section", {
|
|
131
|
-
className: "starter-connection",
|
|
132
|
-
"data-state": state,
|
|
133
|
-
role: state === "error" ? "alert" : "status",
|
|
134
|
-
children: [
|
|
135
|
-
/* @__PURE__ */ jsx2("div", {
|
|
136
|
-
className: "starter-connection-icon",
|
|
137
|
-
children: /* @__PURE__ */ jsx2(AppIcon2, {
|
|
138
|
-
name: state === "connected" ? "check" : state === "error" ? "error" : "loading",
|
|
139
|
-
size: 24
|
|
140
|
-
})
|
|
141
|
-
}),
|
|
142
|
-
/* @__PURE__ */ jsxs("div", {
|
|
143
|
-
className: "starter-connection-copy",
|
|
144
|
-
children: [
|
|
145
|
-
/* @__PURE__ */ jsx2("span", {
|
|
146
|
-
className: "starter-eyebrow",
|
|
147
|
-
children: "Lakehouse connection"
|
|
148
|
-
}),
|
|
149
|
-
/* @__PURE__ */ jsx2("h2", {
|
|
150
|
-
children: state === "connected" ? "Connected" : state === "error" ? "Connection not verified" : "Checking connection…"
|
|
151
|
-
}),
|
|
152
|
-
/* @__PURE__ */ jsx2("p", {
|
|
153
|
-
children: state === "connected" ? "A query completed successfully using this app’s current profile. You’re ready to build your first view." : state === "error" ? connection.snapshot ? "An earlier query succeeded, but the latest check failed. Check the profile and try again." : "The query could not complete. Check the profile and lakehouse access, then try again." : "Running a lightweight query with this app’s current profile."
|
|
154
|
-
}),
|
|
155
|
-
state === "connected" && /* @__PURE__ */ jsx2("small", {
|
|
156
|
-
children: "This check does not verify access to every dataset."
|
|
157
|
-
})
|
|
158
|
-
]
|
|
159
|
-
}),
|
|
160
|
-
state === "error" && /* @__PURE__ */ jsx2(Button2, {
|
|
161
|
-
onClick: () => connection.refetch(),
|
|
162
|
-
children: "Try again"
|
|
163
|
-
})
|
|
164
|
-
]
|
|
165
|
-
}),
|
|
166
|
-
/* @__PURE__ */ jsxs("section", {
|
|
167
|
-
className: "starter-next",
|
|
168
|
-
"aria-labelledby": "starter-next-title",
|
|
169
|
-
children: [
|
|
170
|
-
/* @__PURE__ */ jsxs("div", {
|
|
171
|
-
className: "starter-next-heading",
|
|
172
|
-
children: [
|
|
173
|
-
/* @__PURE__ */ jsx2("span", {
|
|
174
|
-
className: "starter-eyebrow",
|
|
175
|
-
children: "Next steps"
|
|
176
|
-
}),
|
|
177
|
-
/* @__PURE__ */ jsx2("h2", {
|
|
178
|
-
id: "starter-next-title",
|
|
179
|
-
children: "Turn this starter into a useful app"
|
|
180
|
-
}),
|
|
181
|
-
/* @__PURE__ */ jsx2("p", {
|
|
182
|
-
children: "Start with one question your readers need answered."
|
|
183
|
-
})
|
|
184
|
-
]
|
|
185
|
-
}),
|
|
186
|
-
/* @__PURE__ */ jsxs("ol", {
|
|
187
|
-
className: "starter-steps",
|
|
188
|
-
children: [
|
|
189
|
-
/* @__PURE__ */ jsxs("li", {
|
|
190
|
-
children: [
|
|
191
|
-
/* @__PURE__ */ jsx2("strong", {
|
|
192
|
-
children: "Choose a question"
|
|
193
|
-
}),
|
|
194
|
-
/* @__PURE__ */ jsx2("p", {
|
|
195
|
-
children: "Decide what someone should learn or do after opening this app."
|
|
196
|
-
})
|
|
197
|
-
]
|
|
198
|
-
}),
|
|
199
|
-
/* @__PURE__ */ jsxs("li", {
|
|
200
|
-
children: [
|
|
201
|
-
/* @__PURE__ */ jsx2("strong", {
|
|
202
|
-
children: "Find the right data"
|
|
203
|
-
}),
|
|
204
|
-
/* @__PURE__ */ jsx2("p", {
|
|
205
|
-
children: "Inspect the relevant catalogs, tables, and columns before writing the query."
|
|
206
|
-
})
|
|
207
|
-
]
|
|
208
|
-
}),
|
|
209
|
-
/* @__PURE__ */ jsxs("li", {
|
|
210
|
-
children: [
|
|
211
|
-
/* @__PURE__ */ jsx2("strong", {
|
|
212
|
-
children: "Build the first view"
|
|
213
|
-
}),
|
|
214
|
-
/* @__PURE__ */ jsxs("p", {
|
|
215
|
-
children: [
|
|
216
|
-
"Replace the connection check in ",
|
|
217
|
-
/* @__PURE__ */ jsx2("code", {
|
|
218
|
-
children: "src/operations.ts"
|
|
219
|
-
}),
|
|
220
|
-
", then render its result in ",
|
|
221
|
-
/* @__PURE__ */ jsx2("code", {
|
|
222
|
-
children: "src/App.tsx"
|
|
223
|
-
}),
|
|
224
|
-
"."
|
|
225
|
-
]
|
|
226
|
-
})
|
|
227
|
-
]
|
|
228
|
-
})
|
|
229
|
-
]
|
|
230
|
-
})
|
|
231
|
-
]
|
|
232
|
-
})
|
|
233
|
-
]
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
// src/react/ui/GlossaryExplanation.tsx
|
|
237
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
238
|
-
function GlossaryExplanation({
|
|
239
|
-
entry,
|
|
240
|
-
empty,
|
|
241
|
-
title,
|
|
242
|
-
description,
|
|
243
|
-
visual,
|
|
244
|
-
queries,
|
|
245
|
-
dataContext,
|
|
246
|
-
className,
|
|
247
|
-
...props
|
|
248
|
-
}) {
|
|
249
|
-
return /* @__PURE__ */ jsx3(AboutData2, {
|
|
250
|
-
...props,
|
|
251
|
-
shortcut: false,
|
|
252
|
-
iconOnly: true,
|
|
253
|
-
variant: "ghost",
|
|
254
|
-
title: title ?? entry.term,
|
|
255
|
-
description,
|
|
256
|
-
visual,
|
|
257
|
-
references: { kind: "entries", entries: [entry] },
|
|
258
|
-
empty,
|
|
259
|
-
dataContext,
|
|
260
|
-
queries,
|
|
261
|
-
className: className ?? "altertable-inspect-trigger",
|
|
262
|
-
tooltip: "Explore this term",
|
|
263
|
-
"aria-label": props["aria-label"] ?? `Explore ${entry.term}`,
|
|
264
|
-
children: /* @__PURE__ */ jsx3(AppIcon2, {
|
|
265
|
-
name: "openDetails"
|
|
266
|
-
})
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
// src/react/ui/GlossaryDefinition.tsx
|
|
270
|
-
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
271
|
-
function GlossaryDefinition({
|
|
272
|
-
entry,
|
|
273
|
-
children
|
|
274
|
-
}) {
|
|
275
|
-
return /* @__PURE__ */ jsxs2(HelpPopover2, {
|
|
276
|
-
trigger: children ?? entry.term,
|
|
277
|
-
triggerLabel: `Explain ${entry.term}`,
|
|
278
|
-
label: entry.term,
|
|
279
|
-
triggerProps: {
|
|
280
|
-
className: "altertable-glossary-definition-trigger",
|
|
281
|
-
"data-atbl-control": "help"
|
|
282
|
-
},
|
|
283
|
-
panelProps: { className: "altertable-glossary-definition-popover" },
|
|
284
|
-
children: [
|
|
285
|
-
/* @__PURE__ */ jsx4("strong", {
|
|
286
|
-
children: entry.term
|
|
287
|
-
}),
|
|
288
|
-
/* @__PURE__ */ jsx4("div", {
|
|
289
|
-
children: entry.definition
|
|
290
|
-
})
|
|
291
|
-
]
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
// src/react/ui/use-chart-scroll-to-end.ts
|
|
295
|
-
import { useLayoutEffect, useRef } from "react";
|
|
296
|
-
function useChartScrollToEnd(items) {
|
|
297
|
-
const scrollport = useRef(null);
|
|
298
|
-
useLayoutEffect(() => {
|
|
299
|
-
const element = scrollport.current;
|
|
300
|
-
if (element)
|
|
301
|
-
element.scrollLeft = element.scrollWidth - element.clientWidth;
|
|
302
|
-
}, [items]);
|
|
303
|
-
return scrollport;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// src/react/ui/TrendChart.tsx
|
|
307
|
-
import {
|
|
308
|
-
Fragment as Fragment2,
|
|
309
|
-
useRef as useRef3,
|
|
310
|
-
useState as useState3
|
|
311
|
-
} from "react";
|
|
312
|
-
import {
|
|
313
|
-
AreaChart as RechartsAreaChart,
|
|
314
|
-
LineChart as RechartsLineChart,
|
|
315
|
-
ReferenceLine
|
|
316
|
-
} from "recharts";
|
|
317
|
-
|
|
318
|
-
// src/react/ui/chart-date-axis.tsx
|
|
319
|
-
import {
|
|
320
|
-
createContext,
|
|
321
|
-
useCallback,
|
|
322
|
-
useContext,
|
|
323
|
-
useEffect,
|
|
324
|
-
useMemo,
|
|
325
|
-
useState
|
|
326
|
-
} from "react";
|
|
327
|
-
import { XAxis, usePlotArea } from "recharts";
|
|
328
|
-
|
|
329
|
-
// src/core/time-interval.ts
|
|
330
|
-
/*!
|
|
331
|
-
* TypeScript port of d3-time 3.1.0 (ISC), https://github.com/d3/d3-time/tree/v3.1.0
|
|
332
|
-
* Numeric tick-step helpers adapted from d3-array 3.2.4 (ISC).
|
|
333
|
-
*
|
|
334
|
-
* Copyright 2010-2022 Mike Bostock (d3-time)
|
|
335
|
-
* Copyright 2010-2023 Mike Bostock (d3-array tick-step helpers)
|
|
336
|
-
*
|
|
337
|
-
* Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
338
|
-
* with or without fee is hereby granted, provided that the above copyright notice
|
|
339
|
-
* and this permission notice appear in all copies.
|
|
340
|
-
*
|
|
341
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
342
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
343
|
-
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
344
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
345
|
-
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
346
|
-
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
347
|
-
* THIS SOFTWARE.
|
|
348
|
-
*/
|
|
349
|
-
function timeInterval(floor, offset, count, field) {
|
|
350
|
-
function interval(value) {
|
|
351
|
-
const date = arguments.length === 0 ? new Date : new Date(+value);
|
|
352
|
-
floor(date);
|
|
353
|
-
return date;
|
|
354
|
-
}
|
|
355
|
-
interval.floor = (value) => {
|
|
356
|
-
const date = new Date(+value);
|
|
357
|
-
floor(date);
|
|
358
|
-
return date;
|
|
359
|
-
};
|
|
360
|
-
interval.ceil = (value) => {
|
|
361
|
-
const date = new Date(+value - 1);
|
|
362
|
-
floor(date);
|
|
363
|
-
offset(date, 1);
|
|
364
|
-
floor(date);
|
|
365
|
-
return date;
|
|
366
|
-
};
|
|
367
|
-
interval.round = (value) => {
|
|
368
|
-
const before = interval(value);
|
|
369
|
-
const after = interval.ceil(value);
|
|
370
|
-
return +value - +before < +after - +value ? before : after;
|
|
371
|
-
};
|
|
372
|
-
interval.offset = (value, step) => {
|
|
373
|
-
const date = new Date(+value);
|
|
374
|
-
offset(date, step == null ? 1 : Math.floor(step));
|
|
375
|
-
return date;
|
|
376
|
-
};
|
|
377
|
-
interval.range = (start, stop, step) => {
|
|
378
|
-
const range = [];
|
|
379
|
-
const date = interval.ceil(start);
|
|
380
|
-
const stride = step == null ? 1 : Math.floor(step);
|
|
381
|
-
if (!(+date < +stop) || !(stride > 0))
|
|
382
|
-
return range;
|
|
383
|
-
let previous;
|
|
384
|
-
do {
|
|
385
|
-
previous = new Date(+date);
|
|
386
|
-
range.push(previous);
|
|
387
|
-
offset(date, stride);
|
|
388
|
-
floor(date);
|
|
389
|
-
} while (+previous < +date && +date < +stop);
|
|
390
|
-
return range;
|
|
391
|
-
};
|
|
392
|
-
interval.filter = (test) => timeInterval((date) => {
|
|
393
|
-
if (!Number.isNaN(+date)) {
|
|
394
|
-
floor(date);
|
|
395
|
-
while (!test(date)) {
|
|
396
|
-
date.setTime(+date - 1);
|
|
397
|
-
floor(date);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}, (date, step) => {
|
|
401
|
-
if (!Number.isNaN(+date)) {
|
|
402
|
-
const direction = step < 0 ? -1 : 1;
|
|
403
|
-
for (let remaining = Math.abs(step);remaining > 0; --remaining) {
|
|
404
|
-
do {
|
|
405
|
-
offset(date, direction);
|
|
406
|
-
} while (!test(date));
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
if (count) {
|
|
411
|
-
interval.count = (start, end) => {
|
|
412
|
-
countStart.setTime(+start);
|
|
413
|
-
countEnd.setTime(+end);
|
|
414
|
-
floor(countStart);
|
|
415
|
-
floor(countEnd);
|
|
416
|
-
return Math.floor(count(countStart, countEnd));
|
|
417
|
-
};
|
|
418
|
-
interval.every = (step) => {
|
|
419
|
-
step = Math.floor(step);
|
|
420
|
-
if (!Number.isFinite(step) || !(step > 0))
|
|
421
|
-
return null;
|
|
422
|
-
if (step === 1)
|
|
423
|
-
return interval;
|
|
424
|
-
return interval.filter(field ? (date) => field(date) % step === 0 : (date) => interval.count(0, date) % step === 0);
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
return interval;
|
|
428
|
-
}
|
|
429
|
-
var countStart = new Date;
|
|
430
|
-
var countEnd = new Date;
|
|
431
|
-
var durationSecond = 1000;
|
|
432
|
-
var durationMinute = durationSecond * 60;
|
|
433
|
-
var durationHour = durationMinute * 60;
|
|
434
|
-
var durationDay = durationHour * 24;
|
|
435
|
-
var durationWeek = durationDay * 7;
|
|
436
|
-
var durationMonth = durationDay * 30;
|
|
437
|
-
var durationYear = durationDay * 365;
|
|
438
|
-
var millisecond = timeInterval(() => {}, (date, step) => {
|
|
439
|
-
date.setTime(+date + step);
|
|
440
|
-
}, (start, end) => {
|
|
441
|
-
return +end - +start;
|
|
442
|
-
});
|
|
443
|
-
millisecond.every = (k) => {
|
|
444
|
-
k = Math.floor(k);
|
|
445
|
-
if (!isFinite(k) || !(k > 0))
|
|
446
|
-
return null;
|
|
447
|
-
if (!(k > 1))
|
|
448
|
-
return millisecond;
|
|
449
|
-
return timeInterval((date) => {
|
|
450
|
-
date.setTime(Math.floor(+date / k) * k);
|
|
451
|
-
}, (date, step) => {
|
|
452
|
-
date.setTime(+date + step * k);
|
|
453
|
-
}, (start, end) => {
|
|
454
|
-
return (+end - +start) / k;
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
var milliseconds = millisecond.range;
|
|
458
|
-
var second = timeInterval((date) => {
|
|
459
|
-
date.setTime(+date - date.getMilliseconds());
|
|
460
|
-
}, (date, step) => {
|
|
461
|
-
date.setTime(+date + step * durationSecond);
|
|
462
|
-
}, (start, end) => {
|
|
463
|
-
return (+end - +start) / durationSecond;
|
|
464
|
-
}, (date) => {
|
|
465
|
-
return date.getUTCSeconds();
|
|
466
|
-
});
|
|
467
|
-
var seconds = second.range;
|
|
468
|
-
var timeMinute = timeInterval((date) => {
|
|
469
|
-
date.setTime(+date - date.getMilliseconds() - date.getSeconds() * durationSecond);
|
|
470
|
-
}, (date, step) => {
|
|
471
|
-
date.setTime(+date + step * durationMinute);
|
|
472
|
-
}, (start, end) => {
|
|
473
|
-
return (+end - +start) / durationMinute;
|
|
474
|
-
}, (date) => {
|
|
475
|
-
return date.getMinutes();
|
|
476
|
-
});
|
|
477
|
-
var timeMinutes = timeMinute.range;
|
|
478
|
-
var utcMinute = timeInterval((date) => {
|
|
479
|
-
date.setUTCSeconds(0, 0);
|
|
480
|
-
}, (date, step) => {
|
|
481
|
-
date.setTime(+date + step * durationMinute);
|
|
482
|
-
}, (start, end) => {
|
|
483
|
-
return (+end - +start) / durationMinute;
|
|
484
|
-
}, (date) => {
|
|
485
|
-
return date.getUTCMinutes();
|
|
486
|
-
});
|
|
487
|
-
var utcMinutes = utcMinute.range;
|
|
488
|
-
var timeHour = timeInterval((date) => {
|
|
489
|
-
date.setTime(+date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
|
|
490
|
-
}, (date, step) => {
|
|
491
|
-
date.setTime(+date + step * durationHour);
|
|
492
|
-
}, (start, end) => {
|
|
493
|
-
return (+end - +start) / durationHour;
|
|
494
|
-
}, (date) => {
|
|
495
|
-
return date.getHours();
|
|
496
|
-
});
|
|
497
|
-
var timeHours = timeHour.range;
|
|
498
|
-
var utcHour = timeInterval((date) => {
|
|
499
|
-
date.setUTCMinutes(0, 0, 0);
|
|
500
|
-
}, (date, step) => {
|
|
501
|
-
date.setTime(+date + step * durationHour);
|
|
502
|
-
}, (start, end) => {
|
|
503
|
-
return (+end - +start) / durationHour;
|
|
504
|
-
}, (date) => {
|
|
505
|
-
return date.getUTCHours();
|
|
506
|
-
});
|
|
507
|
-
var utcHours = utcHour.range;
|
|
508
|
-
var timeDay = timeInterval((date) => date.setHours(0, 0, 0, 0), (date, step) => date.setDate(date.getDate() + step), (start, end) => (+end - +start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay, (date) => date.getDate() - 1);
|
|
509
|
-
var timeDays = timeDay.range;
|
|
510
|
-
var utcDay = timeInterval((date) => {
|
|
511
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
512
|
-
}, (date, step) => {
|
|
513
|
-
date.setUTCDate(date.getUTCDate() + step);
|
|
514
|
-
}, (start, end) => {
|
|
515
|
-
return (+end - +start) / durationDay;
|
|
516
|
-
}, (date) => {
|
|
517
|
-
return date.getUTCDate() - 1;
|
|
518
|
-
});
|
|
519
|
-
var utcDays = utcDay.range;
|
|
520
|
-
var unixDay = timeInterval((date) => {
|
|
521
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
522
|
-
}, (date, step) => {
|
|
523
|
-
date.setUTCDate(date.getUTCDate() + step);
|
|
524
|
-
}, (start, end) => {
|
|
525
|
-
return (+end - +start) / durationDay;
|
|
526
|
-
}, (date) => {
|
|
527
|
-
return Math.floor(+date / durationDay);
|
|
528
|
-
});
|
|
529
|
-
var unixDays = unixDay.range;
|
|
530
|
-
function timeWeekday(i) {
|
|
531
|
-
return timeInterval((date) => {
|
|
532
|
-
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
|
533
|
-
date.setHours(0, 0, 0, 0);
|
|
534
|
-
}, (date, step) => {
|
|
535
|
-
date.setDate(date.getDate() + step * 7);
|
|
536
|
-
}, (start, end) => {
|
|
537
|
-
return (+end - +start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
var timeSunday = timeWeekday(0);
|
|
541
|
-
var timeMonday = timeWeekday(1);
|
|
542
|
-
var timeTuesday = timeWeekday(2);
|
|
543
|
-
var timeWednesday = timeWeekday(3);
|
|
544
|
-
var timeThursday = timeWeekday(4);
|
|
545
|
-
var timeFriday = timeWeekday(5);
|
|
546
|
-
var timeSaturday = timeWeekday(6);
|
|
547
|
-
var timeSundays = timeSunday.range;
|
|
548
|
-
var timeMondays = timeMonday.range;
|
|
549
|
-
var timeTuesdays = timeTuesday.range;
|
|
550
|
-
var timeWednesdays = timeWednesday.range;
|
|
551
|
-
var timeThursdays = timeThursday.range;
|
|
552
|
-
var timeFridays = timeFriday.range;
|
|
553
|
-
var timeSaturdays = timeSaturday.range;
|
|
554
|
-
function utcWeekday(i) {
|
|
555
|
-
return timeInterval((date) => {
|
|
556
|
-
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
|
557
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
558
|
-
}, (date, step) => {
|
|
559
|
-
date.setUTCDate(date.getUTCDate() + step * 7);
|
|
560
|
-
}, (start, end) => {
|
|
561
|
-
return (+end - +start) / durationWeek;
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
var utcSunday = utcWeekday(0);
|
|
565
|
-
var utcMonday = utcWeekday(1);
|
|
566
|
-
var utcTuesday = utcWeekday(2);
|
|
567
|
-
var utcWednesday = utcWeekday(3);
|
|
568
|
-
var utcThursday = utcWeekday(4);
|
|
569
|
-
var utcFriday = utcWeekday(5);
|
|
570
|
-
var utcSaturday = utcWeekday(6);
|
|
571
|
-
var utcSundays = utcSunday.range;
|
|
572
|
-
var utcMondays = utcMonday.range;
|
|
573
|
-
var utcTuesdays = utcTuesday.range;
|
|
574
|
-
var utcWednesdays = utcWednesday.range;
|
|
575
|
-
var utcThursdays = utcThursday.range;
|
|
576
|
-
var utcFridays = utcFriday.range;
|
|
577
|
-
var utcSaturdays = utcSaturday.range;
|
|
578
|
-
var timeMonth = timeInterval((date) => {
|
|
579
|
-
date.setDate(1);
|
|
580
|
-
date.setHours(0, 0, 0, 0);
|
|
581
|
-
}, (date, step) => {
|
|
582
|
-
date.setMonth(date.getMonth() + step);
|
|
583
|
-
}, (start, end) => {
|
|
584
|
-
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
|
585
|
-
}, (date) => {
|
|
586
|
-
return date.getMonth();
|
|
587
|
-
});
|
|
588
|
-
var timeMonths = timeMonth.range;
|
|
589
|
-
var utcMonth = timeInterval((date) => {
|
|
590
|
-
date.setUTCDate(1);
|
|
591
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
592
|
-
}, (date, step) => {
|
|
593
|
-
date.setUTCMonth(date.getUTCMonth() + step);
|
|
594
|
-
}, (start, end) => {
|
|
595
|
-
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
|
596
|
-
}, (date) => {
|
|
597
|
-
return date.getUTCMonth();
|
|
598
|
-
});
|
|
599
|
-
var utcMonths = utcMonth.range;
|
|
600
|
-
var timeYear = timeInterval((date) => {
|
|
601
|
-
date.setMonth(0, 1);
|
|
602
|
-
date.setHours(0, 0, 0, 0);
|
|
603
|
-
}, (date, step) => {
|
|
604
|
-
date.setFullYear(date.getFullYear() + step);
|
|
605
|
-
}, (start, end) => {
|
|
606
|
-
return end.getFullYear() - start.getFullYear();
|
|
607
|
-
}, (date) => {
|
|
608
|
-
return date.getFullYear();
|
|
609
|
-
});
|
|
610
|
-
timeYear.every = (k) => {
|
|
611
|
-
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
|
|
612
|
-
date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
|
613
|
-
date.setMonth(0, 1);
|
|
614
|
-
date.setHours(0, 0, 0, 0);
|
|
615
|
-
}, (date, step) => {
|
|
616
|
-
date.setFullYear(date.getFullYear() + step * k);
|
|
617
|
-
});
|
|
618
|
-
};
|
|
619
|
-
var timeYears = timeYear.range;
|
|
620
|
-
var utcYear = timeInterval((date) => {
|
|
621
|
-
date.setUTCMonth(0, 1);
|
|
622
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
623
|
-
}, (date, step) => {
|
|
624
|
-
date.setUTCFullYear(date.getUTCFullYear() + step);
|
|
625
|
-
}, (start, end) => {
|
|
626
|
-
return end.getUTCFullYear() - start.getUTCFullYear();
|
|
627
|
-
}, (date) => {
|
|
628
|
-
return date.getUTCFullYear();
|
|
629
|
-
});
|
|
630
|
-
utcYear.every = (k) => {
|
|
631
|
-
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
|
|
632
|
-
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
|
633
|
-
date.setUTCMonth(0, 1);
|
|
634
|
-
date.setUTCHours(0, 0, 0, 0);
|
|
635
|
-
}, (date, step) => {
|
|
636
|
-
date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
var utcYears = utcYear.range;
|
|
640
|
-
var e10 = Math.sqrt(50);
|
|
641
|
-
var e5 = Math.sqrt(10);
|
|
642
|
-
var e2 = Math.sqrt(2);
|
|
643
|
-
function tickSpec(start, stop, count) {
|
|
644
|
-
const step = (stop - start) / Math.max(0, count), power = Math.floor(Math.log10(step)), error = step / Math.pow(10, power), factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
|
|
645
|
-
let i1, i2, inc;
|
|
646
|
-
if (power < 0) {
|
|
647
|
-
inc = Math.pow(10, -power) / factor;
|
|
648
|
-
i1 = Math.round(start * inc);
|
|
649
|
-
i2 = Math.round(stop * inc);
|
|
650
|
-
if (i1 / inc < start)
|
|
651
|
-
++i1;
|
|
652
|
-
if (i2 / inc > stop)
|
|
653
|
-
--i2;
|
|
654
|
-
inc = -inc;
|
|
655
|
-
} else {
|
|
656
|
-
inc = Math.pow(10, power) * factor;
|
|
657
|
-
i1 = Math.round(start / inc);
|
|
658
|
-
i2 = Math.round(stop / inc);
|
|
659
|
-
if (i1 * inc < start)
|
|
660
|
-
++i1;
|
|
661
|
-
if (i2 * inc > stop)
|
|
662
|
-
--i2;
|
|
663
|
-
}
|
|
664
|
-
if (i2 < i1 && 0.5 <= count && count < 2)
|
|
665
|
-
return tickSpec(start, stop, count * 2);
|
|
666
|
-
return [i1, i2, inc];
|
|
667
|
-
}
|
|
668
|
-
function tickIncrement(start, stop, count) {
|
|
669
|
-
return tickSpec(start, stop, count)[2];
|
|
670
|
-
}
|
|
671
|
-
function tickStep(start, stop, count) {
|
|
672
|
-
const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
|
|
673
|
-
return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
|
|
674
|
-
}
|
|
675
|
-
function ticker(year, month, week, day, hour, minute) {
|
|
676
|
-
const tickIntervals = [
|
|
677
|
-
[second, 1, durationSecond],
|
|
678
|
-
[second, 5, 5 * durationSecond],
|
|
679
|
-
[second, 15, 15 * durationSecond],
|
|
680
|
-
[second, 30, 30 * durationSecond],
|
|
681
|
-
[minute, 1, durationMinute],
|
|
682
|
-
[minute, 5, 5 * durationMinute],
|
|
683
|
-
[minute, 15, 15 * durationMinute],
|
|
684
|
-
[minute, 30, 30 * durationMinute],
|
|
685
|
-
[hour, 1, durationHour],
|
|
686
|
-
[hour, 3, 3 * durationHour],
|
|
687
|
-
[hour, 6, 6 * durationHour],
|
|
688
|
-
[hour, 12, 12 * durationHour],
|
|
689
|
-
[day, 1, durationDay],
|
|
690
|
-
[day, 2, 2 * durationDay],
|
|
691
|
-
[week, 1, durationWeek],
|
|
692
|
-
[month, 1, durationMonth],
|
|
693
|
-
[month, 3, 3 * durationMonth],
|
|
694
|
-
[year, 1, durationYear]
|
|
695
|
-
];
|
|
696
|
-
function ticks(start, stop, count) {
|
|
697
|
-
const reverse = +stop < +start;
|
|
698
|
-
if (reverse)
|
|
699
|
-
[start, stop] = [stop, start];
|
|
700
|
-
const interval = typeof count !== "number" ? count : tickInterval(start, stop, count);
|
|
701
|
-
const ticks = interval ? interval.range(start, +stop + 1) : [];
|
|
702
|
-
return reverse ? ticks.reverse() : ticks;
|
|
703
|
-
}
|
|
704
|
-
function tickInterval(start, stop, count) {
|
|
705
|
-
const target = Math.abs(+stop - +start) / count;
|
|
706
|
-
let low = 0;
|
|
707
|
-
let high = tickIntervals.length;
|
|
708
|
-
if (Number.isNaN(target))
|
|
709
|
-
low = high;
|
|
710
|
-
while (low < high) {
|
|
711
|
-
const middle = low + high >>> 1;
|
|
712
|
-
if (tickIntervals[middle][2] <= target)
|
|
713
|
-
low = middle + 1;
|
|
714
|
-
else
|
|
715
|
-
high = middle;
|
|
716
|
-
}
|
|
717
|
-
const i = low;
|
|
718
|
-
if (i === tickIntervals.length)
|
|
719
|
-
return year.every(tickStep(+start / durationYear, +stop / durationYear, count));
|
|
720
|
-
if (i === 0)
|
|
721
|
-
return millisecond.every(Math.max(tickStep(+start, +stop, count), 1));
|
|
722
|
-
const previous = tickIntervals[i - 1];
|
|
723
|
-
const next = tickIntervals[i];
|
|
724
|
-
const [t, step] = target / previous[2] < next[2] / target ? previous : next;
|
|
725
|
-
return t.every(step);
|
|
726
|
-
}
|
|
727
|
-
return [ticks, tickInterval];
|
|
728
|
-
}
|
|
729
|
-
var [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
|
|
730
|
-
var [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
|
|
731
|
-
|
|
732
|
-
// src/react/ui/chart-time.ts
|
|
733
|
-
var day = 86400000;
|
|
734
|
-
var calendarDatePattern = /^\d{4}-\d{2}-\d{2}$/;
|
|
735
|
-
function isCalendarDate(value) {
|
|
736
|
-
return typeof value === "string" && calendarDatePattern.test(value);
|
|
737
|
-
}
|
|
738
|
-
function chartTimestamp(value, numeric = false) {
|
|
739
|
-
if (isCalendarDate(value)) {
|
|
740
|
-
return parseDateTime2(`${value}T00:00:00Z`)?.getTime() ?? null;
|
|
741
|
-
}
|
|
742
|
-
if (value instanceof Date || typeof value === "string" || numeric && typeof value === "number") {
|
|
743
|
-
return parseDateTime2(value)?.getTime() ?? null;
|
|
744
|
-
}
|
|
745
|
-
return null;
|
|
746
|
-
}
|
|
747
|
-
function timeModel(values, numeric = false) {
|
|
748
|
-
const timestamps = new Set;
|
|
749
|
-
for (const value of values) {
|
|
750
|
-
const timestamp = chartTimestamp(value, numeric);
|
|
751
|
-
if (timestamp == null)
|
|
752
|
-
return null;
|
|
753
|
-
timestamps.add(timestamp);
|
|
754
|
-
}
|
|
755
|
-
const times = [...timestamps].sort((a, b) => a - b);
|
|
756
|
-
const start = times[0];
|
|
757
|
-
const end = times.at(-1);
|
|
758
|
-
if (start == null || end == null)
|
|
759
|
-
return null;
|
|
760
|
-
let minimumInterval = Infinity;
|
|
761
|
-
for (let index = 1;index < times.length; index++) {
|
|
762
|
-
minimumInterval = Math.min(minimumInterval, times[index] - times[index - 1]);
|
|
763
|
-
}
|
|
764
|
-
if (times.length === 1)
|
|
765
|
-
minimumInterval = day;
|
|
766
|
-
const dateOnly = values.every(isCalendarDate);
|
|
767
|
-
const seconds = times.some((value) => value % 60000 !== 0) || minimumInterval < 60000;
|
|
768
|
-
const milliseconds = times.some((value) => value % 1000 !== 0) || minimumInterval < 1000;
|
|
769
|
-
function tooltip(value) {
|
|
770
|
-
const time = chartTimestamp(value, true);
|
|
771
|
-
if (time == null)
|
|
772
|
-
return typeof value === "string" || typeof value === "number" ? String(value) : "";
|
|
773
|
-
if (dateOnly)
|
|
774
|
-
return formatDate2(new Date(time).toISOString().slice(0, 10));
|
|
775
|
-
if (milliseconds) {
|
|
776
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
777
|
-
timeZone: "UTC",
|
|
778
|
-
year: "numeric",
|
|
779
|
-
month: "short",
|
|
780
|
-
day: "numeric",
|
|
781
|
-
hour: "2-digit",
|
|
782
|
-
minute: "2-digit",
|
|
783
|
-
second: "2-digit",
|
|
784
|
-
fractionalSecondDigits: 3,
|
|
785
|
-
hourCycle: "h23"
|
|
786
|
-
}).format(time);
|
|
787
|
-
}
|
|
788
|
-
return formatDateTime2(time, {
|
|
789
|
-
precision: seconds ? "second" : "minute",
|
|
790
|
-
timeZone: "UTC"
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
return {
|
|
794
|
-
start,
|
|
795
|
-
end,
|
|
796
|
-
times,
|
|
797
|
-
minimumInterval,
|
|
798
|
-
tooltip
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
function datePart(value, options) {
|
|
802
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
803
|
-
...options,
|
|
804
|
-
timeZone: "UTC"
|
|
805
|
-
}).format(value);
|
|
806
|
-
}
|
|
807
|
-
function timeTicks2(model, width) {
|
|
808
|
-
const { start, end } = model;
|
|
809
|
-
const firstDate = new Date(start);
|
|
810
|
-
const lastDate = new Date(end);
|
|
811
|
-
const spansYears = firstDate.getUTCFullYear() !== lastDate.getUTCFullYear();
|
|
812
|
-
const spansDates = firstDate.toISOString().slice(0, 10) !== lastDate.toISOString().slice(0, 10);
|
|
813
|
-
const count = Math.max(2, Math.min(12, Math.floor(width / 80), model.times.length));
|
|
814
|
-
let ticks = start === end ? [start] : utcTicks(new Date(start), new Date(end), Math.min(count, (end - start) / model.minimumInterval)).map(Number);
|
|
815
|
-
const step = ticks.length > 1 ? ticks[1] - ticks[0] : Math.max(end - start, model.minimumInterval);
|
|
816
|
-
const candidates = [...new Set([start, ...ticks, end])].sort((a, b) => a - b);
|
|
817
|
-
ticks = [start];
|
|
818
|
-
const gap = step < 1000 ? 110 : 80;
|
|
819
|
-
for (const value of candidates.slice(1)) {
|
|
820
|
-
if ((value - ticks.at(-1)) / (end - start) * width >= gap)
|
|
821
|
-
ticks.push(value);
|
|
822
|
-
}
|
|
823
|
-
if (end !== start && ticks.at(-1) !== end) {
|
|
824
|
-
if (ticks.length > 1 && (end - ticks.at(-1)) / (end - start) * width < gap)
|
|
825
|
-
ticks.pop();
|
|
826
|
-
ticks.push(end);
|
|
827
|
-
}
|
|
828
|
-
function label(value, index) {
|
|
829
|
-
const previous = index > 0 ? new Date(ticks[index - 1]) : undefined;
|
|
830
|
-
const date = new Date(value);
|
|
831
|
-
const yearChanged = !previous || previous.getUTCFullYear() !== date.getUTCFullYear();
|
|
832
|
-
const dateChanged = !previous || previous.toISOString().slice(0, 10) !== date.toISOString().slice(0, 10);
|
|
833
|
-
if (step >= 300 * day)
|
|
834
|
-
return { main: String(date.getUTCFullYear()), context: "" };
|
|
835
|
-
if (step >= 28 * day && (model.minimumInterval >= 28 * day || end - start >= 180 * day))
|
|
836
|
-
return {
|
|
837
|
-
main: datePart(value, { month: "short" }),
|
|
838
|
-
context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
|
|
839
|
-
};
|
|
840
|
-
if (step >= day && !(model.minimumInterval < day && end - start <= 3 * day))
|
|
841
|
-
return {
|
|
842
|
-
main: datePart(value, { month: "short", day: "numeric" }),
|
|
843
|
-
context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
|
|
844
|
-
};
|
|
845
|
-
return {
|
|
846
|
-
main: datePart(value, {
|
|
847
|
-
hour: "2-digit",
|
|
848
|
-
minute: "2-digit",
|
|
849
|
-
...step < 60000 ? { second: "2-digit" } : {},
|
|
850
|
-
...step < 1000 ? { fractionalSecondDigits: 3 } : {},
|
|
851
|
-
hourCycle: "h23"
|
|
852
|
-
}),
|
|
853
|
-
context: spansDates && dateChanged ? datePart(value, {
|
|
854
|
-
month: "short",
|
|
855
|
-
day: "numeric",
|
|
856
|
-
...spansYears && yearChanged ? { year: "numeric" } : {}
|
|
857
|
-
}) : ""
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
return { ticks, label };
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// src/react/ui/chart-date-axis.tsx
|
|
864
|
-
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
865
|
-
var ChartDateAxesContext = createContext(null);
|
|
866
|
-
function ChartDateAxes({
|
|
867
|
-
data,
|
|
868
|
-
children
|
|
869
|
-
}) {
|
|
870
|
-
const [formatters, setFormatters] = useState(() => new Map);
|
|
871
|
-
const register = useCallback((id, formatter) => {
|
|
872
|
-
setFormatters((current) => new Map(current).set(id, formatter));
|
|
873
|
-
return () => setFormatters((current) => {
|
|
874
|
-
const next = new Map(current);
|
|
875
|
-
next.delete(id);
|
|
876
|
-
return next;
|
|
877
|
-
});
|
|
878
|
-
}, []);
|
|
879
|
-
return /* @__PURE__ */ jsx5(ChartDateAxesContext.Provider, {
|
|
880
|
-
value: { data, formatters, register },
|
|
881
|
-
children
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
function useDateAxisLabel(id = 0) {
|
|
885
|
-
return useContext(ChartDateAxesContext)?.formatters.get(id);
|
|
886
|
-
}
|
|
887
|
-
function field(row, key) {
|
|
888
|
-
if (row == null || typeof row !== "object")
|
|
889
|
-
return;
|
|
890
|
-
if (key in row)
|
|
891
|
-
return row[key];
|
|
892
|
-
return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : undefined, row);
|
|
893
|
-
}
|
|
894
|
-
var xAxisDefaults = {
|
|
895
|
-
stroke: "var(--atbl-muted)",
|
|
896
|
-
tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
|
|
897
|
-
tickLine: false,
|
|
898
|
-
axisLine: { stroke: "var(--atbl-border)" },
|
|
899
|
-
tick: { fontSize: "var(--atbl-type-meta-size)" }
|
|
900
|
-
};
|
|
901
|
-
function ChartXAxis(props) {
|
|
902
|
-
const context = useContext(ChartDateAxesContext);
|
|
903
|
-
const plot = usePlotArea();
|
|
904
|
-
const data = context?.data;
|
|
905
|
-
const { dataKey, ...axisProps } = props;
|
|
906
|
-
const numeric = props.scale === "utc";
|
|
907
|
-
const enabled = numeric || props.type == null && props.scale == null && props.tickFormatter == null && props.ticks == null;
|
|
908
|
-
const model = useMemo(() => {
|
|
909
|
-
if (!enabled || !data?.length || dataKey == null)
|
|
910
|
-
return null;
|
|
911
|
-
return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), numeric);
|
|
912
|
-
}, [data, dataKey, enabled, numeric]);
|
|
913
|
-
const register = context?.register;
|
|
914
|
-
const id = props.xAxisId ?? 0;
|
|
915
|
-
useEffect(() => model ? register?.(id, model.tooltip) : undefined, [register, id, model]);
|
|
916
|
-
if (!model || dataKey == null) {
|
|
917
|
-
return /* @__PURE__ */ jsx5(XAxis, {
|
|
918
|
-
...xAxisDefaults,
|
|
919
|
-
...props
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
const automaticTicks = props.ticks == null && props.tickFormatter == null ? timeTicks2(model, plot?.width ?? 400) : null;
|
|
923
|
-
return /* @__PURE__ */ jsx5(XAxis, {
|
|
924
|
-
...xAxisDefaults,
|
|
925
|
-
scale: "utc",
|
|
926
|
-
domain: model.start === model.end ? [
|
|
927
|
-
model.start - model.minimumInterval / 2,
|
|
928
|
-
model.end + model.minimumInterval / 2
|
|
929
|
-
] : [model.start, model.end],
|
|
930
|
-
ticks: automaticTicks?.ticks,
|
|
931
|
-
interval: automaticTicks ? 0 : undefined,
|
|
932
|
-
height: 48,
|
|
933
|
-
tickFormatter: model.tooltip,
|
|
934
|
-
tick: automaticTicks ? ({ x, y, payload, index }) => {
|
|
935
|
-
const label = automaticTicks.label(Number(payload.value), index);
|
|
936
|
-
return /* @__PURE__ */ jsxs3("text", {
|
|
937
|
-
x,
|
|
938
|
-
y: Number(y) + 5,
|
|
939
|
-
fill: "var(--atbl-muted)",
|
|
940
|
-
fontSize: "var(--atbl-type-meta-size)",
|
|
941
|
-
textAnchor: index === 0 ? "start" : index === automaticTicks.ticks.length - 1 ? "end" : "middle",
|
|
942
|
-
children: [
|
|
943
|
-
/* @__PURE__ */ jsx5("tspan", {
|
|
944
|
-
x,
|
|
945
|
-
dy: "0.8em",
|
|
946
|
-
children: label.main
|
|
947
|
-
}),
|
|
948
|
-
label.context && /* @__PURE__ */ jsx5("tspan", {
|
|
949
|
-
x,
|
|
950
|
-
dy: "1.4em",
|
|
951
|
-
children: label.context
|
|
952
|
-
})
|
|
953
|
-
]
|
|
954
|
-
});
|
|
955
|
-
} : xAxisDefaults.tick,
|
|
956
|
-
...axisProps,
|
|
957
|
-
type: "number",
|
|
958
|
-
dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
// src/react/ui/chart-primitives.tsx
|
|
963
|
-
import { useContext as useContext3, useLayoutEffect as useLayoutEffect2 } from "react";
|
|
964
|
-
|
|
965
|
-
// src/react/ui/chart-interaction.tsx
|
|
966
|
-
import {
|
|
967
|
-
createContext as createContext2,
|
|
968
|
-
useContext as useContext2,
|
|
969
|
-
useId,
|
|
970
|
-
useEffect as useEffect2
|
|
971
|
-
} from "react";
|
|
972
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
973
|
-
var ChartInteractionContext = createContext2(null);
|
|
974
|
-
function isChartSeriesActive(interaction, seriesId) {
|
|
975
|
-
return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
|
|
976
|
-
}
|
|
977
|
-
function useChartSeries(id) {
|
|
978
|
-
const generatedId = useId();
|
|
979
|
-
const interaction = useContext2(ChartInteractionContext);
|
|
980
|
-
const seriesId = id ?? generatedId;
|
|
981
|
-
const registerSeries = interaction?.registerSeries;
|
|
982
|
-
useEffect2(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
|
|
983
|
-
return {
|
|
984
|
-
id: seriesId,
|
|
985
|
-
active: isChartSeriesActive(interaction, seriesId)
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
function ChartSeries({
|
|
989
|
-
id,
|
|
990
|
-
children
|
|
991
|
-
}) {
|
|
992
|
-
const interaction = useContext2(ChartInteractionContext);
|
|
993
|
-
return /* @__PURE__ */ jsx6("g", {
|
|
994
|
-
onPointerOver: () => interaction?.setHoveredSeriesId(id),
|
|
995
|
-
onPointerDown: () => interaction?.setHoveredSeriesId(id),
|
|
996
|
-
children
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
// src/react/ui/chart-primitives.tsx
|
|
1001
|
-
import {
|
|
1002
|
-
Area,
|
|
1003
|
-
Dot,
|
|
1004
|
-
Bar,
|
|
1005
|
-
Line,
|
|
1006
|
-
Scatter,
|
|
1007
|
-
YAxis,
|
|
1008
|
-
CartesianGrid,
|
|
1009
|
-
Tooltip,
|
|
1010
|
-
DefaultTooltipContent
|
|
1011
|
-
} from "recharts";
|
|
1012
|
-
|
|
1013
|
-
// src/react/ui/ChartLegend.tsx
|
|
1014
|
-
import {
|
|
1015
|
-
Children,
|
|
1016
|
-
useId as useId2,
|
|
1017
|
-
useEffect as useEffect3,
|
|
1018
|
-
useRef as useRef2,
|
|
1019
|
-
useState as useState2
|
|
1020
|
-
} from "react";
|
|
1021
|
-
import { jsx as jsx7, jsxs as jsxs4, Fragment } from "react/jsx-runtime";
|
|
1022
|
-
function ChartLegendRoot({
|
|
1023
|
-
children,
|
|
1024
|
-
layout = "horizontal",
|
|
1025
|
-
align = "start",
|
|
1026
|
-
maxVisibleItems,
|
|
1027
|
-
className,
|
|
1028
|
-
"aria-label": ariaLabel = "Chart legend",
|
|
1029
|
-
...props
|
|
1030
|
-
}) {
|
|
1031
|
-
const [expanded, setExpanded] = useState2(false);
|
|
1032
|
-
const listId = useId2();
|
|
1033
|
-
const containerRef = useRef2(null);
|
|
1034
|
-
const [columns, setColumns] = useState2(2);
|
|
1035
|
-
useEffect3(() => {
|
|
1036
|
-
const container = containerRef.current;
|
|
1037
|
-
if (!container)
|
|
1038
|
-
return;
|
|
1039
|
-
function measure() {
|
|
1040
|
-
const list = containerRef.current?.firstElementChild;
|
|
1041
|
-
if (list) {
|
|
1042
|
-
setColumns(getComputedStyle(list).gridTemplateColumns.split(" ").length);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
const observer = new ResizeObserver(measure);
|
|
1046
|
-
observer.observe(container);
|
|
1047
|
-
measure();
|
|
1048
|
-
return () => observer.disconnect();
|
|
1049
|
-
}, [layout]);
|
|
1050
|
-
const items = Children.toArray(children);
|
|
1051
|
-
const rowCapacity = layout === "vertical" ? 6 : columns * (layout === "single-row" ? 1 : 2);
|
|
1052
|
-
const configuredLimit = typeof maxVisibleItems === "number" && Number.isFinite(maxVisibleItems) ? Math.max(1, Math.floor(maxVisibleItems)) : rowCapacity;
|
|
1053
|
-
const cappedLimit = Math.min(configuredLimit, rowCapacity);
|
|
1054
|
-
const limit = layout === "vertical" ? configuredLimit : cappedLimit >= columns ? Math.floor(cappedLimit / columns) * columns : cappedLimit;
|
|
1055
|
-
const visibleCount = items.length > limit ? limit - 1 : limit;
|
|
1056
|
-
const hiddenCount = Math.max(0, items.length - visibleCount);
|
|
1057
|
-
return /* @__PURE__ */ jsx7("div", {
|
|
1058
|
-
ref: containerRef,
|
|
1059
|
-
className: "altertable-chart-legend-container",
|
|
1060
|
-
children: /* @__PURE__ */ jsxs4("ul", {
|
|
1061
|
-
id: listId,
|
|
1062
|
-
...props,
|
|
1063
|
-
"aria-label": ariaLabel,
|
|
1064
|
-
"data-layout": layout,
|
|
1065
|
-
"data-align": align,
|
|
1066
|
-
className: classNames("altertable-chart-legend", className),
|
|
1067
|
-
children: [
|
|
1068
|
-
expanded ? items : items.slice(0, visibleCount),
|
|
1069
|
-
hiddenCount > 0 && /* @__PURE__ */ jsx7("li", {
|
|
1070
|
-
className: "altertable-chart-legend-overflow",
|
|
1071
|
-
children: /* @__PURE__ */ jsx7("button", {
|
|
1072
|
-
type: "button",
|
|
1073
|
-
"data-atbl-control": "action",
|
|
1074
|
-
"data-atbl-focus": "ring",
|
|
1075
|
-
className: "altertable-chart-legend-action",
|
|
1076
|
-
"aria-expanded": expanded,
|
|
1077
|
-
"aria-controls": props.id ?? listId,
|
|
1078
|
-
onClick: () => setExpanded((value) => !value),
|
|
1079
|
-
children: expanded ? "Show fewer" : `+${hiddenCount} more`
|
|
1080
|
-
})
|
|
1081
|
-
})
|
|
1082
|
-
]
|
|
1083
|
-
})
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
function ChartLegendItem({
|
|
1087
|
-
inactive,
|
|
1088
|
-
className,
|
|
1089
|
-
...props
|
|
1090
|
-
}) {
|
|
1091
|
-
return /* @__PURE__ */ jsx7("li", {
|
|
1092
|
-
...props,
|
|
1093
|
-
"data-inactive": inactive || undefined,
|
|
1094
|
-
className: classNames("altertable-chart-legend-item", className)
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
function ChartLegendMarker({
|
|
1098
|
-
kind,
|
|
1099
|
-
color = kind === "bar" ? chartBarFill : "var(--atbl-chart-1)",
|
|
1100
|
-
className,
|
|
1101
|
-
style,
|
|
1102
|
-
...props
|
|
1103
|
-
}) {
|
|
1104
|
-
return /* @__PURE__ */ jsxs4("svg", {
|
|
1105
|
-
...props,
|
|
1106
|
-
"aria-hidden": "true",
|
|
1107
|
-
focusable: "false",
|
|
1108
|
-
viewBox: kind === "square" ? "0 0 8 8" : "0 0 20 12",
|
|
1109
|
-
"data-kind": kind,
|
|
1110
|
-
className: classNames("altertable-chart-legend-marker", className),
|
|
1111
|
-
style: { color, ...style },
|
|
1112
|
-
children: [
|
|
1113
|
-
kind === "square" && /* @__PURE__ */ jsx7("rect", {
|
|
1114
|
-
width: "8",
|
|
1115
|
-
height: "8",
|
|
1116
|
-
fill: "currentColor"
|
|
1117
|
-
}),
|
|
1118
|
-
kind === "bar" && /* @__PURE__ */ jsx7("path", {
|
|
1119
|
-
d: "M6 11V3Q6 1 8 1H12Q14 1 14 3V11Z",
|
|
1120
|
-
fill: "currentColor"
|
|
1121
|
-
}),
|
|
1122
|
-
kind === "slice" && /* @__PURE__ */ jsx7("rect", {
|
|
1123
|
-
x: "5",
|
|
1124
|
-
y: "1",
|
|
1125
|
-
width: "10",
|
|
1126
|
-
height: "10",
|
|
1127
|
-
rx: "2",
|
|
1128
|
-
fill: "currentColor"
|
|
1129
|
-
}),
|
|
1130
|
-
kind === "point" && /* @__PURE__ */ jsx7("circle", {
|
|
1131
|
-
cx: "10",
|
|
1132
|
-
cy: "6",
|
|
1133
|
-
r: "3",
|
|
1134
|
-
fill: "currentColor"
|
|
1135
|
-
}),
|
|
1136
|
-
kind === "line" && /* @__PURE__ */ jsxs4(Fragment, {
|
|
1137
|
-
children: [
|
|
1138
|
-
/* @__PURE__ */ jsx7("path", {
|
|
1139
|
-
d: "M1 6H19",
|
|
1140
|
-
fill: "none",
|
|
1141
|
-
stroke: "currentColor",
|
|
1142
|
-
strokeWidth: "2",
|
|
1143
|
-
strokeLinecap: "round"
|
|
1144
|
-
}),
|
|
1145
|
-
/* @__PURE__ */ jsx7("circle", {
|
|
1146
|
-
cx: "10",
|
|
1147
|
-
cy: "6",
|
|
1148
|
-
r: "2.5",
|
|
1149
|
-
fill: "var(--atbl-surface)",
|
|
1150
|
-
stroke: "currentColor",
|
|
1151
|
-
strokeWidth: "2"
|
|
1152
|
-
})
|
|
1153
|
-
]
|
|
1154
|
-
}),
|
|
1155
|
-
kind === "area" && /* @__PURE__ */ jsxs4(Fragment, {
|
|
1156
|
-
children: [
|
|
1157
|
-
/* @__PURE__ */ jsx7("path", {
|
|
1158
|
-
d: "M1 10L7 5L13 7L19 2V11H1Z",
|
|
1159
|
-
fill: "currentColor",
|
|
1160
|
-
fillOpacity: "0.14"
|
|
1161
|
-
}),
|
|
1162
|
-
/* @__PURE__ */ jsx7("path", {
|
|
1163
|
-
d: "M1 10L7 5L13 7L19 2",
|
|
1164
|
-
fill: "none",
|
|
1165
|
-
stroke: "currentColor",
|
|
1166
|
-
strokeWidth: "2",
|
|
1167
|
-
strokeLinejoin: "round",
|
|
1168
|
-
strokeLinecap: "round"
|
|
1169
|
-
})
|
|
1170
|
-
]
|
|
1171
|
-
})
|
|
1172
|
-
]
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
function ChartLegendLabel({
|
|
1176
|
-
className,
|
|
1177
|
-
children,
|
|
1178
|
-
title,
|
|
1179
|
-
...props
|
|
1180
|
-
}) {
|
|
1181
|
-
return /* @__PURE__ */ jsx7("span", {
|
|
1182
|
-
...props,
|
|
1183
|
-
title: title ?? (typeof children === "string" ? children : undefined),
|
|
1184
|
-
className: classNames("altertable-chart-legend-label", className),
|
|
1185
|
-
children
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
var ChartLegend = Object.assign(ChartLegendRoot, {
|
|
1189
|
-
Item: ChartLegendItem,
|
|
1190
|
-
Marker: ChartLegendMarker,
|
|
1191
|
-
Label: ChartLegendLabel
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
// src/react/ui/chart-primitives.tsx
|
|
1195
|
-
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1196
|
-
var seriesColor = "var(--atbl-chart-1)";
|
|
1197
|
-
function ChartDot({
|
|
1198
|
-
active = false,
|
|
1199
|
-
stroke = seriesColor,
|
|
1200
|
-
fill = active ? stroke : "var(--atbl-surface)",
|
|
1201
|
-
r = active ? 4.5 : 3,
|
|
1202
|
-
...props
|
|
1203
|
-
}) {
|
|
1204
|
-
return /* @__PURE__ */ jsx8(Dot, {
|
|
1205
|
-
stroke,
|
|
1206
|
-
fill,
|
|
1207
|
-
r,
|
|
1208
|
-
strokeWidth: 2,
|
|
1209
|
-
...props
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
function NearestChartDot({
|
|
1213
|
-
seriesId,
|
|
1214
|
-
cx,
|
|
1215
|
-
cy,
|
|
1216
|
-
stroke
|
|
1217
|
-
}) {
|
|
1218
|
-
const interaction = useContext3(ChartInteractionContext);
|
|
1219
|
-
const registerPoint = interaction?.registerPoint;
|
|
1220
|
-
useLayoutEffect2(() => {
|
|
1221
|
-
if (cx == null || cy == null)
|
|
1222
|
-
return;
|
|
1223
|
-
return registerPoint?.(seriesId, cx, cy);
|
|
1224
|
-
}, [registerPoint, seriesId, cx, cy]);
|
|
1225
|
-
const active = isChartSeriesActive(interaction, seriesId);
|
|
1226
|
-
return active ? /* @__PURE__ */ jsx8(ChartDot, {
|
|
1227
|
-
cx,
|
|
1228
|
-
cy,
|
|
1229
|
-
stroke,
|
|
1230
|
-
active: true,
|
|
1231
|
-
style: { pointerEvents: "none" }
|
|
1232
|
-
}) : null;
|
|
1233
|
-
}
|
|
1234
|
-
function ChartBar(props) {
|
|
1235
|
-
const series = useChartSeries(props.id);
|
|
1236
|
-
return /* @__PURE__ */ jsx8(ChartSeries, {
|
|
1237
|
-
id: series.id,
|
|
1238
|
-
children: /* @__PURE__ */ jsx8(Bar, {
|
|
1239
|
-
fill: chartBarFill,
|
|
1240
|
-
radius: props.stackId == null ? [5, 5, 0, 0] : 0,
|
|
1241
|
-
maxBarSize: 30,
|
|
1242
|
-
activeBar: series.active ? { opacity: 0.75 } : false,
|
|
1243
|
-
isAnimationActive: false,
|
|
1244
|
-
...props,
|
|
1245
|
-
id: series.id
|
|
1246
|
-
})
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
function ChartLine({
|
|
1250
|
-
stroke = seriesColor,
|
|
1251
|
-
dot = false,
|
|
1252
|
-
activeDot,
|
|
1253
|
-
...props
|
|
1254
|
-
}) {
|
|
1255
|
-
const series = useChartSeries(props.id);
|
|
1256
|
-
return /* @__PURE__ */ jsx8(ChartSeries, {
|
|
1257
|
-
id: series.id,
|
|
1258
|
-
children: /* @__PURE__ */ jsx8(Line, {
|
|
1259
|
-
type: "linear",
|
|
1260
|
-
stroke,
|
|
1261
|
-
strokeWidth: 2,
|
|
1262
|
-
strokeLinecap: "round",
|
|
1263
|
-
strokeLinejoin: "round",
|
|
1264
|
-
dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(ChartDot, {
|
|
1265
|
-
cx,
|
|
1266
|
-
cy,
|
|
1267
|
-
stroke
|
|
1268
|
-
}) : dot,
|
|
1269
|
-
activeDot: activeDot === undefined || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(NearestChartDot, {
|
|
1270
|
-
seriesId: series.id,
|
|
1271
|
-
cx,
|
|
1272
|
-
cy,
|
|
1273
|
-
stroke
|
|
1274
|
-
}) : activeDot,
|
|
1275
|
-
isAnimationActive: false,
|
|
1276
|
-
...props,
|
|
1277
|
-
id: series.id
|
|
1278
|
-
})
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
function ChartArea({
|
|
1282
|
-
stroke = seriesColor,
|
|
1283
|
-
dot = false,
|
|
1284
|
-
activeDot,
|
|
1285
|
-
...props
|
|
1286
|
-
}) {
|
|
1287
|
-
const series = useChartSeries(props.id);
|
|
1288
|
-
return /* @__PURE__ */ jsx8(ChartSeries, {
|
|
1289
|
-
id: series.id,
|
|
1290
|
-
children: /* @__PURE__ */ jsx8(Area, {
|
|
1291
|
-
legendType: "square",
|
|
1292
|
-
type: "linear",
|
|
1293
|
-
stroke,
|
|
1294
|
-
strokeWidth: 2,
|
|
1295
|
-
strokeLinecap: "round",
|
|
1296
|
-
strokeLinejoin: "round",
|
|
1297
|
-
fill: stroke,
|
|
1298
|
-
fillOpacity: 0.14,
|
|
1299
|
-
dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(ChartDot, {
|
|
1300
|
-
cx,
|
|
1301
|
-
cy,
|
|
1302
|
-
stroke
|
|
1303
|
-
}) : dot,
|
|
1304
|
-
activeDot: activeDot === undefined || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx8(NearestChartDot, {
|
|
1305
|
-
seriesId: series.id,
|
|
1306
|
-
cx,
|
|
1307
|
-
cy,
|
|
1308
|
-
stroke
|
|
1309
|
-
}) : activeDot,
|
|
1310
|
-
isAnimationActive: false,
|
|
1311
|
-
...props,
|
|
1312
|
-
id: series.id
|
|
1313
|
-
})
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
function ChartScatter(props) {
|
|
1317
|
-
const series = useChartSeries(props.id);
|
|
1318
|
-
return /* @__PURE__ */ jsx8(ChartSeries, {
|
|
1319
|
-
id: series.id,
|
|
1320
|
-
children: /* @__PURE__ */ jsx8(Scatter, {
|
|
1321
|
-
fill: seriesColor,
|
|
1322
|
-
isAnimationActive: false,
|
|
1323
|
-
...props,
|
|
1324
|
-
id: series.id
|
|
1325
|
-
})
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
function ChartYAxis(props) {
|
|
1329
|
-
return /* @__PURE__ */ jsx8(YAxis, {
|
|
1330
|
-
stroke: "var(--atbl-muted)",
|
|
1331
|
-
tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
|
|
1332
|
-
tickLine: false,
|
|
1333
|
-
axisLine: false,
|
|
1334
|
-
tick: { fontSize: "var(--atbl-type-meta-size)" },
|
|
1335
|
-
...props
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
function ChartGrid(props) {
|
|
1339
|
-
return /* @__PURE__ */ jsx8(CartesianGrid, {
|
|
1340
|
-
stroke: "var(--atbl-border)",
|
|
1341
|
-
vertical: false,
|
|
1342
|
-
...props
|
|
1343
|
-
});
|
|
1344
|
-
}
|
|
1345
|
-
function ChartTooltipContent(props) {
|
|
1346
|
-
if (!props.active || !props.payload?.length)
|
|
1347
|
-
return null;
|
|
1348
|
-
return /* @__PURE__ */ jsx8(TooltipSurface, {
|
|
1349
|
-
"data-variant": "chart",
|
|
1350
|
-
role: "tooltip",
|
|
1351
|
-
children: /* @__PURE__ */ jsx8(DefaultTooltipContent, {
|
|
1352
|
-
...props,
|
|
1353
|
-
separator: "",
|
|
1354
|
-
payload: props.payload?.map((entry) => ({
|
|
1355
|
-
...entry,
|
|
1356
|
-
unit: undefined,
|
|
1357
|
-
formatter: (value, name, _item, index, payload) => {
|
|
1358
|
-
const formatter = entry.formatter ?? props.formatter;
|
|
1359
|
-
const formatted = formatter ? formatter(value, name, entry, index, props.payload ?? payload) : Array.isArray(value) ? value.map((item) => typeof item === "number" ? formatNumber2(item) : item).join(" ~ ") : typeof value === "number" ? formatNumber2(value) : value;
|
|
1360
|
-
if (formatted == null)
|
|
1361
|
-
return null;
|
|
1362
|
-
const [displayValue, displayName] = Array.isArray(formatted) ? formatted : [formatted, name];
|
|
1363
|
-
return [
|
|
1364
|
-
/* @__PURE__ */ jsxs5("span", {
|
|
1365
|
-
className: "altertable-chart-tooltip-row",
|
|
1366
|
-
children: [
|
|
1367
|
-
/* @__PURE__ */ jsx8(ChartLegend.Marker, {
|
|
1368
|
-
kind: "square",
|
|
1369
|
-
className: "altertable-chart-tooltip-marker",
|
|
1370
|
-
color: entry.color ?? entry.stroke ?? entry.fill ?? "var(--atbl-chart-1)"
|
|
1371
|
-
}),
|
|
1372
|
-
/* @__PURE__ */ jsxs5("span", {
|
|
1373
|
-
className: "altertable-chart-tooltip-reading",
|
|
1374
|
-
children: [
|
|
1375
|
-
displayName,
|
|
1376
|
-
displayName !== undefined && displayName !== "" ? props.separator ?? " : " : "",
|
|
1377
|
-
displayValue,
|
|
1378
|
-
entry.unit
|
|
1379
|
-
]
|
|
1380
|
-
})
|
|
1381
|
-
]
|
|
1382
|
-
}, entry.graphicalItemId),
|
|
1383
|
-
""
|
|
1384
|
-
];
|
|
1385
|
-
}
|
|
1386
|
-
})),
|
|
1387
|
-
contentStyle: {
|
|
1388
|
-
margin: 0,
|
|
1389
|
-
padding: 0,
|
|
1390
|
-
background: "transparent",
|
|
1391
|
-
border: 0,
|
|
1392
|
-
whiteSpace: "normal",
|
|
1393
|
-
...props.contentStyle
|
|
1394
|
-
},
|
|
1395
|
-
labelStyle: {
|
|
1396
|
-
color: "var(--atbl-text)",
|
|
1397
|
-
fontSize: "var(--atbl-type-body-size)",
|
|
1398
|
-
fontWeight: 650,
|
|
1399
|
-
lineHeight: 1.2,
|
|
1400
|
-
...props.labelStyle
|
|
1401
|
-
},
|
|
1402
|
-
itemStyle: {
|
|
1403
|
-
color: "var(--atbl-text)",
|
|
1404
|
-
paddingTop: 2,
|
|
1405
|
-
paddingBottom: 0,
|
|
1406
|
-
...props.itemStyle
|
|
1407
|
-
}
|
|
1408
|
-
})
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
|
-
function ChartTooltip(props) {
|
|
1412
|
-
const dateLabel = useDateAxisLabel(props.axisId);
|
|
1413
|
-
const interaction = useContext3(ChartInteractionContext);
|
|
1414
|
-
return /* @__PURE__ */ jsx8(Tooltip, {
|
|
1415
|
-
labelFormatter: dateLabel,
|
|
1416
|
-
content: (content) => /* @__PURE__ */ jsx8(ChartTooltipContent, {
|
|
1417
|
-
...content,
|
|
1418
|
-
payload: interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload
|
|
1419
|
-
}),
|
|
1420
|
-
position: interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : undefined,
|
|
1421
|
-
cursor: false,
|
|
1422
|
-
isAnimationActive: false,
|
|
1423
|
-
...props
|
|
1424
|
-
});
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
// src/react/ui/chart-data.ts
|
|
1428
|
-
function validateChartIds(kind, items) {
|
|
1429
|
-
const ids = new Set;
|
|
1430
|
-
for (const item of items) {
|
|
1431
|
-
invariant(item.id.trim().length > 0, `${kind} chart IDs must be nonempty and unique: blank ID.`);
|
|
1432
|
-
invariant(!ids.has(item.id), `${kind} chart IDs must be nonempty and unique: duplicate "${item.id}".`);
|
|
1433
|
-
ids.add(item.id);
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
function validateValueChartItems(kind, items) {
|
|
1437
|
-
validateChartIds(kind, items);
|
|
1438
|
-
for (const item of items) {
|
|
1439
|
-
invariant(Number.isFinite(item.value), `${kind} chart "${item.id}" requires finite values.`);
|
|
1440
|
-
invariant(kind !== "bar" && kind !== "pie" || item.value >= 0, `${kind} chart "${item.id}" requires nonnegative values.`);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
function validateScatterChartItems(items) {
|
|
1444
|
-
validateChartIds("scatter", items);
|
|
1445
|
-
for (const item of items) {
|
|
1446
|
-
invariant(Number.isFinite(item.x) && Number.isFinite(item.y), `scatter chart "${item.id}" requires finite values for x and y.`);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
// src/react/ui/TrendChart.tsx
|
|
1451
|
-
import { jsx as jsx9, jsxs as jsxs6, Fragment as Fragment3 } from "react/jsx-runtime";
|
|
1452
|
-
function TrendChart({
|
|
1453
|
-
items,
|
|
1454
|
-
unit,
|
|
1455
|
-
ariaLabel,
|
|
1456
|
-
formatValue = formatNumber2,
|
|
1457
|
-
kind,
|
|
1458
|
-
itemActions
|
|
1459
|
-
}) {
|
|
1460
|
-
validateValueChartItems(kind, items);
|
|
1461
|
-
const Plot = kind === "area" ? RechartsAreaChart : RechartsLineChart;
|
|
1462
|
-
const chartActions = useChartActions();
|
|
1463
|
-
const [activeIndex, setActiveIndex] = useState3();
|
|
1464
|
-
const scrollport = useChartScrollToEnd(items);
|
|
1465
|
-
const menuTriggers = useRef3(new Map);
|
|
1466
|
-
const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
|
|
1467
|
-
const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
|
|
1468
|
-
const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
|
|
1469
|
-
return /* @__PURE__ */ jsxs6("section", {
|
|
1470
|
-
className: "altertable-trend-chart",
|
|
1471
|
-
"aria-label": ariaLabel,
|
|
1472
|
-
children: [
|
|
1473
|
-
items.length === 0 && /* @__PURE__ */ jsx9("span", {
|
|
1474
|
-
children: "No data"
|
|
1475
|
-
}),
|
|
1476
|
-
items.length > 0 && /* @__PURE__ */ jsx9(Fragment3, {
|
|
1477
|
-
children: /* @__PURE__ */ jsx9("div", {
|
|
1478
|
-
className: "altertable-trend-scroll",
|
|
1479
|
-
ref: scrollport,
|
|
1480
|
-
children: /* @__PURE__ */ jsxs6("div", {
|
|
1481
|
-
className: "altertable-trend-plot",
|
|
1482
|
-
style: { minWidth: items.length * 40 },
|
|
1483
|
-
children: [
|
|
1484
|
-
/* @__PURE__ */ jsx9("div", {
|
|
1485
|
-
className: "altertable-chart-canvas",
|
|
1486
|
-
"aria-hidden": "true",
|
|
1487
|
-
children: /* @__PURE__ */ jsxs6(Plot, {
|
|
1488
|
-
data: items.map((item) => ({
|
|
1489
|
-
...item,
|
|
1490
|
-
plotValue: item.value / magnitude
|
|
1491
|
-
})),
|
|
1492
|
-
responsive: true,
|
|
1493
|
-
width: "100%",
|
|
1494
|
-
height: 220,
|
|
1495
|
-
margin: { top: 12, right: 0, bottom: 12, left: 0 },
|
|
1496
|
-
accessibilityLayer: false,
|
|
1497
|
-
tabIndex: -1,
|
|
1498
|
-
children: [
|
|
1499
|
-
/* @__PURE__ */ jsx9(ChartXAxis, {
|
|
1500
|
-
hide: true,
|
|
1501
|
-
dataKey: "id",
|
|
1502
|
-
scale: "band"
|
|
1503
|
-
}),
|
|
1504
|
-
/* @__PURE__ */ jsx9(ChartYAxis, {
|
|
1505
|
-
hide: true,
|
|
1506
|
-
domain: [low, high === low ? low + 1 : high]
|
|
1507
|
-
}),
|
|
1508
|
-
/* @__PURE__ */ jsx9(ReferenceLine, {
|
|
1509
|
-
y: 0,
|
|
1510
|
-
stroke: "var(--atbl-border)"
|
|
1511
|
-
}),
|
|
1512
|
-
kind === "area" && /* @__PURE__ */ jsx9(ChartArea, {
|
|
1513
|
-
dataKey: "plotValue",
|
|
1514
|
-
stroke: "none",
|
|
1515
|
-
fill: "var(--atbl-chart-1)",
|
|
1516
|
-
dot: false,
|
|
1517
|
-
activeDot: false
|
|
1518
|
-
}),
|
|
1519
|
-
/* @__PURE__ */ jsx9(ChartLine, {
|
|
1520
|
-
dataKey: "plotValue",
|
|
1521
|
-
dot: ({ cx, cy, index }) => index === activeIndex ? /* @__PURE__ */ jsx9(ChartDot, {
|
|
1522
|
-
cx,
|
|
1523
|
-
cy,
|
|
1524
|
-
active: index === activeIndex
|
|
1525
|
-
}) : /* @__PURE__ */ jsx9("g", {}),
|
|
1526
|
-
activeDot: false
|
|
1527
|
-
})
|
|
1528
|
-
]
|
|
1529
|
-
})
|
|
1530
|
-
}),
|
|
1531
|
-
/* @__PURE__ */ jsx9("div", {
|
|
1532
|
-
className: "altertable-trend-points",
|
|
1533
|
-
children: items.map((item, index) => {
|
|
1534
|
-
const declaredActions = itemActions?.(item) ?? [];
|
|
1535
|
-
const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
|
|
1536
|
-
const action = getPrimaryExplorationAction(actions);
|
|
1537
|
-
const menuTrigger = {
|
|
1538
|
-
get current() {
|
|
1539
|
-
return menuTriggers.current.get(item.id) ?? null;
|
|
1540
|
-
}
|
|
1541
|
-
};
|
|
1542
|
-
return /* @__PURE__ */ jsx9(Fragment2, {
|
|
1543
|
-
children: /* @__PURE__ */ jsxs6("div", {
|
|
1544
|
-
className: "altertable-chart-item-actions",
|
|
1545
|
-
children: [
|
|
1546
|
-
/* @__PURE__ */ jsx9(Tooltip2, {
|
|
1547
|
-
variant: "chart",
|
|
1548
|
-
onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? undefined : current),
|
|
1549
|
-
content: /* @__PURE__ */ jsxs6(Fragment3, {
|
|
1550
|
-
children: [
|
|
1551
|
-
/* @__PURE__ */ jsx9("strong", {
|
|
1552
|
-
children: item.label
|
|
1553
|
-
}),
|
|
1554
|
-
/* @__PURE__ */ jsxs6("span", {
|
|
1555
|
-
children: [
|
|
1556
|
-
formatValue(item.value),
|
|
1557
|
-
" ",
|
|
1558
|
-
unit
|
|
1559
|
-
]
|
|
1560
|
-
})
|
|
1561
|
-
]
|
|
1562
|
-
}),
|
|
1563
|
-
className: "altertable-chart-column",
|
|
1564
|
-
children: action ? /* @__PURE__ */ jsxs6("button", {
|
|
1565
|
-
"data-atbl-focus": "ring",
|
|
1566
|
-
"data-atbl-control": "action",
|
|
1567
|
-
type: "button",
|
|
1568
|
-
className: "altertable-trend-point",
|
|
1569
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
|
|
1570
|
-
...explorationMenuEvents(menuTrigger),
|
|
1571
|
-
onClick: (event) => action.onSelect(event.currentTarget),
|
|
1572
|
-
children: [
|
|
1573
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1574
|
-
className: "altertable-trend-hit"
|
|
1575
|
-
}),
|
|
1576
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1577
|
-
className: "altertable-trend-label",
|
|
1578
|
-
children: item.label
|
|
1579
|
-
})
|
|
1580
|
-
]
|
|
1581
|
-
}) : actions.length > 1 ? /* @__PURE__ */ jsxs6(MenuTrigger2, {
|
|
1582
|
-
children: [
|
|
1583
|
-
/* @__PURE__ */ jsxs6(PressButton, {
|
|
1584
|
-
...explorationMenuEvents(menuTrigger),
|
|
1585
|
-
ref: (element) => {
|
|
1586
|
-
if (element)
|
|
1587
|
-
menuTriggers.current.set(item.id, element);
|
|
1588
|
-
else
|
|
1589
|
-
menuTriggers.current.delete(item.id);
|
|
1590
|
-
},
|
|
1591
|
-
className: "altertable-trend-point",
|
|
1592
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
|
|
1593
|
-
children: [
|
|
1594
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1595
|
-
className: "altertable-trend-hit"
|
|
1596
|
-
}),
|
|
1597
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1598
|
-
className: "altertable-trend-label",
|
|
1599
|
-
children: item.label
|
|
1600
|
-
})
|
|
1601
|
-
]
|
|
1602
|
-
}),
|
|
1603
|
-
/* @__PURE__ */ jsx9(ExplorationActionMenu, {
|
|
1604
|
-
actions,
|
|
1605
|
-
ariaLabel: `${item.label} actions`,
|
|
1606
|
-
triggerRef: menuTrigger
|
|
1607
|
-
})
|
|
1608
|
-
]
|
|
1609
|
-
}) : /* @__PURE__ */ jsxs6("button", {
|
|
1610
|
-
"data-atbl-focus": "ring",
|
|
1611
|
-
"data-atbl-control": "default",
|
|
1612
|
-
type: "button",
|
|
1613
|
-
tabIndex: -1,
|
|
1614
|
-
className: "altertable-trend-point",
|
|
1615
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
|
|
1616
|
-
children: [
|
|
1617
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1618
|
-
className: "altertable-trend-hit"
|
|
1619
|
-
}),
|
|
1620
|
-
/* @__PURE__ */ jsx9("span", {
|
|
1621
|
-
className: "altertable-trend-label",
|
|
1622
|
-
children: item.label
|
|
1623
|
-
})
|
|
1624
|
-
]
|
|
1625
|
-
})
|
|
1626
|
-
}),
|
|
1627
|
-
action && /* @__PURE__ */ jsx9(ExplorationActionControl2, {
|
|
1628
|
-
contextOnly: declaredActions.length === 1,
|
|
1629
|
-
indicator: "chevron",
|
|
1630
|
-
ref: (element) => {
|
|
1631
|
-
if (element)
|
|
1632
|
-
menuTriggers.current.set(item.id, element);
|
|
1633
|
-
else
|
|
1634
|
-
menuTriggers.current.delete(item.id);
|
|
1635
|
-
},
|
|
1636
|
-
actions,
|
|
1637
|
-
ariaLabel: `${item.label} actions`,
|
|
1638
|
-
hidePrimary: Boolean(action)
|
|
1639
|
-
})
|
|
1640
|
-
]
|
|
1641
|
-
})
|
|
1642
|
-
}, item.id);
|
|
1643
|
-
})
|
|
1644
|
-
})
|
|
1645
|
-
]
|
|
1646
|
-
})
|
|
1647
|
-
})
|
|
1648
|
-
}),
|
|
1649
|
-
chartActions.feedback
|
|
1650
|
-
]
|
|
1651
|
-
});
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
// src/react/ui/LineChart.tsx
|
|
1655
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1656
|
-
function LineChart(props) {
|
|
1657
|
-
return /* @__PURE__ */ jsx10(TrendChart, {
|
|
1658
|
-
...props,
|
|
1659
|
-
kind: "line"
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
// src/react/ui/AreaChart.tsx
|
|
1663
|
-
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1664
|
-
function AreaChart(props) {
|
|
1665
|
-
return /* @__PURE__ */ jsx11(TrendChart, {
|
|
1666
|
-
...props,
|
|
1667
|
-
kind: "area"
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
// src/react/ui/PieChart.tsx
|
|
1671
|
-
import { useRef as useRef4, useState as useState4 } from "react";
|
|
1672
|
-
import { jsx as jsx12, jsxs as jsxs7, Fragment as Fragment4 } from "react/jsx-runtime";
|
|
1673
|
-
function PieChart({
|
|
1674
|
-
items,
|
|
1675
|
-
unit,
|
|
1676
|
-
ariaLabel,
|
|
1677
|
-
showLegend = true,
|
|
1678
|
-
formatValue = (value) => new Intl.NumberFormat().format(value),
|
|
1679
|
-
itemActions
|
|
1680
|
-
}) {
|
|
1681
|
-
validateValueChartItems("pie", items);
|
|
1682
|
-
const chartActions = useChartActions();
|
|
1683
|
-
const [previewId, setPreviewId] = useState4(null);
|
|
1684
|
-
const [plotOpen, setPlotOpen] = useState4(false);
|
|
1685
|
-
const [legendId, setLegendId] = useState4(null);
|
|
1686
|
-
const menuTriggers = useRef4(new Map);
|
|
1687
|
-
const plotMenuTriggers = useRef4(new Map);
|
|
1688
|
-
const maximum = items.reduce((max, item) => Math.max(max, item.value), 0);
|
|
1689
|
-
const total = maximum ? items.reduce((sum, item) => sum + item.value / maximum, 0) : 0;
|
|
1690
|
-
let cursor = -Math.PI / 2;
|
|
1691
|
-
const slices = [];
|
|
1692
|
-
for (const [index, item] of items.entries()) {
|
|
1693
|
-
let point = function(angle) {
|
|
1694
|
-
return `${110 + Math.cos(angle) * 100},${110 + Math.sin(angle) * 100}`;
|
|
1695
|
-
};
|
|
1696
|
-
const share = total ? item.value / maximum / total : 0;
|
|
1697
|
-
const start = cursor;
|
|
1698
|
-
cursor += share * Math.PI * 2;
|
|
1699
|
-
const middle = (start + cursor) / 2;
|
|
1700
|
-
slices.push({
|
|
1701
|
-
row: item,
|
|
1702
|
-
share,
|
|
1703
|
-
color: `var(--atbl-chart-${index % 8 + 1})`,
|
|
1704
|
-
path: `${share === 1 ? "M" : "M110,110 L"}${point(start)} A100,100 0 0 1 ${point(middle)} A100,100 0 0 1 ${point(cursor)} Z`
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
function percent(share) {
|
|
1708
|
-
return new Intl.NumberFormat("en-US", {
|
|
1709
|
-
style: "percent",
|
|
1710
|
-
maximumFractionDigits: 1
|
|
1711
|
-
}).format(share);
|
|
1712
|
-
}
|
|
1713
|
-
function detail(slice) {
|
|
1714
|
-
const item = slice.row;
|
|
1715
|
-
return /* @__PURE__ */ jsxs7(Fragment4, {
|
|
1716
|
-
children: [
|
|
1717
|
-
/* @__PURE__ */ jsx12("strong", {
|
|
1718
|
-
children: item.label
|
|
1719
|
-
}),
|
|
1720
|
-
/* @__PURE__ */ jsxs7("span", {
|
|
1721
|
-
children: [
|
|
1722
|
-
formatValue(item.value),
|
|
1723
|
-
" ",
|
|
1724
|
-
unit,
|
|
1725
|
-
" · ",
|
|
1726
|
-
percent(slice.share)
|
|
1727
|
-
]
|
|
1728
|
-
})
|
|
1729
|
-
]
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
function actionsFor(slice) {
|
|
1733
|
-
const item = slice.row;
|
|
1734
|
-
return chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit} · ${percent(slice.share)}`);
|
|
1735
|
-
}
|
|
1736
|
-
const preview = slices.find((slice) => slice.row.id === previewId);
|
|
1737
|
-
return /* @__PURE__ */ jsxs7("section", {
|
|
1738
|
-
className: "altertable-pie-chart",
|
|
1739
|
-
"aria-label": ariaLabel,
|
|
1740
|
-
children: [
|
|
1741
|
-
items.length === 0 && /* @__PURE__ */ jsx12("span", {
|
|
1742
|
-
children: "No data"
|
|
1743
|
-
}),
|
|
1744
|
-
items.length > 0 && /* @__PURE__ */ jsxs7(Fragment4, {
|
|
1745
|
-
children: [
|
|
1746
|
-
/* @__PURE__ */ jsxs7("div", {
|
|
1747
|
-
className: "altertable-pie-plot",
|
|
1748
|
-
children: [
|
|
1749
|
-
/* @__PURE__ */ jsx12(Tooltip2, {
|
|
1750
|
-
variant: "chart",
|
|
1751
|
-
className: "altertable-pie-tooltip",
|
|
1752
|
-
onOpenChange: setPlotOpen,
|
|
1753
|
-
content: preview ? detail(preview) : null,
|
|
1754
|
-
children: /* @__PURE__ */ jsx12("svg", {
|
|
1755
|
-
viewBox: "0 0 220 220",
|
|
1756
|
-
"aria-hidden": itemActions ? undefined : true,
|
|
1757
|
-
"aria-label": itemActions ? ariaLabel : undefined,
|
|
1758
|
-
focusable: itemActions ? undefined : false,
|
|
1759
|
-
role: itemActions ? "group" : undefined,
|
|
1760
|
-
children: total === 0 ? /* @__PURE__ */ jsx12("circle", {
|
|
1761
|
-
cx: "110",
|
|
1762
|
-
cy: "110",
|
|
1763
|
-
r: "100",
|
|
1764
|
-
className: "altertable-pie-empty"
|
|
1765
|
-
}) : slices.filter((slice) => slice.share > 0).map((slice) => {
|
|
1766
|
-
const item = slice.row;
|
|
1767
|
-
const menuTrigger = {
|
|
1768
|
-
get current() {
|
|
1769
|
-
return menuTriggers.current.get(item.id) ?? plotMenuTriggers.current.get(item.id) ?? null;
|
|
1770
|
-
}
|
|
1771
|
-
};
|
|
1772
|
-
const action = getPrimaryExplorationAction(actionsFor(slice));
|
|
1773
|
-
const opensMenu = !action && (itemActions?.(item).length ?? 0) > 1;
|
|
1774
|
-
return /* @__PURE__ */ jsx12("path", {
|
|
1775
|
-
d: slice.path,
|
|
1776
|
-
fill: slice.color,
|
|
1777
|
-
className: "altertable-pie-slice",
|
|
1778
|
-
"data-active": item.id === (plotOpen && previewId ? previewId : showLegend ? legendId : null) || undefined,
|
|
1779
|
-
onPointerDown: (event) => {
|
|
1780
|
-
if (plotOpen && previewId !== item.id)
|
|
1781
|
-
event.preventDefault();
|
|
1782
|
-
setPreviewId(item.id);
|
|
1783
|
-
},
|
|
1784
|
-
onClick: (event) => {
|
|
1785
|
-
if (action)
|
|
1786
|
-
action.onSelect(event.currentTarget);
|
|
1787
|
-
else if (opensMenu)
|
|
1788
|
-
menuTrigger.current?.click();
|
|
1789
|
-
},
|
|
1790
|
-
onContextMenu: explorationMenuEvents(menuTrigger).onContextMenu,
|
|
1791
|
-
onKeyDown: (event) => {
|
|
1792
|
-
explorationMenuEvents(menuTrigger).onKeyDown(event);
|
|
1793
|
-
if ((action || opensMenu) && (event.key === "Enter" || event.key === " ")) {
|
|
1794
|
-
event.preventDefault();
|
|
1795
|
-
if (action)
|
|
1796
|
-
action.onSelect(event.currentTarget);
|
|
1797
|
-
else
|
|
1798
|
-
menuTrigger.current?.click();
|
|
1799
|
-
}
|
|
1800
|
-
},
|
|
1801
|
-
"aria-label": action ? `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}` : opensMenu ? `${item.label}: ${formatValue(item.value)} ${unit}. Actions` : undefined,
|
|
1802
|
-
role: action || opensMenu ? "button" : undefined,
|
|
1803
|
-
"data-atbl-control": action || opensMenu ? "action" : undefined,
|
|
1804
|
-
tabIndex: action || opensMenu ? 0 : undefined,
|
|
1805
|
-
onPointerEnter: (event) => {
|
|
1806
|
-
if (event.pointerType === "mouse")
|
|
1807
|
-
setPreviewId(item.id);
|
|
1808
|
-
},
|
|
1809
|
-
onPointerLeave: (event) => {
|
|
1810
|
-
if (event.pointerType === "mouse")
|
|
1811
|
-
setPreviewId(null);
|
|
1812
|
-
}
|
|
1813
|
-
}, item.id);
|
|
1814
|
-
})
|
|
1815
|
-
})
|
|
1816
|
-
}),
|
|
1817
|
-
slices.map((slice) => {
|
|
1818
|
-
const item = slice.row;
|
|
1819
|
-
const actions = actionsFor(slice);
|
|
1820
|
-
if (actions.length === 0)
|
|
1821
|
-
return null;
|
|
1822
|
-
return /* @__PURE__ */ jsx12("span", {
|
|
1823
|
-
className: "altertable-sr-only",
|
|
1824
|
-
children: /* @__PURE__ */ jsx12(ExplorationActionControl2, {
|
|
1825
|
-
ref: (element) => {
|
|
1826
|
-
if (element)
|
|
1827
|
-
plotMenuTriggers.current.set(item.id, element);
|
|
1828
|
-
else
|
|
1829
|
-
plotMenuTriggers.current.delete(item.id);
|
|
1830
|
-
},
|
|
1831
|
-
actions,
|
|
1832
|
-
ariaLabel: `${item.label} actions`,
|
|
1833
|
-
contextOnly: true,
|
|
1834
|
-
hidePrimary: true
|
|
1835
|
-
})
|
|
1836
|
-
}, item.id);
|
|
1837
|
-
}),
|
|
1838
|
-
total === 0 && /* @__PURE__ */ jsx12("span", {
|
|
1839
|
-
className: "altertable-pie-empty-label",
|
|
1840
|
-
children: "No nonzero values"
|
|
1841
|
-
})
|
|
1842
|
-
]
|
|
1843
|
-
}),
|
|
1844
|
-
showLegend && /* @__PURE__ */ jsx12(ChartLegend, {
|
|
1845
|
-
layout: "vertical",
|
|
1846
|
-
"aria-label": `${ariaLabel} legend`,
|
|
1847
|
-
className: "altertable-pie-legend",
|
|
1848
|
-
children: slices.map((slice) => {
|
|
1849
|
-
const item = slice.row;
|
|
1850
|
-
const actions = actionsFor(slice);
|
|
1851
|
-
const menuTrigger = {
|
|
1852
|
-
get current() {
|
|
1853
|
-
return menuTriggers.current.get(item.id) ?? null;
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
const label = `${item.label}: ${formatValue(item.value)} ${unit}, ${percent(slice.share)}${actions.length ? ". Actions" : ""}`;
|
|
1857
|
-
const contents = /* @__PURE__ */ jsxs7(Fragment4, {
|
|
1858
|
-
children: [
|
|
1859
|
-
/* @__PURE__ */ jsx12(ChartLegend.Marker, {
|
|
1860
|
-
kind: "square",
|
|
1861
|
-
color: slice.color
|
|
1862
|
-
}),
|
|
1863
|
-
/* @__PURE__ */ jsx12(ChartLegend.Label, {
|
|
1864
|
-
className: "altertable-pie-label",
|
|
1865
|
-
children: item.label
|
|
1866
|
-
}),
|
|
1867
|
-
actions.length > 0 && /* @__PURE__ */ jsx12(AppIcon2, {
|
|
1868
|
-
name: "moreActions",
|
|
1869
|
-
size: 14,
|
|
1870
|
-
className: "altertable-pie-menu-indicator"
|
|
1871
|
-
}),
|
|
1872
|
-
/* @__PURE__ */ jsx12("strong", {
|
|
1873
|
-
className: "altertable-pie-value",
|
|
1874
|
-
children: formatValue(item.value)
|
|
1875
|
-
}),
|
|
1876
|
-
/* @__PURE__ */ jsx12("span", {
|
|
1877
|
-
className: "altertable-pie-share",
|
|
1878
|
-
children: percent(slice.share)
|
|
1879
|
-
})
|
|
1880
|
-
]
|
|
1881
|
-
});
|
|
1882
|
-
return /* @__PURE__ */ jsx12(ChartLegend.Item, {
|
|
1883
|
-
children: /* @__PURE__ */ jsx12(Tooltip2, {
|
|
1884
|
-
variant: "chart",
|
|
1885
|
-
content: detail(slice),
|
|
1886
|
-
onOpenChange: (open) => setLegendId((current) => open ? item.id : current === item.id ? null : current),
|
|
1887
|
-
children: actions.length ? /* @__PURE__ */ jsxs7(MenuTrigger2, {
|
|
1888
|
-
children: [
|
|
1889
|
-
/* @__PURE__ */ jsx12(PressButton, {
|
|
1890
|
-
...explorationMenuEvents(menuTrigger),
|
|
1891
|
-
ref: (element) => {
|
|
1892
|
-
if (element)
|
|
1893
|
-
menuTriggers.current.set(item.id, element);
|
|
1894
|
-
else
|
|
1895
|
-
menuTriggers.current.delete(item.id);
|
|
1896
|
-
},
|
|
1897
|
-
"aria-label": label,
|
|
1898
|
-
children: contents
|
|
1899
|
-
}),
|
|
1900
|
-
/* @__PURE__ */ jsx12(ExplorationActionMenu, {
|
|
1901
|
-
actions,
|
|
1902
|
-
ariaLabel: item.label,
|
|
1903
|
-
triggerRef: menuTrigger,
|
|
1904
|
-
placement: "bottom start"
|
|
1905
|
-
})
|
|
1906
|
-
]
|
|
1907
|
-
}) : /* @__PURE__ */ jsx12("button", {
|
|
1908
|
-
type: "button",
|
|
1909
|
-
"data-atbl-focus": "ring",
|
|
1910
|
-
"data-atbl-control": "default",
|
|
1911
|
-
tabIndex: -1,
|
|
1912
|
-
"aria-label": label,
|
|
1913
|
-
children: contents
|
|
1914
|
-
})
|
|
1915
|
-
})
|
|
1916
|
-
}, item.id);
|
|
1917
|
-
})
|
|
1918
|
-
})
|
|
1919
|
-
]
|
|
1920
|
-
}),
|
|
1921
|
-
chartActions.feedback
|
|
1922
|
-
]
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
// src/react/ui/ScatterChart.tsx
|
|
1926
|
-
import { jsx as jsx13, jsxs as jsxs8, Fragment as Fragment5 } from "react/jsx-runtime";
|
|
1927
|
-
function formatNumber(value) {
|
|
1928
|
-
return new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 }).format(value);
|
|
1929
|
-
}
|
|
1930
|
-
function scale(values) {
|
|
1931
|
-
const magnitude = values.reduce((max, value) => Math.max(max, Math.abs(value)), 1);
|
|
1932
|
-
const low = values.reduce((min, value) => Math.min(min, value / magnitude), 0);
|
|
1933
|
-
const high = values.reduce((max, value) => Math.max(max, value / magnitude), 0) || (low === 0 ? 1 : 0);
|
|
1934
|
-
const span = high - low;
|
|
1935
|
-
return {
|
|
1936
|
-
position(value) {
|
|
1937
|
-
return (value / magnitude - low) / span * 100;
|
|
1938
|
-
},
|
|
1939
|
-
ticks: [low, low + span / 2, high].map((value) => value * magnitude)
|
|
1940
|
-
};
|
|
1941
|
-
}
|
|
1942
|
-
function ScatterChart({
|
|
1943
|
-
items,
|
|
1944
|
-
xLabel,
|
|
1945
|
-
yLabel,
|
|
1946
|
-
xUnit,
|
|
1947
|
-
yUnit,
|
|
1948
|
-
ariaLabel,
|
|
1949
|
-
formatX = formatNumber,
|
|
1950
|
-
formatY = formatNumber
|
|
1951
|
-
}) {
|
|
1952
|
-
validateScatterChartItems(items);
|
|
1953
|
-
const xScale = scale(items.map((item) => item.x));
|
|
1954
|
-
const yScale = scale(items.map((item) => item.y));
|
|
1955
|
-
return /* @__PURE__ */ jsxs8("section", {
|
|
1956
|
-
className: "altertable-scatter-chart",
|
|
1957
|
-
"aria-label": ariaLabel,
|
|
1958
|
-
children: [
|
|
1959
|
-
items.length === 0 && /* @__PURE__ */ jsx13("span", {
|
|
1960
|
-
children: "No data"
|
|
1961
|
-
}),
|
|
1962
|
-
items.length > 0 && /* @__PURE__ */ jsxs8(Fragment5, {
|
|
1963
|
-
children: [
|
|
1964
|
-
/* @__PURE__ */ jsxs8("p", {
|
|
1965
|
-
className: "altertable-scatter-axis-title",
|
|
1966
|
-
children: [
|
|
1967
|
-
yLabel,
|
|
1968
|
-
yUnit && ` (${yUnit})`
|
|
1969
|
-
]
|
|
1970
|
-
}),
|
|
1971
|
-
/* @__PURE__ */ jsx13("div", {
|
|
1972
|
-
className: "altertable-scatter-axes",
|
|
1973
|
-
children: /* @__PURE__ */ jsxs8("div", {
|
|
1974
|
-
className: "altertable-scatter-plot",
|
|
1975
|
-
children: [
|
|
1976
|
-
yScale.ticks.map((value, index) => /* @__PURE__ */ jsx13("div", {
|
|
1977
|
-
className: "altertable-scatter-gridline",
|
|
1978
|
-
style: { bottom: `${index * 50}%` },
|
|
1979
|
-
"aria-hidden": "true",
|
|
1980
|
-
children: /* @__PURE__ */ jsx13("span", {
|
|
1981
|
-
title: formatY(value),
|
|
1982
|
-
children: formatY(value)
|
|
1983
|
-
})
|
|
1984
|
-
}, index)),
|
|
1985
|
-
xScale.ticks.map((value, index) => /* @__PURE__ */ jsx13("span", {
|
|
1986
|
-
className: "altertable-scatter-x-tick",
|
|
1987
|
-
"data-edge": index,
|
|
1988
|
-
style: { left: `${index * 50}%` },
|
|
1989
|
-
"aria-hidden": "true",
|
|
1990
|
-
title: formatX(value),
|
|
1991
|
-
children: formatX(value)
|
|
1992
|
-
}, index)),
|
|
1993
|
-
items.map((item) => /* @__PURE__ */ jsx13(Tooltip2, {
|
|
1994
|
-
variant: "chart",
|
|
1995
|
-
content: /* @__PURE__ */ jsxs8(Fragment5, {
|
|
1996
|
-
children: [
|
|
1997
|
-
/* @__PURE__ */ jsx13("strong", {
|
|
1998
|
-
children: item.label
|
|
1999
|
-
}),
|
|
2000
|
-
/* @__PURE__ */ jsxs8("span", {
|
|
2001
|
-
children: [
|
|
2002
|
-
xLabel,
|
|
2003
|
-
": ",
|
|
2004
|
-
formatX(item.x),
|
|
2005
|
-
" ",
|
|
2006
|
-
xUnit
|
|
2007
|
-
]
|
|
2008
|
-
}),
|
|
2009
|
-
/* @__PURE__ */ jsxs8("span", {
|
|
2010
|
-
children: [
|
|
2011
|
-
yLabel,
|
|
2012
|
-
": ",
|
|
2013
|
-
formatY(item.y),
|
|
2014
|
-
" ",
|
|
2015
|
-
yUnit
|
|
2016
|
-
]
|
|
2017
|
-
})
|
|
2018
|
-
]
|
|
2019
|
-
}),
|
|
2020
|
-
className: "altertable-scatter-tooltip",
|
|
2021
|
-
style: {
|
|
2022
|
-
left: `${xScale.position(item.x)}%`,
|
|
2023
|
-
bottom: `${yScale.position(item.y)}%`
|
|
2024
|
-
},
|
|
2025
|
-
children: /* @__PURE__ */ jsx13("button", {
|
|
2026
|
-
"data-atbl-focus": "ring",
|
|
2027
|
-
"data-atbl-control": "default",
|
|
2028
|
-
type: "button",
|
|
2029
|
-
tabIndex: -1,
|
|
2030
|
-
className: "altertable-scatter-point",
|
|
2031
|
-
"aria-label": `${item.label}: ${xLabel} ${formatX(item.x)} ${xUnit}, ${yLabel} ${formatY(item.y)} ${yUnit}`,
|
|
2032
|
-
children: /* @__PURE__ */ jsx13("span", {})
|
|
2033
|
-
})
|
|
2034
|
-
}, item.id))
|
|
2035
|
-
]
|
|
2036
|
-
})
|
|
2037
|
-
}),
|
|
2038
|
-
/* @__PURE__ */ jsxs8("p", {
|
|
2039
|
-
className: "altertable-scatter-axis-title altertable-scatter-x-title",
|
|
2040
|
-
children: [
|
|
2041
|
-
xLabel,
|
|
2042
|
-
xUnit && ` (${xUnit})`
|
|
2043
|
-
]
|
|
2044
|
-
})
|
|
2045
|
-
]
|
|
2046
|
-
})
|
|
2047
|
-
]
|
|
2048
|
-
});
|
|
2049
|
-
}
|
|
2050
|
-
// src/react/ui/BarChart.tsx
|
|
2051
|
-
import {
|
|
2052
|
-
Fragment as Fragment6,
|
|
2053
|
-
useRef as useRef5,
|
|
2054
|
-
useState as useState5
|
|
2055
|
-
} from "react";
|
|
2056
|
-
import { BarChart as RechartsBarChart, Cell } from "recharts";
|
|
2057
|
-
import { jsx as jsx14, jsxs as jsxs9, Fragment as Fragment7 } from "react/jsx-runtime";
|
|
2058
|
-
function BarChart({
|
|
2059
|
-
items,
|
|
2060
|
-
unit,
|
|
2061
|
-
ariaLabel,
|
|
2062
|
-
formatValue = formatNumber2,
|
|
2063
|
-
itemActions
|
|
2064
|
-
}) {
|
|
2065
|
-
validateValueChartItems("bar", items);
|
|
2066
|
-
const chartActions = useChartActions();
|
|
2067
|
-
const [activeId, setActiveId] = useState5();
|
|
2068
|
-
const scrollport = useChartScrollToEnd(items);
|
|
2069
|
-
const menuTriggers = useRef5(new Map);
|
|
2070
|
-
const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
|
|
2071
|
-
return /* @__PURE__ */ jsxs9("section", {
|
|
2072
|
-
className: "altertable-selectable-bars",
|
|
2073
|
-
"aria-label": ariaLabel,
|
|
2074
|
-
children: [
|
|
2075
|
-
items.length === 0 && /* @__PURE__ */ jsx14("span", {
|
|
2076
|
-
children: "No data"
|
|
2077
|
-
}),
|
|
2078
|
-
/* @__PURE__ */ jsx14("div", {
|
|
2079
|
-
className: "altertable-selectable-bars-scroll",
|
|
2080
|
-
ref: scrollport,
|
|
2081
|
-
children: /* @__PURE__ */ jsxs9("div", {
|
|
2082
|
-
className: "altertable-selectable-bars-plot",
|
|
2083
|
-
style: { minWidth: items.length * 45 },
|
|
2084
|
-
children: [
|
|
2085
|
-
/* @__PURE__ */ jsx14("div", {
|
|
2086
|
-
className: "altertable-chart-canvas",
|
|
2087
|
-
"aria-hidden": "true",
|
|
2088
|
-
children: /* @__PURE__ */ jsxs9(RechartsBarChart, {
|
|
2089
|
-
data: items.map((item) => ({
|
|
2090
|
-
...item,
|
|
2091
|
-
plotValue: item.value / maximum
|
|
2092
|
-
})),
|
|
2093
|
-
responsive: true,
|
|
2094
|
-
width: "100%",
|
|
2095
|
-
height: 220,
|
|
2096
|
-
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
2097
|
-
accessibilityLayer: false,
|
|
2098
|
-
tabIndex: -1,
|
|
2099
|
-
barCategoryGap: "24%",
|
|
2100
|
-
children: [
|
|
2101
|
-
/* @__PURE__ */ jsx14(ChartXAxis, {
|
|
2102
|
-
hide: true,
|
|
2103
|
-
dataKey: "id",
|
|
2104
|
-
scale: "band"
|
|
2105
|
-
}),
|
|
2106
|
-
/* @__PURE__ */ jsx14(ChartYAxis, {
|
|
2107
|
-
hide: true,
|
|
2108
|
-
domain: [0, 1],
|
|
2109
|
-
allowDataOverflow: true
|
|
2110
|
-
}),
|
|
2111
|
-
/* @__PURE__ */ jsx14(ChartBar, {
|
|
2112
|
-
dataKey: "plotValue",
|
|
2113
|
-
minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
|
|
2114
|
-
children: items.map((item) => /* @__PURE__ */ jsx14(Cell, {
|
|
2115
|
-
fill: chartBarFill,
|
|
2116
|
-
opacity: activeId === item.id ? 0.75 : 1
|
|
2117
|
-
}, item.id))
|
|
2118
|
-
})
|
|
2119
|
-
]
|
|
2120
|
-
})
|
|
2121
|
-
}),
|
|
2122
|
-
/* @__PURE__ */ jsx14("div", {
|
|
2123
|
-
className: "altertable-selectable-bars-items",
|
|
2124
|
-
children: items.map((item) => {
|
|
2125
|
-
const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
|
|
2126
|
-
const action = getPrimaryExplorationAction(actions);
|
|
2127
|
-
const menuTrigger = {
|
|
2128
|
-
get current() {
|
|
2129
|
-
return menuTriggers.current.get(item.id) ?? null;
|
|
2130
|
-
}
|
|
2131
|
-
};
|
|
2132
|
-
return /* @__PURE__ */ jsx14(Fragment6, {
|
|
2133
|
-
children: /* @__PURE__ */ jsxs9("div", {
|
|
2134
|
-
className: "altertable-chart-item-actions",
|
|
2135
|
-
children: [
|
|
2136
|
-
/* @__PURE__ */ jsx14(Tooltip2, {
|
|
2137
|
-
variant: "chart",
|
|
2138
|
-
onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? undefined : current),
|
|
2139
|
-
content: /* @__PURE__ */ jsxs9(Fragment7, {
|
|
2140
|
-
children: [
|
|
2141
|
-
/* @__PURE__ */ jsx14("strong", {
|
|
2142
|
-
children: item.label
|
|
2143
|
-
}),
|
|
2144
|
-
/* @__PURE__ */ jsxs9("span", {
|
|
2145
|
-
children: [
|
|
2146
|
-
formatValue(item.value),
|
|
2147
|
-
" ",
|
|
2148
|
-
unit
|
|
2149
|
-
]
|
|
2150
|
-
})
|
|
2151
|
-
]
|
|
2152
|
-
}),
|
|
2153
|
-
className: "altertable-chart-column",
|
|
2154
|
-
children: action ? /* @__PURE__ */ jsx14("button", {
|
|
2155
|
-
"data-atbl-focus": "ring",
|
|
2156
|
-
"data-atbl-control": "action",
|
|
2157
|
-
type: "button",
|
|
2158
|
-
className: "altertable-selectable-bars-item",
|
|
2159
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
|
|
2160
|
-
...explorationMenuEvents(menuTrigger),
|
|
2161
|
-
onClick: (event) => action.onSelect(event.currentTarget),
|
|
2162
|
-
children: /* @__PURE__ */ jsx14("span", {
|
|
2163
|
-
className: "altertable-selectable-bars-area"
|
|
2164
|
-
})
|
|
2165
|
-
}) : actions.length ? /* @__PURE__ */ jsx14("button", {
|
|
2166
|
-
type: "button",
|
|
2167
|
-
"data-atbl-focus": "ring",
|
|
2168
|
-
"data-atbl-control": "action",
|
|
2169
|
-
className: "altertable-selectable-bars-item",
|
|
2170
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
|
|
2171
|
-
...explorationMenuEvents(menuTrigger),
|
|
2172
|
-
onClick: (event) => openExplorationMenu(menuTrigger, event),
|
|
2173
|
-
children: /* @__PURE__ */ jsx14("span", {
|
|
2174
|
-
className: "altertable-selectable-bars-area"
|
|
2175
|
-
})
|
|
2176
|
-
}) : /* @__PURE__ */ jsx14("button", {
|
|
2177
|
-
"data-atbl-focus": "ring",
|
|
2178
|
-
"data-atbl-control": "default",
|
|
2179
|
-
type: "button",
|
|
2180
|
-
tabIndex: -1,
|
|
2181
|
-
className: "altertable-selectable-bars-item",
|
|
2182
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
|
|
2183
|
-
children: /* @__PURE__ */ jsx14("span", {
|
|
2184
|
-
className: "altertable-selectable-bars-area"
|
|
2185
|
-
})
|
|
2186
|
-
})
|
|
2187
|
-
}),
|
|
2188
|
-
/* @__PURE__ */ jsx14("div", {
|
|
2189
|
-
className: "altertable-chart-item-label-row",
|
|
2190
|
-
children: actions.length ? /* @__PURE__ */ jsxs9(MenuTrigger2, {
|
|
2191
|
-
children: [
|
|
2192
|
-
/* @__PURE__ */ jsxs9(PressButton, {
|
|
2193
|
-
className: "altertable-selectable-bars-label",
|
|
2194
|
-
variant: "ghost",
|
|
2195
|
-
size: "compact",
|
|
2196
|
-
...explorationMenuEvents(menuTrigger),
|
|
2197
|
-
ref: (element) => {
|
|
2198
|
-
if (element)
|
|
2199
|
-
menuTriggers.current.set(item.id, element);
|
|
2200
|
-
else
|
|
2201
|
-
menuTriggers.current.delete(item.id);
|
|
2202
|
-
},
|
|
2203
|
-
"aria-label": `${item.label}: Actions`,
|
|
2204
|
-
children: [
|
|
2205
|
-
item.label,
|
|
2206
|
-
/* @__PURE__ */ jsx14(AppIcon2, {
|
|
2207
|
-
name: "disclosure",
|
|
2208
|
-
size: 12
|
|
2209
|
-
})
|
|
2210
|
-
]
|
|
2211
|
-
}),
|
|
2212
|
-
/* @__PURE__ */ jsx14(ExplorationActionMenu, {
|
|
2213
|
-
actions,
|
|
2214
|
-
ariaLabel: item.label,
|
|
2215
|
-
triggerRef: menuTrigger,
|
|
2216
|
-
placement: "bottom"
|
|
2217
|
-
})
|
|
2218
|
-
]
|
|
2219
|
-
}) : /* @__PURE__ */ jsx14("span", {
|
|
2220
|
-
className: "altertable-selectable-bars-label",
|
|
2221
|
-
children: item.label
|
|
2222
|
-
})
|
|
2223
|
-
})
|
|
2224
|
-
]
|
|
2225
|
-
})
|
|
2226
|
-
}, item.id);
|
|
2227
|
-
})
|
|
2228
|
-
})
|
|
2229
|
-
]
|
|
2230
|
-
})
|
|
2231
|
-
}),
|
|
2232
|
-
chartActions.feedback
|
|
2233
|
-
]
|
|
2234
|
-
});
|
|
2235
|
-
}
|
|
2236
|
-
// src/react/ui/RadioGroup.tsx
|
|
2237
|
-
import {
|
|
2238
|
-
RadioGroup as AriaRadioGroup,
|
|
2239
|
-
Radio as AriaRadio,
|
|
2240
|
-
Label
|
|
2241
|
-
} from "react-aria-components";
|
|
2242
|
-
import { jsx as jsx15, jsxs as jsxs10, Fragment as Fragment8 } from "react/jsx-runtime";
|
|
2243
|
-
function RadioGroup({
|
|
2244
|
-
label,
|
|
2245
|
-
className,
|
|
2246
|
-
children,
|
|
2247
|
-
...props
|
|
2248
|
-
}) {
|
|
2249
|
-
return /* @__PURE__ */ jsxs10(AriaRadioGroup, {
|
|
2250
|
-
...props,
|
|
2251
|
-
className: classNames("altertable-radio-group", className),
|
|
2252
|
-
children: [
|
|
2253
|
-
/* @__PURE__ */ jsx15(Label, {
|
|
2254
|
-
className: "altertable-control-label",
|
|
2255
|
-
children: label
|
|
2256
|
-
}),
|
|
2257
|
-
children
|
|
2258
|
-
]
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
|
-
function Radio({ className, children, ...props }) {
|
|
2262
|
-
return /* @__PURE__ */ jsx15(AriaRadio, {
|
|
2263
|
-
...props,
|
|
2264
|
-
"data-atbl-control": "action",
|
|
2265
|
-
"data-atbl-focus": "ring",
|
|
2266
|
-
className: classNames("altertable-radio", className),
|
|
2267
|
-
children: (state) => /* @__PURE__ */ jsxs10(Fragment8, {
|
|
2268
|
-
children: [
|
|
2269
|
-
/* @__PURE__ */ jsx15("span", {
|
|
2270
|
-
className: "altertable-radio-mark",
|
|
2271
|
-
"aria-hidden": "true"
|
|
2272
|
-
}),
|
|
2273
|
-
typeof children === "function" ? children(state) : children
|
|
2274
|
-
]
|
|
2275
|
-
})
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
function SegmentedControl({
|
|
2279
|
-
options,
|
|
2280
|
-
className,
|
|
2281
|
-
...props
|
|
2282
|
-
}) {
|
|
2283
|
-
validateChoiceOptions(options);
|
|
2284
|
-
return /* @__PURE__ */ jsx15(RadioGroup, {
|
|
2285
|
-
...props,
|
|
2286
|
-
orientation: "horizontal",
|
|
2287
|
-
className: classNames("altertable-segmented-control", className),
|
|
2288
|
-
children: /* @__PURE__ */ jsx15("div", {
|
|
2289
|
-
className: "altertable-segmented-options",
|
|
2290
|
-
children: options.map((option) => /* @__PURE__ */ jsx15(Radio, {
|
|
2291
|
-
value: option.id,
|
|
2292
|
-
"data-atbl-internal-surface": "option",
|
|
2293
|
-
children: option.label
|
|
2294
|
-
}, option.id))
|
|
2295
|
-
})
|
|
2296
|
-
});
|
|
2297
|
-
}
|
|
2298
|
-
// src/react/ui/CheckboxGroup.tsx
|
|
2299
|
-
import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
2300
|
-
function CheckboxGroup({
|
|
2301
|
-
label,
|
|
2302
|
-
values,
|
|
2303
|
-
onChange,
|
|
2304
|
-
className,
|
|
2305
|
-
children,
|
|
2306
|
-
disabled,
|
|
2307
|
-
...props
|
|
2308
|
-
}) {
|
|
2309
|
-
invariant(new Set(values).size === values.length, "Checkbox group values must be unique.");
|
|
2310
|
-
return /* @__PURE__ */ jsxs11("fieldset", {
|
|
2311
|
-
...props,
|
|
2312
|
-
disabled,
|
|
2313
|
-
className: classNames("altertable-checkbox-group", className),
|
|
2314
|
-
children: [
|
|
2315
|
-
/* @__PURE__ */ jsx16("legend", {
|
|
2316
|
-
children: label
|
|
2317
|
-
}),
|
|
2318
|
-
/* @__PURE__ */ jsx16(CheckboxGroupContext, {
|
|
2319
|
-
value: {
|
|
2320
|
-
values,
|
|
2321
|
-
disabled,
|
|
2322
|
-
onChange(value, checked) {
|
|
2323
|
-
onChange(checked ? [...values.filter((item) => item !== value), value] : values.filter((item) => item !== value));
|
|
2324
|
-
}
|
|
2325
|
-
},
|
|
2326
|
-
children
|
|
2327
|
-
})
|
|
2328
|
-
]
|
|
2329
|
-
});
|
|
2330
|
-
}
|
|
2331
|
-
// src/react/ui/ComposedChart.tsx
|
|
2332
|
-
import {
|
|
2333
|
-
useState as useState7,
|
|
2334
|
-
useCallback as useCallback2
|
|
2335
|
-
} from "react";
|
|
2336
|
-
|
|
2337
|
-
// src/react/ui/ComposedChartLegend.tsx
|
|
2338
|
-
import { useState as useState6 } from "react";
|
|
2339
|
-
import { Legend } from "recharts";
|
|
2340
|
-
import { jsx as jsx17, jsxs as jsxs12, Fragment as Fragment9 } from "react/jsx-runtime";
|
|
2341
|
-
var legendMarkerKinds = {
|
|
2342
|
-
square: "area",
|
|
2343
|
-
rect: "bar",
|
|
2344
|
-
line: "line",
|
|
2345
|
-
plainline: "line"
|
|
2346
|
-
};
|
|
2347
|
-
function createLegendItemKeys() {
|
|
2348
|
-
const identities = new WeakMap;
|
|
2349
|
-
let nextIdentity = 0;
|
|
2350
|
-
function identity(value) {
|
|
2351
|
-
let id = identities.get(value);
|
|
2352
|
-
if (id === undefined) {
|
|
2353
|
-
id = nextIdentity++;
|
|
2354
|
-
identities.set(value, id);
|
|
2355
|
-
}
|
|
2356
|
-
return id;
|
|
2357
|
-
}
|
|
2358
|
-
return (payload) => {
|
|
2359
|
-
const keys = payload.map((entry) => {
|
|
2360
|
-
const source = entry.payload;
|
|
2361
|
-
const id = source && typeof source === "object" && "id" in source ? source.id : undefined;
|
|
2362
|
-
if (typeof id === "string" || typeof id === "number")
|
|
2363
|
-
return ["series", typeof id, id].join(KEY_SEPARATOR);
|
|
2364
|
-
const key = entry.dataKey;
|
|
2365
|
-
if (typeof key === "string" || typeof key === "number")
|
|
2366
|
-
return ["data", typeof key, key].join(KEY_SEPARATOR);
|
|
2367
|
-
return ["object", identity(typeof key === "function" ? key : entry)].join(KEY_SEPARATOR);
|
|
2368
|
-
});
|
|
2369
|
-
const counts = new Map;
|
|
2370
|
-
for (const key of keys)
|
|
2371
|
-
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
2372
|
-
return keys.map((key, index) => {
|
|
2373
|
-
if (counts.get(key) === 1)
|
|
2374
|
-
return key;
|
|
2375
|
-
const entry = payload[index];
|
|
2376
|
-
const source = entry.payload;
|
|
2377
|
-
return [
|
|
2378
|
-
key,
|
|
2379
|
-
"object",
|
|
2380
|
-
identity(source && typeof source === "object" ? source : entry)
|
|
2381
|
-
].join(KEY_SEPARATOR);
|
|
2382
|
-
});
|
|
2383
|
-
};
|
|
2384
|
-
}
|
|
2385
|
-
function LegendContent({
|
|
2386
|
-
payload = [],
|
|
2387
|
-
maxVisibleItems,
|
|
2388
|
-
formatter,
|
|
2389
|
-
layout,
|
|
2390
|
-
align,
|
|
2391
|
-
labelStyle,
|
|
2392
|
-
iconType,
|
|
2393
|
-
iconSize = 8,
|
|
2394
|
-
inactiveColor = "var(--atbl-muted)",
|
|
2395
|
-
position,
|
|
2396
|
-
verticalAlign,
|
|
2397
|
-
onClick,
|
|
2398
|
-
onMouseEnter,
|
|
2399
|
-
onMouseLeave,
|
|
2400
|
-
"aria-label": ariaLabel
|
|
2401
|
-
}) {
|
|
2402
|
-
const [getItemKeys] = useState6(createLegendItemKeys);
|
|
2403
|
-
const itemKeys = getItemKeys(payload);
|
|
2404
|
-
if (!payload.some((entry) => entry.type !== "none"))
|
|
2405
|
-
return null;
|
|
2406
|
-
const vertical = layout === "vertical" || layout === "auto" && (position === "left" || position === "right");
|
|
2407
|
-
return /* @__PURE__ */ jsx17(ChartLegend, {
|
|
2408
|
-
"aria-label": ariaLabel,
|
|
2409
|
-
className: position === "top" || position == null && verticalAlign === "top" ? "altertable-composed-chart-legend-above" : position === "bottom" || position == null && verticalAlign !== "middle" && !vertical ? "altertable-composed-chart-legend-below" : undefined,
|
|
2410
|
-
maxVisibleItems,
|
|
2411
|
-
layout: vertical ? "vertical" : "horizontal",
|
|
2412
|
-
align: align === "right" ? "end" : align === "left" ? "start" : "center",
|
|
2413
|
-
children: payload.map((entry, index) => {
|
|
2414
|
-
if (entry.type === "none")
|
|
2415
|
-
return null;
|
|
2416
|
-
const type = iconType ?? entry.type;
|
|
2417
|
-
const kind = iconType ? legendMarkerKinds[type ?? "none"] ?? "point" : "square";
|
|
2418
|
-
const formatLabel = entry.formatter ?? formatter;
|
|
2419
|
-
const label = formatLabel ? formatLabel(entry.value, entry, index) : entry.value;
|
|
2420
|
-
const content = /* @__PURE__ */ jsxs12(Fragment9, {
|
|
2421
|
-
children: [
|
|
2422
|
-
type !== "none" && (entry.legendIcon ?? /* @__PURE__ */ jsx17(ChartLegend.Marker, {
|
|
2423
|
-
kind,
|
|
2424
|
-
color: entry.inactive ? inactiveColor : entry.color,
|
|
2425
|
-
style: {
|
|
2426
|
-
width: iconSize,
|
|
2427
|
-
height: kind === "square" ? iconSize : iconSize * 0.6
|
|
2428
|
-
}
|
|
2429
|
-
})),
|
|
2430
|
-
/* @__PURE__ */ jsx17(ChartLegend.Label, {
|
|
2431
|
-
style: labelStyle,
|
|
2432
|
-
children: label
|
|
2433
|
-
})
|
|
2434
|
-
]
|
|
2435
|
-
});
|
|
2436
|
-
return /* @__PURE__ */ jsx17(ChartLegend.Item, {
|
|
2437
|
-
inactive: entry.inactive,
|
|
2438
|
-
onMouseEnter: onMouseEnter ? (event) => onMouseEnter(entry, index, event) : undefined,
|
|
2439
|
-
onMouseLeave: onMouseLeave ? (event) => onMouseLeave(entry, index, event) : undefined,
|
|
2440
|
-
children: onClick ? /* @__PURE__ */ jsx17("button", {
|
|
2441
|
-
type: "button",
|
|
2442
|
-
"data-atbl-control": "action",
|
|
2443
|
-
"data-atbl-focus": "ring",
|
|
2444
|
-
className: "altertable-chart-legend-action",
|
|
2445
|
-
onClick: (event) => onClick(entry, index, event),
|
|
2446
|
-
children: content
|
|
2447
|
-
}) : content
|
|
2448
|
-
}, itemKeys[index]);
|
|
2449
|
-
})
|
|
2450
|
-
});
|
|
2451
|
-
}
|
|
2452
|
-
function ComposedChartLegend({
|
|
2453
|
-
maxVisibleItems,
|
|
2454
|
-
...props
|
|
2455
|
-
}) {
|
|
2456
|
-
return /* @__PURE__ */ jsx17(Legend, {
|
|
2457
|
-
iconSize: 8,
|
|
2458
|
-
inactiveColor: "var(--atbl-muted)",
|
|
2459
|
-
content: /* @__PURE__ */ jsx17(LegendContent, {
|
|
2460
|
-
maxVisibleItems
|
|
2461
|
-
}),
|
|
2462
|
-
...props
|
|
2463
|
-
});
|
|
2464
|
-
}
|
|
2465
|
-
|
|
2466
|
-
// src/react/ui/ComposedChart.tsx
|
|
2467
|
-
import {
|
|
2468
|
-
ComposedChart as RechartsComposedChart,
|
|
2469
|
-
ZAxis,
|
|
2470
|
-
ReferenceLine as ReferenceLine2,
|
|
2471
|
-
ReferenceArea,
|
|
2472
|
-
ReferenceDot,
|
|
2473
|
-
Brush,
|
|
2474
|
-
Cell as Cell2,
|
|
2475
|
-
Label as Label2,
|
|
2476
|
-
LabelList,
|
|
2477
|
-
ErrorBar
|
|
2478
|
-
} from "recharts";
|
|
2479
|
-
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
2480
|
-
function findNearestSeriesId(hoveredSeriesId, points, position) {
|
|
2481
|
-
if (!position || hoveredSeriesId != null && !points.has(hoveredSeriesId))
|
|
2482
|
-
return hoveredSeriesId;
|
|
2483
|
-
let selected = hoveredSeriesId;
|
|
2484
|
-
let distance = Infinity;
|
|
2485
|
-
for (const [id, point] of points) {
|
|
2486
|
-
const candidate = Math.hypot(point.x - position.x, point.y - position.y);
|
|
2487
|
-
if (candidate < distance) {
|
|
2488
|
-
distance = candidate;
|
|
2489
|
-
selected = id;
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
return selected;
|
|
2493
|
-
}
|
|
2494
|
-
function ComposedChartRoot({
|
|
2495
|
-
data,
|
|
2496
|
-
ariaLabel,
|
|
2497
|
-
width = "100%",
|
|
2498
|
-
height = 300,
|
|
2499
|
-
responsive = true,
|
|
2500
|
-
className,
|
|
2501
|
-
...props
|
|
2502
|
-
}) {
|
|
2503
|
-
const [hasPointerFocus, setHasPointerFocus] = useState7(false);
|
|
2504
|
-
const [isPointerInspection, setIsPointerInspection] = useState7(false);
|
|
2505
|
-
const [hoveredSeriesId, setHoveredSeriesId] = useState7(null);
|
|
2506
|
-
const [pointerPosition, setPointerPosition] = useState7(null);
|
|
2507
|
-
const [points, setPoints] = useState7(() => new Map);
|
|
2508
|
-
const registerPoint = useCallback2((id, x, y) => {
|
|
2509
|
-
setPoints((current) => new Map(current).set(id, { x, y }));
|
|
2510
|
-
return () => setPoints((current) => {
|
|
2511
|
-
const next = new Map(current);
|
|
2512
|
-
next.delete(id);
|
|
2513
|
-
return next;
|
|
2514
|
-
});
|
|
2515
|
-
}, []);
|
|
2516
|
-
function trackPointer(event) {
|
|
2517
|
-
const svg = event.currentTarget.querySelector('svg[role="application"]');
|
|
2518
|
-
if (!(svg instanceof SVGSVGElement) || !(event.target instanceof Node) || !svg.contains(event.target)) {
|
|
2519
|
-
resetPointerInspection();
|
|
2520
|
-
return false;
|
|
2521
|
-
}
|
|
2522
|
-
setIsPointerInspection(true);
|
|
2523
|
-
if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
|
|
2524
|
-
setPointerPosition(null);
|
|
2525
|
-
return true;
|
|
2526
|
-
}
|
|
2527
|
-
const matrix = svg.getScreenCTM();
|
|
2528
|
-
if (!matrix)
|
|
2529
|
-
return true;
|
|
2530
|
-
const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(matrix.inverse());
|
|
2531
|
-
setPointerPosition({ x: point.x, y: point.y });
|
|
2532
|
-
return true;
|
|
2533
|
-
}
|
|
2534
|
-
function resetPointerInspection() {
|
|
2535
|
-
setIsPointerInspection(false);
|
|
2536
|
-
setHoveredSeriesId(null);
|
|
2537
|
-
setPointerPosition(null);
|
|
2538
|
-
}
|
|
2539
|
-
const activeSeriesId = findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
|
|
2540
|
-
const [seriesIds, setSeriesIds] = useState7(() => new Set);
|
|
2541
|
-
const registerSeries = useCallback2((id) => {
|
|
2542
|
-
setSeriesIds((current) => new Set(current).add(id));
|
|
2543
|
-
return () => {
|
|
2544
|
-
setSeriesIds((current) => {
|
|
2545
|
-
const next = new Set(current);
|
|
2546
|
-
next.delete(id);
|
|
2547
|
-
return next;
|
|
2548
|
-
});
|
|
2549
|
-
};
|
|
2550
|
-
}, []);
|
|
2551
|
-
return /* @__PURE__ */ jsx18(ChartInteractionContext.Provider, {
|
|
2552
|
-
value: {
|
|
2553
|
-
isPointerInspection,
|
|
2554
|
-
activeSeriesId,
|
|
2555
|
-
activePoint: activeSeriesId == null ? undefined : points.get(activeSeriesId),
|
|
2556
|
-
registerPoint,
|
|
2557
|
-
setHoveredSeriesId,
|
|
2558
|
-
seriesCount: seriesIds.size,
|
|
2559
|
-
registerSeries
|
|
2560
|
-
},
|
|
2561
|
-
children: /* @__PURE__ */ jsx18("section", {
|
|
2562
|
-
className: classNames("altertable-composed-chart", className),
|
|
2563
|
-
"aria-label": ariaLabel,
|
|
2564
|
-
"data-atbl-internal-pointer-focus": hasPointerFocus || undefined,
|
|
2565
|
-
onPointerDownCapture: (event) => {
|
|
2566
|
-
setHasPointerFocus(trackPointer(event));
|
|
2567
|
-
},
|
|
2568
|
-
onPointerOverCapture: trackPointer,
|
|
2569
|
-
onPointerMoveCapture: trackPointer,
|
|
2570
|
-
onPointerLeave: (event) => {
|
|
2571
|
-
if (event.pointerType !== "touch") {
|
|
2572
|
-
resetPointerInspection();
|
|
2573
|
-
}
|
|
2574
|
-
},
|
|
2575
|
-
onKeyDownCapture: () => {
|
|
2576
|
-
setHasPointerFocus(false);
|
|
2577
|
-
resetPointerInspection();
|
|
2578
|
-
},
|
|
2579
|
-
onBlurCapture: (event) => {
|
|
2580
|
-
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
2581
|
-
setHasPointerFocus(false);
|
|
2582
|
-
resetPointerInspection();
|
|
2583
|
-
}
|
|
2584
|
-
},
|
|
2585
|
-
children: /* @__PURE__ */ jsx18(ChartDateAxes, {
|
|
2586
|
-
data,
|
|
2587
|
-
children: /* @__PURE__ */ jsx18(RechartsComposedChart, {
|
|
2588
|
-
"data-atbl-focus": "inset",
|
|
2589
|
-
...props,
|
|
2590
|
-
data,
|
|
2591
|
-
width,
|
|
2592
|
-
height,
|
|
2593
|
-
responsive,
|
|
2594
|
-
"aria-label": ariaLabel
|
|
2595
|
-
})
|
|
2596
|
-
})
|
|
2597
|
-
})
|
|
2598
|
-
});
|
|
2599
|
-
}
|
|
2600
|
-
var ComposedChart = Object.assign(ComposedChartRoot, {
|
|
2601
|
-
Dot: ChartDot,
|
|
2602
|
-
Area: ChartArea,
|
|
2603
|
-
Bar: ChartBar,
|
|
2604
|
-
Line: ChartLine,
|
|
2605
|
-
Scatter: ChartScatter,
|
|
2606
|
-
XAxis: ChartXAxis,
|
|
2607
|
-
YAxis: ChartYAxis,
|
|
2608
|
-
ZAxis,
|
|
2609
|
-
CartesianGrid: ChartGrid,
|
|
2610
|
-
Tooltip: ChartTooltip,
|
|
2611
|
-
Legend: ComposedChartLegend,
|
|
2612
|
-
ReferenceLine: ReferenceLine2,
|
|
2613
|
-
ReferenceArea,
|
|
2614
|
-
ReferenceDot,
|
|
2615
|
-
Brush,
|
|
2616
|
-
Cell: Cell2,
|
|
2617
|
-
Label: Label2,
|
|
2618
|
-
LabelList,
|
|
2619
|
-
ErrorBar
|
|
2620
|
-
});
|
|
2621
|
-
// src/react/ui/FunnelChart.tsx
|
|
2622
|
-
import { Fragment as Fragment10, useEffect as useEffect4, useRef as useRef6, useState as useState8 } from "react";
|
|
2623
|
-
|
|
2624
|
-
// src/react/ui/useSvgId.ts
|
|
2625
|
-
import { useId as useId3 } from "react";
|
|
2626
|
-
var svgIdCharacterPattern = /[a-zA-Z0-9-]/;
|
|
2627
|
-
function useSvgId() {
|
|
2628
|
-
const id = useId3();
|
|
2629
|
-
const encodedId = Array.from(id, (character) => svgIdCharacterPattern.test(character) ? character : `_${character.codePointAt(0).toString(16)}_`).join("");
|
|
2630
|
-
return ["svg", encodedId].join("-");
|
|
2631
|
-
}
|
|
2632
|
-
|
|
2633
|
-
// src/react/ui/FunnelChart.tsx
|
|
2634
|
-
import { jsx as jsx19, jsxs as jsxs13, Fragment as Fragment11 } from "react/jsx-runtime";
|
|
2635
|
-
function createFunnelModel(steps, series, chartId) {
|
|
2636
|
-
for (const [kind, items] of [
|
|
2637
|
-
["funnel step", steps],
|
|
2638
|
-
["funnel series", series]
|
|
2639
|
-
]) {
|
|
2640
|
-
const ids = new Set;
|
|
2641
|
-
for (const item of items) {
|
|
2642
|
-
invariant(item.id.trim().length > 0 && !ids.has(item.id), `${kind} chart IDs must be nonblank and unique.`);
|
|
2643
|
-
ids.add(item.id);
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
for (const item of series) {
|
|
2647
|
-
invariant(item.values.length === steps.length, "funnel chart counts must align with steps.");
|
|
2648
|
-
item.values.forEach((value, index) => {
|
|
2649
|
-
invariant(Number.isFinite(value) && value >= 0, "funnel chart counts must be finite and nonnegative.");
|
|
2650
|
-
invariant(index === 0 || value <= item.values[index - 1], "funnel chart counts must be nonincreasing.");
|
|
2651
|
-
});
|
|
2652
|
-
}
|
|
2653
|
-
const populations = series.map((item, index) => ({
|
|
2654
|
-
id: item.id,
|
|
2655
|
-
label: item.label,
|
|
2656
|
-
color: `var(--atbl-chart-${index % 8 + 1})`,
|
|
2657
|
-
hatchId: [chartId, "hatch", index].join("-")
|
|
2658
|
-
}));
|
|
2659
|
-
const rows = steps.map((step, index) => ({
|
|
2660
|
-
id: step.id,
|
|
2661
|
-
label: step.label,
|
|
2662
|
-
index,
|
|
2663
|
-
readings: new Map(series.map((item, seriesIndex) => {
|
|
2664
|
-
const first = item.values[0] ?? 0;
|
|
2665
|
-
const current = item.values[index];
|
|
2666
|
-
const previous = item.values[Math.max(0, index - 1)];
|
|
2667
|
-
const dropped = previous - current;
|
|
2668
|
-
const conversion = first > 0 ? current / first : null;
|
|
2669
|
-
const dropOff = first > 0 ? dropped / first : null;
|
|
2670
|
-
return [
|
|
2671
|
-
item.id,
|
|
2672
|
-
{
|
|
2673
|
-
population: populations[seriesIndex],
|
|
2674
|
-
current,
|
|
2675
|
-
previous,
|
|
2676
|
-
dropped,
|
|
2677
|
-
conversion,
|
|
2678
|
-
dropOff,
|
|
2679
|
-
conversionPercent: (conversion ?? 0) * 100,
|
|
2680
|
-
dropOffPercent: (dropOff ?? (index === 0 ? 1 : 0)) * 100
|
|
2681
|
-
}
|
|
2682
|
-
];
|
|
2683
|
-
}))
|
|
2684
|
-
}));
|
|
2685
|
-
return { populations, rows };
|
|
2686
|
-
}
|
|
2687
|
-
function FunnelChart({
|
|
2688
|
-
steps,
|
|
2689
|
-
series,
|
|
2690
|
-
unit,
|
|
2691
|
-
ariaLabel,
|
|
2692
|
-
className,
|
|
2693
|
-
formatValue = formatNumber2
|
|
2694
|
-
}) {
|
|
2695
|
-
const chartId = useSvgId();
|
|
2696
|
-
const [highlighted, setHighlighted] = useState8(null);
|
|
2697
|
-
const clearTimer = useRef6(null);
|
|
2698
|
-
function cancelClear() {
|
|
2699
|
-
if (clearTimer.current !== null)
|
|
2700
|
-
clearTimeout(clearTimer.current);
|
|
2701
|
-
clearTimer.current = null;
|
|
2702
|
-
}
|
|
2703
|
-
useEffect4(() => cancelClear, []);
|
|
2704
|
-
function highlight(id, conversion, step) {
|
|
2705
|
-
cancelClear();
|
|
2706
|
-
setHighlighted({ id, conversion, step });
|
|
2707
|
-
}
|
|
2708
|
-
function clearHighlight() {
|
|
2709
|
-
cancelClear();
|
|
2710
|
-
setHighlighted(null);
|
|
2711
|
-
}
|
|
2712
|
-
function scheduleClear() {
|
|
2713
|
-
cancelClear();
|
|
2714
|
-
clearTimer.current = setTimeout(() => setHighlighted(null), 100);
|
|
2715
|
-
}
|
|
2716
|
-
const { populations, rows } = createFunnelModel(steps, series, chartId);
|
|
2717
|
-
return /* @__PURE__ */ jsx19("section", {
|
|
2718
|
-
className: classNames("altertable-funnel-chart", className),
|
|
2719
|
-
"aria-label": ariaLabel,
|
|
2720
|
-
onKeyDownCapture: clearHighlight,
|
|
2721
|
-
children: steps.length === 0 || series.length === 0 ? /* @__PURE__ */ jsx19("span", {
|
|
2722
|
-
children: "No data"
|
|
2723
|
-
}) : /* @__PURE__ */ jsxs13(Fragment11, {
|
|
2724
|
-
children: [
|
|
2725
|
-
/* @__PURE__ */ jsxs13("div", {
|
|
2726
|
-
className: "altertable-funnel-header",
|
|
2727
|
-
children: [
|
|
2728
|
-
/* @__PURE__ */ jsx19(ChartLegend, {
|
|
2729
|
-
"aria-label": "Funnel series",
|
|
2730
|
-
layout: "single-row",
|
|
2731
|
-
children: populations.map((item) => /* @__PURE__ */ jsxs13(ChartLegend.Item, {
|
|
2732
|
-
className: "altertable-funnel-summary-item",
|
|
2733
|
-
children: [
|
|
2734
|
-
/* @__PURE__ */ jsxs13("span", {
|
|
2735
|
-
className: "altertable-funnel-series-label",
|
|
2736
|
-
children: [
|
|
2737
|
-
/* @__PURE__ */ jsx19(ChartLegend.Marker, {
|
|
2738
|
-
kind: "square",
|
|
2739
|
-
color: item.color
|
|
2740
|
-
}),
|
|
2741
|
-
/* @__PURE__ */ jsx19(ChartLegend.Label, {
|
|
2742
|
-
children: item.label
|
|
2743
|
-
})
|
|
2744
|
-
]
|
|
2745
|
-
}),
|
|
2746
|
-
/* @__PURE__ */ jsx19("strong", {
|
|
2747
|
-
className: "altertable-funnel-series-value",
|
|
2748
|
-
children: formatPercent2(rows.at(-1)?.readings.get(item.id)?.conversion ?? null)
|
|
2749
|
-
})
|
|
2750
|
-
]
|
|
2751
|
-
}, item.id))
|
|
2752
|
-
}),
|
|
2753
|
-
/* @__PURE__ */ jsxs13("p", {
|
|
2754
|
-
className: "altertable-funnel-path",
|
|
2755
|
-
children: [
|
|
2756
|
-
steps[0].label,
|
|
2757
|
-
" → ",
|
|
2758
|
-
steps.at(-1).label
|
|
2759
|
-
]
|
|
2760
|
-
})
|
|
2761
|
-
]
|
|
2762
|
-
}),
|
|
2763
|
-
/* @__PURE__ */ jsx19("div", {
|
|
2764
|
-
className: "altertable-funnel-scroll",
|
|
2765
|
-
children: /* @__PURE__ */ jsx19("div", {
|
|
2766
|
-
style: {
|
|
2767
|
-
minWidth: steps.length * Math.max(96, series.length * 40)
|
|
2768
|
-
},
|
|
2769
|
-
children: /* @__PURE__ */ jsxs13(ComposedChart, {
|
|
2770
|
-
data: rows,
|
|
2771
|
-
ariaLabel: `${ariaLabel} plot`,
|
|
2772
|
-
height: 300,
|
|
2773
|
-
barCategoryGap: "4%",
|
|
2774
|
-
barGap: 1,
|
|
2775
|
-
onMouseLeave: clearHighlight,
|
|
2776
|
-
children: [
|
|
2777
|
-
/* @__PURE__ */ jsx19(ComposedChart.CartesianGrid, {}),
|
|
2778
|
-
/* @__PURE__ */ jsx19(ComposedChart.XAxis, {
|
|
2779
|
-
dataKey: "label",
|
|
2780
|
-
interval: 0,
|
|
2781
|
-
height: 48
|
|
2782
|
-
}),
|
|
2783
|
-
/* @__PURE__ */ jsx19(ComposedChart.YAxis, {
|
|
2784
|
-
domain: [0, 100],
|
|
2785
|
-
width: 42,
|
|
2786
|
-
tickFormatter: (value) => formatPercent2(value / 100)
|
|
2787
|
-
}),
|
|
2788
|
-
/* @__PURE__ */ jsx19("defs", {
|
|
2789
|
-
children: populations.map((item) => /* @__PURE__ */ jsxs13("pattern", {
|
|
2790
|
-
id: item.hatchId,
|
|
2791
|
-
patternUnits: "userSpaceOnUse",
|
|
2792
|
-
width: "6",
|
|
2793
|
-
height: "6",
|
|
2794
|
-
patternTransform: "rotate(45)",
|
|
2795
|
-
children: [
|
|
2796
|
-
/* @__PURE__ */ jsx19("rect", {
|
|
2797
|
-
width: "8",
|
|
2798
|
-
height: "8",
|
|
2799
|
-
fill: item.color,
|
|
2800
|
-
fillOpacity: 0.16
|
|
2801
|
-
}),
|
|
2802
|
-
/* @__PURE__ */ jsx19("line", {
|
|
2803
|
-
x1: "0",
|
|
2804
|
-
y1: "0",
|
|
2805
|
-
x2: "0",
|
|
2806
|
-
y2: "8",
|
|
2807
|
-
stroke: item.color,
|
|
2808
|
-
strokeOpacity: 0.4,
|
|
2809
|
-
strokeWidth: "2"
|
|
2810
|
-
})
|
|
2811
|
-
]
|
|
2812
|
-
}, item.id))
|
|
2813
|
-
}),
|
|
2814
|
-
populations.map((item) => /* @__PURE__ */ jsxs13(Fragment10, {
|
|
2815
|
-
children: [
|
|
2816
|
-
/* @__PURE__ */ jsx19(ComposedChart.Bar, {
|
|
2817
|
-
dataKey: (row) => row.readings.get(item.id)?.conversionPercent ?? 0,
|
|
2818
|
-
name: item.label,
|
|
2819
|
-
stackId: item.id,
|
|
2820
|
-
fill: item.color,
|
|
2821
|
-
radius: 0,
|
|
2822
|
-
maxBarSize: undefined,
|
|
2823
|
-
activeBar: false,
|
|
2824
|
-
minPointSize: 0,
|
|
2825
|
-
opacity: !highlighted || highlighted.id === item.id ? 1 : 0.2,
|
|
2826
|
-
onMouseEnter: (bar) => highlight(item.id, true, bar.payload.index),
|
|
2827
|
-
onMouseLeave: scheduleClear,
|
|
2828
|
-
onClick: (bar) => highlight(item.id, true, bar.payload.index)
|
|
2829
|
-
}),
|
|
2830
|
-
/* @__PURE__ */ jsx19(ComposedChart.Bar, {
|
|
2831
|
-
dataKey: (row) => row.readings.get(item.id)?.dropOffPercent ?? 0,
|
|
2832
|
-
name: `${item.label} drop-off`,
|
|
2833
|
-
stackId: item.id,
|
|
2834
|
-
fill: `url(#${item.hatchId})`,
|
|
2835
|
-
opacity: !highlighted || highlighted.id === item.id ? 1 : 0.2,
|
|
2836
|
-
onMouseEnter: (bar) => highlight(item.id, false, bar.payload.index),
|
|
2837
|
-
onMouseLeave: scheduleClear,
|
|
2838
|
-
onClick: (bar) => highlight(item.id, false, bar.payload.index),
|
|
2839
|
-
radius: 0,
|
|
2840
|
-
maxBarSize: undefined,
|
|
2841
|
-
activeBar: false
|
|
2842
|
-
})
|
|
2843
|
-
]
|
|
2844
|
-
}, item.id)),
|
|
2845
|
-
/* @__PURE__ */ jsx19(ComposedChart.Tooltip, {
|
|
2846
|
-
content: ({ active, activeIndex }) => {
|
|
2847
|
-
const row = activeIndex == null ? undefined : rows[Number(activeIndex)];
|
|
2848
|
-
if (!active || !row)
|
|
2849
|
-
return null;
|
|
2850
|
-
const tooltipItems = [...row.readings.values()].filter((value) => !highlighted || highlighted.step !== row.index || value.population.id === highlighted.id).flatMap((value) => {
|
|
2851
|
-
const item = value.population;
|
|
2852
|
-
const selected = highlighted?.step === row.index;
|
|
2853
|
-
const readings = selected ? [highlighted.conversion] : [true, false];
|
|
2854
|
-
return readings.map((conversion) => {
|
|
2855
|
-
const key = [
|
|
2856
|
-
item.id,
|
|
2857
|
-
conversion ? "conversion" : "drop-off"
|
|
2858
|
-
].join(KEY_SEPARATOR);
|
|
2859
|
-
return {
|
|
2860
|
-
name: item.label,
|
|
2861
|
-
graphicalItemId: key,
|
|
2862
|
-
dataKey: key,
|
|
2863
|
-
color: item.color,
|
|
2864
|
-
value: (conversion ? value.conversion : value.dropOff) ?? 0,
|
|
2865
|
-
formatter: () => /* @__PURE__ */ jsxs13(Fragment11, {
|
|
2866
|
-
children: [
|
|
2867
|
-
formatPercent2(conversion ? value.conversion : value.dropOff),
|
|
2868
|
-
" ",
|
|
2869
|
-
conversion ? "conversion" : "drop-off",
|
|
2870
|
-
/* @__PURE__ */ jsxs13("span", {
|
|
2871
|
-
className: "altertable-funnel-tooltip-detail",
|
|
2872
|
-
children: [
|
|
2873
|
-
formatValue(conversion ? value.current : value.dropped),
|
|
2874
|
-
" ",
|
|
2875
|
-
"of ",
|
|
2876
|
-
formatValue(value.previous),
|
|
2877
|
-
" ",
|
|
2878
|
-
unit
|
|
2879
|
-
]
|
|
2880
|
-
})
|
|
2881
|
-
]
|
|
2882
|
-
})
|
|
2883
|
-
};
|
|
2884
|
-
});
|
|
2885
|
-
});
|
|
2886
|
-
return /* @__PURE__ */ jsx19(ChartTooltipContent, {
|
|
2887
|
-
active: true,
|
|
2888
|
-
label: row.label,
|
|
2889
|
-
payload: tooltipItems
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
})
|
|
2893
|
-
]
|
|
2894
|
-
})
|
|
2895
|
-
})
|
|
2896
|
-
}),
|
|
2897
|
-
/* @__PURE__ */ jsx19("ul", {
|
|
2898
|
-
className: "altertable-sr-only",
|
|
2899
|
-
children: rows.map((row) => /* @__PURE__ */ jsxs13("li", {
|
|
2900
|
-
children: [
|
|
2901
|
-
row.label,
|
|
2902
|
-
[...row.readings.values()].map((value) => /* @__PURE__ */ jsxs13("span", {
|
|
2903
|
-
children: [
|
|
2904
|
-
" ",
|
|
2905
|
-
"· ",
|
|
2906
|
-
value.population.label,
|
|
2907
|
-
": ",
|
|
2908
|
-
formatValue(value.current),
|
|
2909
|
-
" ",
|
|
2910
|
-
unit,
|
|
2911
|
-
", ",
|
|
2912
|
-
formatPercent2(value.conversion),
|
|
2913
|
-
" conversion,",
|
|
2914
|
-
" ",
|
|
2915
|
-
formatValue(value.dropped),
|
|
2916
|
-
" dropped off"
|
|
2917
|
-
]
|
|
2918
|
-
}, value.population.id))
|
|
2919
|
-
]
|
|
2920
|
-
}, row.id))
|
|
2921
|
-
})
|
|
2922
|
-
]
|
|
2923
|
-
})
|
|
2924
|
-
});
|
|
2925
|
-
}
|
|
2926
|
-
// src/react/ui/RetentionChart.tsx
|
|
2927
|
-
import { Fragment as Fragment12 } from "react";
|
|
2928
|
-
import { jsx as jsx20, jsxs as jsxs14, Fragment as Fragment13 } from "react/jsx-runtime";
|
|
2929
|
-
function createRetentionModel(series, unit, formatValue) {
|
|
2930
|
-
const ids = new Set;
|
|
2931
|
-
const rowsByOffset = new Map;
|
|
2932
|
-
const cohorts = series.map((item, index) => {
|
|
2933
|
-
invariant(item.id.trim().length > 0 && !ids.has(item.id), "retention series chart IDs must be nonblank and unique.");
|
|
2934
|
-
ids.add(item.id);
|
|
2935
|
-
invariant(Number.isFinite(item.cohortSize) && item.cohortSize >= 0, "retention chart counts must be finite and nonnegative.");
|
|
2936
|
-
const seen = new Set;
|
|
2937
|
-
let previous;
|
|
2938
|
-
const readings = [...item.points].sort((a, b) => a.offset - b.offset).map((point) => {
|
|
2939
|
-
invariant(Number.isSafeInteger(point.offset) && point.offset >= 0 && !seen.has(point.offset), "retention chart offsets must be unique nonnegative integers within each series.");
|
|
2940
|
-
seen.add(point.offset);
|
|
2941
|
-
invariant(point.rate === null || Number.isFinite(point.rate) && point.rate >= 0 && point.rate <= 1, "retention chart rates must be finite fractions between 0 and 1, or null.");
|
|
2942
|
-
invariant(point.rate === null === (point.retainedCount === null), "retention chart unobserved rates and counts must both be null.");
|
|
2943
|
-
if (point.retainedCount !== null) {
|
|
2944
|
-
invariant(Number.isFinite(point.retainedCount) && point.retainedCount >= 0, "retention chart counts must be finite and nonnegative.");
|
|
2945
|
-
invariant(point.retainedCount <= item.cohortSize, "retention chart retained counts cannot exceed cohort size.");
|
|
2946
|
-
}
|
|
2947
|
-
let row = rowsByOffset.get(point.offset);
|
|
2948
|
-
invariant(!row || row.label === point.label, "retention chart labels must agree for the same offset.");
|
|
2949
|
-
if (!row) {
|
|
2950
|
-
row = {
|
|
2951
|
-
offset: point.offset,
|
|
2952
|
-
label: point.label,
|
|
2953
|
-
readings: new Map
|
|
2954
|
-
};
|
|
2955
|
-
rowsByOffset.set(point.offset, row);
|
|
2956
|
-
}
|
|
2957
|
-
const percent = point.rate === null ? null : point.rate * 100;
|
|
2958
|
-
const reading = {
|
|
2959
|
-
point,
|
|
2960
|
-
completePercent: point.incomplete ? null : percent,
|
|
2961
|
-
incompletePercent: point.incomplete ? percent : null,
|
|
2962
|
-
description: point.rate === null || point.retainedCount === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
|
|
2963
|
-
};
|
|
2964
|
-
if (point.incomplete && previous) {
|
|
2965
|
-
previous.incompletePercent = previous.completePercent ?? previous.incompletePercent;
|
|
2966
|
-
}
|
|
2967
|
-
row.readings.set(item.id, reading);
|
|
2968
|
-
previous = reading;
|
|
2969
|
-
return reading;
|
|
2970
|
-
});
|
|
2971
|
-
return {
|
|
2972
|
-
id: item.id,
|
|
2973
|
-
label: item.label,
|
|
2974
|
-
color: `var(--atbl-chart-${index % 8 + 1})`,
|
|
2975
|
-
readings
|
|
2976
|
-
};
|
|
2977
|
-
});
|
|
2978
|
-
const rows = [...rowsByOffset.values()].sort((a, b) => a.offset - b.offset);
|
|
2979
|
-
return { rows, rowsByOffset, cohorts };
|
|
2980
|
-
}
|
|
2981
|
-
function RetentionChart({
|
|
2982
|
-
series,
|
|
2983
|
-
unit,
|
|
2984
|
-
ariaLabel,
|
|
2985
|
-
className,
|
|
2986
|
-
formatValue = formatNumber2
|
|
2987
|
-
}) {
|
|
2988
|
-
const { rows, rowsByOffset, cohorts } = createRetentionModel(series, unit, formatValue);
|
|
2989
|
-
return /* @__PURE__ */ jsx20("section", {
|
|
2990
|
-
className: classNames("altertable-retention-chart", className),
|
|
2991
|
-
"aria-label": ariaLabel,
|
|
2992
|
-
children: rows.length === 0 ? /* @__PURE__ */ jsx20("span", {
|
|
2993
|
-
children: "No data"
|
|
2994
|
-
}) : /* @__PURE__ */ jsxs14(Fragment13, {
|
|
2995
|
-
children: [
|
|
2996
|
-
/* @__PURE__ */ jsxs14(ComposedChart, {
|
|
2997
|
-
data: rows,
|
|
2998
|
-
ariaLabel: `${ariaLabel} plot`,
|
|
2999
|
-
children: [
|
|
3000
|
-
/* @__PURE__ */ jsx20(ComposedChart.CartesianGrid, {}),
|
|
3001
|
-
/* @__PURE__ */ jsx20(ComposedChart.XAxis, {
|
|
3002
|
-
dataKey: "offset",
|
|
3003
|
-
type: "number",
|
|
3004
|
-
domain: [0, Math.max(1, rows.at(-1)?.offset ?? 0)],
|
|
3005
|
-
ticks: rows.map((row) => row.offset),
|
|
3006
|
-
tickFormatter: (value) => rowsByOffset.get(Number(value))?.label ?? ""
|
|
3007
|
-
}),
|
|
3008
|
-
/* @__PURE__ */ jsx20(ComposedChart.YAxis, {
|
|
3009
|
-
domain: [0, 100],
|
|
3010
|
-
width: 42,
|
|
3011
|
-
tickFormatter: (value) => `${value}%`
|
|
3012
|
-
}),
|
|
3013
|
-
cohorts.map((item) => /* @__PURE__ */ jsxs14(Fragment12, {
|
|
3014
|
-
children: [
|
|
3015
|
-
/* @__PURE__ */ jsx20(ComposedChart.Line, {
|
|
3016
|
-
dataKey: (row) => row.readings.get(item.id)?.completePercent ?? null,
|
|
3017
|
-
name: item.label,
|
|
3018
|
-
stroke: item.color,
|
|
3019
|
-
connectNulls: false
|
|
3020
|
-
}),
|
|
3021
|
-
/* @__PURE__ */ jsx20(ComposedChart.Line, {
|
|
3022
|
-
dataKey: (row) => row.readings.get(item.id)?.incompletePercent ?? null,
|
|
3023
|
-
name: item.label,
|
|
3024
|
-
stroke: item.color,
|
|
3025
|
-
strokeDasharray: "3 3",
|
|
3026
|
-
dot: false,
|
|
3027
|
-
activeDot: false,
|
|
3028
|
-
connectNulls: false
|
|
3029
|
-
})
|
|
3030
|
-
]
|
|
3031
|
-
}, item.id)),
|
|
3032
|
-
/* @__PURE__ */ jsx20(ComposedChart.Tooltip, {
|
|
3033
|
-
filterNull: false,
|
|
3034
|
-
content: ({ active, label }) => {
|
|
3035
|
-
const row = typeof label === "number" ? rowsByOffset.get(label) : undefined;
|
|
3036
|
-
if (!active || !row)
|
|
3037
|
-
return null;
|
|
3038
|
-
return /* @__PURE__ */ jsxs14(TooltipSurface, {
|
|
3039
|
-
"data-variant": "chart",
|
|
3040
|
-
role: "tooltip",
|
|
3041
|
-
children: [
|
|
3042
|
-
/* @__PURE__ */ jsx20("strong", {
|
|
3043
|
-
children: row.label
|
|
3044
|
-
}),
|
|
3045
|
-
cohorts.map((item) => {
|
|
3046
|
-
const reading = row.readings.get(item.id);
|
|
3047
|
-
if (!reading)
|
|
3048
|
-
return null;
|
|
3049
|
-
return /* @__PURE__ */ jsxs14("span", {
|
|
3050
|
-
children: [
|
|
3051
|
-
item.label,
|
|
3052
|
-
": ",
|
|
3053
|
-
reading.description
|
|
3054
|
-
]
|
|
3055
|
-
}, item.id);
|
|
3056
|
-
})
|
|
3057
|
-
]
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
})
|
|
3061
|
-
]
|
|
3062
|
-
}),
|
|
3063
|
-
/* @__PURE__ */ jsx20(ChartLegend, {
|
|
3064
|
-
"aria-label": `${ariaLabel} cohorts`,
|
|
3065
|
-
children: cohorts.map((item) => /* @__PURE__ */ jsxs14(ChartLegend.Item, {
|
|
3066
|
-
children: [
|
|
3067
|
-
/* @__PURE__ */ jsx20(ChartLegend.Marker, {
|
|
3068
|
-
kind: "square",
|
|
3069
|
-
color: item.color
|
|
3070
|
-
}),
|
|
3071
|
-
/* @__PURE__ */ jsx20(ChartLegend.Label, {
|
|
3072
|
-
children: item.label
|
|
3073
|
-
})
|
|
3074
|
-
]
|
|
3075
|
-
}, item.id))
|
|
3076
|
-
}),
|
|
3077
|
-
/* @__PURE__ */ jsx20("ul", {
|
|
3078
|
-
className: "altertable-sr-only",
|
|
3079
|
-
"aria-label": `${ariaLabel} readings`,
|
|
3080
|
-
children: cohorts.map((item) => /* @__PURE__ */ jsxs14("li", {
|
|
3081
|
-
children: [
|
|
3082
|
-
item.label,
|
|
3083
|
-
item.readings.map((reading) => /* @__PURE__ */ jsxs14("span", {
|
|
3084
|
-
children: [
|
|
3085
|
-
" ",
|
|
3086
|
-
"· ",
|
|
3087
|
-
reading.point.label,
|
|
3088
|
-
": ",
|
|
3089
|
-
reading.description
|
|
3090
|
-
]
|
|
3091
|
-
}, reading.point.offset))
|
|
3092
|
-
]
|
|
3093
|
-
}, item.id))
|
|
3094
|
-
})
|
|
3095
|
-
]
|
|
3096
|
-
})
|
|
3097
|
-
});
|
|
3098
|
-
}
|
|
3099
|
-
// src/react/ui/JourneyChart.tsx
|
|
3100
|
-
import { useLayoutEffect as useLayoutEffect3, useRef as useRef7, useState as useState9 } from "react";
|
|
3101
|
-
|
|
3102
|
-
// src/react/ui/journey-flow.ts
|
|
3103
|
-
var journeyOutcomeLabels = {
|
|
3104
|
-
truncated: "More steps",
|
|
3105
|
-
"drop-off": "Drop-off",
|
|
3106
|
-
converted: "Converted",
|
|
3107
|
-
end: "End of path"
|
|
3108
|
-
};
|
|
3109
|
-
function journeyNodes(path) {
|
|
3110
|
-
const nodes = path.steps.map((step, depth) => ({
|
|
3111
|
-
key: JSON.stringify([depth, "event", step.event, step.property]),
|
|
3112
|
-
label: step.property === null ? step.event : `${step.event} · ${step.property}`,
|
|
3113
|
-
depth,
|
|
3114
|
-
outcome: "event"
|
|
3115
|
-
}));
|
|
3116
|
-
const outcome = path.truncated ? "truncated" : path.converted === false ? "drop-off" : path.converted === true ? "converted" : "end";
|
|
3117
|
-
nodes.push({
|
|
3118
|
-
key: JSON.stringify([nodes.length, outcome]),
|
|
3119
|
-
label: journeyOutcomeLabels[outcome],
|
|
3120
|
-
depth: nodes.length,
|
|
3121
|
-
outcome
|
|
3122
|
-
});
|
|
3123
|
-
return nodes;
|
|
3124
|
-
}
|
|
3125
|
-
function buildJourneyFlow(paths, expandedBranch) {
|
|
3126
|
-
const nodes = new Map;
|
|
3127
|
-
const links = new Map;
|
|
3128
|
-
for (const path of paths) {
|
|
3129
|
-
const fullSequence = journeyNodes(path);
|
|
3130
|
-
if (path.truncated)
|
|
3131
|
-
fullSequence.pop();
|
|
3132
|
-
const sequence = expandedBranch === undefined ? fullSequence : fullSequence.flatMap((node, index) => {
|
|
3133
|
-
const branchKeys = fullSequence.slice(0, index + 1).map((step) => step.key);
|
|
3134
|
-
const parentExpanded = index <= 1 || branchKeys.slice(0, index).every((key, depth) => expandedBranch[depth] === key);
|
|
3135
|
-
if (!parentExpanded)
|
|
3136
|
-
return [];
|
|
3137
|
-
return [
|
|
3138
|
-
{
|
|
3139
|
-
...node,
|
|
3140
|
-
key: JSON.stringify(branchKeys),
|
|
3141
|
-
branchKeys,
|
|
3142
|
-
expandable: index >= 1 && index < fullSequence.length - 1,
|
|
3143
|
-
expanded: branchKeys.every((key, depth) => expandedBranch[depth] === key)
|
|
3144
|
-
}
|
|
3145
|
-
];
|
|
3146
|
-
});
|
|
3147
|
-
sequence.forEach((node, index) => {
|
|
3148
|
-
const current = nodes.get(node.key) ?? {
|
|
3149
|
-
...node,
|
|
3150
|
-
count: 0,
|
|
3151
|
-
pathKeys: []
|
|
3152
|
-
};
|
|
3153
|
-
current.count += path.count;
|
|
3154
|
-
if ("expandable" in node && node.expandable)
|
|
3155
|
-
current.expandable = true;
|
|
3156
|
-
current.pathKeys.push(path.id);
|
|
3157
|
-
nodes.set(node.key, current);
|
|
3158
|
-
const previous = sequence[index - 1];
|
|
3159
|
-
if (!previous)
|
|
3160
|
-
return;
|
|
3161
|
-
const key = JSON.stringify([previous.key, node.key]);
|
|
3162
|
-
const link = links.get(key) ?? {
|
|
3163
|
-
key,
|
|
3164
|
-
source: previous.key,
|
|
3165
|
-
target: node.key,
|
|
3166
|
-
count: 0,
|
|
3167
|
-
pathKeys: []
|
|
3168
|
-
};
|
|
3169
|
-
link.count += path.count;
|
|
3170
|
-
link.pathKeys.push(path.id);
|
|
3171
|
-
links.set(key, link);
|
|
3172
|
-
});
|
|
3173
|
-
}
|
|
3174
|
-
return { nodes: [...nodes.values()], links: [...links.values()] };
|
|
3175
|
-
}
|
|
3176
|
-
function limitJourneyFlow(graph, visibleEventsByDepth = {}) {
|
|
3177
|
-
const nodes = [];
|
|
3178
|
-
const replacements = new Map;
|
|
3179
|
-
for (const depth of new Set(graph.nodes.map((node) => node.depth))) {
|
|
3180
|
-
const column = graph.nodes.filter((node) => node.depth === depth).sort((a, b) => Number(Boolean(b.expanded)) - Number(Boolean(a.expanded)) || b.count - a.count || a.key.localeCompare(b.key));
|
|
3181
|
-
const events = column.filter((node) => node.outcome === "event");
|
|
3182
|
-
const outcomes = column.filter((node) => node.outcome !== "event");
|
|
3183
|
-
const limit = visibleEventsByDepth[depth] ?? 3;
|
|
3184
|
-
if (events.length <= limit) {
|
|
3185
|
-
nodes.push(...column);
|
|
3186
|
-
continue;
|
|
3187
|
-
}
|
|
3188
|
-
nodes.push(...events.slice(0, limit), ...outcomes);
|
|
3189
|
-
const hidden = events.slice(limit);
|
|
3190
|
-
const key = JSON.stringify(["other", depth]);
|
|
3191
|
-
hidden.forEach((node) => replacements.set(node.key, key));
|
|
3192
|
-
nodes.push({
|
|
3193
|
-
key,
|
|
3194
|
-
label: "More events",
|
|
3195
|
-
depth,
|
|
3196
|
-
outcome: "other",
|
|
3197
|
-
hiddenBranchCount: hidden.length,
|
|
3198
|
-
count: hidden.reduce((sum, node) => sum + node.count, 0),
|
|
3199
|
-
pathKeys: [...new Set(hidden.flatMap((node) => node.pathKeys))]
|
|
3200
|
-
});
|
|
3201
|
-
}
|
|
3202
|
-
const links = new Map;
|
|
3203
|
-
for (const link of graph.links) {
|
|
3204
|
-
const source = replacements.get(link.source) ?? link.source;
|
|
3205
|
-
const target = replacements.get(link.target) ?? link.target;
|
|
3206
|
-
const key = JSON.stringify([source, target]);
|
|
3207
|
-
const existing = links.get(key);
|
|
3208
|
-
if (existing) {
|
|
3209
|
-
existing.count += link.count;
|
|
3210
|
-
existing.pathKeys.push(...link.pathKeys);
|
|
3211
|
-
} else {
|
|
3212
|
-
links.set(key, {
|
|
3213
|
-
...link,
|
|
3214
|
-
key,
|
|
3215
|
-
source,
|
|
3216
|
-
target,
|
|
3217
|
-
pathKeys: [...link.pathKeys]
|
|
3218
|
-
});
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
return { nodes, links: [...links.values()] };
|
|
3222
|
-
}
|
|
3223
|
-
|
|
3224
|
-
// src/react/ui/JourneyChart.tsx
|
|
3225
|
-
import { jsx as jsx21, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
3226
|
-
function JourneyChart({
|
|
3227
|
-
paths,
|
|
3228
|
-
unit,
|
|
3229
|
-
ariaLabel,
|
|
3230
|
-
className,
|
|
3231
|
-
formatValue = formatNumber2
|
|
3232
|
-
}) {
|
|
3233
|
-
const ids = new Set;
|
|
3234
|
-
let total = 0;
|
|
3235
|
-
for (const path of paths) {
|
|
3236
|
-
invariant(path.id.trim().length > 0 && !ids.has(path.id), "journey path chart IDs must be nonblank and unique.");
|
|
3237
|
-
ids.add(path.id);
|
|
3238
|
-
invariant(Number.isFinite(path.count) && path.count >= 0, "journey chart counts must be finite and nonnegative.");
|
|
3239
|
-
total += path.count;
|
|
3240
|
-
invariant(path.steps.length > 0 && path.steps.every((step) => step.event.trim().length > 0), "journey chart paths require nonblank events.");
|
|
3241
|
-
}
|
|
3242
|
-
invariant(Number.isFinite(total), "journey chart total count must be finite.");
|
|
3243
|
-
return /* @__PURE__ */ jsx21("section", {
|
|
3244
|
-
className: classNames("altertable-journey-chart", className),
|
|
3245
|
-
"aria-label": ariaLabel,
|
|
3246
|
-
children: paths.length === 0 ? /* @__PURE__ */ jsx21("span", {
|
|
3247
|
-
children: "No data"
|
|
3248
|
-
}) : /* @__PURE__ */ jsx21(JourneyFlow, {
|
|
3249
|
-
paths,
|
|
3250
|
-
unit,
|
|
3251
|
-
formatValue
|
|
3252
|
-
}, JSON.stringify(paths))
|
|
3253
|
-
});
|
|
3254
|
-
}
|
|
3255
|
-
function JourneyFlow({
|
|
3256
|
-
paths,
|
|
3257
|
-
unit,
|
|
3258
|
-
formatValue
|
|
3259
|
-
}) {
|
|
3260
|
-
const [expandedBranch, setExpandedBranch] = useState9([]);
|
|
3261
|
-
const [visibleEventsByDepth, setVisibleEventsByDepth] = useState9({});
|
|
3262
|
-
const graph = limitJourneyFlow(buildJourneyFlow(paths, expandedBranch), visibleEventsByDepth);
|
|
3263
|
-
const scrollRef = useRef7(null);
|
|
3264
|
-
const pendingDepth = useRef7(null);
|
|
3265
|
-
const depthCount = Math.max(0, ...graph.nodes.map((node) => node.depth)) + 1;
|
|
3266
|
-
const startingCount = graph.nodes.filter((node) => node.depth === 0).reduce((sum, node) => sum + node.count, 0);
|
|
3267
|
-
function percent(count) {
|
|
3268
|
-
return formatPercent2(startingCount > 0 ? count / startingCount : null);
|
|
3269
|
-
}
|
|
3270
|
-
const nodeWidth = 176;
|
|
3271
|
-
const nodeHeight = 96;
|
|
3272
|
-
const barWidth = 16;
|
|
3273
|
-
const rowSpacing = nodeHeight + 80;
|
|
3274
|
-
const columnSpacing = nodeWidth + 112;
|
|
3275
|
-
const width = 34 + nodeWidth + (depthCount - 1) * columnSpacing;
|
|
3276
|
-
function columnX(depth) {
|
|
3277
|
-
return 10 + depth * columnSpacing;
|
|
3278
|
-
}
|
|
3279
|
-
useLayoutEffect3(() => {
|
|
3280
|
-
const depth = pendingDepth.current;
|
|
3281
|
-
const container = scrollRef.current;
|
|
3282
|
-
if (depth === null || !container || depth >= depthCount)
|
|
3283
|
-
return;
|
|
3284
|
-
pendingDepth.current = null;
|
|
3285
|
-
const left = columnX(depth);
|
|
3286
|
-
const right = left + nodeWidth + 24;
|
|
3287
|
-
const nextLeft = left < container.scrollLeft ? left - 24 : right > container.scrollLeft + container.clientWidth ? right - container.clientWidth : container.scrollLeft;
|
|
3288
|
-
if (nextLeft !== container.scrollLeft)
|
|
3289
|
-
container.scrollTo({
|
|
3290
|
-
left: Math.max(0, nextLeft),
|
|
3291
|
-
behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth"
|
|
3292
|
-
});
|
|
3293
|
-
});
|
|
3294
|
-
const columns = Array.from({ length: depthCount }, (_, depth) => graph.nodes.filter((node) => node.depth === depth).sort((a, b) => {
|
|
3295
|
-
function rank(node) {
|
|
3296
|
-
return node.outcome === "event" ? 0 : node.outcome === "other" ? 1 : 2;
|
|
3297
|
-
}
|
|
3298
|
-
return rank(a) - rank(b) || b.count - a.count || a.key.localeCompare(b.key);
|
|
3299
|
-
}));
|
|
3300
|
-
const positions = new Map;
|
|
3301
|
-
columns.forEach((column, depth) => {
|
|
3302
|
-
const parent = columns[depth - 1]?.find((node) => node.expanded);
|
|
3303
|
-
const parentY = parent ? positions.get(parent.key)?.y : undefined;
|
|
3304
|
-
const top = Math.max(104, (parentY ?? 104) - (column.length > 1 ? rowSpacing : 0));
|
|
3305
|
-
column.forEach((node, index) => positions.set(node.key, {
|
|
3306
|
-
node,
|
|
3307
|
-
x: columnX(depth),
|
|
3308
|
-
y: top + index * rowSpacing
|
|
3309
|
-
}));
|
|
3310
|
-
});
|
|
3311
|
-
const height = Math.max(280, ...[...positions.values()].map((position) => position.y + nodeHeight + 40));
|
|
3312
|
-
const outgoingOffsets = new Map;
|
|
3313
|
-
const incomingOffsets = new Map;
|
|
3314
|
-
const orderedLinks = [...graph.links].sort((a, b) => (positions.get(a.source)?.y ?? 0) - (positions.get(b.source)?.y ?? 0) || (positions.get(a.target)?.y ?? 0) - (positions.get(b.target)?.y ?? 0));
|
|
3315
|
-
const links = orderedLinks.flatMap((link) => {
|
|
3316
|
-
const source = positions.get(link.source);
|
|
3317
|
-
const target = positions.get(link.target);
|
|
3318
|
-
if (!source || !target || link.count <= 0 || startingCount <= 0)
|
|
3319
|
-
return [];
|
|
3320
|
-
const x0 = source.x + barWidth;
|
|
3321
|
-
const x1 = target.x;
|
|
3322
|
-
const mid = (x0 + x1) / 2;
|
|
3323
|
-
const sourceTop = source.y + (outgoingOffsets.get(link.source) ?? 0);
|
|
3324
|
-
const targetTop = target.y + (incomingOffsets.get(link.target) ?? 0);
|
|
3325
|
-
const thickness = link.count / startingCount * nodeHeight;
|
|
3326
|
-
outgoingOffsets.set(link.source, (outgoingOffsets.get(link.source) ?? 0) + thickness);
|
|
3327
|
-
incomingOffsets.set(link.target, (incomingOffsets.get(link.target) ?? 0) + thickness);
|
|
3328
|
-
return [
|
|
3329
|
-
{
|
|
3330
|
-
muted: target.node.outcome === "end" || target.node.outcome === "other",
|
|
3331
|
-
d: `M${x0},${sourceTop} C${mid},${sourceTop} ${mid},${targetTop} ${x1},${targetTop} L${x1},${targetTop + thickness} C${mid},${targetTop + thickness} ${mid},${sourceTop + thickness} ${x0},${sourceTop + thickness} Z`
|
|
3332
|
-
}
|
|
3333
|
-
];
|
|
3334
|
-
});
|
|
3335
|
-
return /* @__PURE__ */ jsx21("div", {
|
|
3336
|
-
ref: scrollRef,
|
|
3337
|
-
className: "altertable-journey-scroll",
|
|
3338
|
-
children: /* @__PURE__ */ jsxs15("div", {
|
|
3339
|
-
className: "altertable-journey-plot",
|
|
3340
|
-
style: { minWidth: width, minHeight: height },
|
|
3341
|
-
children: [
|
|
3342
|
-
/* @__PURE__ */ jsxs15("svg", {
|
|
3343
|
-
width: "100%",
|
|
3344
|
-
height: "100%",
|
|
3345
|
-
"aria-hidden": "true",
|
|
3346
|
-
focusable: "false",
|
|
3347
|
-
children: [
|
|
3348
|
-
/* @__PURE__ */ jsx21("path", {
|
|
3349
|
-
d: links.filter((link) => !link.muted).map((link) => link.d).join(" "),
|
|
3350
|
-
fill: "color-mix(in srgb, var(--atbl-chart-5) 22%, var(--atbl-surface))"
|
|
3351
|
-
}),
|
|
3352
|
-
/* @__PURE__ */ jsx21("path", {
|
|
3353
|
-
d: links.filter((link) => link.muted).map((link) => link.d).join(" "),
|
|
3354
|
-
fill: "color-mix(in srgb, var(--atbl-muted) 22%, var(--atbl-surface))"
|
|
3355
|
-
})
|
|
3356
|
-
]
|
|
3357
|
-
}),
|
|
3358
|
-
columns.map((column, depth) => /* @__PURE__ */ jsx21("span", {
|
|
3359
|
-
className: "altertable-journey-stage",
|
|
3360
|
-
style: { left: columnX(depth) },
|
|
3361
|
-
children: column.length > 0 && column.every((node) => node.outcome !== "event" && node.outcome !== "other") ? "Outcome" : `Step ${depth + 1}`
|
|
3362
|
-
}, depth)),
|
|
3363
|
-
[...positions.values()].map(({ node, x, y }) => /* @__PURE__ */ jsxs15("div", {
|
|
3364
|
-
className: "altertable-journey-node",
|
|
3365
|
-
style: {
|
|
3366
|
-
left: x,
|
|
3367
|
-
top: y,
|
|
3368
|
-
width: nodeWidth,
|
|
3369
|
-
height: startingCount > 0 ? node.count / startingCount * nodeHeight : 0
|
|
3370
|
-
},
|
|
3371
|
-
children: [
|
|
3372
|
-
/* @__PURE__ */ jsx21("div", {
|
|
3373
|
-
className: "altertable-journey-bar",
|
|
3374
|
-
"data-event": node.outcome === "event" || undefined,
|
|
3375
|
-
"aria-hidden": "true",
|
|
3376
|
-
style: { width: barWidth }
|
|
3377
|
-
}),
|
|
3378
|
-
/* @__PURE__ */ jsxs15("section", {
|
|
3379
|
-
"aria-label": `${node.label}, step ${node.depth + 1}, ${formatValue(node.count)} ${unit}`,
|
|
3380
|
-
className: "altertable-journey-label",
|
|
3381
|
-
children: [
|
|
3382
|
-
/* @__PURE__ */ jsx21("span", {
|
|
3383
|
-
className: "altertable-journey-name",
|
|
3384
|
-
title: node.label,
|
|
3385
|
-
children: node.label
|
|
3386
|
-
}),
|
|
3387
|
-
/* @__PURE__ */ jsxs15("span", {
|
|
3388
|
-
children: [
|
|
3389
|
-
formatValue(node.count),
|
|
3390
|
-
" ",
|
|
3391
|
-
unit,
|
|
3392
|
-
" · ",
|
|
3393
|
-
percent(node.count)
|
|
3394
|
-
]
|
|
3395
|
-
}),
|
|
3396
|
-
node.hiddenBranchCount ? /* @__PURE__ */ jsxs15("span", {
|
|
3397
|
-
children: [
|
|
3398
|
-
node.hiddenBranchCount,
|
|
3399
|
-
" hidden",
|
|
3400
|
-
" ",
|
|
3401
|
-
node.hiddenBranchCount === 1 ? "event" : "events"
|
|
3402
|
-
]
|
|
3403
|
-
}) : null
|
|
3404
|
-
]
|
|
3405
|
-
}),
|
|
3406
|
-
node.expandable && /* @__PURE__ */ jsx21(Button2, {
|
|
3407
|
-
variant: "outline",
|
|
3408
|
-
size: "icon-compact",
|
|
3409
|
-
className: "altertable-journey-expand",
|
|
3410
|
-
"aria-label": `${node.expanded ? "Less" : "More"} after ${node.label}, step ${node.depth + 1}`,
|
|
3411
|
-
"aria-expanded": Boolean(node.expanded),
|
|
3412
|
-
onClick: () => {
|
|
3413
|
-
pendingDepth.current = node.expanded ? null : node.depth + 1;
|
|
3414
|
-
setVisibleEventsByDepth((limits) => Object.fromEntries(Object.entries(limits).filter(([depth]) => Number(depth) <= node.depth)));
|
|
3415
|
-
setExpandedBranch(node.expanded ? (node.branchKeys ?? []).slice(0, -1) : node.branchKeys ?? []);
|
|
3416
|
-
},
|
|
3417
|
-
children: node.expanded ? "−" : "›"
|
|
3418
|
-
}),
|
|
3419
|
-
node.outcome === "other" && /* @__PURE__ */ jsx21(Button2, {
|
|
3420
|
-
size: "compact",
|
|
3421
|
-
variant: "ghost",
|
|
3422
|
-
className: "altertable-journey-more",
|
|
3423
|
-
"aria-label": `Show more events at step ${node.depth + 1}`,
|
|
3424
|
-
onClick: () => setVisibleEventsByDepth((limits) => ({
|
|
3425
|
-
...limits,
|
|
3426
|
-
[node.depth]: (limits[node.depth] ?? 3) + 3
|
|
3427
|
-
})),
|
|
3428
|
-
children: "Show more events"
|
|
3429
|
-
})
|
|
3430
|
-
]
|
|
3431
|
-
}, node.key))
|
|
3432
|
-
]
|
|
3433
|
-
})
|
|
3434
|
-
});
|
|
3435
|
-
}
|
|
3436
|
-
export {
|
|
3437
|
-
AboutData2 as AboutData,
|
|
3438
|
-
AppIcon2 as AppIcon,
|
|
3439
|
-
AreaChart,
|
|
3440
|
-
BarChart,
|
|
3441
|
-
ChartLegend,
|
|
3442
|
-
Checkbox2 as Checkbox,
|
|
3443
|
-
CheckboxGroup,
|
|
3444
|
-
ChoicePicker2 as ChoicePicker,
|
|
3445
|
-
ComposedChart,
|
|
3446
|
-
DataApp,
|
|
3447
|
-
DataAppProvider2 as DataAppProvider,
|
|
3448
|
-
DataTable2 as DataTable,
|
|
3449
|
-
DataTableEmptyRow2 as DataTableEmptyRow,
|
|
3450
|
-
DataTableShare2 as DataTableShare,
|
|
3451
|
-
DataTableTimestamp2 as DataTableTimestamp,
|
|
3452
|
-
DataValue2 as DataValue,
|
|
3453
|
-
DataWidget2 as DataWidget,
|
|
3454
|
-
DateDisplay2 as DateDisplay,
|
|
3455
|
-
DateRangePicker2 as DateRangePicker,
|
|
3456
|
-
DimensionPicker2 as DimensionPicker,
|
|
3457
|
-
ExplorationActionControl2 as ExplorationActionControl,
|
|
3458
|
-
FilterActions2 as FilterActions,
|
|
3459
|
-
FilterBar2 as FilterBar,
|
|
3460
|
-
FunnelChart,
|
|
3461
|
-
GettingStarted,
|
|
3462
|
-
GlossaryDefinition,
|
|
3463
|
-
GlossaryExplanation,
|
|
3464
|
-
GradientScroll2 as GradientScroll,
|
|
3465
|
-
HelpPopover2 as HelpPopover,
|
|
3466
|
-
JourneyChart,
|
|
3467
|
-
LineChart,
|
|
3468
|
-
LiveControl2 as LiveControl,
|
|
3469
|
-
Menu2 as Menu,
|
|
3470
|
-
PressButton as MenuButton,
|
|
3471
|
-
MenuItem2 as MenuItem,
|
|
3472
|
-
MenuPopover2 as MenuPopover,
|
|
3473
|
-
MenuSection2 as MenuSection,
|
|
3474
|
-
MenuSeparator2 as MenuSeparator,
|
|
3475
|
-
MenuTrigger2 as MenuTrigger,
|
|
3476
|
-
MetricWidget2 as MetricWidget,
|
|
3477
|
-
NumberField2 as NumberField,
|
|
3478
|
-
NumberFilterPicker2 as NumberFilterPicker,
|
|
3479
|
-
NumberRangeField2 as NumberRangeField,
|
|
3480
|
-
PieChart,
|
|
3481
|
-
PresentStory2 as PresentStory,
|
|
3482
|
-
Radio,
|
|
3483
|
-
RadioGroup,
|
|
3484
|
-
RetentionChart,
|
|
3485
|
-
ScatterChart,
|
|
3486
|
-
SearchField2 as SearchField,
|
|
3487
|
-
SearchMatch2 as SearchMatch,
|
|
3488
|
-
SearchTypeahead2 as SearchTypeahead,
|
|
3489
|
-
SectionHeading2 as SectionHeading,
|
|
3490
|
-
SegmentedControl,
|
|
3491
|
-
Select2 as Select,
|
|
3492
|
-
Sheet2 as Sheet,
|
|
3493
|
-
Tab2 as Tab,
|
|
3494
|
-
TabList2 as TabList,
|
|
3495
|
-
TabPanel2 as TabPanel,
|
|
3496
|
-
TabPanels2 as TabPanels,
|
|
3497
|
-
TableWidget2 as TableWidget,
|
|
3498
|
-
Tabs2 as Tabs,
|
|
3499
|
-
TextWidget2 as TextWidget,
|
|
3500
|
-
Tooltip2 as Tooltip,
|
|
3501
|
-
TooltipProvider2 as TooltipProvider,
|
|
3502
|
-
VariableBar2 as VariableBar,
|
|
3503
|
-
VisualizationWidget2 as VisualizationWidget,
|
|
3504
|
-
injectDataAppStyles2 as injectDataAppStyles,
|
|
3505
|
-
isPlainKeyEvent2 as isPlainKeyEvent,
|
|
3506
|
-
matchSearchText2 as matchSearchText,
|
|
3507
|
-
searchItems2 as searchItems,
|
|
3508
|
-
useAppVariables2 as useAppVariables,
|
|
3509
|
-
useDateFormatting2 as useDateFormatting,
|
|
3510
|
-
useSvgId,
|
|
3511
|
-
useViewTab2 as useViewTab
|
|
3512
|
-
};
|
|
3513
|
-
|
|
3514
|
-
//# debugId=7CD02365D10882B064756E2164756E21
|