@carto/ps-react-ui 4.6.1 → 4.6.3
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/options-CthfUJDz.js +46 -0
- package/dist/options-CthfUJDz.js.map +1 -0
- package/dist/styles-BYTyKQFP.js +142 -0
- package/dist/{styles-Y8q7Jff3.js.map → styles-BYTyKQFP.js.map} +1 -1
- package/dist/types/widgets/utils/chart-config/index.d.ts +1 -1
- package/dist/types/widgets/utils/chart-config/option-builders.d.ts +27 -0
- package/dist/widgets/actions.js +125 -120
- package/dist/widgets/actions.js.map +1 -1
- package/dist/widgets/bar.js +34 -30
- package/dist/widgets/bar.js.map +1 -1
- package/dist/widgets/echart.js +1 -1
- package/dist/widgets/histogram.js +64 -61
- package/dist/widgets/histogram.js.map +1 -1
- package/dist/widgets/pie.js +37 -36
- package/dist/widgets/pie.js.map +1 -1
- package/dist/widgets/scatterplot.js +30 -29
- package/dist/widgets/scatterplot.js.map +1 -1
- package/dist/widgets/timeseries.js +34 -33
- package/dist/widgets/timeseries.js.map +1 -1
- package/dist/widgets/utils.js +1 -1
- package/package.json +1 -1
- package/src/widgets/actions/relative-data/relative-data.test.tsx +23 -0
- package/src/widgets/actions/relative-data/relative-data.tsx +11 -2
- package/src/widgets/bar/config.ts +5 -0
- package/src/widgets/echart/options.ts +1 -4
- package/src/widgets/histogram/config.ts +9 -4
- package/src/widgets/pie/config.ts +2 -0
- package/src/widgets/scatterplot/config.ts +2 -0
- package/src/widgets/timeseries/config.ts +2 -0
- package/src/widgets/utils/chart-config/index.ts +2 -0
- package/src/widgets/utils/chart-config/option-builders.test.ts +105 -1
- package/src/widgets/utils/chart-config/option-builders.ts +56 -0
- package/dist/options-D9wflre6.js +0 -49
- package/dist/options-D9wflre6.js.map +0 -1
- package/dist/styles-Y8q7Jff3.js +0 -118
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeseries.js","sources":["../../src/widgets/timeseries/config.ts","../../src/widgets/timeseries/style.ts","../../src/widgets/timeseries/skeleton.tsx"],"sourcesContent":["import {\n getCommonOptions,\n mergeEchartWidgetConfig,\n type EchartOptionsProps,\n} from '../echart'\nimport type {\n TimeseriesConfig,\n TimeseriesWidgetConfig,\n TimeseriesWidgetData,\n} from './types'\nimport {\n flattenObjectArrayToCSV,\n buildLegendConfig,\n buildGridConfig,\n createTooltipFormatter,\n createChartDownloadConfig,\n applyYAxisFormatter,\n applyXAxisFormatter,\n} from '../utils/chart-config'\n\nexport const timeseriesDownloadConfig =\n createChartDownloadConfig<TimeseriesWidgetData>(flattenObjectArrayToCSV)\n\n/**\n * Generates ECharts configuration for line and area chart widgets over time, with smooth curves, rotated axis labels, and CARTO qualitative color palette.\n *\n * @param props - Timeseries configuration including data and theme.\n * @returns Widget config with ECharts option object.\n */\nexport function timeseriesConfig(\n props: TimeseriesConfig,\n): TimeseriesWidgetConfig {\n return {\n type: 'timeseries',\n option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),\n formatter: props.formatter,\n labelFormatter: props.labelFormatter,\n }\n}\n\nfunction getOption({\n data = [],\n theme,\n formatter,\n labelFormatter,\n}: TimeseriesConfig): EchartOptionsProps {\n const hasLegend = (data?.length ?? 0) > 1\n\n const yAxis = {\n type: 'value' as const,\n axisLabel: {\n margin: 0,\n padding: [\n 0,\n parseInt(theme.spacing(0.75)),\n parseInt(theme.spacing(1.25)),\n -parseInt(theme.spacing(1)),\n ],\n show: true,\n showMaxLabel: true,\n showMinLabel: false,\n verticalAlign: 'bottom' as const,\n },\n axisLine: {\n show: false,\n },\n axisTick: {\n show: false,\n },\n splitLine: {\n show: true,\n lineStyle: {\n color: theme.palette.black[4],\n },\n },\n }\n\n return {\n legend: buildLegendConfig({ hasLegend, labelFormatter }),\n grid: {\n ...buildGridConfig(hasLegend, theme),\n outerBounds: {\n left: parseInt(theme.spacing(3)),\n right: parseInt(theme.spacing(1)),\n top: parseInt(theme.spacing(2)),\n },\n },\n xAxis: applyXAxisFormatter(\n {\n type: 'category',\n axisTick: {\n alignWithLabel: true,\n },\n axisLabel: {\n show: true,\n showMaxLabel: true,\n showMinLabel: true,\n rotate: 45,\n },\n },\n labelFormatter,\n ),\n yAxis: applyYAxisFormatter(yAxis, formatter),\n tooltip: {\n formatter: createTooltipFormatter((item) => {\n const value = item.value as Record<string, string | number>\n const index = item.dimensionNames?.[item.encode?.y?.at(0) ?? 1]\n const _value = value[index ?? '']\n\n const formattedValue =\n typeof _value === 'number' && formatter\n ? formatter(_value)\n : (_value ?? '')\n\n const marker = typeof item.marker === 'string' ? item.marker : ''\n const seriesName = item.seriesName ? `${item.seriesName}: ` : ''\n const name = labelFormatter\n ? String(labelFormatter(item.name ?? ''))\n : (item.name ?? '')\n\n return { name, seriesName, marker, value: formattedValue }\n }),\n },\n color: Object.values(theme.palette.qualitative.bold),\n series: data.map((_: unknown, index: number) => ({\n datasetIndex: index,\n type: 'line',\n smooth: true,\n emphasis: {\n focus: 'series',\n },\n })),\n } as EchartOptionsProps\n}\n","import type { SxProps, Theme } from '@mui/material'\nimport { baseSkeletonStyles } from '../utils/skeleton'\n\nexport const styles = {\n skeleton: {\n graph: {\n container: {\n ...baseSkeletonStyles.graph.container,\n position: 'relative',\n },\n grid: {\n display: 'flex',\n justifyContent: 'space-between',\n flex: '1 1 auto',\n alignItems: 'flex-end',\n width: '100%',\n },\n },\n histogram: {\n item: {\n flex: 1,\n maxWidth: ({ spacing }) => spacing(8),\n\n '& + &': {\n marginLeft: '1px',\n },\n },\n },\n legend: {\n display: 'flex',\n alignItems: 'center',\n gap: ({ spacing }) => spacing(2),\n height: ({ spacing }) => spacing(5),\n },\n },\n} satisfies Record<string, SxProps<Theme>>\n","import { Box, Skeleton } from '@mui/material'\nimport { styles } from './style'\n\nexport function TimeseriesSkeleton() {\n return (\n <Box sx={styles.skeleton.graph.container}>\n {/* Timeseries bar */}\n <Box sx={styles.skeleton.graph.grid}>\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='20%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='40%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='60%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='20%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='80%'\n />\n </Box>\n {/* Legend */}\n <Box sx={styles.skeleton.legend}>\n {Array(2)\n .fill(0)\n .map((_, i) => (\n <Box\n key={`skeleton-${i}`}\n sx={{\n display: 'flex',\n alignItems: 'center',\n gap: ({ spacing }) => spacing(1.5),\n }}\n >\n <Skeleton variant='circular' width={8} height={8} />\n <Skeleton width={48} height={8} />\n </Box>\n ))}\n </Box>\n </Box>\n )\n}\n"],"names":["timeseriesDownloadConfig","createChartDownloadConfig","flattenObjectArrayToCSV","timeseriesConfig","props","type","option","mergeEchartWidgetConfig","getCommonOptions","getOption","formatter","labelFormatter","data","theme","hasLegend","length","yAxis","axisLabel","margin","padding","parseInt","spacing","show","showMaxLabel","showMinLabel","verticalAlign","axisLine","axisTick","splitLine","lineStyle","color","palette","black","legend","buildLegendConfig","grid","buildGridConfig","outerBounds","left","right","top","xAxis","applyXAxisFormatter","alignWithLabel","rotate","applyYAxisFormatter","tooltip","createTooltipFormatter","item","value","index","dimensionNames","encode","y","at","_value","formattedValue","marker","seriesName","name","String","Object","values","qualitative","bold","series","map","_","datasetIndex","smooth","emphasis","focus","styles","skeleton","graph","container","baseSkeletonStyles","position","display","justifyContent","flex","alignItems","width","histogram","maxWidth","marginLeft","gap","height","TimeseriesSkeleton","$","_c","t0","Symbol","for","Box","jsx","Skeleton","t1","Array","fill","_temp2","i","jsxs","_temp"],"mappings":";;;;;;;;;;;AAoBO,MAAMA,IACXC,EAAgDC,CAAuB;AAQlE,SAASC,EACdC,GACwB;AACxB,SAAO;AAAA,IACLC,MAAM;AAAA,IACNC,QAAQC,EAAwBC,EAAiBJ,C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AAA,CAAK;AAAA,IAEd,gBAAA+C,EAACC,GAAA,EACK,IAAAxB,EAAMC,SAASU,UAAUnC,MACrB,SAAA,eACD,QAAA,MAAA,CAAK;AAAA,EAAA,GAEhB,GAAMyC,OAAAE,KAAAA,IAAAF,EAAA,CAAA;AAAA,MAAAQ;AAAA,SAAAR,EAAA,CAAA,MAAAG,uBAAAC,IAAA,2BAAA,KA5BRI,sBAACH,GAAA,EAAQ,IAAAtB,EAAMC,SAASC,MAAMC,WAE5BgB,UAAAA;AAAAA,IAAAA;AAAAA,IA4BA,gBAAAI,EAACD,GAAA,EAAQ,IAAAtB,EAAMC,SAASxC,QACrBiE,UAAAA,MAAM,CAAC,EAACC,KACD,CAAC,EAACjC,IACHkC,CAYJ,EAAA,CACL;AAAA,EAAA,GACF,GAAMX,OAAAQ,KAAAA,IAAAR,EAAA,CAAA,GA/CNQ;AA+CM;AAjDH,SAAAG,EAAAjC,GAAAkC,GAAA;AAAA,SAoCK,gBAAAC,EAACR,KAEK,IAAA;AAAA,IAAAhB,SACO;AAAA,IAAMG,YACH;AAAA,IAAQK,KACfiB;AAAAA,EAAAA,GAGP,UAAA;AAAA,IAAA,gBAAAR,EAACC,KAAiB,SAAA,YAAkB,OAAA,GAAW,QAAA,GAAC;AAAA,IAChD,gBAAAD,EAACC,GAAA,EAAgB,OAAA,IAAY,QAAA,EAAA,CAAC;AAAA,EAAA,EAAA,GARzB,YAAYK,CAAC,EASpB;AAAM;AA9CX,SAAAE,EAAAZ,GAAA;AAyCe,QAAA;AAAA,IAAAtE,SAAAA;AAAAA,EAAAA,IAAAsE;AAAW,SAAKtE,EAAQ,GAAG;AAAC;"}
|
|
1
|
+
{"version":3,"file":"timeseries.js","sources":["../../src/widgets/timeseries/config.ts","../../src/widgets/timeseries/style.ts","../../src/widgets/timeseries/skeleton.tsx"],"sourcesContent":["import {\n getCommonOptions,\n mergeEchartWidgetConfig,\n type EchartOptionsProps,\n} from '../echart'\nimport type {\n TimeseriesConfig,\n TimeseriesWidgetConfig,\n TimeseriesWidgetData,\n} from './types'\nimport {\n flattenObjectArrayToCSV,\n buildLegendConfig,\n buildGridConfig,\n createTooltipFormatter,\n createChartDownloadConfig,\n applyYAxisFormatter,\n applyXAxisFormatter,\n buildSeriesLabelConfig,\n} from '../utils/chart-config'\n\nexport const timeseriesDownloadConfig =\n createChartDownloadConfig<TimeseriesWidgetData>(flattenObjectArrayToCSV)\n\n/**\n * Generates ECharts configuration for line and area chart widgets over time, with smooth curves, rotated axis labels, and CARTO qualitative color palette.\n *\n * @param props - Timeseries configuration including data and theme.\n * @returns Widget config with ECharts option object.\n */\nexport function timeseriesConfig(\n props: TimeseriesConfig,\n): TimeseriesWidgetConfig {\n return {\n type: 'timeseries',\n option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),\n formatter: props.formatter,\n labelFormatter: props.labelFormatter,\n }\n}\n\nfunction getOption({\n data = [],\n theme,\n formatter,\n labelFormatter,\n}: TimeseriesConfig): EchartOptionsProps {\n const hasLegend = (data?.length ?? 0) > 1\n\n const yAxis = {\n type: 'value' as const,\n axisLabel: {\n margin: 0,\n padding: [\n 0,\n parseInt(theme.spacing(0.75)),\n parseInt(theme.spacing(1.25)),\n -parseInt(theme.spacing(1)),\n ],\n show: true,\n showMaxLabel: true,\n showMinLabel: false,\n verticalAlign: 'bottom' as const,\n },\n axisLine: {\n show: false,\n },\n axisTick: {\n show: false,\n },\n splitLine: {\n show: true,\n lineStyle: {\n color: theme.palette.black[4],\n },\n },\n }\n\n return {\n legend: buildLegendConfig({ hasLegend, labelFormatter }),\n grid: {\n ...buildGridConfig(hasLegend, theme),\n outerBounds: {\n left: parseInt(theme.spacing(3)),\n right: parseInt(theme.spacing(1)),\n top: parseInt(theme.spacing(2)),\n },\n },\n xAxis: applyXAxisFormatter(\n {\n type: 'category',\n axisTick: {\n alignWithLabel: true,\n },\n axisLabel: {\n show: true,\n showMaxLabel: true,\n showMinLabel: true,\n rotate: 45,\n },\n },\n labelFormatter,\n ),\n yAxis: applyYAxisFormatter(yAxis, formatter),\n tooltip: {\n formatter: createTooltipFormatter((item) => {\n const value = item.value as Record<string, string | number>\n const index = item.dimensionNames?.[item.encode?.y?.at(0) ?? 1]\n const _value = value[index ?? '']\n\n const formattedValue =\n typeof _value === 'number' && formatter\n ? formatter(_value)\n : (_value ?? '')\n\n const marker = typeof item.marker === 'string' ? item.marker : ''\n const seriesName = item.seriesName ? `${item.seriesName}: ` : ''\n const name = labelFormatter\n ? String(labelFormatter(item.name ?? ''))\n : (item.name ?? '')\n\n return { name, seriesName, marker, value: formattedValue }\n }),\n },\n color: Object.values(theme.palette.qualitative.bold),\n series: data.map((_: unknown, index: number) => ({\n datasetIndex: index,\n type: 'line',\n smooth: true,\n emphasis: {\n focus: 'series',\n },\n ...buildSeriesLabelConfig(formatter),\n })),\n } as EchartOptionsProps\n}\n","import type { SxProps, Theme } from '@mui/material'\nimport { baseSkeletonStyles } from '../utils/skeleton'\n\nexport const styles = {\n skeleton: {\n graph: {\n container: {\n ...baseSkeletonStyles.graph.container,\n position: 'relative',\n },\n grid: {\n display: 'flex',\n justifyContent: 'space-between',\n flex: '1 1 auto',\n alignItems: 'flex-end',\n width: '100%',\n },\n },\n histogram: {\n item: {\n flex: 1,\n maxWidth: ({ spacing }) => spacing(8),\n\n '& + &': {\n marginLeft: '1px',\n },\n },\n },\n legend: {\n display: 'flex',\n alignItems: 'center',\n gap: ({ spacing }) => spacing(2),\n height: ({ spacing }) => spacing(5),\n },\n },\n} satisfies Record<string, SxProps<Theme>>\n","import { Box, Skeleton } from '@mui/material'\nimport { styles } from './style'\n\nexport function TimeseriesSkeleton() {\n return (\n <Box sx={styles.skeleton.graph.container}>\n {/* Timeseries bar */}\n <Box sx={styles.skeleton.graph.grid}>\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='20%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='40%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='60%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='20%'\n />\n <Skeleton\n sx={styles.skeleton.histogram.item}\n variant='rectangular'\n height='80%'\n />\n </Box>\n {/* Legend */}\n <Box sx={styles.skeleton.legend}>\n {Array(2)\n .fill(0)\n .map((_, i) => (\n <Box\n key={`skeleton-${i}`}\n sx={{\n display: 'flex',\n alignItems: 'center',\n gap: ({ spacing }) => spacing(1.5),\n }}\n >\n <Skeleton variant='circular' width={8} height={8} />\n <Skeleton width={48} height={8} />\n </Box>\n ))}\n </Box>\n </Box>\n )\n}\n"],"names":["timeseriesDownloadConfig","createChartDownloadConfig","flattenObjectArrayToCSV","timeseriesConfig","props","type","option","mergeEchartWidgetConfig","getCommonOptions","getOption","formatter","labelFormatter","data","theme","hasLegend","length","yAxis","axisLabel","margin","padding","parseInt","spacing","show","showMaxLabel","showMinLabel","verticalAlign","axisLine","axisTick","splitLine","lineStyle","color","palette","black","legend","buildLegendConfig","grid","buildGridConfig","outerBounds","left","right","top","xAxis","applyXAxisFormatter","alignWithLabel","rotate","applyYAxisFormatter","tooltip","createTooltipFormatter","item","value","index","dimensionNames","encode","y","at","_value","formattedValue","marker","seriesName","name","String","Object","values","qualitative","bold","series","map","_","datasetIndex","smooth","emphasis","focus","buildSeriesLabelConfig","styles","skeleton","graph","container","baseSkeletonStyles","position","display","justifyContent","flex","alignItems","width","histogram","maxWidth","marginLeft","gap","height","TimeseriesSkeleton","$","_c","t0","Symbol","for","Box","jsx","Skeleton","t1","Array","fill","_temp2","i","jsxs","_temp"],"mappings":";;;;;;;;;;;AAqBO,MAAMA,IACXC,EAAgDC,CAAuB;AAQlE,SAASC,EACdC,GACwB;AACxB,SAAO;AAAA,IACLC,MAAM;AAAA,IACNC,QAAQC,EAAwBC,EAAiBJ,CAAK,GAAGK,EAAUL,CAAK,CAAC;AAAA,IACzEM,WAAWN,EAAMM;AAAAA,IACjBC,gBAAgBP,EAAMO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AAAxB,EAAMC,SAASU,UAAUpC,MACrB,SAAA,eACD,QAAA,MAAA,CAAK;AAAA,EAAA,GAEhB,GAAM0C,OAAAE,KAAAA,IAAAF,EAAA,CAAA;AAAA,MAAAQ;AAAA,SAAAR,EAAA,CAAA,MAAAG,uBAAAC,IAAA,2BAAA,KA5BRI,sBAACH,GAAA,EAAQ,IAAAtB,EAAMC,SAASC,MAAMC,WAE5BgB,UAAAA;AAAAA,IAAAA;AAAAA,IA4BA,gBAAAI,EAACD,GAAA,EAAQ,IAAAtB,EAAMC,SAASzC,QACrBkE,UAAAA,MAAM,CAAC,EAACC,KACD,CAAC,EAAClC,IACHmC,CAYJ,EAAA,CACL;AAAA,EAAA,GACF,GAAMX,OAAAQ,KAAAA,IAAAR,EAAA,CAAA,GA/CNQ;AA+CM;AAjDH,SAAAG,EAAAlC,GAAAmC,GAAA;AAAA,SAoCK,gBAAAC,EAACR,KAEK,IAAA;AAAA,IAAAhB,SACO;AAAA,IAAMG,YACH;AAAA,IAAQK,KACfiB;AAAAA,EAAAA,GAGP,UAAA;AAAA,IAAA,gBAAAR,EAACC,KAAiB,SAAA,YAAkB,OAAA,GAAW,QAAA,GAAC;AAAA,IAChD,gBAAAD,EAACC,GAAA,EAAgB,OAAA,IAAY,QAAA,EAAA,CAAC;AAAA,EAAA,EAAA,GARzB,YAAYK,CAAC,EASpB;AAAM;AA9CX,SAAAE,EAAAZ,GAAA;AAyCe,QAAA;AAAA,IAAAvE,SAAAA;AAAAA,EAAAA,IAAAuE;AAAW,SAAKvE,EAAQ,GAAG;AAAC;"}
|
package/dist/widgets/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { d as i, a as n } from "../formatter-B9Bxn1k7.js";
|
|
2
2
|
import { c as f, f as p, s as c } from "../download-config-C3I0jWIL.js";
|
|
3
|
-
import { a as m, b as u, c as C, d as b, e as x, f as g, g as F, h as y, n as A } from "../styles-
|
|
3
|
+
import { a as m, b as u, c as C, d as b, e as x, f as g, g as F, h as y, n as A } from "../styles-BYTyKQFP.js";
|
|
4
4
|
function r({
|
|
5
5
|
type: a,
|
|
6
6
|
getOptions: e
|
package/package.json
CHANGED
|
@@ -406,6 +406,29 @@ describe('RelativeData', () => {
|
|
|
406
406
|
expect(widget?.formatter).toBeUndefined()
|
|
407
407
|
})
|
|
408
408
|
|
|
409
|
+
test('removes percentage formatter when defaultIsRelative=true and toggling to absolute', async () => {
|
|
410
|
+
// Widget starts with defaultIsRelative=true and no formatter
|
|
411
|
+
useWidgetStore.getState().setWidget(widgetId, { sourceData: mockData })
|
|
412
|
+
|
|
413
|
+
render(<RelativeData id={widgetId} defaultIsRelative />)
|
|
414
|
+
|
|
415
|
+
// Pipeline runs with isRelative=true — applies percentage formatter
|
|
416
|
+
await useWidgetStore.getState().executeConfigPipeline(widgetId, {})
|
|
417
|
+
|
|
418
|
+
let widget = useWidgetStore.getState().getWidget(widgetId)
|
|
419
|
+
expect(widget?.formatter).toBeDefined()
|
|
420
|
+
expect(typeof widget?.formatter).toBe('function')
|
|
421
|
+
|
|
422
|
+
// Toggle to absolute (first toggle is OFF when defaultIsRelative=true)
|
|
423
|
+
const button = screen.getByRole('button')
|
|
424
|
+
fireEvent.click(button)
|
|
425
|
+
|
|
426
|
+
await useWidgetStore.getState().executeConfigPipeline(widgetId, {})
|
|
427
|
+
|
|
428
|
+
widget = useWidgetStore.getState().getWidget(widgetId)
|
|
429
|
+
expect(widget?.formatter).toBeUndefined()
|
|
430
|
+
})
|
|
431
|
+
|
|
409
432
|
test('stores originalFormatter/originalMax in widget root on toggle', () => {
|
|
410
433
|
const customFormatter = (value: number) => `$${value}`
|
|
411
434
|
useWidgetStore
|
|
@@ -50,11 +50,20 @@ export function RelativeData({
|
|
|
50
50
|
(w as RelativeDataState | undefined)?.isRelative ?? defaultIsRelative,
|
|
51
51
|
}))
|
|
52
52
|
|
|
53
|
-
// Initialize store with default value on mount
|
|
53
|
+
// Initialize store with default value on mount.
|
|
54
|
+
// When defaultIsRelative=true, capture originals so toggling OFF can restore them.
|
|
54
55
|
useEffect(() => {
|
|
55
56
|
const current = widgetStoreActions.getWidget<RelativeDataState>(id)
|
|
56
57
|
if (current?.isRelative === undefined) {
|
|
57
|
-
|
|
58
|
+
if (defaultIsRelative) {
|
|
59
|
+
widgetStoreActions.setWidget(id, {
|
|
60
|
+
isRelative: true,
|
|
61
|
+
originalFormatter: current?.formatter,
|
|
62
|
+
originalMax: (current as unknown as Record<string, number>)?.max,
|
|
63
|
+
})
|
|
64
|
+
} else {
|
|
65
|
+
widgetStoreActions.setWidget(id, { isRelative: defaultIsRelative })
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
}, [id, defaultIsRelative])
|
|
60
69
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
createChartDownloadConfig,
|
|
14
14
|
applyXAxisFormatter,
|
|
15
15
|
niceNum,
|
|
16
|
+
buildSeriesLabelConfig,
|
|
16
17
|
} from '../utils/chart-config'
|
|
17
18
|
|
|
18
19
|
export const barDownloadConfig = createChartDownloadConfig<BarWidgetData>(
|
|
@@ -60,6 +61,9 @@ function getOption({
|
|
|
60
61
|
axisLabel: {
|
|
61
62
|
padding: [parseInt(theme.spacing(0.5)), 0, 0, 0],
|
|
62
63
|
margin: 0,
|
|
64
|
+
showMinLabel: undefined,
|
|
65
|
+
showMaxLabel: undefined,
|
|
66
|
+
hideOverlap: true,
|
|
63
67
|
},
|
|
64
68
|
},
|
|
65
69
|
labelFormatter,
|
|
@@ -130,6 +134,7 @@ function getOption({
|
|
|
130
134
|
emphasis: {
|
|
131
135
|
focus: 'series',
|
|
132
136
|
},
|
|
137
|
+
...buildSeriesLabelConfig(formatter),
|
|
133
138
|
})),
|
|
134
139
|
} as EchartOptionsProps
|
|
135
140
|
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createTooltipPositioner,
|
|
11
11
|
createTooltipFormatter,
|
|
12
12
|
niceNum,
|
|
13
|
+
buildHistogramSeriesLabelConfig,
|
|
13
14
|
} from '../utils/chart-config'
|
|
14
15
|
import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
|
|
15
16
|
import type { ConfigProps } from '../loader/types'
|
|
@@ -108,6 +109,7 @@ export function histogramConfig(props: HistogramConfig): HistogramWidgetConfig {
|
|
|
108
109
|
type: 'histogram',
|
|
109
110
|
option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
|
|
110
111
|
formatter: props.formatter,
|
|
112
|
+
labelFormatter: props.labelFormatter,
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -126,7 +128,7 @@ function getOption({
|
|
|
126
128
|
let niceMax = 1
|
|
127
129
|
|
|
128
130
|
return {
|
|
129
|
-
legend: buildLegendConfig({ hasLegend }),
|
|
131
|
+
legend: buildLegendConfig({ hasLegend, labelFormatter }),
|
|
130
132
|
grid: buildGridConfig(hasLegend, theme),
|
|
131
133
|
xAxis: {
|
|
132
134
|
type: 'category',
|
|
@@ -137,8 +139,8 @@ function getOption({
|
|
|
137
139
|
axisLabel: {
|
|
138
140
|
fontSize: theme.typography.overlineDelicate.fontSize,
|
|
139
141
|
fontFamily: theme.typography.overlineDelicate.fontFamily,
|
|
140
|
-
showMinLabel:
|
|
141
|
-
showMaxLabel:
|
|
142
|
+
showMinLabel: undefined,
|
|
143
|
+
showMaxLabel: undefined,
|
|
142
144
|
hideOverlap: true,
|
|
143
145
|
margin: 0,
|
|
144
146
|
padding: [
|
|
@@ -209,7 +211,9 @@ function getOption({
|
|
|
209
211
|
|
|
210
212
|
const marker = typeof item.marker === 'string' ? item.marker : ''
|
|
211
213
|
const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
|
|
212
|
-
const name =
|
|
214
|
+
const name = labelFormatter
|
|
215
|
+
? String(labelFormatter(item.name ?? ''))
|
|
216
|
+
: (item.name ?? '')
|
|
213
217
|
|
|
214
218
|
return { name, seriesName, marker, value: formattedValue }
|
|
215
219
|
}),
|
|
@@ -222,6 +226,7 @@ function getOption({
|
|
|
222
226
|
emphasis: {
|
|
223
227
|
focus: 'series',
|
|
224
228
|
},
|
|
229
|
+
...buildHistogramSeriesLabelConfig(formatter),
|
|
225
230
|
})),
|
|
226
231
|
} as EchartOptionsProps
|
|
227
232
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
createTooltipFormatter,
|
|
13
13
|
createChartDownloadConfig,
|
|
14
14
|
niceNum,
|
|
15
|
+
buildSeriesLabelConfig,
|
|
15
16
|
} from '../utils/chart-config'
|
|
16
17
|
|
|
17
18
|
export const pieDownloadConfig = createChartDownloadConfig<PieWidgetData>(
|
|
@@ -133,6 +134,7 @@ function getOption({
|
|
|
133
134
|
emphasis: {
|
|
134
135
|
focus: 'series',
|
|
135
136
|
},
|
|
137
|
+
...buildSeriesLabelConfig(formatter, 'x'),
|
|
136
138
|
})),
|
|
137
139
|
}
|
|
138
140
|
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
createChartDownloadConfig,
|
|
16
16
|
applyYAxisFormatter,
|
|
17
17
|
applyXAxisFormatter,
|
|
18
|
+
buildSeriesLabelConfig,
|
|
18
19
|
} from '../utils/chart-config'
|
|
19
20
|
|
|
20
21
|
export const scatterplotDownloadConfig =
|
|
@@ -129,6 +130,7 @@ function getOption({
|
|
|
129
130
|
datasetIndex: index,
|
|
130
131
|
type: 'scatter',
|
|
131
132
|
symbolSize: 8,
|
|
133
|
+
...buildSeriesLabelConfig(formatter),
|
|
132
134
|
})),
|
|
133
135
|
} as EchartOptionsProps
|
|
134
136
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
createChartDownloadConfig,
|
|
17
17
|
applyYAxisFormatter,
|
|
18
18
|
applyXAxisFormatter,
|
|
19
|
+
buildSeriesLabelConfig,
|
|
19
20
|
} from '../utils/chart-config'
|
|
20
21
|
|
|
21
22
|
export const timeseriesDownloadConfig =
|
|
@@ -129,6 +130,7 @@ function getOption({
|
|
|
129
130
|
emphasis: {
|
|
130
131
|
focus: 'series',
|
|
131
132
|
},
|
|
133
|
+
...buildSeriesLabelConfig(formatter),
|
|
132
134
|
})),
|
|
133
135
|
} as EchartOptionsProps
|
|
134
136
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import {
|
|
2
|
+
import type { CallbackDataParams } from 'echarts/types/dist/shared'
|
|
3
|
+
import {
|
|
4
|
+
niceNum,
|
|
5
|
+
buildSeriesLabelConfig,
|
|
6
|
+
buildHistogramSeriesLabelConfig,
|
|
7
|
+
} from './option-builders'
|
|
3
8
|
|
|
4
9
|
describe('niceNum', () => {
|
|
5
10
|
it('should return 0 for 0', () => {
|
|
@@ -38,3 +43,102 @@ describe('niceNum', () => {
|
|
|
38
43
|
expect(niceNum(1)).toBe(1)
|
|
39
44
|
})
|
|
40
45
|
})
|
|
46
|
+
|
|
47
|
+
describe('buildSeriesLabelConfig', () => {
|
|
48
|
+
it('should return empty object when no formatter provided', () => {
|
|
49
|
+
expect(buildSeriesLabelConfig()).toEqual({})
|
|
50
|
+
expect(buildSeriesLabelConfig(undefined)).toEqual({})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should return label config with formatter when formatter provided', () => {
|
|
54
|
+
const formatter = (v: number) => `$${v}`
|
|
55
|
+
const result = buildSeriesLabelConfig(formatter)
|
|
56
|
+
expect(result).toHaveProperty('label')
|
|
57
|
+
expect((result as { label: { formatter: unknown } }).label).toHaveProperty(
|
|
58
|
+
'formatter',
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('should format value from dataset params using y encode key', () => {
|
|
63
|
+
const formatter = (v: number) => `$${v}`
|
|
64
|
+
const result = buildSeriesLabelConfig(formatter, 'y')
|
|
65
|
+
const label = (
|
|
66
|
+
result as {
|
|
67
|
+
label: { formatter: (p: Partial<CallbackDataParams>) => string }
|
|
68
|
+
}
|
|
69
|
+
).label
|
|
70
|
+
const params = {
|
|
71
|
+
encode: { y: [1] },
|
|
72
|
+
dimensionNames: ['category', 'amount'],
|
|
73
|
+
value: { category: 'A', amount: 42 },
|
|
74
|
+
}
|
|
75
|
+
expect(label.formatter(params as unknown as CallbackDataParams)).toBe('$42')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('should format value from dataset params using x encode key', () => {
|
|
79
|
+
const formatter = (v: number) => `${v}%`
|
|
80
|
+
const result = buildSeriesLabelConfig(formatter, 'x')
|
|
81
|
+
const label = (
|
|
82
|
+
result as {
|
|
83
|
+
label: { formatter: (p: Partial<CallbackDataParams>) => string }
|
|
84
|
+
}
|
|
85
|
+
).label
|
|
86
|
+
const params = {
|
|
87
|
+
encode: { x: [1] },
|
|
88
|
+
dimensionNames: ['name', 'value'],
|
|
89
|
+
value: { name: 'Foo', value: 75 },
|
|
90
|
+
}
|
|
91
|
+
expect(label.formatter(params as unknown as CallbackDataParams)).toBe('75%')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should return empty string when encode index is undefined', () => {
|
|
95
|
+
const formatter = (v: number) => `$${v}`
|
|
96
|
+
const result = buildSeriesLabelConfig(formatter, 'y')
|
|
97
|
+
const label = (
|
|
98
|
+
result as {
|
|
99
|
+
label: { formatter: (p: Partial<CallbackDataParams>) => string }
|
|
100
|
+
}
|
|
101
|
+
).label
|
|
102
|
+
const params = {
|
|
103
|
+
encode: {},
|
|
104
|
+
dimensionNames: ['category', 'amount'],
|
|
105
|
+
value: { category: 'A', amount: 42 },
|
|
106
|
+
}
|
|
107
|
+
expect(label.formatter(params as unknown as CallbackDataParams)).toBe('')
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
describe('buildHistogramSeriesLabelConfig', () => {
|
|
112
|
+
it('should return empty object when no formatter provided', () => {
|
|
113
|
+
expect(buildHistogramSeriesLabelConfig()).toEqual({})
|
|
114
|
+
expect(buildHistogramSeriesLabelConfig(undefined)).toEqual({})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('should format raw numeric value', () => {
|
|
118
|
+
const formatter = (v: number) => `${v} units`
|
|
119
|
+
const result = buildHistogramSeriesLabelConfig(formatter)
|
|
120
|
+
const label = (
|
|
121
|
+
result as {
|
|
122
|
+
label: { formatter: (p: Partial<CallbackDataParams>) => string }
|
|
123
|
+
}
|
|
124
|
+
).label
|
|
125
|
+
const params = { value: 100 }
|
|
126
|
+
expect(label.formatter(params as unknown as CallbackDataParams)).toBe(
|
|
127
|
+
'100 units',
|
|
128
|
+
)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('should stringify non-numeric values', () => {
|
|
132
|
+
const formatter = (v: number) => `${v} units`
|
|
133
|
+
const result = buildHistogramSeriesLabelConfig(formatter)
|
|
134
|
+
const label = (
|
|
135
|
+
result as {
|
|
136
|
+
label: { formatter: (p: Partial<CallbackDataParams>) => string }
|
|
137
|
+
}
|
|
138
|
+
).label
|
|
139
|
+
const params = { value: 'text' }
|
|
140
|
+
expect(label.formatter(params as unknown as CallbackDataParams)).toBe(
|
|
141
|
+
'text',
|
|
142
|
+
)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
@@ -225,3 +225,59 @@ export function createTooltipFormatter(
|
|
|
225
225
|
return tooltip(name, formattedValues.join(''))
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Builds a series `label` config that applies formatter to the data value
|
|
231
|
+
* extracted from a dataset row using ECharts encode/dimensionNames.
|
|
232
|
+
*
|
|
233
|
+
* Does not set `show` — labels remain hidden by default per ECharts defaults.
|
|
234
|
+
*
|
|
235
|
+
* @param formatter - Optional numeric value formatter
|
|
236
|
+
* @param encodeKey - The encode dimension key to extract ('y' for vertical charts, 'x' for horizontal)
|
|
237
|
+
*/
|
|
238
|
+
export function buildSeriesLabelConfig(
|
|
239
|
+
formatter?: (value: number) => string,
|
|
240
|
+
encodeKey = 'y',
|
|
241
|
+
): { label: { formatter: (params: CallbackDataParams) => string } } | object {
|
|
242
|
+
if (!formatter) return {}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
label: {
|
|
246
|
+
formatter: (params: CallbackDataParams) => {
|
|
247
|
+
const encodeIndex = params.encode?.[encodeKey]?.[0]
|
|
248
|
+
if (encodeIndex === undefined) return ''
|
|
249
|
+
const dimName = params.dimensionNames?.[encodeIndex]
|
|
250
|
+
const row = params.value as Record<string, string | number>
|
|
251
|
+
const value = dimName ? row[dimName] : undefined
|
|
252
|
+
return typeof value === 'number'
|
|
253
|
+
? formatter(value)
|
|
254
|
+
: String(value ?? '')
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Builds a series `label` config that applies formatter to a raw numeric value.
|
|
262
|
+
* Used by histogram where series data is number[] (not datasets).
|
|
263
|
+
*
|
|
264
|
+
* Does not set `show` — labels remain hidden by default per ECharts defaults.
|
|
265
|
+
*
|
|
266
|
+
* @param formatter - Optional numeric value formatter
|
|
267
|
+
*/
|
|
268
|
+
export function buildHistogramSeriesLabelConfig(
|
|
269
|
+
formatter?: (value: number) => string,
|
|
270
|
+
): { label: { formatter: (params: CallbackDataParams) => string } } | object {
|
|
271
|
+
if (!formatter) return {}
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
label: {
|
|
275
|
+
formatter: (params: CallbackDataParams) => {
|
|
276
|
+
const value = params.value as number
|
|
277
|
+
return typeof value === 'number'
|
|
278
|
+
? formatter(value)
|
|
279
|
+
: String(value ?? '')
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
}
|
|
283
|
+
}
|
package/dist/options-D9wflre6.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
function t({
|
|
2
|
-
theme: o
|
|
3
|
-
}) {
|
|
4
|
-
return {
|
|
5
|
-
grid: {
|
|
6
|
-
left: parseInt(o.spacing(1)),
|
|
7
|
-
top: parseInt(o.spacing(3)),
|
|
8
|
-
right: parseInt(o.spacing(1)),
|
|
9
|
-
bottom: parseInt(o.spacing(4)),
|
|
10
|
-
containLabel: !0
|
|
11
|
-
},
|
|
12
|
-
toolbox: {
|
|
13
|
-
show: !1
|
|
14
|
-
},
|
|
15
|
-
tooltip: {
|
|
16
|
-
axisPointer: {
|
|
17
|
-
type: "shadow",
|
|
18
|
-
shadowStyle: {
|
|
19
|
-
color: "rgba(44,48,50, 0.08)"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
backgroundColor: o.palette.grey[900],
|
|
23
|
-
borderWidth: 0,
|
|
24
|
-
padding: [parseInt(o.spacing(1)), parseInt(o.spacing(1))],
|
|
25
|
-
textStyle: {
|
|
26
|
-
color: o.palette.common.white,
|
|
27
|
-
fontSize: 11,
|
|
28
|
-
fontFamily: o.typography.caption.fontFamily
|
|
29
|
-
},
|
|
30
|
-
trigger: "axis"
|
|
31
|
-
},
|
|
32
|
-
legend: {
|
|
33
|
-
type: "scroll",
|
|
34
|
-
bottom: 0
|
|
35
|
-
},
|
|
36
|
-
axisPointer: {
|
|
37
|
-
lineStyle: {
|
|
38
|
-
color: o.palette.grey[400]
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
xAxis: {},
|
|
42
|
-
yAxis: {},
|
|
43
|
-
color: [o.palette.secondary.main, ...Object.values(o.palette.qualitative?.bold ?? {})]
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
t as g
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=options-D9wflre6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options-D9wflre6.js","sources":["../src/widgets/echart/options.ts"],"sourcesContent":["import type { EchartOptionsProps, EchartWidgetOptionProps } from './types'\n\n/**\n * Returns the shared base ECharts options used across all EChart-based widgets (bar, pie, histogram, etc.).\n *\n * @remarks\n * Configures grid spacing, tooltip styling, legend, axis pointer, and the default color palette\n * derived from the MUI theme.\n */\nexport function getCommonOptions({\n theme,\n}: EchartWidgetOptionProps<unknown>): EchartOptionsProps {\n return {\n grid: {\n left: parseInt(theme.spacing(1)),\n top: parseInt(theme.spacing(3)),\n right: parseInt(theme.spacing(1)),\n bottom: parseInt(theme.spacing(4)),\n containLabel: true,\n },\n toolbox: {\n show: false,\n },\n tooltip: {\n axisPointer: {\n type: 'shadow',\n shadowStyle: {\n color: 'rgba(44,48,50, 0.08)',\n },\n },\n backgroundColor: theme.palette.grey[900],\n borderWidth: 0,\n padding: [parseInt(theme.spacing(1)), parseInt(theme.spacing(1))],\n textStyle: {\n color: theme.palette.common.white,\n fontSize: 11,\n fontFamily: theme.typography.caption.fontFamily,\n },\n trigger: 'axis',\n },\n legend: {\n type: 'scroll',\n bottom: 0,\n },\n axisPointer: {\n lineStyle: {\n color: theme.palette.grey[400],\n },\n },\n xAxis: {},\n yAxis: {},\n color: [\n theme.palette.secondary.main,\n ...Object.values(\n (theme.palette as { qualitative?: { bold?: Record<string, string> } })\n .qualitative?.bold ?? {},\n ),\n ],\n }\n}\n"],"names":["getCommonOptions","theme","grid","left","parseInt","spacing","top","right","bottom","containLabel","toolbox","show","tooltip","axisPointer","type","shadowStyle","color","backgroundColor","palette","grey","borderWidth","padding","textStyle","common","white","fontSize","fontFamily","typography","caption","trigger","legend","lineStyle","xAxis","yAxis","secondary","main","Object","values","qualitative","bold"],"mappings":"AASO,SAASA,EAAiB;AAAA,EAC/BC,OAAAA;AACgC,GAAuB;AACvD,SAAO;AAAA,IACLC,MAAM;AAAA,MACJC,MAAMC,SAASH,EAAMI,QAAQ,CAAC,CAAC;AAAA,MAC/BC,KAAKF,SAASH,EAAMI,QAAQ,CAAC,CAAC;AAAA,MAC9BE,OAAOH,SAASH,EAAMI,QAAQ,CAAC,CAAC;AAAA,MAChCG,QAAQJ,SAASH,EAAMI,QAAQ,CAAC,CAAC;AAAA,MACjCI,cAAc;AAAA,IAAA;AAAA,IAEhBC,SAAS;AAAA,MACPC,MAAM;AAAA,IAAA;AAAA,IAERC,SAAS;AAAA,MACPC,aAAa;AAAA,QACXC,MAAM;AAAA,QACNC,aAAa;AAAA,UACXC,OAAO;AAAA,QAAA;AAAA,MACT;AAAA,MAEFC,iBAAiBhB,EAAMiB,QAAQC,KAAK,GAAG;AAAA,MACvCC,aAAa;AAAA,MACbC,SAAS,CAACjB,SAASH,EAAMI,QAAQ,CAAC,CAAC,GAAGD,SAASH,EAAMI,QAAQ,CAAC,CAAC,CAAC;AAAA,MAChEiB,WAAW;AAAA,QACTN,OAAOf,EAAMiB,QAAQK,OAAOC;AAAAA,QAC5BC,UAAU;AAAA,QACVC,YAAYzB,EAAM0B,WAAWC,QAAQF;AAAAA,MAAAA;AAAAA,MAEvCG,SAAS;AAAA,IAAA;AAAA,IAEXC,QAAQ;AAAA,MACNhB,MAAM;AAAA,MACNN,QAAQ;AAAA,IAAA;AAAA,IAEVK,aAAa;AAAA,MACXkB,WAAW;AAAA,QACTf,OAAOf,EAAMiB,QAAQC,KAAK,GAAG;AAAA,MAAA;AAAA,IAC/B;AAAA,IAEFa,OAAO,CAAA;AAAA,IACPC,OAAO,CAAA;AAAA,IACPjB,OAAO,CACLf,EAAMiB,QAAQgB,UAAUC,MACxB,GAAGC,OAAOC,OACPpC,EAAMiB,QACJoB,aAAaC,QAAQ,CAAA,CAC1B,CAAC;AAAA,EAAA;AAGP;"}
|
package/dist/styles-Y8q7Jff3.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
function u(t) {
|
|
2
|
-
if (t === 0) return 0;
|
|
3
|
-
const e = Math.abs(t), n = Math.pow(10, Math.floor(Math.log10(e))), i = Math.ceil(e / n) * n;
|
|
4
|
-
return t < 0 ? -i : i;
|
|
5
|
-
}
|
|
6
|
-
function d({
|
|
7
|
-
hasLegend: t,
|
|
8
|
-
labelFormatter: e
|
|
9
|
-
}) {
|
|
10
|
-
return {
|
|
11
|
-
show: t,
|
|
12
|
-
icon: "circle",
|
|
13
|
-
left: 0,
|
|
14
|
-
bottom: 0,
|
|
15
|
-
orient: "horizontal",
|
|
16
|
-
type: "scroll",
|
|
17
|
-
...e && {
|
|
18
|
-
formatter: (n) => String(e(n))
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function x(t, e) {
|
|
23
|
-
return {
|
|
24
|
-
...!t && {
|
|
25
|
-
bottom: parseInt(e.spacing(3))
|
|
26
|
-
},
|
|
27
|
-
...t && {
|
|
28
|
-
bottom: parseInt(e.spacing(7))
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function y(t) {
|
|
33
|
-
return function(e, n, i, o, a) {
|
|
34
|
-
const l = {
|
|
35
|
-
top: parseInt(t.spacing(0.5))
|
|
36
|
-
};
|
|
37
|
-
return a.contentSize[0] < a.viewSize[0] - e[0] ? l.left = e[0] : l.right = a.viewSize[0] - e[0], l;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function m(t) {
|
|
41
|
-
if (t)
|
|
42
|
-
return (e) => t(e);
|
|
43
|
-
}
|
|
44
|
-
function b(t, e) {
|
|
45
|
-
const n = t && !Array.isArray(t), i = t, o = e && n ? (a) => String(e(a)) : void 0;
|
|
46
|
-
return {
|
|
47
|
-
...i,
|
|
48
|
-
axisLabel: {
|
|
49
|
-
...typeof i.axisLabel == "object" && i.axisLabel ? i.axisLabel : {},
|
|
50
|
-
formatter: o
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function F(t, e) {
|
|
55
|
-
let n = m(e);
|
|
56
|
-
const i = t && !Array.isArray(t), o = t;
|
|
57
|
-
return (!i || o.type !== "value") && (n = void 0), {
|
|
58
|
-
...o,
|
|
59
|
-
axisLabel: {
|
|
60
|
-
...typeof o.axisLabel == "object" && o.axisLabel ? o.axisLabel : {},
|
|
61
|
-
formatter: n
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function v(t) {
|
|
66
|
-
return (e) => {
|
|
67
|
-
const n = Array.isArray(e) ? e : [e], i = (r, s) => `<div style="margin: 0px 0 0;line-height:1;">${r ? `<div style="font-size:11px;color:#FFFFFF;font-weight:400;line-height:1; margin-bottom: 10px">${r}</div>` : ""}<div style="margin: 0;line-height:1;">${s}</div><div style="clear:both"></div></div>`, o = n.map((r) => {
|
|
68
|
-
const {
|
|
69
|
-
name: s,
|
|
70
|
-
seriesName: c,
|
|
71
|
-
marker: f,
|
|
72
|
-
value: h
|
|
73
|
-
} = t(r, n);
|
|
74
|
-
return {
|
|
75
|
-
name: s,
|
|
76
|
-
seriesName: c,
|
|
77
|
-
marker: f,
|
|
78
|
-
value: h
|
|
79
|
-
};
|
|
80
|
-
}), a = o[0]?.name ?? "", p = a || n.length > 1 ? "margin: 10px 0 0;line-height:1;" : "margin: 0;line-height:1;", g = o.map(({
|
|
81
|
-
seriesName: r,
|
|
82
|
-
marker: s,
|
|
83
|
-
value: c
|
|
84
|
-
}) => `<div style="${p}"><div style="margin: 0px 0 0;line-height:1;">${s}${r ? `<span style="font-size:11px;color:#FFFFFF;font-weight:400;margin-left:2px;margin-right:10px">${r}</span>` : ""}<span style="float:right;margin-left:10px;font-size:11px;color:#FFFFFF;font-weight:900">${c}</span></div></div>`);
|
|
85
|
-
return i(a, g.join(""));
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const w = {
|
|
89
|
-
graph: {
|
|
90
|
-
/**
|
|
91
|
-
* Common container style for chart widget skeletons
|
|
92
|
-
*/
|
|
93
|
-
container: {
|
|
94
|
-
display: "flex",
|
|
95
|
-
alignItems: "center",
|
|
96
|
-
justifyContent: "space-between",
|
|
97
|
-
flexDirection: "column",
|
|
98
|
-
gap: ({
|
|
99
|
-
spacing: t
|
|
100
|
-
}) => t(1),
|
|
101
|
-
height: ({
|
|
102
|
-
spacing: t
|
|
103
|
-
}) => t(38)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
export {
|
|
108
|
-
b as a,
|
|
109
|
-
F as b,
|
|
110
|
-
w as c,
|
|
111
|
-
x as d,
|
|
112
|
-
d as e,
|
|
113
|
-
m as f,
|
|
114
|
-
v as g,
|
|
115
|
-
y as h,
|
|
116
|
-
u as n
|
|
117
|
-
};
|
|
118
|
-
//# sourceMappingURL=styles-Y8q7Jff3.js.map
|