@carto/ps-react-ui 4.4.1 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js.map +1 -1
- package/dist/error-CEkRPccv.js.map +1 -1
- package/dist/exports-Cr43OCul.js.map +1 -1
- package/dist/formatter-B1Xh8XDH.js +5 -0
- package/dist/formatter-B1Xh8XDH.js.map +1 -0
- package/dist/lasso-tool-BYbxrJ-7.js.map +1 -1
- package/dist/note-t51drNe0.js.map +1 -1
- package/dist/options-D9wflre6.js.map +1 -1
- package/dist/row-DTCV0Ocm.js.map +1 -1
- package/dist/series-CYNOu2Ju.js.map +1 -1
- package/dist/smart-tooltip-D4vwQpFf.js.map +1 -1
- package/dist/styles-C_8vOEep.js +167 -0
- package/dist/styles-C_8vOEep.js.map +1 -0
- package/dist/tooltip-BDnrRKrp.js.map +1 -1
- package/dist/types/components/basemaps/basemaps.d.ts +20 -0
- package/dist/types/components/geolocation-controls/geolocation-controls.d.ts +11 -0
- package/dist/types/components/lasso-tool/lasso-tool-inline.d.ts +17 -0
- package/dist/types/components/lasso-tool/lasso-tool.d.ts +21 -0
- package/dist/types/components/list-data/list-data.d.ts +16 -0
- package/dist/types/components/measurement-tools/measurement-tools.d.ts +20 -0
- package/dist/types/components/smart-tooltip/smart-tooltip.d.ts +17 -0
- package/dist/types/components/tooltip/tooltip.d.ts +13 -0
- package/dist/types/components/zoom-controls/zoom-controls.d.ts +16 -0
- package/dist/types/hooks/use-widget-ref.d.ts +4 -4
- package/dist/types/widgets/actions/download/download.d.ts +11 -0
- package/dist/types/widgets/actions/download/exports.d.ts +15 -0
- package/dist/types/widgets/actions/fullscreen/fullscreen.d.ts +13 -0
- package/dist/types/widgets/actions/index.d.ts +1 -1
- package/dist/types/widgets/actions/relative-data/relative-data.d.ts +1 -0
- package/dist/types/widgets/bar/config.d.ts +8 -4
- package/dist/types/widgets/category/category-ui.d.ts +3 -0
- package/dist/types/widgets/category/components/category-bar.d.ts +3 -0
- package/dist/types/widgets/category/components/category-legend.d.ts +3 -0
- package/dist/types/widgets/category/components/category-row-multi.d.ts +3 -0
- package/dist/types/widgets/category/components/category-row-other.d.ts +3 -0
- package/dist/types/widgets/category/components/category-row-single.d.ts +3 -0
- package/dist/types/widgets/category/config.d.ts +11 -0
- package/dist/types/widgets/echart/echart-ui.d.ts +7 -0
- package/dist/types/widgets/echart/echart.d.ts +6 -0
- package/dist/types/widgets/echart/options.d.ts +7 -0
- package/dist/types/widgets/echart/types.d.ts +1 -0
- package/dist/types/widgets/echart/utils.d.ts +41 -0
- package/dist/types/widgets/error/error.d.ts +10 -0
- package/dist/types/widgets/formula/components/item.d.ts +3 -0
- package/dist/types/widgets/formula/components/prefix.d.ts +3 -0
- package/dist/types/widgets/formula/components/row.d.ts +3 -0
- package/dist/types/widgets/formula/components/series.d.ts +3 -0
- package/dist/types/widgets/formula/components/suffix.d.ts +3 -0
- package/dist/types/widgets/formula/components/value.d.ts +3 -0
- package/dist/types/widgets/formula/config.d.ts +11 -0
- package/dist/types/widgets/formula/formula-ui.d.ts +3 -0
- package/dist/types/widgets/histogram/config.d.ts +8 -4
- package/dist/types/widgets/loader/loader.d.ts +22 -0
- package/dist/types/widgets/loader/utils.d.ts +26 -3
- package/dist/types/widgets/markdown/config.d.ts +10 -0
- package/dist/types/widgets/markdown/markdown-ui.d.ts +7 -0
- package/dist/types/widgets/markdown/markdown.d.ts +3 -0
- package/dist/types/widgets/note/note.d.ts +10 -0
- package/dist/types/widgets/pie/config.d.ts +8 -4
- package/dist/types/widgets/range/components/range-item.d.ts +3 -0
- package/dist/types/widgets/range/config.d.ts +5 -0
- package/dist/types/widgets/range/range-ui.d.ts +3 -0
- package/dist/types/widgets/scatterplot/config.d.ts +7 -3
- package/dist/types/widgets/selection-summary/selection-summary.d.ts +11 -0
- package/dist/types/widgets/skeleton-loader/skeleton-loader.d.ts +10 -0
- package/dist/types/widgets/spread/components/max-value.d.ts +3 -0
- package/dist/types/widgets/spread/components/min-value.d.ts +3 -0
- package/dist/types/widgets/spread/components/separator.d.ts +3 -0
- package/dist/types/widgets/spread/config.d.ts +11 -0
- package/dist/types/widgets/spread/spread-ui.d.ts +3 -0
- package/dist/types/widgets/subheader/subheader.d.ts +11 -0
- package/dist/types/widgets/table/config.d.ts +8 -3
- package/dist/types/widgets/table/hooks/use-pagination.d.ts +11 -3
- package/dist/types/widgets/table/hooks/use-selection.d.ts +11 -2
- package/dist/types/widgets/table/hooks/use-sort.d.ts +11 -3
- package/dist/types/widgets/timeseries/config.d.ts +8 -4
- package/dist/types/widgets/utils/chart-config/download-config.d.ts +3 -0
- package/dist/types/widgets/{_shared → utils}/chart-config/index.d.ts +2 -0
- package/dist/types/widgets/{_shared → utils}/chart-config/option-builders.d.ts +1 -1
- package/dist/types/widgets/utils/formatter.d.ts +1 -0
- package/dist/types/widgets/utils/index.d.ts +7 -0
- package/dist/types/widgets/wrapper/components/actions.d.ts +3 -0
- package/dist/types/widgets/wrapper/components/options.d.ts +3 -0
- package/dist/types/widgets/wrapper/components/title.d.ts +3 -0
- package/dist/types/widgets/wrapper/wrapper-ui.d.ts +14 -0
- package/dist/types/widgets/wrapper/wrapper.d.ts +14 -0
- package/dist/use-widget-ref-wtFLDFCD.js.map +1 -1
- package/dist/utils-BOhInag6.js.map +1 -1
- package/dist/widgets/actions.js +651 -628
- package/dist/widgets/actions.js.map +1 -1
- package/dist/widgets/bar.js +66 -86
- package/dist/widgets/bar.js.map +1 -1
- package/dist/widgets/category.js +21 -21
- package/dist/widgets/category.js.map +1 -1
- package/dist/widgets/echart.js.map +1 -1
- package/dist/widgets/formula.js +54 -54
- package/dist/widgets/formula.js.map +1 -1
- package/dist/widgets/histogram.js +45 -65
- package/dist/widgets/histogram.js.map +1 -1
- package/dist/widgets/loader.js.map +1 -1
- package/dist/widgets/markdown.js.map +1 -1
- package/dist/widgets/pie.js +122 -99
- package/dist/widgets/pie.js.map +1 -1
- package/dist/widgets/range.js +23 -22
- package/dist/widgets/range.js.map +1 -1
- package/dist/widgets/scatterplot.js +39 -59
- package/dist/widgets/scatterplot.js.map +1 -1
- package/dist/widgets/selection-summary.js.map +1 -1
- package/dist/widgets/skeleton-loader.js.map +1 -1
- package/dist/widgets/spread.js +40 -41
- package/dist/widgets/spread.js.map +1 -1
- package/dist/widgets/subheader.js.map +1 -1
- package/dist/widgets/table.js.map +1 -1
- package/dist/widgets/timeseries.js +39 -59
- package/dist/widgets/timeseries.js.map +1 -1
- package/dist/widgets/utils.js +31 -0
- package/dist/widgets/utils.js.map +1 -0
- package/dist/widgets/wrapper.js.map +1 -1
- package/package.json +5 -1
- package/src/components/basemaps/basemaps.tsx +20 -0
- package/src/components/geolocation-controls/geolocation-controls.tsx +11 -0
- package/src/components/lasso-tool/lasso-tool-inline.tsx +17 -0
- package/src/components/lasso-tool/lasso-tool.tsx +21 -0
- package/src/components/list-data/list-data.tsx +16 -0
- package/src/components/measurement-tools/measurement-tools.tsx +20 -0
- package/src/components/smart-tooltip/smart-tooltip.tsx +17 -0
- package/src/components/tooltip/tooltip.tsx +13 -0
- package/src/components/zoom-controls/zoom-controls.tsx +16 -0
- package/src/hooks/use-widget-ref.ts +4 -4
- package/src/widgets/README.md +10 -10
- package/src/widgets/actions/download/download.tsx +11 -0
- package/src/widgets/actions/download/exports.tsx +15 -0
- package/src/widgets/actions/fullscreen/fullscreen.tsx +13 -0
- package/src/widgets/actions/index.ts +1 -0
- package/src/widgets/actions/relative-data/relative-data.test.tsx +62 -1
- package/src/widgets/actions/relative-data/relative-data.tsx +62 -39
- package/src/widgets/bar/config.ts +12 -20
- package/src/widgets/bar/style.ts +1 -1
- package/src/widgets/category/category-ui.tsx +4 -2
- package/src/widgets/category/components/category-bar.tsx +3 -0
- package/src/widgets/category/components/category-legend.tsx +3 -0
- package/src/widgets/category/components/category-row-multi.tsx +3 -0
- package/src/widgets/category/components/category-row-other.tsx +3 -0
- package/src/widgets/category/components/category-row-single.tsx +3 -0
- package/src/widgets/category/config.ts +11 -0
- package/src/widgets/echart/echart-ui.tsx +7 -0
- package/src/widgets/echart/echart.tsx +6 -0
- package/src/widgets/echart/options.ts +7 -0
- package/src/widgets/echart/types.ts +1 -0
- package/src/widgets/echart/utils.ts +41 -0
- package/src/widgets/error/error.tsx +10 -0
- package/src/widgets/formula/components/item.tsx +3 -0
- package/src/widgets/formula/components/prefix.tsx +3 -0
- package/src/widgets/formula/components/row.tsx +3 -0
- package/src/widgets/formula/components/series.tsx +3 -0
- package/src/widgets/formula/components/suffix.tsx +3 -0
- package/src/widgets/formula/components/value.tsx +4 -2
- package/src/widgets/formula/config.ts +11 -0
- package/src/widgets/formula/formula-ui.tsx +3 -0
- package/src/widgets/histogram/config.ts +11 -20
- package/src/widgets/histogram/style.ts +1 -1
- package/src/widgets/loader/loader.tsx +22 -0
- package/src/widgets/loader/utils.ts +26 -3
- package/src/widgets/markdown/config.ts +10 -0
- package/src/widgets/markdown/markdown-ui.tsx +7 -0
- package/src/widgets/markdown/markdown.tsx +3 -0
- package/src/widgets/note/note.tsx +10 -0
- package/src/widgets/pie/config.ts +85 -30
- package/src/widgets/pie/style.ts +1 -1
- package/src/widgets/range/components/range-item.tsx +5 -2
- package/src/widgets/range/config.ts +5 -0
- package/src/widgets/range/range-ui.tsx +3 -0
- package/src/widgets/scatterplot/config.ts +11 -20
- package/src/widgets/scatterplot/style.ts +1 -1
- package/src/widgets/selection-summary/selection-summary.tsx +11 -0
- package/src/widgets/skeleton-loader/skeleton-loader.tsx +10 -0
- package/src/widgets/spread/components/max-value.tsx +4 -2
- package/src/widgets/spread/components/min-value.tsx +4 -2
- package/src/widgets/spread/components/separator.tsx +3 -0
- package/src/widgets/spread/config.ts +11 -0
- package/src/widgets/spread/spread-ui.tsx +3 -0
- package/src/widgets/subheader/subheader.tsx +11 -0
- package/src/widgets/table/config.ts +8 -3
- package/src/widgets/table/hooks/use-pagination.ts +11 -3
- package/src/widgets/table/hooks/use-selection.ts +11 -2
- package/src/widgets/table/hooks/use-sort.ts +11 -3
- package/src/widgets/timeseries/config.ts +11 -20
- package/src/widgets/timeseries/style.ts +1 -1
- package/src/widgets/utils/chart-config/download-config.ts +22 -0
- package/src/widgets/{_shared → utils}/chart-config/index.ts +4 -0
- package/src/widgets/{_shared → utils}/chart-config/option-builders.ts +1 -1
- package/src/widgets/utils/formatter.ts +1 -0
- package/src/widgets/utils/index.ts +26 -0
- package/src/widgets/wrapper/components/actions.tsx +3 -0
- package/src/widgets/wrapper/components/options.tsx +3 -0
- package/src/widgets/wrapper/components/title.tsx +3 -0
- package/src/widgets/wrapper/wrapper-ui.tsx +14 -0
- package/src/widgets/wrapper/wrapper.tsx +14 -0
- package/dist/styles-CAroD5Rc.js +0 -123
- package/dist/styles-CAroD5Rc.js.map +0 -1
- /package/dist/types/widgets/{_shared → utils}/chart-config/config-factory.d.ts +0 -0
- /package/dist/types/widgets/{_shared → utils}/chart-config/csv-modifiers.d.ts +0 -0
- /package/dist/types/widgets/{_shared → utils}/chart-config/option-builders.test.d.ts +0 -0
- /package/dist/types/widgets/{_shared → utils}/skeleton/index.d.ts +0 -0
- /package/dist/types/widgets/{_shared → utils}/skeleton/styles.d.ts +0 -0
- /package/src/widgets/{_shared → utils}/chart-config/config-factory.ts +0 -0
- /package/src/widgets/{_shared → utils}/chart-config/csv-modifiers.ts +0 -0
- /package/src/widgets/{_shared → utils}/chart-config/option-builders.test.ts +0 -0
- /package/src/widgets/{_shared → utils}/skeleton/index.ts +0 -0
- /package/src/widgets/{_shared → utils}/skeleton/styles.ts +0 -0
|
@@ -9,9 +9,21 @@ export type ConfigOrFn<TConfig, TData = unknown> =
|
|
|
9
9
|
| ((baseConfig: TConfig, data: TData) => Partial<TConfig>)
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Resolves a config that may be either
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Resolves a widget config that may be either a partial object or a function receiving the computed base config and data. If it is a function, calls it with `baseConfig` and `data`; otherwise returns the value as-is.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The config object or function to resolve.
|
|
15
|
+
* @param baseConfig - The computed base configuration.
|
|
16
|
+
* @param data - The widget data.
|
|
17
|
+
* @returns Resolved partial config, or undefined.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const resolved = resolveConfig(
|
|
22
|
+
* (base, data) => ({ maxItems: base.maxItems + 5 }),
|
|
23
|
+
* baseConfig,
|
|
24
|
+
* widgetData,
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
15
27
|
*/
|
|
16
28
|
export function resolveConfig<TConfig, TData>(
|
|
17
29
|
config: ConfigOrFn<TConfig, TData> | undefined,
|
|
@@ -24,6 +36,17 @@ export function resolveConfig<TConfig, TData>(
|
|
|
24
36
|
return config
|
|
25
37
|
}
|
|
26
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Deep-merges two partial widget config objects using `deepmerge`, with arrays replaced rather than concatenated.
|
|
41
|
+
*
|
|
42
|
+
* @param options - A tuple of two partial configs to merge (base and override).
|
|
43
|
+
* @returns The merged config object.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* const finalConfig = mergeWidgetConfig(baseConfig, resolvedConfig)
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
27
50
|
export function mergeWidgetConfig<T>(
|
|
28
51
|
...options: [Partial<T> | undefined, Partial<T> | undefined]
|
|
29
52
|
): T {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { downloadToCSV, type DownloadItem } from '../actions'
|
|
2
2
|
import type { MarkdownWidgetConfig, MarkdownWidgetData } from './types'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Creates download configuration for markdown widgets, supporting CSV export of text content. Does not require `refUI` since it only exports text.
|
|
6
|
+
*
|
|
7
|
+
* @returns Array of download items for use with the Download action.
|
|
8
|
+
*/
|
|
4
9
|
export function markdownDownloadConfig(): DownloadItem<MarkdownWidgetData>[] {
|
|
5
10
|
return [
|
|
6
11
|
{
|
|
@@ -13,6 +18,11 @@ export function markdownDownloadConfig(): DownloadItem<MarkdownWidgetData>[] {
|
|
|
13
18
|
]
|
|
14
19
|
}
|
|
15
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Returns the default configuration for markdown content display widgets.
|
|
23
|
+
*
|
|
24
|
+
* @returns Default markdown widget config (empty object).
|
|
25
|
+
*/
|
|
16
26
|
export function markdownConfig(): MarkdownWidgetConfig {
|
|
17
27
|
return {}
|
|
18
28
|
}
|
|
@@ -38,6 +38,13 @@ const COMPONENTS: Components = {
|
|
|
38
38
|
li: ({ children }) => <ListItem sx={styles.li}>{children}</ListItem>,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Presentational component that renders a Markdown string as MUI-styled HTML using react-markdown.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Maps Markdown elements (headings, paragraphs, links, lists) to MUI Typography and Link components.
|
|
46
|
+
* Custom component overrides can be passed via the `overrides` prop.
|
|
47
|
+
*/
|
|
41
48
|
export function MarkdownUI({ children, overrides }: MarkdownComponentProps) {
|
|
42
49
|
return (
|
|
43
50
|
<ReactMarkdown
|
|
@@ -4,6 +4,9 @@ import type { MarkdownWidgetData } from './types'
|
|
|
4
4
|
import { MarkdownUI } from '.'
|
|
5
5
|
import { useShallow } from 'zustand/shallow'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Stateful markdown widget component that reads content from the widget store and renders it as formatted rich text.
|
|
9
|
+
*/
|
|
7
10
|
export function Markdown({ id }: MarkdownUIProps) {
|
|
8
11
|
const content = useWidgetStore(
|
|
9
12
|
useShallow(
|
|
@@ -37,6 +37,16 @@ const COMPONENTS: Components = {
|
|
|
37
37
|
li: DEFAULT_P,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Displays text content with markdown support and automatic show more/less functionality for long content. Automatically detects content exceeding 3 lines and shows an expand/collapse button.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* <WidgetNote>
|
|
46
|
+
* {"**Important:** This data is from Q4 2024."}
|
|
47
|
+
* </WidgetNote>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
40
50
|
export function WidgetNote({
|
|
41
51
|
children,
|
|
42
52
|
labels = DEFAULT_LABELS,
|
|
@@ -8,33 +8,27 @@ import {
|
|
|
8
8
|
buildGridConfig,
|
|
9
9
|
buildLegendConfig,
|
|
10
10
|
flattenObjectArrayToCSV,
|
|
11
|
+
createTooltipPositioner,
|
|
11
12
|
createTooltipFormatter,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export function pieDownloadConfig({
|
|
17
|
-
refUI,
|
|
18
|
-
}: ConfigProps): DownloadItem<PieWidgetData>[] {
|
|
19
|
-
return [
|
|
20
|
-
{
|
|
21
|
-
...downloadToPNG,
|
|
22
|
-
modifier: () => downloadToPNG.modifier(refUI),
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
...downloadToCSV,
|
|
26
|
-
modifier: async (data) => {
|
|
27
|
-
const rows = flattenObjectArrayToCSV(data)
|
|
28
|
-
return downloadToCSV.modifier(rows)
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
]
|
|
32
|
-
}
|
|
13
|
+
createChartDownloadConfig,
|
|
14
|
+
niceNum,
|
|
15
|
+
} from '../utils/chart-config'
|
|
33
16
|
|
|
17
|
+
export const pieDownloadConfig = createChartDownloadConfig<PieWidgetData>(
|
|
18
|
+
flattenObjectArrayToCSV,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generates ECharts configuration for pie and donut chart widgets. Falls back to a horizontal bar layout when multiple data series are provided.
|
|
23
|
+
*
|
|
24
|
+
* @param props - Pie chart configuration including data and theme.
|
|
25
|
+
* @returns Widget config with ECharts option object.
|
|
26
|
+
*/
|
|
34
27
|
export function pieConfig(props: PieConfig): PieWidgetConfig {
|
|
35
28
|
return {
|
|
36
29
|
type: 'pie',
|
|
37
30
|
option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
|
|
31
|
+
formatter: props.formatter,
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
34
|
|
|
@@ -46,22 +40,83 @@ function getOption({
|
|
|
46
40
|
const multiSeries = (data?.length ?? 0) > 1
|
|
47
41
|
|
|
48
42
|
if (multiSeries) {
|
|
43
|
+
let niceMin = 0
|
|
44
|
+
let niceMax = 1
|
|
45
|
+
|
|
49
46
|
return {
|
|
47
|
+
legend: buildLegendConfig(true),
|
|
48
|
+
grid: {
|
|
49
|
+
...buildGridConfig(true, theme),
|
|
50
|
+
right: parseInt(theme.spacing(4)),
|
|
51
|
+
},
|
|
50
52
|
xAxis: {
|
|
51
53
|
type: 'value',
|
|
52
|
-
|
|
54
|
+
min: (extent: { min: number }) => {
|
|
55
|
+
niceMin = extent.min < 0 ? niceNum(extent.min) : 0
|
|
56
|
+
return niceMin
|
|
57
|
+
},
|
|
58
|
+
max: (extent: { min: number; max: number }) => {
|
|
59
|
+
niceMax = extent.max <= 0 ? 1 : niceNum(extent.max)
|
|
60
|
+
return niceMax
|
|
61
|
+
},
|
|
62
|
+
axisLabel: {
|
|
63
|
+
fontSize: theme.typography.overlineDelicate.fontSize,
|
|
64
|
+
fontFamily: theme.typography.overlineDelicate.fontFamily,
|
|
65
|
+
margin: parseInt(theme.spacing(1)),
|
|
66
|
+
show: true,
|
|
67
|
+
showMaxLabel: true,
|
|
68
|
+
showMinLabel: true,
|
|
69
|
+
verticalAlign: 'bottom' as const,
|
|
70
|
+
inside: true,
|
|
71
|
+
formatter: (value: number) => {
|
|
72
|
+
if (value !== niceMax && value !== niceMin) return ''
|
|
73
|
+
if (value === 0) return ''
|
|
74
|
+
return formatter ? formatter(value) : String(value)
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
axisLine: {
|
|
78
|
+
show: false,
|
|
79
|
+
},
|
|
80
|
+
axisTick: {
|
|
81
|
+
show: false,
|
|
82
|
+
},
|
|
83
|
+
splitLine: {
|
|
84
|
+
show: true,
|
|
85
|
+
lineStyle: {
|
|
86
|
+
color: theme.palette.black[4],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
53
89
|
},
|
|
54
90
|
yAxis: {
|
|
55
91
|
type: 'category',
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
92
|
+
axisLine: {
|
|
93
|
+
show: false,
|
|
94
|
+
},
|
|
95
|
+
axisTick: {
|
|
96
|
+
show: false,
|
|
97
|
+
},
|
|
98
|
+
axisLabel: {
|
|
99
|
+
padding: [parseInt(theme.spacing(0.5)), 0, 0, 0],
|
|
100
|
+
},
|
|
61
101
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
102
|
+
tooltip: {
|
|
103
|
+
position: createTooltipPositioner(theme),
|
|
104
|
+
formatter: createTooltipFormatter((item) => {
|
|
105
|
+
const value = item.value as Record<string, string | number>
|
|
106
|
+
const index = item.dimensionNames?.[item.encode?.x?.at(0) ?? 1]
|
|
107
|
+
const _value = value[index ?? '']
|
|
108
|
+
|
|
109
|
+
const formattedValue =
|
|
110
|
+
typeof _value === 'number' && formatter
|
|
111
|
+
? formatter(_value)
|
|
112
|
+
: (_value ?? '')
|
|
113
|
+
|
|
114
|
+
const marker = typeof item.marker === 'string' ? item.marker : ''
|
|
115
|
+
const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
|
|
116
|
+
const name = item.name ?? ''
|
|
117
|
+
|
|
118
|
+
return { name, seriesName, marker, value: formattedValue }
|
|
119
|
+
}),
|
|
65
120
|
},
|
|
66
121
|
series: data.map((_: unknown, index: number) => ({
|
|
67
122
|
datasetIndex: index,
|
package/src/widgets/pie/style.ts
CHANGED
|
@@ -5,10 +5,13 @@ import type { RangeItemProps, RangeWidgetState } from '../types'
|
|
|
5
5
|
import { styles } from '../style'
|
|
6
6
|
import { useShallow } from 'zustand/shallow'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import { defaultFormatter } from '../../utils/formatter'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type EditingState = '' | 'min' | 'max'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Renders a single range slider with editable min/max text inputs, reading its configuration from the widget store.
|
|
14
|
+
*/
|
|
12
15
|
export function RangeItem({ id, index }: RangeItemProps) {
|
|
13
16
|
const item = useWidgetStore(
|
|
14
17
|
useShallow((state) => state.getWidget<RangeWidgetState>(id)?.data[index]),
|
|
@@ -2,6 +2,9 @@ import type { RangeUIProps } from './types'
|
|
|
2
2
|
import { Row } from '../formula/components/row'
|
|
3
3
|
import { RangeItem } from './components/range-item'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Renders a range widget with one or more interactive dual-slider controls for selecting value ranges.
|
|
7
|
+
*/
|
|
5
8
|
export function RangeUI(props: RangeUIProps) {
|
|
6
9
|
return (
|
|
7
10
|
<Row id={props.id}>
|
|
@@ -12,35 +12,26 @@ import {
|
|
|
12
12
|
scatterplotDataToCSV,
|
|
13
13
|
buildLegendConfig,
|
|
14
14
|
createTooltipFormatter,
|
|
15
|
+
createChartDownloadConfig,
|
|
15
16
|
applyYAxisFormatter,
|
|
16
|
-
} from '../
|
|
17
|
-
import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
|
|
18
|
-
import type { ConfigProps } from '../loader/types'
|
|
17
|
+
} from '../utils/chart-config'
|
|
19
18
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}: ConfigProps): DownloadItem<ScatterplotWidgetData>[] {
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
...downloadToPNG,
|
|
26
|
-
modifier: () => downloadToPNG.modifier(refUI),
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
...downloadToCSV,
|
|
30
|
-
modifier: async (data) => {
|
|
31
|
-
const rows = scatterplotDataToCSV(data)
|
|
32
|
-
return downloadToCSV.modifier(rows)
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
]
|
|
36
|
-
}
|
|
19
|
+
export const scatterplotDownloadConfig =
|
|
20
|
+
createChartDownloadConfig<ScatterplotWidgetData>(scatterplotDataToCSV)
|
|
37
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Generates ECharts configuration for X-Y scatter plot widgets with value axes, legend support, and CARTO qualitative color palette.
|
|
24
|
+
*
|
|
25
|
+
* @param props - Scatterplot configuration including data points and theme.
|
|
26
|
+
* @returns Widget config with ECharts option object.
|
|
27
|
+
*/
|
|
38
28
|
export function scatterplotConfig(
|
|
39
29
|
props: ScatterplotConfig,
|
|
40
30
|
): ScatterplotWidgetConfig {
|
|
41
31
|
return {
|
|
42
32
|
type: 'scatterplot',
|
|
43
33
|
option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
|
|
34
|
+
formatter: props.formatter,
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
37
|
|
|
@@ -13,6 +13,17 @@ const DEFAULT_SELECTION_LABELS: SelectionSummaryLabels = {
|
|
|
13
13
|
clear: 'Clear',
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Displays the count of selected items with an optional clear button. Commonly used with the LockSelection action to show selection state in widgets.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <WidgetSelectionSummary
|
|
22
|
+
* selections={selectedItems.length}
|
|
23
|
+
* onClear={() => setSelectedItems([])}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
16
27
|
export function WidgetSelectionSummary({
|
|
17
28
|
selections,
|
|
18
29
|
onClear,
|
|
@@ -3,6 +3,16 @@ import { useWidgetStore } from '../stores/widget-store'
|
|
|
3
3
|
import { Suspense } from 'react'
|
|
4
4
|
import { useShallow } from 'zustand/shallow'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Displays a skeleton loading placeholder while widget data is loading. Subscribes to widget loading state in the store and renders the provided Skeleton component or children accordingly.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <SkeletonLoader id="sales-chart" Skeleton={BarSkeleton}>
|
|
12
|
+
* <Bar id="sales-chart" />
|
|
13
|
+
* </SkeletonLoader>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
6
16
|
export function SkeletonLoader({
|
|
7
17
|
id,
|
|
8
18
|
children,
|
|
@@ -2,9 +2,11 @@ import { type SpreadWidgetState, type ValueProps } from '../types'
|
|
|
2
2
|
import { useWidgetStore } from '../../stores/widget-store'
|
|
3
3
|
import { Item } from '../../formula/components/item'
|
|
4
4
|
import { useShallow } from 'zustand/shallow'
|
|
5
|
+
import { defaultFormatter } from '../../utils/formatter'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Displays the formatted maximum value for a spread widget data item.
|
|
9
|
+
*/
|
|
8
10
|
export function MaxValue({ id, index = 0, ...props }: ValueProps) {
|
|
9
11
|
const max = useWidgetStore(
|
|
10
12
|
useShallow(
|
|
@@ -2,9 +2,11 @@ import { type SpreadWidgetState, type ValueProps } from '../types'
|
|
|
2
2
|
import { useWidgetStore } from '../../stores/widget-store'
|
|
3
3
|
import { Item } from '../../formula/components/item'
|
|
4
4
|
import { useShallow } from 'zustand/shallow'
|
|
5
|
+
import { defaultFormatter } from '../../utils/formatter'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Displays the formatted minimum value for a spread widget data item.
|
|
9
|
+
*/
|
|
8
10
|
export function MinValue({ id, index = 0, ...props }: ValueProps) {
|
|
9
11
|
const min = useWidgetStore(
|
|
10
12
|
useShallow(
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Item } from '../../formula/components/item'
|
|
2
2
|
import type { ItemProps } from '../../formula/types'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Renders a dash separator between the min and max values in a spread widget.
|
|
6
|
+
*/
|
|
4
7
|
export function Separator(props: Omit<ItemProps, 'children'>) {
|
|
5
8
|
return <Item {...props}>-</Item>
|
|
6
9
|
}
|
|
@@ -2,6 +2,12 @@ import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
|
|
|
2
2
|
import type { ConfigProps } from '../loader/types'
|
|
3
3
|
import type { SpreadWidgetConfig, SpreadWidgetData } from './types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Creates download configuration for spread widgets, supporting PNG (screenshot) and CSV (min/max data) exports.
|
|
7
|
+
*
|
|
8
|
+
* @param props - Configuration with `refUI` reference for PNG export.
|
|
9
|
+
* @returns Array of download items for use with the Download action.
|
|
10
|
+
*/
|
|
5
11
|
export function spreadDownloadConfig({
|
|
6
12
|
refUI,
|
|
7
13
|
}: ConfigProps): DownloadItem<SpreadWidgetData>[] {
|
|
@@ -21,6 +27,11 @@ export function spreadDownloadConfig({
|
|
|
21
27
|
]
|
|
22
28
|
}
|
|
23
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Returns the default configuration for spread (min/max value range) widgets.
|
|
32
|
+
*
|
|
33
|
+
* @returns Default spread widget config with empty series.
|
|
34
|
+
*/
|
|
24
35
|
export function spreadConfig(): SpreadWidgetConfig {
|
|
25
36
|
return {
|
|
26
37
|
series: [],
|
|
@@ -7,6 +7,9 @@ import { Prefix, Row, Suffix, Series } from '../formula'
|
|
|
7
7
|
import { useWidgetRef } from '../../hooks'
|
|
8
8
|
import { Box } from '@mui/material'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Renders a spread widget displaying min-max value pairs with optional prefixes, suffixes, and series indicators.
|
|
12
|
+
*/
|
|
10
13
|
export function SpreadUI(props: SpreadUIProps) {
|
|
11
14
|
const { ref } = useWidgetRef(props.id)
|
|
12
15
|
|
|
@@ -2,6 +2,17 @@ import { Box } from '@mui/material'
|
|
|
2
2
|
import { styles } from './style'
|
|
3
3
|
import type { WidgetSubHeaderProps } from './types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Flexible two-slot layout for displaying supplementary widget information such as totals, timestamps, or controls. Uses flexbox with space-between justification.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <WidgetSubHeader
|
|
11
|
+
* slotLeft={<Typography variant="caption">Total: 1,234</Typography>}
|
|
12
|
+
* slotRight={<Typography variant="caption">Updated: 2m ago</Typography>}
|
|
13
|
+
* />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
5
16
|
export function WidgetSubHeader({
|
|
6
17
|
slotLeft,
|
|
7
18
|
slotRight,
|
|
@@ -17,8 +17,10 @@ export const DEFAULT_COLUMN_ID = null
|
|
|
17
17
|
export const DEFAULT_DIRECTION: SortDirection = 'asc'
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Creates download configuration for table widgets, supporting PNG (screenshot) and CSV (data) exports. CSV output uses column keys as headers and filters out `id` fields.
|
|
21
|
+
*
|
|
22
|
+
* @param props - Configuration with `refUI` reference for PNG export.
|
|
23
|
+
* @returns Array of download items for use with the Download action.
|
|
22
24
|
*/
|
|
23
25
|
export function tableDownloadConfig({
|
|
24
26
|
refUI,
|
|
@@ -59,7 +61,10 @@ export function tableDownloadConfig({
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
|
-
*
|
|
64
|
+
* Returns the default configuration for table widgets with pagination and sorting, including column definitions and local data mode.
|
|
65
|
+
*
|
|
66
|
+
* @param columns - Array of column definitions for the table.
|
|
67
|
+
* @returns Default table widget config.
|
|
63
68
|
*/
|
|
64
69
|
export function tableConfig(columns: TableColumn[] = []): TableWidgetConfig {
|
|
65
70
|
return {
|
|
@@ -37,9 +37,17 @@ export interface UsePaginationResult<T> {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Hook for managing table pagination
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* Hook for managing table pagination with support for both local (client-side) and remote (server-side) modes.
|
|
41
|
+
* State is persisted in the widget store for the given widget ID.
|
|
42
|
+
*
|
|
43
|
+
* @param widgetId - The widget ID to persist pagination state under.
|
|
44
|
+
* @param data - The full data array (used for local pagination and total count fallback).
|
|
45
|
+
* @returns Pagination state and navigation helpers.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* const { page, setPage, paginatedData, totalPages } = usePagination(widgetId, data)
|
|
50
|
+
* ```
|
|
43
51
|
*/
|
|
44
52
|
export function usePagination<T extends TableRow>(
|
|
45
53
|
widgetId: string,
|
|
@@ -30,8 +30,17 @@ export interface UseSelectionResult {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Hook for managing table row selection
|
|
34
|
-
* Selection
|
|
33
|
+
* Hook for managing table row selection with persistence across pagination.
|
|
34
|
+
* Selection state is stored in the widget store for the given widget ID.
|
|
35
|
+
*
|
|
36
|
+
* @param widgetId - The widget ID to persist selection state under.
|
|
37
|
+
* @param options - Optional configuration including an `onSelectionChange` callback.
|
|
38
|
+
* @returns Selection state and control functions (toggle, select, deselect, clear).
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* const { selectedIds, isAllSelected, handleSelectRow, clearSelection } = useSelection(widgetId)
|
|
43
|
+
* ```
|
|
35
44
|
*/
|
|
36
45
|
export function useSelection(
|
|
37
46
|
widgetId: string,
|
|
@@ -27,9 +27,17 @@ export interface UseSortResult<T> extends SortState {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Hook for managing table sorting
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* Hook for managing table sorting with support for both local (client-side) and remote (server-side) modes.
|
|
31
|
+
* State is persisted in the widget store for the given widget ID.
|
|
32
|
+
*
|
|
33
|
+
* @param widgetId - The widget ID to persist sort state under.
|
|
34
|
+
* @param data - The data array to sort (for local mode).
|
|
35
|
+
* @returns Sort state, sorted data, and sort control functions.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* const { sortedData, sortField, sortDirection, handleSort } = useSort(widgetId, data)
|
|
40
|
+
* ```
|
|
33
41
|
*/
|
|
34
42
|
export function useSort<T extends TableRow>(
|
|
35
43
|
widgetId: string,
|
|
@@ -13,35 +13,26 @@ import {
|
|
|
13
13
|
buildLegendConfig,
|
|
14
14
|
buildGridConfig,
|
|
15
15
|
createTooltipFormatter,
|
|
16
|
+
createChartDownloadConfig,
|
|
16
17
|
applyYAxisFormatter,
|
|
17
|
-
} from '../
|
|
18
|
-
import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
|
|
19
|
-
import type { ConfigProps } from '../loader/types'
|
|
18
|
+
} from '../utils/chart-config'
|
|
20
19
|
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
}: ConfigProps): DownloadItem<TimeseriesWidgetData>[] {
|
|
24
|
-
return [
|
|
25
|
-
{
|
|
26
|
-
...downloadToPNG,
|
|
27
|
-
modifier: () => downloadToPNG.modifier(refUI),
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
...downloadToCSV,
|
|
31
|
-
modifier: async (data) => {
|
|
32
|
-
const rows = flattenObjectArrayToCSV(data)
|
|
33
|
-
return downloadToCSV.modifier(rows)
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
]
|
|
37
|
-
}
|
|
20
|
+
export const timeseriesDownloadConfig =
|
|
21
|
+
createChartDownloadConfig<TimeseriesWidgetData>(flattenObjectArrayToCSV)
|
|
38
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Generates ECharts configuration for line and area chart widgets over time, with smooth curves, rotated axis labels, and CARTO qualitative color palette.
|
|
25
|
+
*
|
|
26
|
+
* @param props - Timeseries configuration including data and theme.
|
|
27
|
+
* @returns Widget config with ECharts option object.
|
|
28
|
+
*/
|
|
39
29
|
export function timeseriesConfig(
|
|
40
30
|
props: TimeseriesConfig,
|
|
41
31
|
): TimeseriesWidgetConfig {
|
|
42
32
|
return {
|
|
43
33
|
type: 'timeseries',
|
|
44
34
|
option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
|
|
35
|
+
formatter: props.formatter,
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
38
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { downloadToCSV, downloadToPNG, type DownloadItem } from '../../actions'
|
|
2
|
+
import type { ConfigProps } from '../../loader/types'
|
|
3
|
+
|
|
4
|
+
export function createChartDownloadConfig<TData>(
|
|
5
|
+
csvModifier: (data: TData) => string[][],
|
|
6
|
+
) {
|
|
7
|
+
return function ({ refUI }: ConfigProps): DownloadItem<TData>[] {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
...downloadToPNG,
|
|
11
|
+
modifier: () => downloadToPNG.modifier(refUI),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
...downloadToCSV,
|
|
15
|
+
modifier: async (data) => {
|
|
16
|
+
const rows = csvModifier(data)
|
|
17
|
+
return downloadToCSV.modifier(rows)
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|