@carto/ps-react-ui 4.3.3 → 4.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js +3 -3
- package/dist/components.js.map +1 -1
- package/dist/{lasso-tool-BwRzEW7k.js → lasso-tool-wFqOD6wk.js} +13 -13
- package/dist/lasso-tool-wFqOD6wk.js.map +1 -0
- package/dist/types/components/common-types.d.ts +41 -0
- package/dist/types/components/types.d.ts +1 -1
- package/dist/types/widgets/echart/echart-ui.d.ts +1 -1
- package/dist/types/widgets/echart/types.d.ts +4 -0
- package/dist/widgets/actions.js +1 -1
- package/dist/widgets/bar.js +1 -1
- package/dist/widgets/category.js +1 -1
- package/dist/widgets/echart.js +96 -85
- package/dist/widgets/echart.js.map +1 -1
- package/dist/widgets/formula.js +1 -1
- package/dist/widgets/histogram.js +1 -1
- package/dist/widgets/markdown.js +1 -1
- package/dist/widgets/pie.js +1 -1
- package/dist/widgets/scatterplot.js +1 -1
- package/dist/widgets/spread.js +1 -1
- package/dist/widgets/table.js +1 -1
- package/dist/widgets/timeseries.js +1 -1
- package/dist/widgets/toolbar-actions.js.map +1 -1
- package/dist/widgets/wrapper.js +1 -1
- package/package.json +8 -3
- package/src/components/basemaps/basemaps.test.tsx +196 -0
- package/src/components/basemaps/basemaps.tsx +128 -0
- package/src/components/basemaps/const.ts +13 -0
- package/src/components/basemaps/group-wrapper.test.tsx +38 -0
- package/src/components/basemaps/group-wrapper.tsx +28 -0
- package/src/components/basemaps/group.test.tsx +52 -0
- package/src/components/basemaps/group.tsx +42 -0
- package/src/components/basemaps/header.test.tsx +54 -0
- package/src/components/basemaps/header.tsx +36 -0
- package/src/components/basemaps/styles.ts +76 -0
- package/src/components/basemaps/types.ts +30 -0
- package/src/components/common-types.ts +1 -0
- package/src/components/geolocation-controls/const.ts +6 -0
- package/src/components/geolocation-controls/geolocation-controls.test.tsx +133 -0
- package/src/components/geolocation-controls/geolocation-controls.tsx +95 -0
- package/src/components/geolocation-controls/types.ts +17 -0
- package/src/components/index.ts +64 -0
- package/src/components/lasso-tool/chip.tsx +37 -0
- package/src/components/lasso-tool/const.tsx +70 -0
- package/src/components/lasso-tool/icons.tsx +91 -0
- package/src/components/lasso-tool/lasso-tool-inline.test.tsx +168 -0
- package/src/components/lasso-tool/lasso-tool-inline.tsx +245 -0
- package/src/components/lasso-tool/lasso-tool.test.tsx +212 -0
- package/src/components/lasso-tool/lasso-tool.tsx +479 -0
- package/src/components/lasso-tool/styles.ts +143 -0
- package/src/components/lasso-tool/types.ts +114 -0
- package/src/components/list-data/list-data-skeleton.test.tsx +10 -0
- package/src/components/list-data/list-data-skeleton.tsx +40 -0
- package/src/components/list-data/list-data.test.tsx +94 -0
- package/src/components/list-data/list-data.tsx +106 -0
- package/src/components/list-data/styles.ts +37 -0
- package/src/components/list-data/types.ts +25 -0
- package/src/components/measurement-tools/const.tsx +108 -0
- package/src/components/measurement-tools/icons.tsx +54 -0
- package/src/components/measurement-tools/measurement-tools.test.tsx +165 -0
- package/src/components/measurement-tools/measurement-tools.tsx +443 -0
- package/src/components/measurement-tools/styles.ts +91 -0
- package/src/components/measurement-tools/types.ts +77 -0
- package/src/components/no-data-alert/no-data-alert.test.tsx +31 -0
- package/src/components/no-data-alert/no-data-alert.tsx +59 -0
- package/src/components/responsive-drawer/responsive-drawer.test.tsx +91 -0
- package/src/components/responsive-drawer/responsive-drawer.tsx +53 -0
- package/src/components/smart-tooltip/smart-tooltip.test.tsx +168 -0
- package/src/components/smart-tooltip/smart-tooltip.tsx +40 -0
- package/src/components/tooltip/tooltip.test.tsx +86 -0
- package/src/components/tooltip/tooltip.tsx +30 -0
- package/src/components/types.ts +1 -0
- package/src/components/zoom-controls/styles.ts +27 -0
- package/src/components/zoom-controls/types.ts +19 -0
- package/src/components/zoom-controls/zoom-controls.test.tsx +101 -0
- package/src/components/zoom-controls/zoom-controls.tsx +114 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-debounce.ts +55 -0
- package/src/hooks/use-skeleton.test.tsx +32 -0
- package/src/hooks/use-skeleton.ts +19 -0
- package/src/hooks/use-widget-ref.ts +33 -0
- package/src/widgets/README.md +277 -0
- package/src/widgets/_shared/chart-config/config-factory.ts +67 -0
- package/src/widgets/_shared/chart-config/csv-modifiers.ts +56 -0
- package/src/widgets/_shared/chart-config/index.ts +21 -0
- package/src/widgets/_shared/chart-config/option-builders.ts +203 -0
- package/src/widgets/_shared/skeleton/index.ts +5 -0
- package/src/widgets/_shared/skeleton/styles.ts +20 -0
- package/src/widgets/actions/change-column/change-column-icon.tsx +10 -0
- package/src/widgets/actions/change-column/change-column.test.tsx +163 -0
- package/src/widgets/actions/change-column/change-column.tsx +141 -0
- package/src/widgets/actions/change-column/sortable-column-item.tsx +49 -0
- package/src/widgets/actions/change-column/types.ts +20 -0
- package/src/widgets/actions/download/download.test.tsx +322 -0
- package/src/widgets/actions/download/download.tsx +118 -0
- package/src/widgets/actions/download/exports.test.tsx +275 -0
- package/src/widgets/actions/download/exports.tsx +103 -0
- package/src/widgets/actions/download/types.ts +21 -0
- package/src/widgets/actions/fullscreen/fullscreen.test.tsx +269 -0
- package/src/widgets/actions/fullscreen/fullscreen.tsx +82 -0
- package/src/widgets/actions/fullscreen/styles.ts +17 -0
- package/src/widgets/actions/fullscreen/types.ts +27 -0
- package/src/widgets/actions/index.ts +51 -0
- package/src/widgets/actions/lock-selection/lock-selection.test.tsx +186 -0
- package/src/widgets/actions/lock-selection/lock-selection.tsx +133 -0
- package/src/widgets/actions/lock-selection/types.ts +41 -0
- package/src/widgets/actions/relative-data/relative-data.test.tsx +267 -0
- package/src/widgets/actions/relative-data/relative-data.tsx +133 -0
- package/src/widgets/actions/relative-data/style.ts +9 -0
- package/src/widgets/actions/relative-data/types.ts +31 -0
- package/src/widgets/actions/relative-data/utils.test.ts +223 -0
- package/src/widgets/actions/relative-data/utils.ts +58 -0
- package/src/widgets/actions/searcher/searcher-toggle.test.tsx +354 -0
- package/src/widgets/actions/searcher/searcher-toggle.tsx +73 -0
- package/src/widgets/actions/searcher/searcher.tsx +205 -0
- package/src/widgets/actions/searcher/types.ts +72 -0
- package/src/widgets/actions/shared/styles.ts +12 -0
- package/src/widgets/actions/stack-toggle/grouped-bar-chart-icon.tsx +14 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.test.tsx +270 -0
- package/src/widgets/actions/stack-toggle/stack-toggle.tsx +146 -0
- package/src/widgets/actions/stack-toggle/types.ts +29 -0
- package/src/widgets/actions/zoom-toggle/index.ts +2 -0
- package/src/widgets/actions/zoom-toggle/style.ts +14 -0
- package/src/widgets/actions/zoom-toggle/types.ts +44 -0
- package/src/widgets/actions/zoom-toggle/zoom-toggle.tsx +186 -0
- package/src/widgets/bar/config.ts +122 -0
- package/src/widgets/bar/index.ts +9 -0
- package/src/widgets/bar/skeleton.tsx +60 -0
- package/src/widgets/bar/style.ts +33 -0
- package/src/widgets/bar/types.ts +16 -0
- package/src/widgets/category/category-ui.test.tsx +399 -0
- package/src/widgets/category/category-ui.tsx +156 -0
- package/src/widgets/category/components/category-bar.tsx +28 -0
- package/src/widgets/category/components/category-legend.tsx +30 -0
- package/src/widgets/category/components/category-row-multi.tsx +50 -0
- package/src/widgets/category/components/category-row-other.tsx +23 -0
- package/src/widgets/category/components/category-row-single.tsx +47 -0
- package/src/widgets/category/components/index.ts +14 -0
- package/src/widgets/category/config.ts +85 -0
- package/src/widgets/category/index.ts +30 -0
- package/src/widgets/category/skeleton.tsx +24 -0
- package/src/widgets/category/style.ts +133 -0
- package/src/widgets/category/types.ts +40 -0
- package/src/widgets/echart/const.ts +1 -0
- package/src/widgets/echart/echart-ui.test.tsx +537 -0
- package/src/widgets/echart/echart-ui.tsx +92 -0
- package/src/widgets/echart/echart.test.tsx +562 -0
- package/src/widgets/echart/echart.tsx +68 -0
- package/src/widgets/echart/index.ts +16 -0
- package/src/widgets/echart/options.ts +53 -0
- package/src/widgets/echart/types.ts +45 -0
- package/src/widgets/echart/utils.ts +169 -0
- package/src/widgets/error/error.test.tsx +331 -0
- package/src/widgets/error/error.tsx +40 -0
- package/src/widgets/error/index.ts +2 -0
- package/src/widgets/error/types.ts +14 -0
- package/src/widgets/formula/components/item.test.tsx +249 -0
- package/src/widgets/formula/components/item.tsx +18 -0
- package/src/widgets/formula/components/prefix.test.tsx +341 -0
- package/src/widgets/formula/components/prefix.tsx +18 -0
- package/src/widgets/formula/components/row.test.tsx +364 -0
- package/src/widgets/formula/components/row.tsx +21 -0
- package/src/widgets/formula/components/series.tsx +34 -0
- package/src/widgets/formula/components/suffix.test.tsx +383 -0
- package/src/widgets/formula/components/suffix.tsx +28 -0
- package/src/widgets/formula/components/value.test.tsx +329 -0
- package/src/widgets/formula/components/value.tsx +29 -0
- package/src/widgets/formula/config.ts +27 -0
- package/src/widgets/formula/formula-ui.test.tsx +399 -0
- package/src/widgets/formula/formula-ui.tsx +27 -0
- package/src/widgets/formula/index.ts +24 -0
- package/src/widgets/formula/serializer.test.tsx +144 -0
- package/src/widgets/formula/serializer.ts +28 -0
- package/src/widgets/formula/skeleton.tsx +10 -0
- package/src/widgets/formula/style.ts +23 -0
- package/src/widgets/formula/types.ts +50 -0
- package/src/widgets/histogram/config.ts +143 -0
- package/src/widgets/histogram/index.ts +8 -0
- package/src/widgets/histogram/skeleton.tsx +52 -0
- package/src/widgets/histogram/style.ts +8 -0
- package/src/widgets/histogram/types.ts +17 -0
- package/src/widgets/index.ts +25 -0
- package/src/widgets/loader/index.ts +4 -0
- package/src/widgets/loader/loader.tsx +70 -0
- package/src/widgets/loader/types.ts +11 -0
- package/src/widgets/loader/utils.test.ts +112 -0
- package/src/widgets/loader/utils.ts +35 -0
- package/src/widgets/markdown/config.ts +18 -0
- package/src/widgets/markdown/index.ts +14 -0
- package/src/widgets/markdown/markdown-ui.test.tsx +341 -0
- package/src/widgets/markdown/markdown-ui.tsx +52 -0
- package/src/widgets/markdown/markdown.tsx +20 -0
- package/src/widgets/markdown/skeleton.tsx +12 -0
- package/src/widgets/markdown/style.ts +28 -0
- package/src/widgets/markdown/types.ts +28 -0
- package/src/widgets/no-data/index.ts +2 -0
- package/src/widgets/no-data/no-data.test.tsx +447 -0
- package/src/widgets/no-data/no-data.tsx +116 -0
- package/src/widgets/no-data/style.ts +18 -0
- package/src/widgets/no-data/types.ts +72 -0
- package/src/widgets/note/index.ts +2 -0
- package/src/widgets/note/note.test.tsx +391 -0
- package/src/widgets/note/note.tsx +114 -0
- package/src/widgets/note/style.ts +29 -0
- package/src/widgets/note/types.ts +9 -0
- package/src/widgets/pie/config.ts +177 -0
- package/src/widgets/pie/index.ts +8 -0
- package/src/widgets/pie/skeleton.tsx +70 -0
- package/src/widgets/pie/style.ts +8 -0
- package/src/widgets/pie/types.ts +16 -0
- package/src/widgets/range/components/range-item.tsx +213 -0
- package/src/widgets/range/config.ts +10 -0
- package/src/widgets/range/index.ts +16 -0
- package/src/widgets/range/range-ui.test.tsx +203 -0
- package/src/widgets/range/range-ui.tsx +11 -0
- package/src/widgets/range/serializer.test.ts +70 -0
- package/src/widgets/range/serializer.ts +27 -0
- package/src/widgets/range/skeleton.tsx +14 -0
- package/src/widgets/range/style.ts +37 -0
- package/src/widgets/range/types.ts +39 -0
- package/src/widgets/scatterplot/config.ts +138 -0
- package/src/widgets/scatterplot/index.ts +8 -0
- package/src/widgets/scatterplot/skeleton.tsx +59 -0
- package/src/widgets/scatterplot/style.ts +21 -0
- package/src/widgets/scatterplot/types.ts +17 -0
- package/src/widgets/selection-summary/index.ts +6 -0
- package/src/widgets/selection-summary/selection-summary.tsx +46 -0
- package/src/widgets/selection-summary/style.ts +10 -0
- package/src/widgets/selection-summary/types.ts +14 -0
- package/src/widgets/skeleton-loader/index.ts +2 -0
- package/src/widgets/skeleton-loader/skeleton-loader.test.tsx +139 -0
- package/src/widgets/skeleton-loader/skeleton-loader.tsx +28 -0
- package/src/widgets/skeleton-loader/types.ts +8 -0
- package/src/widgets/spread/components/max-value.tsx +29 -0
- package/src/widgets/spread/components/min-value.tsx +29 -0
- package/src/widgets/spread/components/separator.tsx +6 -0
- package/src/widgets/spread/config.ts +34 -0
- package/src/widgets/spread/index.ts +23 -0
- package/src/widgets/spread/skeleton.tsx +10 -0
- package/src/widgets/spread/spread-ui.test.tsx +368 -0
- package/src/widgets/spread/spread-ui.tsx +29 -0
- package/src/widgets/spread/style.ts +22 -0
- package/src/widgets/spread/types.ts +47 -0
- package/src/widgets/stores/index.ts +9 -0
- package/src/widgets/stores/types.ts +192 -0
- package/src/widgets/stores/widget-store.test.ts +601 -0
- package/src/widgets/stores/widget-store.ts +239 -0
- package/src/widgets/subheader/index.ts +3 -0
- package/src/widgets/subheader/style.ts +20 -0
- package/src/widgets/subheader/subheader.test.tsx +45 -0
- package/src/widgets/subheader/subheader.tsx +16 -0
- package/src/widgets/subheader/types.ts +11 -0
- package/src/widgets/table/components/cell-header.tsx +58 -0
- package/src/widgets/table/components/cell.tsx +80 -0
- package/src/widgets/table/components/index.ts +4 -0
- package/src/widgets/table/components/pagination-actions.tsx +67 -0
- package/src/widgets/table/components/pagination.tsx +41 -0
- package/src/widgets/table/components/row.tsx +60 -0
- package/src/widgets/table/config.ts +71 -0
- package/src/widgets/table/helpers.test.ts +244 -0
- package/src/widgets/table/helpers.ts +107 -0
- package/src/widgets/table/hooks/index.ts +7 -0
- package/src/widgets/table/hooks/use-pagination.test.ts +294 -0
- package/src/widgets/table/hooks/use-pagination.ts +155 -0
- package/src/widgets/table/hooks/use-selection.test.ts +504 -0
- package/src/widgets/table/hooks/use-selection.ts +189 -0
- package/src/widgets/table/hooks/use-sort.test.ts +296 -0
- package/src/widgets/table/hooks/use-sort.ts +138 -0
- package/src/widgets/table/index.ts +53 -0
- package/src/widgets/table/serializer.ts +54 -0
- package/src/widgets/table/skeleton.tsx +48 -0
- package/src/widgets/table/style.ts +34 -0
- package/src/widgets/table/table-ui.tsx +64 -0
- package/src/widgets/table/types.ts +223 -0
- package/src/widgets/timeseries/config.ts +135 -0
- package/src/widgets/timeseries/index.ts +8 -0
- package/src/widgets/timeseries/skeleton.tsx +55 -0
- package/src/widgets/timeseries/style.ts +36 -0
- package/src/widgets/timeseries/types.ts +17 -0
- package/src/widgets/toolbar-actions/index.ts +6 -0
- package/src/widgets/toolbar-actions/styles.ts +38 -0
- package/src/widgets/toolbar-actions/toolbar-actions.test.tsx +691 -0
- package/src/widgets/toolbar-actions/toolbar-actions.tsx +145 -0
- package/src/widgets/toolbar-actions/types.ts +60 -0
- package/src/widgets/wrapper/components/actions.test.tsx +101 -0
- package/src/widgets/wrapper/components/actions.tsx +30 -0
- package/src/widgets/wrapper/components/options.test.tsx +323 -0
- package/src/widgets/wrapper/components/options.tsx +73 -0
- package/src/widgets/wrapper/components/title.test.tsx +126 -0
- package/src/widgets/wrapper/components/title.tsx +32 -0
- package/src/widgets/wrapper/index.ts +16 -0
- package/src/widgets/wrapper/styles.ts +98 -0
- package/src/widgets/wrapper/types.ts +55 -0
- package/src/widgets/wrapper/wrapper-ui.test.tsx +232 -0
- package/src/widgets/wrapper/wrapper-ui.tsx +57 -0
- package/src/widgets/wrapper/wrapper.test.tsx +365 -0
- package/src/widgets/wrapper/wrapper.tsx +50 -0
- package/dist/lasso-tool-BwRzEW7k.js.map +0 -1
- package/dist/types/common/common.d.ts +0 -3
- package/dist/types/common/index.d.ts +0 -26
- package/dist/types/common/lasso-tools.d.ts +0 -36
- package/dist/types/common/measurement-tools.d.ts +0 -65
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Box, IconButton, useTheme } from '@mui/material'
|
|
2
|
+
import {
|
|
3
|
+
SubdirectoryArrowLeftOutlined,
|
|
4
|
+
ZoomInOutlined,
|
|
5
|
+
} from '@mui/icons-material'
|
|
6
|
+
import { useEffect, useCallback } from 'react'
|
|
7
|
+
import { useWidgetStore } from '../../stores/widget-store'
|
|
8
|
+
import type { ZoomToggleProps, ZoomState } from './types'
|
|
9
|
+
import { styles } from './style'
|
|
10
|
+
import { Tooltip } from '../../../components'
|
|
11
|
+
import { getEChartZoomConfig } from '../../echart/utils'
|
|
12
|
+
import type { EchartWidgetState } from '../../echart/types'
|
|
13
|
+
import { useShallow } from 'zustand/shallow'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Widget action to toggle EChart zoom functionality.
|
|
17
|
+
*
|
|
18
|
+
* When zoom is active, displays an inline reset button to disable zoom.
|
|
19
|
+
* Only intended for use in fullscreen ToolbarActions for bar and histogram widgets.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <ZoomToggle
|
|
24
|
+
* id="my-widget"
|
|
25
|
+
* defaultZoom={false}
|
|
26
|
+
* zoomStart={0}
|
|
27
|
+
* zoomEnd={100}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function ZoomToggle({
|
|
32
|
+
id,
|
|
33
|
+
defaultZoom = false,
|
|
34
|
+
defaultZoomStart = 0,
|
|
35
|
+
defaultZoomEnd = 100,
|
|
36
|
+
labels,
|
|
37
|
+
Icon,
|
|
38
|
+
ResetIcon,
|
|
39
|
+
IconButtonProps,
|
|
40
|
+
}: ZoomToggleProps) {
|
|
41
|
+
const theme = useTheme()
|
|
42
|
+
const setWidget = useWidgetStore((state) => state.setWidget)
|
|
43
|
+
const getWidget = useWidgetStore((state) => state.getWidget)
|
|
44
|
+
|
|
45
|
+
const zoom = useWidgetStore(
|
|
46
|
+
useShallow((state) => {
|
|
47
|
+
const widget = state.getWidget<ZoomState>(id)
|
|
48
|
+
return widget?.zoom ?? false
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
const updateZoomOption = useCallback(
|
|
53
|
+
(enabled: boolean, start: number, end: number) => {
|
|
54
|
+
const zoomConfig = getEChartZoomConfig(
|
|
55
|
+
enabled,
|
|
56
|
+
{ start, end },
|
|
57
|
+
{ inside: true, xSlider: true, ySlider: false },
|
|
58
|
+
theme,
|
|
59
|
+
)
|
|
60
|
+
const currentOption = getWidget<EchartWidgetState>(id)?.option
|
|
61
|
+
|
|
62
|
+
setWidget<EchartWidgetState & ZoomState>(id, {
|
|
63
|
+
zoom: enabled,
|
|
64
|
+
zoomStart: start,
|
|
65
|
+
zoomEnd: end,
|
|
66
|
+
option: {
|
|
67
|
+
...currentOption,
|
|
68
|
+
...zoomConfig,
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
[getWidget, id, setWidget, theme],
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
// Initialize zoom state from defaults only if not already set
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const existingState = getWidget<ZoomState>(id)
|
|
78
|
+
|
|
79
|
+
if (existingState?.zoom) return
|
|
80
|
+
|
|
81
|
+
// Apply initial zoom config
|
|
82
|
+
updateZoomOption(
|
|
83
|
+
existingState?.zoom ?? defaultZoom,
|
|
84
|
+
existingState?.zoomStart ?? defaultZoomStart,
|
|
85
|
+
existingState?.zoomEnd ?? defaultZoomEnd,
|
|
86
|
+
)
|
|
87
|
+
}, [
|
|
88
|
+
defaultZoom,
|
|
89
|
+
defaultZoomEnd,
|
|
90
|
+
defaultZoomStart,
|
|
91
|
+
getWidget,
|
|
92
|
+
id,
|
|
93
|
+
updateZoomOption,
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
// Cleanup: reset zoom when component unmounts
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
return () => {
|
|
99
|
+
const existingState = getWidget<ZoomState>(id)
|
|
100
|
+
updateZoomOption(
|
|
101
|
+
false,
|
|
102
|
+
existingState?.zoomStart ?? 0,
|
|
103
|
+
existingState?.zoomEnd ?? 100,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}, [getWidget, id, updateZoomOption])
|
|
107
|
+
|
|
108
|
+
const handleToggle = () => {
|
|
109
|
+
const newZoom = !zoom
|
|
110
|
+
|
|
111
|
+
const existingState = getWidget<ZoomState>(id)
|
|
112
|
+
|
|
113
|
+
updateZoomOption(
|
|
114
|
+
newZoom,
|
|
115
|
+
newZoom ? (existingState?.zoomStart ?? defaultZoomStart) : 0,
|
|
116
|
+
newZoom ? (existingState?.zoomEnd ?? defaultZoomEnd) : 100,
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const handleReset = () => {
|
|
121
|
+
updateZoomOption(true, defaultZoomStart, defaultZoomEnd)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Handle dataZoom event to update zoom range in store
|
|
125
|
+
const handleDataZoom = useCallback(
|
|
126
|
+
(event: unknown) => {
|
|
127
|
+
const zoomEvent = event as {
|
|
128
|
+
start: number
|
|
129
|
+
end: number
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const start = zoomEvent.start
|
|
133
|
+
const end = zoomEvent.end
|
|
134
|
+
|
|
135
|
+
if (start !== undefined && end !== undefined) {
|
|
136
|
+
updateZoomOption(true, start, end)
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
[updateZoomOption],
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
// Register dataZoom event handler when zoom is enabled
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (zoom) {
|
|
145
|
+
setWidget<EchartWidgetState>(id, {
|
|
146
|
+
onEvents: {
|
|
147
|
+
dataZoom: handleDataZoom,
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}, [id, zoom, handleDataZoom, setWidget])
|
|
152
|
+
|
|
153
|
+
const enableLabel = labels?.enable ?? 'Enable zoom'
|
|
154
|
+
const disableLabel = labels?.disable ?? 'Disable zoom'
|
|
155
|
+
const resetLabel = labels?.reset ?? 'Reset zoom'
|
|
156
|
+
const tooltipLabel = zoom ? disableLabel : enableLabel
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Box sx={styles.container}>
|
|
160
|
+
<Tooltip title={tooltipLabel}>
|
|
161
|
+
<IconButton
|
|
162
|
+
size='small'
|
|
163
|
+
aria-label={labels?.ariaLabel ?? tooltipLabel}
|
|
164
|
+
onClick={handleToggle}
|
|
165
|
+
sx={styles.trigger}
|
|
166
|
+
data-active={zoom}
|
|
167
|
+
{...IconButtonProps}
|
|
168
|
+
>
|
|
169
|
+
{Icon ?? <ZoomInOutlined />}
|
|
170
|
+
</IconButton>
|
|
171
|
+
</Tooltip>
|
|
172
|
+
{zoom && (
|
|
173
|
+
<Tooltip title={resetLabel}>
|
|
174
|
+
<IconButton
|
|
175
|
+
size='small'
|
|
176
|
+
aria-label={resetLabel}
|
|
177
|
+
onClick={handleReset}
|
|
178
|
+
{...IconButtonProps}
|
|
179
|
+
>
|
|
180
|
+
{ResetIcon ?? <SubdirectoryArrowLeftOutlined />}
|
|
181
|
+
</IconButton>
|
|
182
|
+
</Tooltip>
|
|
183
|
+
)}
|
|
184
|
+
</Box>
|
|
185
|
+
)
|
|
186
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCommonOptions,
|
|
3
|
+
mergeEchartWidgetConfig,
|
|
4
|
+
type EchartOptionsProps,
|
|
5
|
+
} from '../echart'
|
|
6
|
+
import type { BarConfig, BarWidgetConfig, BarWidgetData } from './types'
|
|
7
|
+
import {
|
|
8
|
+
flattenObjectArrayToCSV,
|
|
9
|
+
buildLegendConfig,
|
|
10
|
+
buildGridConfig,
|
|
11
|
+
createTooltipPositioner,
|
|
12
|
+
createTooltipFormatter,
|
|
13
|
+
applyYAxisFormatter,
|
|
14
|
+
} from '../_shared/chart-config'
|
|
15
|
+
import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
|
|
16
|
+
import type { ConfigProps } from '../loader/types'
|
|
17
|
+
|
|
18
|
+
export function barDownloadConfig({
|
|
19
|
+
refUI,
|
|
20
|
+
}: ConfigProps): DownloadItem<BarWidgetData>[] {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
...downloadToPNG,
|
|
24
|
+
modifier: () => downloadToPNG.modifier(refUI),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
...downloadToCSV,
|
|
28
|
+
modifier: async (data) => {
|
|
29
|
+
const rows = flattenObjectArrayToCSV(data)
|
|
30
|
+
return downloadToCSV.modifier(rows)
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function barConfig(props: BarConfig): BarWidgetConfig {
|
|
37
|
+
return {
|
|
38
|
+
type: 'bar',
|
|
39
|
+
option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function getOption({
|
|
44
|
+
data = [],
|
|
45
|
+
theme,
|
|
46
|
+
formatter,
|
|
47
|
+
}: BarConfig): EchartOptionsProps {
|
|
48
|
+
const hasLegend = (data?.length ?? 0) > 1
|
|
49
|
+
|
|
50
|
+
const yAxis = {
|
|
51
|
+
type: 'value' as const,
|
|
52
|
+
splitNumber: 1,
|
|
53
|
+
axisLabel: {
|
|
54
|
+
fontSize: theme.typography.overlineDelicate.fontSize,
|
|
55
|
+
fontFamily: theme.typography.overlineDelicate.fontFamily,
|
|
56
|
+
margin: parseInt(theme.spacing(1)),
|
|
57
|
+
show: true,
|
|
58
|
+
showMaxLabel: true,
|
|
59
|
+
showMinLabel: false,
|
|
60
|
+
verticalAlign: 'bottom' as const,
|
|
61
|
+
inside: true,
|
|
62
|
+
},
|
|
63
|
+
axisLine: {
|
|
64
|
+
show: false,
|
|
65
|
+
},
|
|
66
|
+
axisTick: {
|
|
67
|
+
show: false,
|
|
68
|
+
},
|
|
69
|
+
splitLine: {
|
|
70
|
+
show: true,
|
|
71
|
+
lineStyle: {
|
|
72
|
+
color: theme.palette.black[4],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
legend: buildLegendConfig(hasLegend),
|
|
79
|
+
grid: buildGridConfig(hasLegend, theme),
|
|
80
|
+
xAxis: {
|
|
81
|
+
type: 'category',
|
|
82
|
+
axisLine: {
|
|
83
|
+
show: false,
|
|
84
|
+
},
|
|
85
|
+
axisTick: {
|
|
86
|
+
show: false,
|
|
87
|
+
},
|
|
88
|
+
axisLabel: {
|
|
89
|
+
padding: [parseInt(theme.spacing(0.5)), 0, 0, 0],
|
|
90
|
+
margin: 0,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
yAxis: applyYAxisFormatter(yAxis, formatter),
|
|
94
|
+
tooltip: {
|
|
95
|
+
position: createTooltipPositioner(theme),
|
|
96
|
+
formatter: createTooltipFormatter((item) => {
|
|
97
|
+
const value = item.value as Record<string, string | number>
|
|
98
|
+
const index = item.dimensionNames?.[item.encode?.y?.at(0) ?? 1]
|
|
99
|
+
const _value = value[index ?? '']
|
|
100
|
+
|
|
101
|
+
const formattedValue =
|
|
102
|
+
typeof _value === 'number' && formatter
|
|
103
|
+
? formatter(_value)
|
|
104
|
+
: (_value ?? '')
|
|
105
|
+
|
|
106
|
+
const marker = typeof item.marker === 'string' ? item.marker : ''
|
|
107
|
+
const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
|
|
108
|
+
const name = item.name ?? ''
|
|
109
|
+
|
|
110
|
+
return { name, seriesName, marker, value: formattedValue }
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
series: data.map((_: unknown, index: number) => ({
|
|
114
|
+
datasetIndex: index,
|
|
115
|
+
type: 'bar',
|
|
116
|
+
barMaxWidth: 100,
|
|
117
|
+
emphasis: {
|
|
118
|
+
focus: 'series',
|
|
119
|
+
},
|
|
120
|
+
})),
|
|
121
|
+
} as EchartOptionsProps
|
|
122
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Box, Skeleton } from '@mui/material'
|
|
2
|
+
import { styles } from './style'
|
|
3
|
+
|
|
4
|
+
export function BarSkeleton() {
|
|
5
|
+
return (
|
|
6
|
+
<Box sx={styles.skeleton.graph.container}>
|
|
7
|
+
<Box sx={styles.skeleton.graph.grid}>
|
|
8
|
+
<Skeleton
|
|
9
|
+
sx={styles.skeleton.item}
|
|
10
|
+
variant='rectangular'
|
|
11
|
+
height='20%'
|
|
12
|
+
/>
|
|
13
|
+
<Skeleton
|
|
14
|
+
sx={styles.skeleton.item}
|
|
15
|
+
variant='rectangular'
|
|
16
|
+
height='40%'
|
|
17
|
+
/>
|
|
18
|
+
<Skeleton
|
|
19
|
+
sx={styles.skeleton.item}
|
|
20
|
+
variant='rectangular'
|
|
21
|
+
height='60%'
|
|
22
|
+
/>
|
|
23
|
+
<Skeleton
|
|
24
|
+
sx={styles.skeleton.item}
|
|
25
|
+
variant='rectangular'
|
|
26
|
+
height='20%'
|
|
27
|
+
/>
|
|
28
|
+
<Skeleton
|
|
29
|
+
sx={styles.skeleton.item}
|
|
30
|
+
variant='rectangular'
|
|
31
|
+
height='80%'
|
|
32
|
+
/>
|
|
33
|
+
</Box>
|
|
34
|
+
<Box
|
|
35
|
+
sx={{
|
|
36
|
+
display: 'flex',
|
|
37
|
+
alignItems: 'center',
|
|
38
|
+
gap: ({ spacing }) => spacing(2),
|
|
39
|
+
height: ({ spacing }) => spacing(5),
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{Array(2)
|
|
43
|
+
.fill(0)
|
|
44
|
+
.map((_, i) => (
|
|
45
|
+
<Box
|
|
46
|
+
key={i}
|
|
47
|
+
sx={{
|
|
48
|
+
display: 'flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap: ({ spacing }) => spacing(1.5),
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<Skeleton variant='circular' width={8} height={8} />
|
|
54
|
+
<Skeleton width={48} height={8} />
|
|
55
|
+
</Box>
|
|
56
|
+
))}
|
|
57
|
+
</Box>
|
|
58
|
+
</Box>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
2
|
+
import { baseSkeletonStyles } from '../_shared/skeleton'
|
|
3
|
+
|
|
4
|
+
export const styles = {
|
|
5
|
+
skeleton: {
|
|
6
|
+
item: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
maxWidth: ({ spacing }) => spacing(12),
|
|
9
|
+
|
|
10
|
+
'& + &': {
|
|
11
|
+
marginLeft: ({ spacing }) => spacing(1),
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
graph: {
|
|
15
|
+
...baseSkeletonStyles.graph,
|
|
16
|
+
grid: {
|
|
17
|
+
display: 'flex',
|
|
18
|
+
justifyContent: 'space-between',
|
|
19
|
+
flex: '1 1 auto',
|
|
20
|
+
alignItems: 'flex-end',
|
|
21
|
+
width: '100%',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
mask: {
|
|
25
|
+
gray: {
|
|
26
|
+
backgroundColor: ({ palette }) => palette.grey[100],
|
|
27
|
+
},
|
|
28
|
+
white: {
|
|
29
|
+
backgroundColor: ({ palette }) => palette.common.white,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} satisfies Record<string, SxProps<Theme>>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EchartWidgetData, EchartWidgetState } from '../echart'
|
|
2
|
+
import type {
|
|
3
|
+
EchartWidgetOptionProps,
|
|
4
|
+
EchartWidgetProps,
|
|
5
|
+
} from '../echart/types'
|
|
6
|
+
import type { ConfigProps } from '../loader'
|
|
7
|
+
|
|
8
|
+
export type BarWidgetData = EchartWidgetData
|
|
9
|
+
|
|
10
|
+
export type BarWidgetState = EchartWidgetState
|
|
11
|
+
|
|
12
|
+
export type BarWidgetConfig = EchartWidgetProps & {
|
|
13
|
+
type: 'bar'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type BarConfig = ConfigProps & EchartWidgetOptionProps<BarWidgetData>
|