@mantine/charts 9.0.0-alpha.6 → 9.0.0-alpha.7
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/cjs/AreaChart/AreaChart.cjs +1 -0
- package/cjs/AreaChart/AreaChart.cjs.map +1 -1
- package/cjs/AreaChart/AreaGradient.cjs +1 -0
- package/cjs/AreaChart/AreaGradient.cjs.map +1 -1
- package/cjs/AreaChart/AreaSplit.cjs +1 -0
- package/cjs/AreaChart/AreaSplit.cjs.map +1 -1
- package/cjs/BarChart/BarChart.cjs +21 -4
- package/cjs/BarChart/BarChart.cjs.map +1 -1
- package/cjs/BarsList/BarsList.cjs +1 -0
- package/cjs/BarsList/BarsList.cjs.map +1 -1
- package/cjs/BubbleChart/BubbleChart.cjs +1 -0
- package/cjs/BubbleChart/BubbleChart.cjs.map +1 -1
- package/cjs/ChartLegend/ChartLegend.cjs +1 -0
- package/cjs/ChartLegend/ChartLegend.cjs.map +1 -1
- package/cjs/ChartTooltip/ChartTooltip.cjs +1 -0
- package/cjs/ChartTooltip/ChartTooltip.cjs.map +1 -1
- package/cjs/CompositeChart/CompositeChart.cjs +1 -0
- package/cjs/CompositeChart/CompositeChart.cjs.map +1 -1
- package/cjs/DonutChart/DonutChart.cjs +6 -5
- package/cjs/DonutChart/DonutChart.cjs.map +1 -1
- package/cjs/FunnelChart/FunnelChart.cjs +9 -9
- package/cjs/FunnelChart/FunnelChart.cjs.map +1 -1
- package/cjs/Heatmap/Heatmap.cjs +1 -0
- package/cjs/Heatmap/Heatmap.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs +1 -0
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapWeeks.cjs +1 -0
- package/cjs/Heatmap/HeatmapWeeks.cjs.map +1 -1
- package/cjs/Heatmap/get-heat-color/get-heat-color.cjs +1 -1
- package/cjs/Heatmap/get-heat-color/get-heat-color.cjs.map +1 -1
- package/cjs/LineChart/LineChart.cjs +1 -0
- package/cjs/LineChart/LineChart.cjs.map +1 -1
- package/cjs/PieChart/PieChart.cjs +6 -5
- package/cjs/PieChart/PieChart.cjs.map +1 -1
- package/cjs/PointLabel/PointLabel.cjs +1 -0
- package/cjs/PointLabel/PointLabel.cjs.map +1 -1
- package/cjs/RadarChart/RadarChart.cjs +1 -0
- package/cjs/RadarChart/RadarChart.cjs.map +1 -1
- package/cjs/RadialBarChart/RadialBarChart.cjs +1 -0
- package/cjs/RadialBarChart/RadialBarChart.cjs.map +1 -1
- package/cjs/ScatterChart/ScatterChart.cjs +1 -0
- package/cjs/ScatterChart/ScatterChart.cjs.map +1 -1
- package/cjs/Sparkline/Sparkline.cjs +1 -0
- package/cjs/Sparkline/Sparkline.cjs.map +1 -1
- package/esm/BarChart/BarChart.mjs +21 -6
- package/esm/BarChart/BarChart.mjs.map +1 -1
- package/esm/DonutChart/DonutChart.mjs +6 -6
- package/esm/DonutChart/DonutChart.mjs.map +1 -1
- package/esm/FunnelChart/FunnelChart.mjs +9 -10
- package/esm/FunnelChart/FunnelChart.mjs.map +1 -1
- package/esm/Heatmap/get-heat-color/get-heat-color.mjs +1 -1
- package/esm/Heatmap/get-heat-color/get-heat-color.mjs.map +1 -1
- package/esm/PieChart/PieChart.mjs +6 -6
- package/esm/PieChart/PieChart.mjs.map +1 -1
- package/lib/BarChart/BarChart.d.ts +1 -0
- package/lib/DonutChart/DonutChart.d.ts +3 -3
- package/lib/PieChart/PieChart.d.ts +3 -3
- package/package.json +3 -3
- package/cjs/SankeyChart/SankeyChart.cjs +0 -202
- package/cjs/SankeyChart/SankeyChart.cjs.map +0 -1
- package/cjs/SankeyChart/SankeyChart.module.cjs +0 -7
- package/cjs/SankeyChart/SankeyChart.module.cjs.map +0 -1
- package/cjs/Treemap/Treemap.cjs +0 -133
- package/cjs/Treemap/Treemap.cjs.map +0 -1
- package/cjs/Treemap/Treemap.module.cjs +0 -7
- package/cjs/Treemap/Treemap.module.cjs.map +0 -1
- package/esm/SankeyChart/SankeyChart.mjs +0 -200
- package/esm/SankeyChart/SankeyChart.mjs.map +0 -1
- package/esm/SankeyChart/SankeyChart.module.mjs +0 -7
- package/esm/SankeyChart/SankeyChart.module.mjs.map +0 -1
- package/esm/Treemap/Treemap.mjs +0 -131
- package/esm/Treemap/Treemap.mjs.map +0 -1
- package/esm/Treemap/Treemap.module.mjs +0 -7
- package/esm/Treemap/Treemap.module.mjs.map +0 -1
- package/lib/SankeyChart/SankeyChart.d.ts +0 -71
- package/lib/SankeyChart/index.d.ts +0 -12
- package/lib/Treemap/Treemap.d.ts +0 -57
- package/lib/Treemap/index.d.ts +0 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
3
4
|
const require_ChartLegend = require("../ChartLegend/ChartLegend.cjs");
|
|
4
5
|
const require_PointLabel = require("../PointLabel/PointLabel.cjs");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AreaChart.cjs","names":["classes","Area","Fragment","AreaGradient","PointLabel","ReferenceLine","Box","ResponsiveContainer","ReChartsAreaChart","Legend","ChartLegend","CartesianGrid","XAxis","Label","YAxis","Tooltip","ChartTooltip","AreaSplit","getDefaultSplitOffset"],"sources":["../../src/AreaChart/AreaChart.tsx"],"sourcesContent":["import { Fragment, useId, useState } from 'react';\nimport {\n Area,\n AreaProps,\n CartesianGrid,\n Label,\n Legend,\n AreaChart as ReChartsAreaChart,\n ReferenceLine,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport { PointLabel } from '../PointLabel/PointLabel';\nimport type {\n BaseChartStylesNames,\n ChartSeries,\n GridChartBaseProps,\n MantineChartDotProps,\n} from '../types';\nimport { AreaGradient } from './AreaGradient';\nimport { AreaSplit } from './AreaSplit';\nimport { getDefaultSplitOffset } from './get-split-offset';\nimport classes from '../grid-chart.module.css';\n\nfunction valueToPercent(value: number) {\n return `${(value * 100).toFixed(0)}%`;\n}\n\nexport interface AreaChartSeries extends ChartSeries {\n strokeDasharray?: string | number;\n color: MantineColor;\n curveType?: AreaChartCurveType;\n}\n\nexport type AreaChartType = 'default' | 'stacked' | 'percent' | 'split';\n\nexport type AreaChartCurveType =\n | 'bump'\n | 'linear'\n | 'natural'\n | 'monotone'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\nexport type AreaChartStylesNames =\n | 'area'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type AreaChartCSSVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface AreaChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<AreaChartFactory>, ElementProps<'div'> {\n /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */\n series: AreaChartSeries[];\n\n /** Controls how chart areas are positioned relative to each other @default 'default' */\n type?: AreaChartType;\n\n /** Determines whether the chart area should be represented with a gradient instead of the solid color @default false */\n withGradient?: boolean;\n\n /** Type of the curve @default 'monotone' */\n curveType?: AreaChartCurveType;\n\n /** Determines whether dots should be displayed @default true */\n withDots?: boolean;\n\n /** Props passed down to all dots. Ignored if `withDots={false}` is set. */\n dotProps?: MantineChartDotProps;\n\n /** Props passed down to all active dots. Ignored if `withDots={false}` is set. */\n activeDotProps?: MantineChartDotProps;\n\n /** Stroke width for the chart areas @default 2 */\n strokeWidth?: number;\n\n /** Props passed down to recharts `AreaChart` component */\n areaChartProps?: React.ComponentProps<typeof ReChartsAreaChart>;\n\n /** Controls fill opacity of all areas @default 0.2 */\n fillOpacity?: number;\n\n /** A tuple of colors used when `type=\"split\"` is set, ignored in all other cases. A tuple may include theme colors reference or any valid CSS colors @default ['green.7', 'red.7'] */\n splitColors?: [MantineColor, MantineColor];\n\n /** Offset for the split gradient. By default, value is inferred from `data` and `series` if possible. Must be generated from the data array with `getSplitOffset` function. */\n splitOffset?: number;\n\n /** If set, points with `null` values are connected @default true */\n connectNulls?: boolean;\n\n /** Additional components that are rendered inside recharts `AreaChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Area` component */\n areaProps?:\n | ((series: AreaChartSeries) => Partial<Omit<AreaProps<any, any>, 'ref'>>)\n | Partial<Omit<AreaProps<any, any>, 'ref'>>;\n\n /** If set, each point has an associated label @default false */\n withPointLabels?: boolean;\n}\n\nexport type AreaChartFactory = Factory<{\n props: AreaChartProps;\n ref: HTMLDivElement;\n stylesNames: AreaChartStylesNames;\n vars: AreaChartCSSVariables;\n}>;\n\nconst defaultProps = {\n withXAxis: true,\n withYAxis: true,\n withDots: true,\n withTooltip: true,\n connectNulls: true,\n strokeWidth: 2,\n tooltipAnimationDuration: 0,\n fillOpacity: 0.2,\n tickLine: 'y',\n strokeDasharray: '5 5',\n curveType: 'monotone',\n gridAxis: 'x',\n type: 'default',\n splitColors: ['green.7', 'red.7'],\n orientation: 'horizontal',\n} satisfies Partial<AreaChartProps>;\n\nconst varsResolver = createVarsResolver<AreaChartFactory>((theme, { textColor, gridColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n },\n}));\n\nexport const AreaChart = factory<AreaChartFactory>((_props) => {\n const props = useProps('AreaChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n series,\n withGradient,\n dataKey,\n withXAxis,\n withYAxis,\n curveType,\n gridProps,\n withDots,\n tickLine,\n strokeDasharray,\n gridAxis,\n unit,\n yAxisProps,\n xAxisProps,\n dotProps,\n activeDotProps,\n strokeWidth,\n tooltipAnimationDuration,\n type,\n legendProps,\n tooltipProps,\n withLegend,\n withTooltip,\n areaChartProps,\n fillOpacity,\n splitColors,\n splitOffset,\n connectNulls,\n onMouseLeave,\n orientation,\n referenceLines,\n dir,\n valueFormatter,\n children,\n areaProps,\n xAxisLabel,\n yAxisLabel,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n withPointLabels,\n gridColor,\n textColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const baseId = useId();\n const splitId = `${baseId}-split`;\n const withXTickLine = gridAxis !== 'none' && (tickLine === 'x' || tickLine === 'xy');\n const withYTickLine = gridAxis !== 'none' && (tickLine === 'y' || tickLine === 'xy');\n const isAnimationActive = (tooltipAnimationDuration || 0) > 0;\n const _withGradient = typeof withGradient === 'boolean' ? withGradient : type === 'default';\n const stacked = type === 'stacked' || type === 'percent';\n const [highlightedArea, setHighlightedArea] = useState<string | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<AreaChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const getStyles = useStyles<AreaChartFactory>({\n name: 'AreaChart',\n classes: classes as any,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const dotsAreas = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n return (\n <Area\n {...getStyles('area')}\n activeDot={{ fill: theme.white, stroke: color, strokeWidth: 2, r: 4, ...activeDotProps }}\n dot={{ fill: color, fillOpacity: dimmed ? 0 : 1, strokeWidth: 2, r: 4, ...dotProps }}\n key={item.name}\n name={item.name}\n type={curveType}\n dataKey={item.name}\n fill=\"none\"\n strokeWidth={strokeWidth}\n stroke=\"none\"\n isAnimationActive={false}\n connectNulls={connectNulls}\n stackId={stacked ? 'stack-dots' : undefined}\n yAxisId={item.yAxisId || undefined}\n {...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}\n />\n );\n });\n\n const areas = series.map((item) => {\n const id = `${baseId}-${item.color.replace(/[^a-zA-Z0-9]/g, '')}`;\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n\n return (\n <Fragment key={item.name}>\n <defs>\n <AreaGradient\n color={color}\n withGradient={_withGradient}\n id={id}\n fillOpacity={fillOpacity}\n />\n </defs>\n <Area\n {...getStyles('area')}\n activeDot={false}\n dot={false}\n name={item.name}\n type={item.curveType ?? curveType}\n dataKey={item.name}\n fill={type === 'split' ? `url(#${splitId})` : `url(#${id})`}\n strokeWidth={strokeWidth}\n stroke={color}\n isAnimationActive={false}\n connectNulls={connectNulls}\n stackId={stacked ? 'stack' : undefined}\n fillOpacity={dimmed ? 0 : 1}\n strokeOpacity={dimmed ? 0.5 : 1}\n strokeDasharray={item.strokeDasharray}\n yAxisId={item.yAxisId || undefined}\n label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}\n {...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}\n />\n </Fragment>\n );\n });\n\n const referenceLinesItems = referenceLines?.map((line, index) => {\n const color = getThemeColor(line.color, theme);\n return (\n <ReferenceLine\n key={index}\n stroke={line.color ? color : 'var(--chart-grid-color)'}\n strokeWidth={1}\n yAxisId={line.yAxisId || undefined}\n {...line}\n label={{\n value: line.label,\n fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n }}\n {...getStyles('referenceLine')}\n />\n );\n });\n\n const tickFormatter = type === 'percent' ? valueToPercent : valueFormatter;\n\n const sharedYAxisProps = {\n axisLine: false,\n ...(orientation === 'vertical'\n ? { dataKey, type: 'category' as const }\n : { type: 'number' as const }),\n tickLine: withYTickLine ? { stroke: 'currentColor' } : false,\n allowDecimals: true,\n unit,\n tickFormatter: orientation === 'vertical' ? undefined : tickFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box {...getStyles('root')} onMouseLeave={handleMouseLeave} dir={dir || 'ltr'} {...others}>\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsAreaChart\n data={data}\n stackOffset={type === 'percent' ? 'expand' : undefined}\n layout={orientation}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n {...areaChartProps}\n >\n {referenceLinesItems}\n {withLegend && (\n <Legend\n verticalAlign=\"top\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload}\n onHighlight={setHighlightedArea}\n legendPosition={legendProps?.verticalAlign || 'top'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n <CartesianGrid\n strokeDasharray={strokeDasharray as string}\n vertical={gridAxis === 'y' || gridAxis === 'xy'}\n horizontal={gridAxis === 'x' || gridAxis === 'xy'}\n {...getStyles('grid')}\n {...gridProps}\n />\n\n <XAxis\n hide={!withXAxis}\n {...(orientation === 'vertical' ? { type: 'number' } : { dataKey })}\n tick={{ transform: 'translate(0, 10)', fontSize: 12, fill: 'currentColor' }}\n stroke=\"\"\n interval=\"preserveStartEnd\"\n tickLine={withXTickLine ? { stroke: 'currentColor' } : false}\n minTickGap={5}\n tickFormatter={orientation === 'vertical' ? tickFormatter : undefined}\n {...getStyles('axis')}\n {...xAxisProps}\n >\n {xAxisLabel && (\n <Label position=\"insideBottom\" offset={-20} fontSize={12} {...getStyles('axisLabel')}>\n {xAxisLabel}\n </Label>\n )}\n {xAxisProps?.children}\n </XAxis>\n\n <YAxis\n orientation=\"left\"\n tick={{ transform: 'translate(-10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withYAxis}\n {...sharedYAxisProps}\n {...yAxisProps}\n >\n {yAxisLabel && (\n <Label\n position=\"insideLeft\"\n angle={-90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {yAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <YAxis\n yAxisId=\"right\"\n orientation=\"right\"\n tick={{ transform: 'translate(10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withRightYAxis}\n {...sharedYAxisProps}\n {...rightYAxisProps}\n >\n {rightYAxisLabel && (\n <Label\n position=\"insideRight\"\n angle={90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {rightYAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={isAnimationActive}\n position={orientation === 'vertical' ? {} : { y: 0 }}\n cursor={{\n stroke: 'var(--chart-grid-color)',\n strokeWidth: 1,\n strokeDasharray,\n }}\n content={({ label, payload, labelFormatter }) => (\n <ChartTooltip\n label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n payload={payload}\n unit={unit}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {type === 'split' && (\n <defs>\n <AreaSplit\n colors={splitColors}\n id={splitId}\n offset={splitOffset ?? getDefaultSplitOffset({ data, series })}\n fillOpacity={fillOpacity}\n />\n </defs>\n )}\n\n {areas}\n {withDots && dotsAreas}\n {children}\n </ReChartsAreaChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nAreaChart.classes = classes;\nAreaChart.varsResolver = varsResolver;\nAreaChart.displayName = '@mantine/charts/AreaChart';\n"],"mappings":";;;;;;;;;;;;;AA2CA,SAAS,eAAe,OAAe;AACrC,QAAO,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;;AA0FrC,M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GAAI;MACJ,CAAA;KAGH,SAAS,WACR,iBAAA,GAAA,kBAAA,KAAC,QAAD,EAAA,UACE,iBAAA,GAAA,kBAAA,KAACC,kBAAAA,WAAD;MACE,QAAQ;MACR,IAAI;MACJ,QAAQ,eAAeC,yBAAAA,sBAAsB;OAAE;OAAM;OAAQ,CAAC;MACjD;MACb,CAAA,EACG,CAAA;KAGR;KACA,YAAY;KACZ;KACiB;;GACA,CAAA;EAClB,CAAA;EAER;AAEF,UAAU,UAAUlB,0BAAAA;AACpB,UAAU,eAAe;AACzB,UAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"AreaChart.cjs","names":["classes","Area","Fragment","AreaGradient","PointLabel","ReferenceLine","Box","ResponsiveContainer","ReChartsAreaChart","Legend","ChartLegend","CartesianGrid","XAxis","Label","YAxis","Tooltip","ChartTooltip","AreaSplit","getDefaultSplitOffset"],"sources":["../../src/AreaChart/AreaChart.tsx"],"sourcesContent":["import { Fragment, useId, useState } from 'react';\nimport {\n Area,\n AreaProps,\n CartesianGrid,\n Label,\n Legend,\n AreaChart as ReChartsAreaChart,\n ReferenceLine,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport { PointLabel } from '../PointLabel/PointLabel';\nimport type {\n BaseChartStylesNames,\n ChartSeries,\n GridChartBaseProps,\n MantineChartDotProps,\n} from '../types';\nimport { AreaGradient } from './AreaGradient';\nimport { AreaSplit } from './AreaSplit';\nimport { getDefaultSplitOffset } from './get-split-offset';\nimport classes from '../grid-chart.module.css';\n\nfunction valueToPercent(value: number) {\n return `${(value * 100).toFixed(0)}%`;\n}\n\nexport interface AreaChartSeries extends ChartSeries {\n strokeDasharray?: string | number;\n color: MantineColor;\n curveType?: AreaChartCurveType;\n}\n\nexport type AreaChartType = 'default' | 'stacked' | 'percent' | 'split';\n\nexport type AreaChartCurveType =\n | 'bump'\n | 'linear'\n | 'natural'\n | 'monotone'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\nexport type AreaChartStylesNames =\n | 'area'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type AreaChartCSSVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface AreaChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<AreaChartFactory>, ElementProps<'div'> {\n /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */\n series: AreaChartSeries[];\n\n /** Controls how chart areas are positioned relative to each other @default 'default' */\n type?: AreaChartType;\n\n /** Determines whether the chart area should be represented with a gradient instead of the solid color @default false */\n withGradient?: boolean;\n\n /** Type of the curve @default 'monotone' */\n curveType?: AreaChartCurveType;\n\n /** Determines whether dots should be displayed @default true */\n withDots?: boolean;\n\n /** Props passed down to all dots. Ignored if `withDots={false}` is set. */\n dotProps?: MantineChartDotProps;\n\n /** Props passed down to all active dots. Ignored if `withDots={false}` is set. */\n activeDotProps?: MantineChartDotProps;\n\n /** Stroke width for the chart areas @default 2 */\n strokeWidth?: number;\n\n /** Props passed down to recharts `AreaChart` component */\n areaChartProps?: React.ComponentProps<typeof ReChartsAreaChart>;\n\n /** Controls fill opacity of all areas @default 0.2 */\n fillOpacity?: number;\n\n /** A tuple of colors used when `type=\"split\"` is set, ignored in all other cases. A tuple may include theme colors reference or any valid CSS colors @default ['green.7', 'red.7'] */\n splitColors?: [MantineColor, MantineColor];\n\n /** Offset for the split gradient. By default, value is inferred from `data` and `series` if possible. Must be generated from the data array with `getSplitOffset` function. */\n splitOffset?: number;\n\n /** If set, points with `null` values are connected @default true */\n connectNulls?: boolean;\n\n /** Additional components that are rendered inside recharts `AreaChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Area` component */\n areaProps?:\n | ((series: AreaChartSeries) => Partial<Omit<AreaProps<any, any>, 'ref'>>)\n | Partial<Omit<AreaProps<any, any>, 'ref'>>;\n\n /** If set, each point has an associated label @default false */\n withPointLabels?: boolean;\n}\n\nexport type AreaChartFactory = Factory<{\n props: AreaChartProps;\n ref: HTMLDivElement;\n stylesNames: AreaChartStylesNames;\n vars: AreaChartCSSVariables;\n}>;\n\nconst defaultProps = {\n withXAxis: true,\n withYAxis: true,\n withDots: true,\n withTooltip: true,\n connectNulls: true,\n strokeWidth: 2,\n tooltipAnimationDuration: 0,\n fillOpacity: 0.2,\n tickLine: 'y',\n strokeDasharray: '5 5',\n curveType: 'monotone',\n gridAxis: 'x',\n type: 'default',\n splitColors: ['green.7', 'red.7'],\n orientation: 'horizontal',\n} satisfies Partial<AreaChartProps>;\n\nconst varsResolver = createVarsResolver<AreaChartFactory>((theme, { textColor, gridColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n },\n}));\n\nexport const AreaChart = factory<AreaChartFactory>((_props) => {\n const props = useProps('AreaChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n series,\n withGradient,\n dataKey,\n withXAxis,\n withYAxis,\n curveType,\n gridProps,\n withDots,\n tickLine,\n strokeDasharray,\n gridAxis,\n unit,\n yAxisProps,\n xAxisProps,\n dotProps,\n activeDotProps,\n strokeWidth,\n tooltipAnimationDuration,\n type,\n legendProps,\n tooltipProps,\n withLegend,\n withTooltip,\n areaChartProps,\n fillOpacity,\n splitColors,\n splitOffset,\n connectNulls,\n onMouseLeave,\n orientation,\n referenceLines,\n dir,\n valueFormatter,\n children,\n areaProps,\n xAxisLabel,\n yAxisLabel,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n withPointLabels,\n gridColor,\n textColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const baseId = useId();\n const splitId = `${baseId}-split`;\n const withXTickLine = gridAxis !== 'none' && (tickLine === 'x' || tickLine === 'xy');\n const withYTickLine = gridAxis !== 'none' && (tickLine === 'y' || tickLine === 'xy');\n const isAnimationActive = (tooltipAnimationDuration || 0) > 0;\n const _withGradient = typeof withGradient === 'boolean' ? withGradient : type === 'default';\n const stacked = type === 'stacked' || type === 'percent';\n const [highlightedArea, setHighlightedArea] = useState<string | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<AreaChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const getStyles = useStyles<AreaChartFactory>({\n name: 'AreaChart',\n classes: classes as any,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const dotsAreas = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n return (\n <Area\n {...getStyles('area')}\n activeDot={{ fill: theme.white, stroke: color, strokeWidth: 2, r: 4, ...activeDotProps }}\n dot={{ fill: color, fillOpacity: dimmed ? 0 : 1, strokeWidth: 2, r: 4, ...dotProps }}\n key={item.name}\n name={item.name}\n type={curveType}\n dataKey={item.name}\n fill=\"none\"\n strokeWidth={strokeWidth}\n stroke=\"none\"\n isAnimationActive={false}\n connectNulls={connectNulls}\n stackId={stacked ? 'stack-dots' : undefined}\n yAxisId={item.yAxisId || undefined}\n {...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}\n />\n );\n });\n\n const areas = series.map((item) => {\n const id = `${baseId}-${item.color.replace(/[^a-zA-Z0-9]/g, '')}`;\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n\n return (\n <Fragment key={item.name}>\n <defs>\n <AreaGradient\n color={color}\n withGradient={_withGradient}\n id={id}\n fillOpacity={fillOpacity}\n />\n </defs>\n <Area\n {...getStyles('area')}\n activeDot={false}\n dot={false}\n name={item.name}\n type={item.curveType ?? curveType}\n dataKey={item.name}\n fill={type === 'split' ? `url(#${splitId})` : `url(#${id})`}\n strokeWidth={strokeWidth}\n stroke={color}\n isAnimationActive={false}\n connectNulls={connectNulls}\n stackId={stacked ? 'stack' : undefined}\n fillOpacity={dimmed ? 0 : 1}\n strokeOpacity={dimmed ? 0.5 : 1}\n strokeDasharray={item.strokeDasharray}\n yAxisId={item.yAxisId || undefined}\n label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}\n {...(typeof areaProps === 'function' ? areaProps(item) : areaProps)}\n />\n </Fragment>\n );\n });\n\n const referenceLinesItems = referenceLines?.map((line, index) => {\n const color = getThemeColor(line.color, theme);\n return (\n <ReferenceLine\n key={index}\n stroke={line.color ? color : 'var(--chart-grid-color)'}\n strokeWidth={1}\n yAxisId={line.yAxisId || undefined}\n {...line}\n label={{\n value: line.label,\n fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n }}\n {...getStyles('referenceLine')}\n />\n );\n });\n\n const tickFormatter = type === 'percent' ? valueToPercent : valueFormatter;\n\n const sharedYAxisProps = {\n axisLine: false,\n ...(orientation === 'vertical'\n ? { dataKey, type: 'category' as const }\n : { type: 'number' as const }),\n tickLine: withYTickLine ? { stroke: 'currentColor' } : false,\n allowDecimals: true,\n unit,\n tickFormatter: orientation === 'vertical' ? undefined : tickFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box {...getStyles('root')} onMouseLeave={handleMouseLeave} dir={dir || 'ltr'} {...others}>\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsAreaChart\n data={data}\n stackOffset={type === 'percent' ? 'expand' : undefined}\n layout={orientation}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n {...areaChartProps}\n >\n {referenceLinesItems}\n {withLegend && (\n <Legend\n verticalAlign=\"top\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload}\n onHighlight={setHighlightedArea}\n legendPosition={legendProps?.verticalAlign || 'top'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n <CartesianGrid\n strokeDasharray={strokeDasharray as string}\n vertical={gridAxis === 'y' || gridAxis === 'xy'}\n horizontal={gridAxis === 'x' || gridAxis === 'xy'}\n {...getStyles('grid')}\n {...gridProps}\n />\n\n <XAxis\n hide={!withXAxis}\n {...(orientation === 'vertical' ? { type: 'number' } : { dataKey })}\n tick={{ transform: 'translate(0, 10)', fontSize: 12, fill: 'currentColor' }}\n stroke=\"\"\n interval=\"preserveStartEnd\"\n tickLine={withXTickLine ? { stroke: 'currentColor' } : false}\n minTickGap={5}\n tickFormatter={orientation === 'vertical' ? tickFormatter : undefined}\n {...getStyles('axis')}\n {...xAxisProps}\n >\n {xAxisLabel && (\n <Label position=\"insideBottom\" offset={-20} fontSize={12} {...getStyles('axisLabel')}>\n {xAxisLabel}\n </Label>\n )}\n {xAxisProps?.children}\n </XAxis>\n\n <YAxis\n orientation=\"left\"\n tick={{ transform: 'translate(-10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withYAxis}\n {...sharedYAxisProps}\n {...yAxisProps}\n >\n {yAxisLabel && (\n <Label\n position=\"insideLeft\"\n angle={-90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {yAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <YAxis\n yAxisId=\"right\"\n orientation=\"right\"\n tick={{ transform: 'translate(10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withRightYAxis}\n {...sharedYAxisProps}\n {...rightYAxisProps}\n >\n {rightYAxisLabel && (\n <Label\n position=\"insideRight\"\n angle={90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {rightYAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={isAnimationActive}\n position={orientation === 'vertical' ? {} : { y: 0 }}\n cursor={{\n stroke: 'var(--chart-grid-color)',\n strokeWidth: 1,\n strokeDasharray,\n }}\n content={({ label, payload, labelFormatter }) => (\n <ChartTooltip\n label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n payload={payload}\n unit={unit}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {type === 'split' && (\n <defs>\n <AreaSplit\n colors={splitColors}\n id={splitId}\n offset={splitOffset ?? getDefaultSplitOffset({ data, series })}\n fillOpacity={fillOpacity}\n />\n </defs>\n )}\n\n {areas}\n {withDots && dotsAreas}\n {children}\n </ReChartsAreaChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nAreaChart.classes = classes;\nAreaChart.varsResolver = varsResolver;\nAreaChart.displayName = '@mantine/charts/AreaChart';\n"],"mappings":";;;;;;;;;;;;;;AA2CA,SAAS,eAAe,OAAe;AACrC,QAAO,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;;AA0FrC,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,UAAU;CACV,aAAa;CACb,cAAc;CACd,aAAa;CACb,0BAA0B;CAC1B,aAAa;CACb,UAAU;CACV,iBAAiB;CACjB,WAAW;CACX,UAAU;CACV,MAAM;CACN,aAAa,CAAC,WAAW,QAAQ;CACjC,aAAa;CACd;AAED,MAAM,gBAAA,GAAA,cAAA,qBAAqD,OAAO,EAAE,WAAW,iBAAiB,EAC9F,MAAM;CACJ,sBAAsB,aAAA,GAAA,cAAA,eA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pB,UAAU,eAAe;AACzB,UAAU,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AreaGradient.cjs","names":[],"sources":["../../src/AreaChart/AreaGradient.tsx"],"sourcesContent":["interface AreaGradientProps {\n color: string;\n id: string;\n withGradient: boolean | undefined;\n fillOpacity: number | undefined;\n}\n\nexport function AreaGradient({ color, id, withGradient, fillOpacity }: AreaGradientProps) {\n return (\n <>\n {withGradient ? (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor={color} stopOpacity={fillOpacity} />\n <stop offset=\"100%\" stopColor={color} stopOpacity={0.01} />\n </linearGradient>\n ) : (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop stopColor={color} stopOpacity={fillOpacity ?? 0.2} />\n </linearGradient>\n )}\n </>\n );\n}\n\nAreaGradient.displayName = '@mantine/charts/AreaGradient';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AreaGradient.cjs","names":[],"sources":["../../src/AreaChart/AreaGradient.tsx"],"sourcesContent":["interface AreaGradientProps {\n color: string;\n id: string;\n withGradient: boolean | undefined;\n fillOpacity: number | undefined;\n}\n\nexport function AreaGradient({ color, id, withGradient, fillOpacity }: AreaGradientProps) {\n return (\n <>\n {withGradient ? (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor={color} stopOpacity={fillOpacity} />\n <stop offset=\"100%\" stopColor={color} stopOpacity={0.01} />\n </linearGradient>\n ) : (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop stopColor={color} stopOpacity={fillOpacity ?? 0.2} />\n </linearGradient>\n )}\n </>\n );\n}\n\nAreaGradient.displayName = '@mantine/charts/AreaGradient';\n"],"mappings":";;;;AAOA,SAAgB,aAAa,EAAE,OAAO,IAAI,cAAc,eAAkC;AACxF,QACE,iBAAA,GAAA,kBAAA,KAAA,kBAAA,UAAA,EAAA,UACG,eACC,iBAAA,GAAA,kBAAA,MAAC,kBAAD;EAAoB;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;YAAhD,CACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;GAAM,QAAO;GAAK,WAAW;GAAO,aAAa;GAAe,CAAA,EAChE,iBAAA,GAAA,kBAAA,KAAC,QAAD;GAAM,QAAO;GAAO,WAAW;GAAO,aAAa;GAAQ,CAAA,CAC5C;MAEjB,iBAAA,GAAA,kBAAA,KAAC,kBAAD;EAAoB;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;YAC9C,iBAAA,GAAA,kBAAA,KAAC,QAAD;GAAM,WAAW;GAAO,aAAa,eAAe;GAAO,CAAA;EAC5C,CAAA,EAElB,CAAA;;AAIP,aAAa,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AreaSplit.cjs","names":[],"sources":["../../src/AreaChart/AreaSplit.tsx"],"sourcesContent":["import { getThemeColor, MantineColor, useMantineTheme } from '@mantine/core';\n\ninterface AreaSplitProps {\n offset: number;\n colors: [MantineColor, MantineColor];\n id?: string;\n fillOpacity: number | undefined;\n}\n\nexport function AreaSplit({ offset, id, colors, fillOpacity }: AreaSplitProps) {\n const theme = useMantineTheme();\n\n return (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop\n offset={offset}\n stopColor={getThemeColor(colors[0], theme)}\n stopOpacity={fillOpacity ?? 0.2}\n />\n <stop\n offset={offset}\n stopColor={getThemeColor(colors[1], theme)}\n stopOpacity={fillOpacity ?? 0.2}\n />\n </linearGradient>\n );\n}\n\nAreaSplit.displayName = '@mantine/charts/AreaSplit';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AreaSplit.cjs","names":[],"sources":["../../src/AreaChart/AreaSplit.tsx"],"sourcesContent":["import { getThemeColor, MantineColor, useMantineTheme } from '@mantine/core';\n\ninterface AreaSplitProps {\n offset: number;\n colors: [MantineColor, MantineColor];\n id?: string;\n fillOpacity: number | undefined;\n}\n\nexport function AreaSplit({ offset, id, colors, fillOpacity }: AreaSplitProps) {\n const theme = useMantineTheme();\n\n return (\n <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n <stop\n offset={offset}\n stopColor={getThemeColor(colors[0], theme)}\n stopOpacity={fillOpacity ?? 0.2}\n />\n <stop\n offset={offset}\n stopColor={getThemeColor(colors[1], theme)}\n stopOpacity={fillOpacity ?? 0.2}\n />\n </linearGradient>\n );\n}\n\nAreaSplit.displayName = '@mantine/charts/AreaSplit';\n"],"mappings":";;;;;AASA,SAAgB,UAAU,EAAE,QAAQ,IAAI,QAAQ,eAA+B;CAC7E,MAAM,SAAA,GAAA,cAAA,kBAAyB;AAE/B,QACE,iBAAA,GAAA,kBAAA,MAAC,kBAAD;EAAoB;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;EAAI,IAAG;YAAhD,CACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;GACU;GACR,YAAA,GAAA,cAAA,eAAyB,OAAO,IAAI,MAAM;GAC1C,aAAa,eAAe;GAC5B,CAAA,EACF,iBAAA,GAAA,kBAAA,KAAC,QAAD;GACU;GACR,YAAA,GAAA,cAAA,eAAyB,OAAO,IAAI,MAAM;GAC1C,aAAa,eAAe;GAC5B,CAAA,CACa;;;AAIrB,UAAU,cAAc"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
3
4
|
const require_ChartLegend = require("../ChartLegend/ChartLegend.cjs");
|
|
4
5
|
const require_grid_chart_module = require("../grid-chart.module.cjs");
|
|
5
6
|
let _mantine_core = require("@mantine/core");
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
8
|
let react = require("react");
|
|
9
|
+
react = require_runtime.__toESM(react);
|
|
8
10
|
let recharts = require("recharts");
|
|
9
11
|
//#region packages/@mantine/charts/src/BarChart/BarChart.tsx
|
|
10
12
|
function valueToPercent(value) {
|
|
@@ -81,6 +83,8 @@ const BarChart = (0, _mantine_core.factory)((_props) => {
|
|
|
81
83
|
const bars = series.map((item) => {
|
|
82
84
|
const color = (0, _mantine_core.getThemeColor)(item.color, theme);
|
|
83
85
|
const dimmed = shouldHighlight && highlightedArea !== item.name;
|
|
86
|
+
const resolvedBarProps = typeof barProps === "function" ? barProps(item) : barProps;
|
|
87
|
+
const userShape = resolvedBarProps?.shape;
|
|
84
88
|
return /* @__PURE__ */ (0, react.createElement)(recharts.Bar, {
|
|
85
89
|
...getStyles("bar"),
|
|
86
90
|
key: item.name,
|
|
@@ -94,10 +98,23 @@ const BarChart = (0, _mantine_core.factory)((_props) => {
|
|
|
94
98
|
stackId: stacked ? "stack" : item.stackId || void 0,
|
|
95
99
|
yAxisId: item.yAxisId || void 0,
|
|
96
100
|
minPointSize: minBarSize,
|
|
97
|
-
...
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
...resolvedBarProps,
|
|
102
|
+
shape: (shapeProps) => {
|
|
103
|
+
const entry = shapeProps.payload;
|
|
104
|
+
const cellColor = entry?.color ? (0, _mantine_core.getThemeColor)(entry.color, theme) : typeof getBarColor === "function" ? (0, _mantine_core.getThemeColor)(getBarColor(entry?.[item.name], item), theme) : getBarFill(barProps, item) || color;
|
|
105
|
+
const coloredProps = {
|
|
106
|
+
...shapeProps,
|
|
107
|
+
fill: cellColor
|
|
108
|
+
};
|
|
109
|
+
if (typeof userShape === "function") return userShape(coloredProps);
|
|
110
|
+
if (react.default.isValidElement(userShape)) return react.default.cloneElement(userShape, coloredProps);
|
|
111
|
+
if (typeof userShape === "object" && userShape) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Rectangle, {
|
|
112
|
+
...coloredProps,
|
|
113
|
+
...userShape
|
|
114
|
+
});
|
|
115
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Rectangle, { ...coloredProps });
|
|
116
|
+
}
|
|
117
|
+
}, withBarValueLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.LabelList, {
|
|
101
118
|
position: orientation === "vertical" ? "right" : "top",
|
|
102
119
|
fontSize: 12,
|
|
103
120
|
fill: "var(--chart-bar-label-color, var(--mantine-color-dimmed))",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarChart.cjs","names":["Bar","Cell","LabelList","ReferenceLine","Box","ResponsiveContainer","ReChartsBarChart","Legend","ChartLegend","XAxis","Label","YAxis","CartesianGrid","Tooltip","ChartTooltip","classes"],"sources":["../../src/BarChart/BarChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n Bar,\n BarProps,\n CartesianGrid,\n Cell,\n Label,\n LabelList,\n LabelListProps,\n Legend,\n BarChart as ReChartsBarChart,\n ReferenceLine,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport type { BaseChartStylesNames, ChartSeries, GridChartBaseProps } from '../types';\nimport classes from '../grid-chart.module.css';\n\nfunction valueToPercent(value: number) {\n return `${(value * 100).toFixed(0)}%`;\n}\n\nexport interface BarChartSeries extends ChartSeries {\n stackId?: string;\n}\n\nexport type BarChartType = 'default' | 'stacked' | 'percent' | 'waterfall';\n\nexport type BarChartStylesNames =\n | 'bar'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type BarChartCssVariables = {\n root:\n | '--chart-text-color'\n | '--chart-grid-color'\n | '--chart-cursor-fill'\n | '--chart-bar-label-color';\n};\n\nexport interface BarChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<BarChartFactory>, ElementProps<'div'> {\n /** Data used to display chart. */\n data: Record<string, any>[];\n\n /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */\n series: BarChartSeries[];\n\n /** Controls how bars are positioned relative to each other @default 'default' */\n type?: BarChartType;\n\n /** Controls fill opacity of all bars @default 1 */\n fillOpacity?: number;\n\n /** Fill of hovered bar section, by default value is based on color scheme */\n cursorFill?: MantineColor;\n\n /** Props passed down to recharts `BarChart` component */\n barChartProps?: React.ComponentProps<typeof ReChartsBarChart>;\n\n /** Additional components that are rendered inside recharts `BarChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Bar` component */\n barProps?:\n | ((series: BarChartSeries) => Partial<Omit<BarProps, 'ref'>>)\n | Partial<Omit<BarProps, 'ref'>>;\n\n /** Determines whether a label with bar value should be displayed on top of each bar, incompatible with `type=\"stacked\"` and `type=\"percent\"` @default false */\n withBarValueLabel?: boolean;\n\n /** Props passed down to recharts `LabelList` component */\n valueLabelProps?:\n | ((series: BarChartSeries) => Partial<Omit<LabelListProps, 'ref'>>)\n | Partial<LabelListProps>;\n\n /** Sets minimum height of the bar in px @default 0 */\n minBarSize?: number;\n\n /** Maximum bar width in px */\n maxBarWidth?: number;\n\n /** Controls color of the bar label, by default the value is determined by the chart orientation */\n barLabelColor?: MantineColor;\n\n /** A function to assign dynamic bar color based on its value */\n getBarColor?: (value: number, series: BarChartSeries) => MantineColor;\n}\n\nexport type BarChartFactory = Factory<{\n props: BarChartProps;\n ref: HTMLDivElement;\n stylesNames: BarChartStylesNames;\n vars: BarChartCssVariables;\n}>;\n\nconst defaultProps = {\n withXAxis: true,\n withYAxis: true,\n withTooltip: true,\n tooltipAnimationDuration: 0,\n fillOpacity: 1,\n tickLine: 'y',\n strokeDasharray: '5 5',\n gridAxis: 'x',\n type: 'default',\n} satisfies Partial<BarChartProps>;\n\nconst varsResolver = createVarsResolver<BarChartFactory>(\n (theme, { textColor, gridColor, cursorFill, barLabelColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n '--chart-cursor-fill': cursorFill ? getThemeColor(cursorFill, theme) : undefined,\n '--chart-bar-label-color': barLabelColor ? getThemeColor(barLabelColor, theme) : undefined,\n },\n })\n);\n\nfunction calculateCumulativeTotal(waterfallData: Record<string, any>[], dataKey: string) {\n let start: number = 0;\n let end: number = 0;\n return waterfallData.map((item) => {\n if (item.standalone) {\n for (const prop in item) {\n if (typeof item[prop] === 'number' && prop !== dataKey) {\n item[prop] = [0, item[prop]];\n }\n }\n } else {\n for (const prop in item) {\n if (typeof item[prop] === 'number' && prop !== dataKey) {\n end += item[prop];\n item[prop] = [start, end];\n start = end;\n }\n }\n }\n return item;\n });\n}\n\nfunction getBarFill(barProps: BarChartProps['barProps'], series: BarChartSeries) {\n if (typeof barProps === 'function') {\n return barProps(series).fill;\n }\n\n return barProps?.fill;\n}\n\nexport const BarChart = factory<BarChartFactory>((_props) => {\n const props = useProps('BarChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withLegend,\n legendProps,\n series,\n onMouseLeave,\n dataKey,\n withTooltip,\n withXAxis,\n withYAxis,\n gridAxis,\n tickLine,\n xAxisProps,\n yAxisProps,\n unit,\n tooltipAnimationDuration,\n strokeDasharray,\n gridProps,\n tooltipProps,\n referenceLines,\n fillOpacity,\n barChartProps,\n type,\n orientation,\n dir,\n valueFormatter,\n children,\n barProps,\n xAxisLabel,\n yAxisLabel,\n withBarValueLabel,\n valueLabelProps,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n minBarSize,\n maxBarWidth,\n mod,\n getBarColor,\n gridColor,\n textColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const withXTickLine = gridAxis !== 'none' && (tickLine === 'x' || tickLine === 'xy');\n const withYTickLine = gridAxis !== 'none' && (tickLine === 'y' || tickLine === 'xy');\n const [highlightedArea, setHighlightedArea] = useState<string | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const stacked = type === 'stacked' || type === 'percent';\n const tickFormatter = type === 'percent' ? valueToPercent : valueFormatter;\n\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<BarChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const inputData = type === 'waterfall' ? calculateCumulativeTotal(data, dataKey) : data;\n\n const getStyles = useStyles<BarChartFactory>({\n name: 'BarChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const bars = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n\n return (\n <Bar\n {...getStyles('bar')}\n key={item.name}\n name={item.name}\n dataKey={item.name}\n fill={color}\n stroke={color}\n isAnimationActive={false}\n fillOpacity={dimmed ? 0.1 : fillOpacity}\n strokeOpacity={dimmed ? 0.2 : 0}\n stackId={stacked ? 'stack' : item.stackId || undefined}\n yAxisId={item.yAxisId || undefined}\n minPointSize={minBarSize}\n {...(typeof barProps === 'function' ? barProps(item) : barProps)}\n >\n {inputData.map((entry, index) => {\n const cellColor = entry.color\n ? getThemeColor(entry.color, theme)\n : typeof getBarColor === 'function'\n ? getThemeColor(getBarColor(entry[item.name], item), theme)\n : getBarFill(barProps, item) || color;\n\n return <Cell key={`cell-${index}`} fill={cellColor} />;\n })}\n {withBarValueLabel && (\n <LabelList\n position={orientation === 'vertical' ? 'right' : 'top'}\n fontSize={12}\n fill=\"var(--chart-bar-label-color, var(--mantine-color-dimmed))\"\n formatter={(val: any) => tickFormatter?.(val as any)}\n {...(typeof valueLabelProps === 'function' ? valueLabelProps(item) : valueLabelProps)}\n />\n )}\n </Bar>\n );\n });\n\n const referenceLinesItems = referenceLines?.map((line, index) => {\n const color = getThemeColor(line.color, theme);\n return (\n <ReferenceLine\n key={index}\n stroke={line.color ? color : 'var(--chart-grid-color)'}\n strokeWidth={1}\n yAxisId={line.yAxisId || undefined}\n {...line}\n label={{\n value: line.label,\n fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n }}\n {...getStyles('referenceLine')}\n />\n );\n });\n\n const sharedYAxisProps = {\n axisLine: false,\n ...(orientation === 'vertical'\n ? { dataKey, type: 'category' as const }\n : { type: 'number' as const }),\n tickLine: withYTickLine ? { stroke: 'currentColor' } : false,\n allowDecimals: true,\n unit,\n tickFormatter: orientation === 'vertical' ? undefined : tickFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box\n {...getStyles('root')}\n onMouseLeave={handleMouseLeave}\n dir={dir || 'ltr'}\n mod={[{ orientation }, mod]}\n {...others}\n >\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsBarChart\n data={inputData}\n stackOffset={type === 'percent' ? 'expand' : undefined}\n layout={orientation}\n maxBarSize={maxBarWidth}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n {...barChartProps}\n >\n {withLegend && (\n <Legend\n verticalAlign=\"top\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload}\n onHighlight={setHighlightedArea}\n legendPosition={legendProps?.verticalAlign || 'top'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n showColor={type !== 'waterfall'}\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n <XAxis\n hide={!withXAxis}\n {...(orientation === 'vertical' ? { type: 'number' } : { dataKey })}\n tick={{ transform: 'translate(0, 10)', fontSize: 12, fill: 'currentColor' }}\n stroke=\"\"\n interval=\"preserveStartEnd\"\n tickLine={withXTickLine ? { stroke: 'currentColor' } : false}\n minTickGap={5}\n tickFormatter={orientation === 'vertical' ? tickFormatter : undefined}\n {...getStyles('axis')}\n {...xAxisProps}\n >\n {xAxisLabel && (\n <Label position=\"insideBottom\" offset={-20} fontSize={12} {...getStyles('axisLabel')}>\n {xAxisLabel}\n </Label>\n )}\n {xAxisProps?.children}\n </XAxis>\n\n <YAxis\n orientation=\"left\"\n tick={{ transform: 'translate(-10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withYAxis}\n {...sharedYAxisProps}\n {...yAxisProps}\n >\n {yAxisLabel && (\n <Label\n position=\"insideLeft\"\n angle={-90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {yAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <YAxis\n yAxisId=\"right\"\n orientation=\"right\"\n tick={{ transform: 'translate(10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withRightYAxis}\n {...sharedYAxisProps}\n {...rightYAxisProps}\n >\n {rightYAxisLabel && (\n <Label\n position=\"insideRight\"\n angle={90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {rightYAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <CartesianGrid\n strokeDasharray={strokeDasharray as string}\n vertical={gridAxis === 'y' || gridAxis === 'xy'}\n horizontal={gridAxis === 'x' || gridAxis === 'xy'}\n {...getStyles('grid')}\n {...gridProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={tooltipAnimationDuration !== 0}\n position={orientation === 'vertical' ? {} : { y: 0 }}\n cursor={{\n stroke: 'var(--chart-grid-color)',\n strokeWidth: 1,\n strokeDasharray,\n fill: 'var(--chart-cursor-fill)',\n }}\n content={({ label, payload, labelFormatter }) => (\n <ChartTooltip\n label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n payload={payload}\n type={type === 'waterfall' ? 'scatter' : undefined}\n unit={unit}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {bars}\n {referenceLinesItems}\n {children}\n </ReChartsBarChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nBarChart.displayName = '@mantine/charts/BarChart';\nBarChart.classes = classes;\nBarChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;;AAqCA,SAAS,eAAe,OAAe;AACrC,QAAO,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;;AA+ErC,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,aAAa;CACb,0BAA0B;CAC1B,aAAa;CACb,UAAU;CACV,iBAAiB;CACjB,UAAU;CACV,MAAM;CACP;AAED,MAAM,gBAAA,GAAA,cAAA,qBACH,OAAO,EAAE,WAAW,WAAW,YAAY,qBAAqB,EAC/D,MAAM;CACJ,sBAAsB,aAAA,GAAA,cAAA,eAA0B,WAAW,MAAM,GAAG,KAAA;CACpE,sBAAsB,aAAA,GAAA,cAAA,eAA0B,WAAW,MAAM,GAAG,KAAA;CACpE,uBAAuB,cAAA,GAAA,cAAA,eAA2B,YAAY,MAAM,GAAG,KAAA;CACvE,2BAA2B,iBAAA,GAAA,cAAA,eAA8B,eAAe,MAAM,GAAG,KAAA;CAClF,EACF,EACF;AAED,SAAS,yBAAyB,eAAsC,SAAiB;CACvF,IAAI,QAAgB;CACpB,IAAI,MAAc;AAClB,QAAO,cAAc,KAAK,SAAS;AACjC,MAAI,KAAK;QACF,MAAM,QAAQ,KACjB,KAAI,OAAO,KAAK,UAAU,YAAY,SAAS,QAC7C,MAAK,QAAQ,CAAC,GAAG,KAAK,MAAM;QAIhC,MAAK,MAAM,QAAQ,KACjB,KAAI,OAAO,KAAK,UAAU,YAAY,SAAS,SAAS;AACtD,UAAO,KAAK;AACZ,QAAK,Q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mBAAmB;MACnB,mBAAmB,6BAA6B;MAChD,UAAU,gBAAgB,aAAa,EAAE,GAAG,EAAE,GAAG,GAAG;MACpD,QAAQ;OACN,QAAQ;OACR,aAAa;OACb;OACA,MAAM;OACP;MACD,UAAU,EAAE,OAAO,SAAS,qBAC1B,iBAAA,GAAA,kBAAA,KAACC,qBAAAA,cAAD;OACE,OAAO,kBAAkB,UAAU,eAAe,OAAO,QAAQ,GAAG;OAC3D;OACT,MAAM,SAAS,cAAc,YAAY,KAAA;OACnC;OACN,YAAY;OACZ,QAAQ;OACA;OACQ;OACJ;OACZ,CAAA;MAEJ,GAAI;MACJ,CAAA;KAGH;KACA;KACA;KACgB;;GACC,CAAA;EAClB,CAAA;EAER;AAEF,SAAS,cAAc;AACvB,SAAS,UAAUC,0BAAAA;AACnB,SAAS,eAAe"}
|
|
1
|
+
{"version":3,"file":"BarChart.cjs","names":["Bar","React","Rectangle","LabelList","ReferenceLine","Box","ResponsiveContainer","ReChartsBarChart","Legend","ChartLegend","XAxis","Label","YAxis","CartesianGrid","Tooltip","ChartTooltip","classes"],"sources":["../../src/BarChart/BarChart.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport {\n Bar,\n BarProps,\n BarShapeProps,\n CartesianGrid,\n Label,\n LabelList,\n LabelListProps,\n Legend,\n BarChart as ReChartsBarChart,\n Rectangle,\n ReferenceLine,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport type { BaseChartStylesNames, ChartSeries, GridChartBaseProps } from '../types';\nimport classes from '../grid-chart.module.css';\n\nfunction valueToPercent(value: number) {\n return `${(value * 100).toFixed(0)}%`;\n}\n\nexport interface BarChartSeries extends ChartSeries {\n stackId?: string;\n}\n\nexport type BarChartType = 'default' | 'stacked' | 'percent' | 'waterfall';\n\nexport type BarChartStylesNames =\n | 'bar'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type BarChartCssVariables = {\n root:\n | '--chart-text-color'\n | '--chart-grid-color'\n | '--chart-cursor-fill'\n | '--chart-bar-label-color';\n};\n\nexport interface BarChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<BarChartFactory>, ElementProps<'div'> {\n /** Data used to display chart. */\n data: Record<string, any>[];\n\n /** An array of objects with `name` and `color` keys. Determines which data should be consumed from the `data` array. */\n series: BarChartSeries[];\n\n /** Controls how bars are positioned relative to each other @default 'default' */\n type?: BarChartType;\n\n /** Controls fill opacity of all bars @default 1 */\n fillOpacity?: number;\n\n /** Fill of hovered bar section, by default value is based on color scheme */\n cursorFill?: MantineColor;\n\n /** Props passed down to recharts `BarChart` component */\n barChartProps?: React.ComponentProps<typeof ReChartsBarChart>;\n\n /** Additional components that are rendered inside recharts `BarChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Bar` component */\n barProps?:\n | ((series: BarChartSeries) => Partial<Omit<BarProps, 'ref'>>)\n | Partial<Omit<BarProps, 'ref'>>;\n\n /** Determines whether a label with bar value should be displayed on top of each bar, incompatible with `type=\"stacked\"` and `type=\"percent\"` @default false */\n withBarValueLabel?: boolean;\n\n /** Props passed down to recharts `LabelList` component */\n valueLabelProps?:\n | ((series: BarChartSeries) => Partial<Omit<LabelListProps, 'ref'>>)\n | Partial<LabelListProps>;\n\n /** Sets minimum height of the bar in px @default 0 */\n minBarSize?: number;\n\n /** Maximum bar width in px */\n maxBarWidth?: number;\n\n /** Controls color of the bar label, by default the value is determined by the chart orientation */\n barLabelColor?: MantineColor;\n\n /** A function to assign dynamic bar color based on its value */\n getBarColor?: (value: number, series: BarChartSeries) => MantineColor;\n}\n\nexport type BarChartFactory = Factory<{\n props: BarChartProps;\n ref: HTMLDivElement;\n stylesNames: BarChartStylesNames;\n vars: BarChartCssVariables;\n}>;\n\nconst defaultProps = {\n withXAxis: true,\n withYAxis: true,\n withTooltip: true,\n tooltipAnimationDuration: 0,\n fillOpacity: 1,\n tickLine: 'y',\n strokeDasharray: '5 5',\n gridAxis: 'x',\n type: 'default',\n} satisfies Partial<BarChartProps>;\n\nconst varsResolver = createVarsResolver<BarChartFactory>(\n (theme, { textColor, gridColor, cursorFill, barLabelColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n '--chart-cursor-fill': cursorFill ? getThemeColor(cursorFill, theme) : undefined,\n '--chart-bar-label-color': barLabelColor ? getThemeColor(barLabelColor, theme) : undefined,\n },\n })\n);\n\nfunction calculateCumulativeTotal(waterfallData: Record<string, any>[], dataKey: string) {\n let start: number = 0;\n let end: number = 0;\n return waterfallData.map((item) => {\n if (item.standalone) {\n for (const prop in item) {\n if (typeof item[prop] === 'number' && prop !== dataKey) {\n item[prop] = [0, item[prop]];\n }\n }\n } else {\n for (const prop in item) {\n if (typeof item[prop] === 'number' && prop !== dataKey) {\n end += item[prop];\n item[prop] = [start, end];\n start = end;\n }\n }\n }\n return item;\n });\n}\n\nfunction getBarFill(barProps: BarChartProps['barProps'], series: BarChartSeries) {\n if (typeof barProps === 'function') {\n return barProps(series).fill;\n }\n\n return barProps?.fill;\n}\n\nexport const BarChart = factory<BarChartFactory>((_props) => {\n const props = useProps('BarChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withLegend,\n legendProps,\n series,\n onMouseLeave,\n dataKey,\n withTooltip,\n withXAxis,\n withYAxis,\n gridAxis,\n tickLine,\n xAxisProps,\n yAxisProps,\n unit,\n tooltipAnimationDuration,\n strokeDasharray,\n gridProps,\n tooltipProps,\n referenceLines,\n fillOpacity,\n barChartProps,\n type,\n orientation,\n dir,\n valueFormatter,\n children,\n barProps,\n xAxisLabel,\n yAxisLabel,\n withBarValueLabel,\n valueLabelProps,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n minBarSize,\n maxBarWidth,\n mod,\n getBarColor,\n gridColor,\n textColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const withXTickLine = gridAxis !== 'none' && (tickLine === 'x' || tickLine === 'xy');\n const withYTickLine = gridAxis !== 'none' && (tickLine === 'y' || tickLine === 'xy');\n const [highlightedArea, setHighlightedArea] = useState<string | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const stacked = type === 'stacked' || type === 'percent';\n const tickFormatter = type === 'percent' ? valueToPercent : valueFormatter;\n\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<BarChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const inputData = type === 'waterfall' ? calculateCumulativeTotal(data, dataKey) : data;\n\n const getStyles = useStyles<BarChartFactory>({\n name: 'BarChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const bars = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n const resolvedBarProps = typeof barProps === 'function' ? barProps(item) : barProps;\n const userShape = resolvedBarProps?.shape;\n\n return (\n <Bar\n {...getStyles('bar')}\n key={item.name}\n name={item.name}\n dataKey={item.name}\n fill={color}\n stroke={color}\n isAnimationActive={false}\n fillOpacity={dimmed ? 0.1 : fillOpacity}\n strokeOpacity={dimmed ? 0.2 : 0}\n stackId={stacked ? 'stack' : item.stackId || undefined}\n yAxisId={item.yAxisId || undefined}\n minPointSize={minBarSize}\n {...resolvedBarProps}\n shape={(shapeProps: BarShapeProps) => {\n const entry = shapeProps.payload;\n const cellColor = entry?.color\n ? getThemeColor(entry.color, theme)\n : typeof getBarColor === 'function'\n ? getThemeColor(getBarColor(entry?.[item.name], item), theme)\n : getBarFill(barProps, item) || color;\n const coloredProps = { ...shapeProps, fill: cellColor };\n if (typeof userShape === 'function') {\n return (userShape as (props: BarShapeProps) => React.ReactElement)(coloredProps);\n }\n if (React.isValidElement(userShape)) {\n return React.cloneElement(userShape, coloredProps as any);\n }\n if (typeof userShape === 'object' && userShape) {\n return <Rectangle {...coloredProps} {...(userShape as any)} />;\n }\n return <Rectangle {...coloredProps} />;\n }}\n >\n {withBarValueLabel && (\n <LabelList\n position={orientation === 'vertical' ? 'right' : 'top'}\n fontSize={12}\n fill=\"var(--chart-bar-label-color, var(--mantine-color-dimmed))\"\n formatter={(val: any) => tickFormatter?.(val as any)}\n {...(typeof valueLabelProps === 'function' ? valueLabelProps(item) : valueLabelProps)}\n />\n )}\n </Bar>\n );\n });\n\n const referenceLinesItems = referenceLines?.map((line, index) => {\n const color = getThemeColor(line.color, theme);\n return (\n <ReferenceLine\n key={index}\n stroke={line.color ? color : 'var(--chart-grid-color)'}\n strokeWidth={1}\n yAxisId={line.yAxisId || undefined}\n {...line}\n label={{\n value: line.label,\n fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n }}\n {...getStyles('referenceLine')}\n />\n );\n });\n\n const sharedYAxisProps = {\n axisLine: false,\n ...(orientation === 'vertical'\n ? { dataKey, type: 'category' as const }\n : { type: 'number' as const }),\n tickLine: withYTickLine ? { stroke: 'currentColor' } : false,\n allowDecimals: true,\n unit,\n tickFormatter: orientation === 'vertical' ? undefined : tickFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box\n {...getStyles('root')}\n onMouseLeave={handleMouseLeave}\n dir={dir || 'ltr'}\n mod={[{ orientation }, mod]}\n {...others}\n >\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsBarChart\n data={inputData}\n stackOffset={type === 'percent' ? 'expand' : undefined}\n layout={orientation}\n maxBarSize={maxBarWidth}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n {...barChartProps}\n >\n {withLegend && (\n <Legend\n verticalAlign=\"top\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload}\n onHighlight={setHighlightedArea}\n legendPosition={legendProps?.verticalAlign || 'top'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n showColor={type !== 'waterfall'}\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n <XAxis\n hide={!withXAxis}\n {...(orientation === 'vertical' ? { type: 'number' } : { dataKey })}\n tick={{ transform: 'translate(0, 10)', fontSize: 12, fill: 'currentColor' }}\n stroke=\"\"\n interval=\"preserveStartEnd\"\n tickLine={withXTickLine ? { stroke: 'currentColor' } : false}\n minTickGap={5}\n tickFormatter={orientation === 'vertical' ? tickFormatter : undefined}\n {...getStyles('axis')}\n {...xAxisProps}\n >\n {xAxisLabel && (\n <Label position=\"insideBottom\" offset={-20} fontSize={12} {...getStyles('axisLabel')}>\n {xAxisLabel}\n </Label>\n )}\n {xAxisProps?.children}\n </XAxis>\n\n <YAxis\n orientation=\"left\"\n tick={{ transform: 'translate(-10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withYAxis}\n {...sharedYAxisProps}\n {...yAxisProps}\n >\n {yAxisLabel && (\n <Label\n position=\"insideLeft\"\n angle={-90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {yAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <YAxis\n yAxisId=\"right\"\n orientation=\"right\"\n tick={{ transform: 'translate(10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withRightYAxis}\n {...sharedYAxisProps}\n {...rightYAxisProps}\n >\n {rightYAxisLabel && (\n <Label\n position=\"insideRight\"\n angle={90}\n textAnchor=\"middle\"\n fontSize={12}\n offset={-5}\n {...getStyles('axisLabel')}\n >\n {rightYAxisLabel}\n </Label>\n )}\n {yAxisProps?.children}\n </YAxis>\n\n <CartesianGrid\n strokeDasharray={strokeDasharray as string}\n vertical={gridAxis === 'y' || gridAxis === 'xy'}\n horizontal={gridAxis === 'x' || gridAxis === 'xy'}\n {...getStyles('grid')}\n {...gridProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={tooltipAnimationDuration !== 0}\n position={orientation === 'vertical' ? {} : { y: 0 }}\n cursor={{\n stroke: 'var(--chart-grid-color)',\n strokeWidth: 1,\n strokeDasharray,\n fill: 'var(--chart-cursor-fill)',\n }}\n content={({ label, payload, labelFormatter }) => (\n <ChartTooltip\n label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n payload={payload}\n type={type === 'waterfall' ? 'scatter' : undefined}\n unit={unit}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n series={series}\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {bars}\n {referenceLinesItems}\n {children}\n </ReChartsBarChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nBarChart.displayName = '@mantine/charts/BarChart';\nBarChart.classes = classes;\nBarChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;;;;;AAsCA,SAAS,eAAe,OAAe;AACrC,QAAO,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;;AA+ErC,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,aAAa;CACb,0BAA0B;CAC1B,aAAa;CACb,UAAU;CACV,iBAAiB;CACjB,UAAU;CACV,MAAM;CACP;AAED,MAAM,gBAAA,GAAA,cAAA,qBACH,OAAO,EAAE,WAAW,WAAW,YAAY,qBAAqB,EAC/D,MAAM;CACJ,sBAAsB,aAAA,GAAA,cAAA,eAA0B,WAAW,MAAM,GAAG,KAAA;CACpE,sBAAsB,aAAA,GAAA,cAAA,eAA0B,WAAW,MAA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J,GAAI;MACJ,CAAA;KAGH;KACA;KACA;KACgB;;GACC,CAAA;EAClB,CAAA;EAER;AAEF,SAAS,cAAc;AACvB,SAAS,UAAUC,0BAAAA;AACnB,SAAS,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarsList.cjs","names":["Box","classes"],"sources":["../../src/BarsList/BarsList.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getSpacing,\n getThemeColor,\n MantineColor,\n MantineSpacing,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from './BarsList.module.css';\n\nexport type BarsListStylesNames = 'root' | 'bar' | 'barLabel' | 'barValue' | 'labelsRow';\n\nexport type BarsListCssVariables = {\n root: '--bars-list-gap' | '--bars-list-min-bar-size' | '--bars-list-bar-height';\n};\n\nexport interface BarsListBarData {\n /** Name of the bar, displayed inside the bar */\n name: string;\n\n /** Numeric value of the bar */\n value: number;\n\n /** Bar background color */\n color?: MantineColor;\n\n /** Bar text color, overrides barTextColor and autoContrast for this specific bar */\n textColor?: MantineColor;\n\n /** Bar variant, used to calculate text color when autoContrast is enabled */\n variant?: 'light' | 'filled';\n}\n\nexport interface BarsListProps\n extends BoxProps, StylesApiProps<BarsListFactory>, ElementProps<'div'> {\n /** Data for bars */\n data: BarsListBarData[];\n\n /** Function to format value display */\n valueFormatter?: (value: number) => string;\n\n /** Label displayed above the bars column */\n barsLabel?: string;\n\n /** Label displayed above the values column */\n valueLabel?: string;\n\n /** Function to pass props down to the bar depending on the bar data payload */\n getBarProps?: (data: BarsListBarData) => React.ComponentProps<'div'>;\n\n /** Function to completely customize bar rendering */\n renderBar?: (data: BarsListBarData, defaultBar: React.ReactNode) => React.ReactNode;\n\n /** Controls gap between bars @default 5 */\n barGap?: MantineSpacing;\n\n /** Minimum bar width @default 100 */\n minBarSize?: number | string;\n\n /** Bar height @default 32 */\n barHeight?: number | string;\n\n /** Default bar background color, used when item does not have color specified */\n barColor?: MantineColor;\n\n /** Bar text color, overrides autoContrast */\n barTextColor?: MantineColor;\n\n /** If set, adjusts text color based on background color */\n autoContrast?: boolean;\n}\n\nexport type BarsListFactory = Factory<{\n props: BarsListProps;\n ref: HTMLDivElement;\n stylesNames: BarsListStylesNames;\n vars: BarsListCssVariables;\n}>;\n\nconst defaultProps = {\n barGap: 5,\n minBarSize: 0,\n barHeight: 32,\n} satisfies Partial<BarsListProps>;\n\nconst varsResolver = createVarsResolver<BarsListFactory>(\n (_theme, { barGap, minBarSize, barHeight }) => ({\n root: {\n '--bars-list-gap': getSpacing(barGap),\n '--bars-list-min-bar-size': rem(minBarSize),\n '--bars-list-bar-height': rem(barHeight),\n },\n })\n);\n\nexport const BarsList = factory<BarsListFactory>((_props) => {\n const props = useProps('BarsList', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n data,\n valueFormatter,\n barsLabel,\n valueLabel,\n getBarProps,\n renderBar,\n barGap,\n minBarSize,\n barHeight,\n barColor,\n barTextColor,\n autoContrast,\n variant,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BarsListFactory>({\n name: 'BarsList',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const maxValue = useMemo(() => Math.max(...data.map((item) => item.value), 0), [data]);\n\n const formatValue = (value: number) => {\n if (valueFormatter) {\n return valueFormatter(value);\n }\n return value.toString();\n };\n\n const bars = data.map((item, index) => {\n const percentage = maxValue > 0 ? (item.value / maxValue) * 100 : 0;\n const barProps = getBarProps ? getBarProps(item) : {};\n const { style: barPropsStyle, className: barPropsClassName, ...restBarProps } = barProps;\n\n const itemBarColor = item.color || barColor || theme.primaryColor;\n const colors = theme.variantColorResolver({\n color: itemBarColor,\n theme,\n variant: item.variant || variant || 'light',\n autoContrast,\n });\n\n const backgroundColor = colors.background;\n\n const textColor =\n item.textColor || barTextColor\n ? getThemeColor(item.textColor || barTextColor, theme)\n : colors.color;\n\n const defaultBar = (\n <div key={index} {...getStyles('bar')}>\n <div\n {...getStyles('barLabel', {\n className: barPropsClassName,\n style: {\n width: `${percentage}%`,\n backgroundColor,\n color: textColor,\n padding: percentage === 0 ? 0 : undefined,\n ...barPropsStyle,\n },\n })}\n {...restBarProps}\n >\n {item.name}\n </div>\n <div {...getStyles('barValue')}>{formatValue(item.value)}</div>\n </div>\n );\n\n if (renderBar) {\n return <div key={index}>{renderBar(item, defaultBar)}</div>;\n }\n\n return defaultBar;\n });\n\n const labelsRow =\n barsLabel || valueLabel ? (\n <div {...getStyles('labelsRow')}>\n <div>{barsLabel}</div>\n <div>{valueLabel}</div>\n </div>\n ) : null;\n\n return (\n <Box {...getStyles('root')} variant={variant} {...others}>\n {labelsRow}\n {bars}\n </Box>\n );\n});\n\nBarsList.displayName = '@mantine/charts/BarsList';\nBarsList.classes = classes;\nBarsList.varsResolver = varsResolver;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BarsList.cjs","names":["Box","classes"],"sources":["../../src/BarsList/BarsList.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getSpacing,\n getThemeColor,\n MantineColor,\n MantineSpacing,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from './BarsList.module.css';\n\nexport type BarsListStylesNames = 'root' | 'bar' | 'barLabel' | 'barValue' | 'labelsRow';\n\nexport type BarsListCssVariables = {\n root: '--bars-list-gap' | '--bars-list-min-bar-size' | '--bars-list-bar-height';\n};\n\nexport interface BarsListBarData {\n /** Name of the bar, displayed inside the bar */\n name: string;\n\n /** Numeric value of the bar */\n value: number;\n\n /** Bar background color */\n color?: MantineColor;\n\n /** Bar text color, overrides barTextColor and autoContrast for this specific bar */\n textColor?: MantineColor;\n\n /** Bar variant, used to calculate text color when autoContrast is enabled */\n variant?: 'light' | 'filled';\n}\n\nexport interface BarsListProps\n extends BoxProps, StylesApiProps<BarsListFactory>, ElementProps<'div'> {\n /** Data for bars */\n data: BarsListBarData[];\n\n /** Function to format value display */\n valueFormatter?: (value: number) => string;\n\n /** Label displayed above the bars column */\n barsLabel?: string;\n\n /** Label displayed above the values column */\n valueLabel?: string;\n\n /** Function to pass props down to the bar depending on the bar data payload */\n getBarProps?: (data: BarsListBarData) => React.ComponentProps<'div'>;\n\n /** Function to completely customize bar rendering */\n renderBar?: (data: BarsListBarData, defaultBar: React.ReactNode) => React.ReactNode;\n\n /** Controls gap between bars @default 5 */\n barGap?: MantineSpacing;\n\n /** Minimum bar width @default 100 */\n minBarSize?: number | string;\n\n /** Bar height @default 32 */\n barHeight?: number | string;\n\n /** Default bar background color, used when item does not have color specified */\n barColor?: MantineColor;\n\n /** Bar text color, overrides autoContrast */\n barTextColor?: MantineColor;\n\n /** If set, adjusts text color based on background color */\n autoContrast?: boolean;\n}\n\nexport type BarsListFactory = Factory<{\n props: BarsListProps;\n ref: HTMLDivElement;\n stylesNames: BarsListStylesNames;\n vars: BarsListCssVariables;\n}>;\n\nconst defaultProps = {\n barGap: 5,\n minBarSize: 0,\n barHeight: 32,\n} satisfies Partial<BarsListProps>;\n\nconst varsResolver = createVarsResolver<BarsListFactory>(\n (_theme, { barGap, minBarSize, barHeight }) => ({\n root: {\n '--bars-list-gap': getSpacing(barGap),\n '--bars-list-min-bar-size': rem(minBarSize),\n '--bars-list-bar-height': rem(barHeight),\n },\n })\n);\n\nexport const BarsList = factory<BarsListFactory>((_props) => {\n const props = useProps('BarsList', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n data,\n valueFormatter,\n barsLabel,\n valueLabel,\n getBarProps,\n renderBar,\n barGap,\n minBarSize,\n barHeight,\n barColor,\n barTextColor,\n autoContrast,\n variant,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BarsListFactory>({\n name: 'BarsList',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const maxValue = useMemo(() => Math.max(...data.map((item) => item.value), 0), [data]);\n\n const formatValue = (value: number) => {\n if (valueFormatter) {\n return valueFormatter(value);\n }\n return value.toString();\n };\n\n const bars = data.map((item, index) => {\n const percentage = maxValue > 0 ? (item.value / maxValue) * 100 : 0;\n const barProps = getBarProps ? getBarProps(item) : {};\n const { style: barPropsStyle, className: barPropsClassName, ...restBarProps } = barProps;\n\n const itemBarColor = item.color || barColor || theme.primaryColor;\n const colors = theme.variantColorResolver({\n color: itemBarColor,\n theme,\n variant: item.variant || variant || 'light',\n autoContrast,\n });\n\n const backgroundColor = colors.background;\n\n const textColor =\n item.textColor || barTextColor\n ? getThemeColor(item.textColor || barTextColor, theme)\n : colors.color;\n\n const defaultBar = (\n <div key={index} {...getStyles('bar')}>\n <div\n {...getStyles('barLabel', {\n className: barPropsClassName,\n style: {\n width: `${percentage}%`,\n backgroundColor,\n color: textColor,\n padding: percentage === 0 ? 0 : undefined,\n ...barPropsStyle,\n },\n })}\n {...restBarProps}\n >\n {item.name}\n </div>\n <div {...getStyles('barValue')}>{formatValue(item.value)}</div>\n </div>\n );\n\n if (renderBar) {\n return <div key={index}>{renderBar(item, defaultBar)}</div>;\n }\n\n return defaultBar;\n });\n\n const labelsRow =\n barsLabel || valueLabel ? (\n <div {...getStyles('labelsRow')}>\n <div>{barsLabel}</div>\n <div>{valueLabel}</div>\n </div>\n ) : null;\n\n return (\n <Box {...getStyles('root')} variant={variant} {...others}>\n {labelsRow}\n {bars}\n </Box>\n );\n});\n\nBarsList.displayName = '@mantine/charts/BarsList';\nBarsList.classes = classes;\nBarsList.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAyFA,MAAM,eAAe;CACnB,QAAQ;CACR,YAAY;CACZ,WAAW;CACZ;AAED,MAAM,gBAAA,GAAA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AO;EAEb,MAAM,aACJ,iBAAA,GAAA,kBAAA,MAAC,OAAD;GAAiB,GAAI,UAAU,MAAM;aAArC,CACE,iBAAA,GAAA,kBAAA,KAAC,OAAD;IACE,GAAI,UAAU,YAAY;KACxB,WAAW;KACX,OAAO;MACL,OAAO,GAAG,WAAW;MACrB;MACA,OAAO;MACP,SAAS,eAAe,IAAI,IAAI,KAAA;MAChC,GAAG;MACJ;KACF,CAAC;IACF,GAAI;cAEH,KAAK;IACF,CAAA,EACN,iBAAA,GAAA,kBAAA,KAAC,OAAD;IAAK,GAAI,UAAU,WAAW;cAAG,YAAY,KAAK,MAAM;IAAO,CAAA,CAC3D;KAjBI,MAiBJ;AAGR,MAAI,UACF,QAAO,iBAAA,GAAA,kBAAA,KAAC,OAAD,EAAA,UAAkB,UAAU,MAAM,WAAW,EAAO,EAA1C,MAA0C;AAG7D,SAAO;GACP;CAEF,MAAM,YACJ,aAAa,aACX,iBAAA,GAAA,kBAAA,MAAC,OAAD;EAAK,GAAI,UAAU,YAAY;YAA/B,CACE,iBAAA,GAAA,kBAAA,KAAC,OAAD,EAAA,UAAM,WAAgB,CAAA,EACtB,iBAAA,GAAA,kBAAA,KAAC,OAAD,EAAA,UAAM,YAAiB,CAAA,CACnB;MACJ;AAEN,QACE,iBAAA,GAAA,kBAAA,MAACA,cAAAA,KAAD;EAAK,GAAI,UAAU,OAAO;EAAW;EAAS,GAAI;YAAlD,CACG,WACA,KACG;;EAER;AAEF,SAAS,cAAc;AACvB,SAAS,UAAUC,wBAAAA;AACnB,SAAS,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BubbleChart.cjs","names":["Group","Text","Box","ResponsiveContainer","ScatterChart","XAxis","YAxis","ZAxis","Tooltip","Scatter","classes"],"sources":["../../src/BubbleChart/BubbleChart.tsx"],"sourcesContent":["import {\n ResponsiveContainer,\n Scatter,\n ScatterChart,\n ScatterProps,\n Tooltip,\n TooltipProps,\n XAxis,\n XAxisProps,\n YAxis,\n YAxisProps,\n ZAxis,\n ZAxisProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n GetStylesApi,\n getThemeColor,\n Group,\n MantineColor,\n StylesApiProps,\n Text,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from '../grid-chart.module.css';\n\nfunction getDomain(data: Record<string, any>[], key: string) {\n const values = data.map((item) => item[key]);\n return [Math.min(...values), Math.max(...values)];\n}\n\ninterface BubbleChartTooltipProps {\n payload: any;\n active: boolean | undefined;\n getStyles: GetStylesApi<BubbleChartFactory>;\n valueFormatter?: (value: number) => string;\n dataKey: BubbleChartDataKey;\n}\n\nfunction BubbleChartTooltip({\n active,\n payload,\n getStyles,\n dataKey,\n valueFormatter,\n}: BubbleChartTooltipProps) {\n if (active && payload && payload.length) {\n const data = payload[0] && payload[0].payload;\n\n return (\n <div {...getStyles('tooltip')}>\n <Group justify=\"space-between\">\n <Text fz=\"sm\">{data[dataKey.x]}</Text>\n <Text fz=\"sm\">{valueFormatter ? valueFormatter(data[dataKey.z]) : data[dataKey.z]}</Text>\n </Group>\n </div>\n );\n }\n\n return null;\n}\n\nexport type BubbleChartStylesNames = 'root' | 'axis' | 'tooltip';\nexport type BubbleChartCssVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface BubbleChartDataKey {\n x: string;\n y: string;\n z: string;\n}\n\nexport interface BubbleChartProps\n extends BoxProps, StylesApiProps<BubbleChartFactory>, ElementProps<'div'> {\n /** Chart data */\n data: Record<string, any>[];\n\n /** Data keys for x, y and z axis */\n dataKey: BubbleChartDataKey;\n\n /** Z axis range */\n range: [number, number];\n\n /** Color of the chart items. Key of `theme.colors` or any valid CSS color. @default blue.6 */\n color?: MantineColor;\n\n /** Props passed down to the `XAxis` recharts component */\n xAxisProps?: Omit<XAxisProps, 'ref'>;\n\n /** Props passed down to the `YAxis` recharts component */\n yAxisProps?: Omit<YAxisProps, 'ref'>;\n\n /** Props passed down to the `ZAxis` recharts component */\n zAxisProps?: Omit<ZAxisProps, 'ref'>;\n\n /** Props passed down to the `Tooltip` component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to the `Scatter` component */\n scatterProps?: Partial<Omit<ScatterProps, 'ref'>>;\n\n /** Color of the text displayed inside the chart @default 'dimmed' */\n textColor?: MantineColor;\n\n /** Color of the grid and cursor lines, by default depends on color scheme */\n gridColor?: MantineColor;\n\n /** Chart label displayed next to the x axis */\n label?: string;\n\n /** Determines whether the tooltip should be displayed @default true */\n withTooltip?: boolean;\n\n /** Function to format z axis values */\n valueFormatter?: (value: number) => string;\n}\n\nexport type BubbleChartFactory = Factory<{\n props: BubbleChartProps;\n ref: HTMLDivElement;\n stylesNames: BubbleChartStylesNames;\n vars: BubbleChartCssVariables;\n}>;\n\nconst defaultProps = {\n color: 'blue.6',\n withTooltip: true,\n} satisfies Partial<BubbleChartProps>;\n\nconst varsResolver = createVarsResolver<BubbleChartFactory>((theme, { textColor, gridColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n },\n}));\n\nexport const BubbleChart = factory<BubbleChartFactory>((_props) => {\n const props = useProps('BubbleChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n xAxisProps,\n yAxisProps,\n zAxisProps,\n tooltipProps,\n scatterProps,\n color,\n label,\n withTooltip,\n dataKey,\n range,\n valueFormatter,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BubbleChartFactory>({\n name: 'BubbleChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const yAxisWidth = label ? undefined : { width: 0 };\n\n return (\n <Box {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ScatterChart>\n <XAxis\n type=\"category\"\n dataKey={dataKey.x}\n interval={0}\n tick={{ fontSize: 12, fill: 'currentColor' }}\n tickLine={{ transform: 'translate(0, -6)', stroke: 'currentColor' }}\n stroke=\"currentColor\"\n {...getStyles('axis')}\n {...xAxisProps}\n />\n\n <YAxis\n type=\"number\"\n dataKey={dataKey.y}\n height={10}\n {...yAxisWidth}\n tick={false}\n tickLine={false}\n axisLine={false}\n label={{ value: label, position: 'insideRight', fontSize: 12, fill: 'currentColor' }}\n {...getStyles('axis')}\n {...yAxisProps}\n />\n\n <ZAxis\n type=\"number\"\n dataKey={dataKey.z}\n domain={getDomain(data, dataKey.z)}\n range={range}\n {...zAxisProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={100}\n isAnimationActive={false}\n cursor={{ stroke: 'var(--chart-grid-color)', strokeWidth: 1, strokeDasharray: '3 3' }}\n content={(payload) => (\n <BubbleChartTooltip\n dataKey={dataKey}\n active={payload.active}\n payload={payload.payload}\n getStyles={getStyles}\n valueFormatter={valueFormatter}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n <Scatter\n data={data}\n fill={getThemeColor(color, theme)}\n isAnimationActive={false}\n {...scatterProps}\n />\n </ScatterChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nBubbleChart.displayName = '@mantine/charts/BubbleChart';\nBubbleChart.classes = classes;\nBubbleChart.varsResolver = varsResolver;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"BubbleChart.cjs","names":["Group","Text","Box","ResponsiveContainer","ScatterChart","XAxis","YAxis","ZAxis","Tooltip","Scatter","classes"],"sources":["../../src/BubbleChart/BubbleChart.tsx"],"sourcesContent":["import {\n ResponsiveContainer,\n Scatter,\n ScatterChart,\n ScatterProps,\n Tooltip,\n TooltipProps,\n XAxis,\n XAxisProps,\n YAxis,\n YAxisProps,\n ZAxis,\n ZAxisProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n GetStylesApi,\n getThemeColor,\n Group,\n MantineColor,\n StylesApiProps,\n Text,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from '../grid-chart.module.css';\n\nfunction getDomain(data: Record<string, any>[], key: string) {\n const values = data.map((item) => item[key]);\n return [Math.min(...values), Math.max(...values)];\n}\n\ninterface BubbleChartTooltipProps {\n payload: any;\n active: boolean | undefined;\n getStyles: GetStylesApi<BubbleChartFactory>;\n valueFormatter?: (value: number) => string;\n dataKey: BubbleChartDataKey;\n}\n\nfunction BubbleChartTooltip({\n active,\n payload,\n getStyles,\n dataKey,\n valueFormatter,\n}: BubbleChartTooltipProps) {\n if (active && payload && payload.length) {\n const data = payload[0] && payload[0].payload;\n\n return (\n <div {...getStyles('tooltip')}>\n <Group justify=\"space-between\">\n <Text fz=\"sm\">{data[dataKey.x]}</Text>\n <Text fz=\"sm\">{valueFormatter ? valueFormatter(data[dataKey.z]) : data[dataKey.z]}</Text>\n </Group>\n </div>\n );\n }\n\n return null;\n}\n\nexport type BubbleChartStylesNames = 'root' | 'axis' | 'tooltip';\nexport type BubbleChartCssVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface BubbleChartDataKey {\n x: string;\n y: string;\n z: string;\n}\n\nexport interface BubbleChartProps\n extends BoxProps, StylesApiProps<BubbleChartFactory>, ElementProps<'div'> {\n /** Chart data */\n data: Record<string, any>[];\n\n /** Data keys for x, y and z axis */\n dataKey: BubbleChartDataKey;\n\n /** Z axis range */\n range: [number, number];\n\n /** Color of the chart items. Key of `theme.colors` or any valid CSS color. @default blue.6 */\n color?: MantineColor;\n\n /** Props passed down to the `XAxis` recharts component */\n xAxisProps?: Omit<XAxisProps, 'ref'>;\n\n /** Props passed down to the `YAxis` recharts component */\n yAxisProps?: Omit<YAxisProps, 'ref'>;\n\n /** Props passed down to the `ZAxis` recharts component */\n zAxisProps?: Omit<ZAxisProps, 'ref'>;\n\n /** Props passed down to the `Tooltip` component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to the `Scatter` component */\n scatterProps?: Partial<Omit<ScatterProps, 'ref'>>;\n\n /** Color of the text displayed inside the chart @default 'dimmed' */\n textColor?: MantineColor;\n\n /** Color of the grid and cursor lines, by default depends on color scheme */\n gridColor?: MantineColor;\n\n /** Chart label displayed next to the x axis */\n label?: string;\n\n /** Determines whether the tooltip should be displayed @default true */\n withTooltip?: boolean;\n\n /** Function to format z axis values */\n valueFormatter?: (value: number) => string;\n}\n\nexport type BubbleChartFactory = Factory<{\n props: BubbleChartProps;\n ref: HTMLDivElement;\n stylesNames: BubbleChartStylesNames;\n vars: BubbleChartCssVariables;\n}>;\n\nconst defaultProps = {\n color: 'blue.6',\n withTooltip: true,\n} satisfies Partial<BubbleChartProps>;\n\nconst varsResolver = createVarsResolver<BubbleChartFactory>((theme, { textColor, gridColor }) => ({\n root: {\n '--chart-text-color': textColor ? getThemeColor(textColor, theme) : undefined,\n '--chart-grid-color': gridColor ? getThemeColor(gridColor, theme) : undefined,\n },\n}));\n\nexport const BubbleChart = factory<BubbleChartFactory>((_props) => {\n const props = useProps('BubbleChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n xAxisProps,\n yAxisProps,\n zAxisProps,\n tooltipProps,\n scatterProps,\n color,\n label,\n withTooltip,\n dataKey,\n range,\n valueFormatter,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BubbleChartFactory>({\n name: 'BubbleChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const yAxisWidth = label ? undefined : { width: 0 };\n\n return (\n <Box {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ScatterChart>\n <XAxis\n type=\"category\"\n dataKey={dataKey.x}\n interval={0}\n tick={{ fontSize: 12, fill: 'currentColor' }}\n tickLine={{ transform: 'translate(0, -6)', stroke: 'currentColor' }}\n stroke=\"currentColor\"\n {...getStyles('axis')}\n {...xAxisProps}\n />\n\n <YAxis\n type=\"number\"\n dataKey={dataKey.y}\n height={10}\n {...yAxisWidth}\n tick={false}\n tickLine={false}\n axisLine={false}\n label={{ value: label, position: 'insideRight', fontSize: 12, fill: 'currentColor' }}\n {...getStyles('axis')}\n {...yAxisProps}\n />\n\n <ZAxis\n type=\"number\"\n dataKey={dataKey.z}\n domain={getDomain(data, dataKey.z)}\n range={range}\n {...zAxisProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={100}\n isAnimationActive={false}\n cursor={{ stroke: 'var(--chart-grid-color)', strokeWidth: 1, strokeDasharray: '3 3' }}\n content={(payload) => (\n <BubbleChartTooltip\n dataKey={dataKey}\n active={payload.active}\n payload={payload.payload}\n getStyles={getStyles}\n valueFormatter={valueFormatter}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n <Scatter\n data={data}\n fill={getThemeColor(color, theme)}\n isAnimationActive={false}\n {...scatterProps}\n />\n </ScatterChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nBubbleChart.displayName = '@mantine/charts/BubbleChart';\nBubbleChart.classes = classes;\nBubbleChart.varsResolver = varsResolver;\n"],"mappings":";;;;;;;AAiCA,SAAS,UAAU,MAA6B,KAAa;CAC3D,MAAM,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK;AAC5C,QAAO,CAAC,KAAK,IAAI,GAAG,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC;;AAWnD,SAAS,mBAAmB,EAC1B,QACA,SACA,WACA,SACA,kBAC0B;AAC1B,KAAI,UAAU,WAAW,QAAQ,QAAQ;EACvC,MAAM,OAAO,QAAQ,MAAM,QAAQ,GAAG;AAEtC,SACE,iBAAA,GAAA,kBAAA,KAAC,OAAD;GAAK,GAAI,UAAU,UAAU;aAC3B,iBAAA,GAAA,kBAAA,MAACA,cAAAA,OAAD;IAAO,SAAQ;cAAf,CACE,iBAAA,GAAA,kBAAA,KAACC,cAAAA,MAAD;KAAM,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;IAC5C,UAAU;KAAE,WAAW;KAAoB,QAAQ;KAAgB;IACnE,QAAO;IACP,GAAI,UAAU,OAAO;IACrB,GAAI;IACJ,CAAA;GAEF,iBAAA,GAAA,kBAAA,KAACC,SAAAA,OAAD;IACE,MAAK;IACL,SAAS,QAAQ;IACjB,QAAQ;IACR,GAAI;IACJ,MAAM;IACN,UAAU;IACV,UAAU;IACV,OAAO;KAAE,OAAO;KAAO,UAAU;KAAe,UAAU;KAAI,MAAM;KAAgB;IACpF,GAAI,UAAU,OAAO;IACrB,GAAI;IACJ,CAAA;GAEF,iBAAA,GAAA,kBAAA,KAACC,SAAAA,OAAD;IACE,MAAK;IACL,SAAS,QAAQ;IACjB,QAAQ,UAAU,MAAM,QAAQ,EAAE;IAC3B;IACP,GAAI;IACJ,CAAA;GAED,eACC,iBAAA,GAAA,kBAAA,KAACC,SAAAA,SAAD;IACE,mBAAmB;IACnB,mBAAmB;IACnB,QAAQ;KAAE,QAAQ;KAA2B,aAAa;KAAG,iBAAiB;KAAO;IACrF,UAAU,YACR,iBAAA,GAAA,kBAAA,KAAC,oBAAD;KACW;KACT,QAAQ,QAAQ;KAChB,SAAS,QAAQ;KACN;KACK;KAChB,CAAA;IAEJ,GAAI;IACJ,CAAA;GAGJ,iBAAA,GAAA,kBAAA,KAACC,SAAAA,SAAD;IACQ;IACN,OAAA,GAAA,cAAA,eAAoB,OAAO,MAAM;IACjC,mBAAmB;IACnB,GAAI;IACJ,CAAA;GACW,EAAA,CAAA,EACK,CAAA;EAClB,CAAA;EAER;AAEF,YAAY,cAAc;AAC1B,YAAY,UAAUC,0BAAAA;AACtB,YAAY,eAAe"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_get_series_labels = require("../utils/get-series-labels/get-series-labels.cjs");
|
|
3
4
|
const require_ChartLegend_module = require("./ChartLegend.module.cjs");
|
|
4
5
|
let _mantine_core = require("@mantine/core");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartLegend.cjs","names":["getSeriesLabels","ColorSwatch","Box","classes"],"sources":["../../src/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ColorSwatch,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartLegend.module.css';\n\nfunction updateChartLegendPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n const newDataKey = item.dataKey?.split('.').pop();\n return {\n ...item,\n dataKey: newDataKey,\n payload: {\n ...item.payload,\n name: newDataKey,\n dataKey: newDataKey,\n },\n };\n });\n}\n\nexport function getFilteredChartLegendPayload(payload: readonly Record<string, any>[]) {\n return updateChartLegendPayload(payload.filter((item) => item.color !== 'none'));\n}\n\nexport type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';\n\nexport interface ChartLegendProps\n extends BoxProps, StylesApiProps<ChartLegendFactory>, ElementProps<'div'> {\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | undefined;\n\n /** Function called when mouse enters/leaves one of the legend items */\n onHighlight: (area: string | null) => void;\n\n /** Position of the legend relative to the chart, used to apply margin on the corresponding side */\n legendPosition: 'top' | 'bottom' | 'middle';\n\n /** Data used for labels, only applicable for area charts: AreaChart, LineChart, BarChart */\n series?: ChartSeries[];\n\n /** Determines whether color swatch should be shown next to the label @default true */\n showColor?: boolean;\n\n /** Determines whether the legend should be centered @default false */\n centered?: boolean;\n}\n\nexport type ChartLegendFactory = Factory<{\n props: ChartLegendProps;\n ref: HTMLDivElement;\n stylesNames: ChartLegendStylesNames;\n}>;\n\nexport const ChartLegend = factory<ChartLegendFactory>((_props) => {\n const props = useProps('ChartLegend', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n onHighlight,\n legendPosition,\n mod,\n series,\n showColor,\n centered,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<ChartLegendFactory>({\n name: 'ChartLegend',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'legend',\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartLegendPayload(payload);\n const labels = getSeriesLabels(series);\n\n const items = filteredPayload.map((item, index) => (\n <div\n key={index}\n {...getStyles('legendItem')}\n onMouseEnter={() => onHighlight(item.dataKey)}\n onMouseLeave={() => onHighlight(null)}\n data-without-color={showColor === false || undefined}\n >\n <ColorSwatch\n color={item.color}\n size={12}\n {...getStyles('legendItemColor')}\n withShadow={false}\n />\n <p {...getStyles('legendItemName')}>{labels[item.dataKey] || item.dataKey}</p>\n </div>\n ));\n\n return (\n <Box mod={[{ position: legendPosition, centered }, mod]} {...getStyles('legend')} {...others}>\n {items}\n </Box>\n );\n});\n\nChartLegend.displayName = '@mantine/charts/ChartLegend';\nChartLegend.classes = classes;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChartLegend.cjs","names":["getSeriesLabels","ColorSwatch","Box","classes"],"sources":["../../src/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ColorSwatch,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartLegend.module.css';\n\nfunction updateChartLegendPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n const newDataKey = item.dataKey?.split('.').pop();\n return {\n ...item,\n dataKey: newDataKey,\n payload: {\n ...item.payload,\n name: newDataKey,\n dataKey: newDataKey,\n },\n };\n });\n}\n\nexport function getFilteredChartLegendPayload(payload: readonly Record<string, any>[]) {\n return updateChartLegendPayload(payload.filter((item) => item.color !== 'none'));\n}\n\nexport type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';\n\nexport interface ChartLegendProps\n extends BoxProps, StylesApiProps<ChartLegendFactory>, ElementProps<'div'> {\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | undefined;\n\n /** Function called when mouse enters/leaves one of the legend items */\n onHighlight: (area: string | null) => void;\n\n /** Position of the legend relative to the chart, used to apply margin on the corresponding side */\n legendPosition: 'top' | 'bottom' | 'middle';\n\n /** Data used for labels, only applicable for area charts: AreaChart, LineChart, BarChart */\n series?: ChartSeries[];\n\n /** Determines whether color swatch should be shown next to the label @default true */\n showColor?: boolean;\n\n /** Determines whether the legend should be centered @default false */\n centered?: boolean;\n}\n\nexport type ChartLegendFactory = Factory<{\n props: ChartLegendProps;\n ref: HTMLDivElement;\n stylesNames: ChartLegendStylesNames;\n}>;\n\nexport const ChartLegend = factory<ChartLegendFactory>((_props) => {\n const props = useProps('ChartLegend', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n onHighlight,\n legendPosition,\n mod,\n series,\n showColor,\n centered,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<ChartLegendFactory>({\n name: 'ChartLegend',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'legend',\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartLegendPayload(payload);\n const labels = getSeriesLabels(series);\n\n const items = filteredPayload.map((item, index) => (\n <div\n key={index}\n {...getStyles('legendItem')}\n onMouseEnter={() => onHighlight(item.dataKey)}\n onMouseLeave={() => onHighlight(null)}\n data-without-color={showColor === false || undefined}\n >\n <ColorSwatch\n color={item.color}\n size={12}\n {...getStyles('legendItemColor')}\n withShadow={false}\n />\n <p {...getStyles('legendItemName')}>{labels[item.dataKey] || item.dataKey}</p>\n </div>\n ));\n\n return (\n <Box mod={[{ position: legendPosition, centered }, mod]} {...getStyles('legend')} {...others}>\n {items}\n </Box>\n );\n});\n\nChartLegend.displayName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AC1E;IAbC,MAaD,CACN;AAEF,QACE,iBAAA,GAAA,kBAAA,KAACC,cAAAA,KAAD;EAAK,KAAK,CAAC;GAAE,UAAU;GAAgB;GAAU,EAAE,IAAI;EAAE,GAAI,UAAU,SAAS;EAAE,GAAI;YACnF;EACG,CAAA;EAER;AAEF,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_get_series_labels = require("../utils/get-series-labels/get-series-labels.cjs");
|
|
3
4
|
const require_ChartTooltip_module = require("./ChartTooltip.module.cjs");
|
|
4
5
|
let _mantine_core = require("@mantine/core");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartTooltip.cjs","names":["getSeriesLabels","Box"],"sources":["../../src/ChartTooltip/ChartTooltip.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartTooltip.module.css';\n\nfunction updateChartTooltipPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n if (!item.payload || item.payload[item.name]) {\n return item;\n }\n const matchFound = item.name.search(/\\./);\n if (matchFound >= 0) {\n const newDataKey = item.name.substring(0, matchFound);\n const nestedPayload = { ...item.payload[newDataKey] };\n const shallowPayload = Object.entries(item.payload).reduce((acc, current) => {\n const [k, v] = current;\n return k === newDataKey ? acc : { ...acc, [k]: v };\n }, {});\n\n return {\n ...item,\n name: item.name.substring(matchFound + 1),\n payload: {\n ...shallowPayload,\n ...nestedPayload,\n },\n };\n }\n return item;\n });\n}\n\nexport function getFilteredChartTooltipPayload(\n payload: readonly Record<string, any>[] | Record<string, any>[],\n segmentId?: string\n) {\n const duplicatesFilter = updateChartTooltipPayload(\n payload.filter((item) => item.fill !== 'none' || !item.color)\n );\n\n if (!segmentId) {\n return duplicatesFilter;\n }\n\n return duplicatesFilter.filter((item) => item.name === segmentId);\n}\n\nfunction getData(item: Record<string, any>, type: 'area' | 'radial' | 'scatter') {\n if (type === 'radial' || type === 'scatter') {\n if (Array.isArray(item.value)) {\n return item.value[1] - item.value[0];\n }\n return item.value;\n }\n\n if (Array.isArray(item.payload[item.dataKey])) {\n return item.payload[item.dataKey][1] - item.payload[item.dataKey][0];\n }\n return item.payload[item.name];\n}\n\nexport type ChartTooltipStylesNames =\n | 'tooltip'\n | 'tooltipItem'\n | 'tooltipItemBody'\n | 'tooltipItemColor'\n | 'tooltipItemName'\n | 'tooltipItemData'\n | 'tooltipLabel'\n | 'tooltipBody';\n\nexport interface ChartTooltipProps\n extends BoxProps, StylesApiProps<ChartTooltipFactory>, ElementProps<'div'> {\n /** Main tooltip label */\n label?: React.ReactNode;\n\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | Record<string, any>[] | undefined;\n\n /** Data units, provided by parent component */\n unit?: string;\n\n /** Tooltip type that determines the content and styles, `area` for LineChart, AreaChart and BarChart, `radial` for DonutChart and PieChart @default 'area' */\n type?: 'area' | 'radial' | 'scatter';\n\n /** Id of the segment to display data for. Only applicable when `type=\"radial\"`. If not set, all data is rendered. */\n segmentId?: string;\n\n /** Chart series data, applicable only for `area` type */\n series?: ChartSeries[];\n\n /** A function to format values */\n valueFormatter?: (value: number) => React.ReactNode;\n\n /** Determines whether the color swatch should be visible @default true */\n showColor?: boolean;\n}\n\nexport type ChartTooltipFactory = Factory<{\n props: ChartTooltipProps;\n ref: HTMLDivElement;\n stylesNames: ChartTooltipStylesNames;\n}>;\n\nconst defaultProps = {\n type: 'area',\n showColor: true,\n} satisfies Partial<ChartTooltipProps>;\n\nexport const ChartTooltip = factory<ChartTooltipFactory>((_props) => {\n const props = useProps('ChartTooltip', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n label,\n unit,\n type,\n segmentId,\n mod,\n series,\n valueFormatter,\n showColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<ChartTooltipFactory>({\n name: 'ChartTooltip',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartTooltipPayload(payload, segmentId);\n const scatterLabel = type === 'scatter' ? payload[0]?.payload?.name : null;\n const labels = getSeriesLabels(series);\n const _label = label || scatterLabel;\n\n const items = filteredPayload.map((item) => (\n <div key={item?.key ?? item.name} data-type={type} {...getStyles('tooltipItem')}>\n <div {...getStyles('tooltipItemBody')}>\n {showColor && (\n <svg {...getStyles('tooltipItemColor')}>\n <circle\n r={6}\n fill={getThemeColor(item.color, theme)}\n width={12}\n height={12}\n cx={6}\n cy={6}\n />\n </svg>\n )}\n <div {...getStyles('tooltipItemName')}>{labels[item.name] || item.name}</div>\n </div>\n <div {...getStyles('tooltipItemData')}>\n {typeof valueFormatter === 'function'\n ? valueFormatter(getData(item, type))\n : getData(item, type)}\n {unit || item.unit}\n </div>\n </div>\n ));\n\n return (\n <Box {...getStyles('tooltip')} mod={[{ type }, mod]} {...others}>\n {_label && <div {...getStyles('tooltipLabel')}>{_label}</div>}\n <div {...getStyles('tooltipBody')}>{items}</div>\n </Box>\n );\n});\n\nChartTooltip.displayName = '@mantine/charts/ChartTooltip';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChartTooltip.cjs","names":["getSeriesLabels","Box"],"sources":["../../src/ChartTooltip/ChartTooltip.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartTooltip.module.css';\n\nfunction updateChartTooltipPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n if (!item.payload || item.payload[item.name]) {\n return item;\n }\n const matchFound = item.name.search(/\\./);\n if (matchFound >= 0) {\n const newDataKey = item.name.substring(0, matchFound);\n const nestedPayload = { ...item.payload[newDataKey] };\n const shallowPayload = Object.entries(item.payload).reduce((acc, current) => {\n const [k, v] = current;\n return k === newDataKey ? acc : { ...acc, [k]: v };\n }, {});\n\n return {\n ...item,\n name: item.name.substring(matchFound + 1),\n payload: {\n ...shallowPayload,\n ...nestedPayload,\n },\n };\n }\n return item;\n });\n}\n\nexport function getFilteredChartTooltipPayload(\n payload: readonly Record<string, any>[] | Record<string, any>[],\n segmentId?: string\n) {\n const duplicatesFilter = updateChartTooltipPayload(\n payload.filter((item) => item.fill !== 'none' || !item.color)\n );\n\n if (!segmentId) {\n return duplicatesFilter;\n }\n\n return duplicatesFilter.filter((item) => item.name === segmentId);\n}\n\nfunction getData(item: Record<string, any>, type: 'area' | 'radial' | 'scatter') {\n if (type === 'radial' || type === 'scatter') {\n if (Array.isArray(item.value)) {\n return item.value[1] - item.value[0];\n }\n return item.value;\n }\n\n if (Array.isArray(item.payload[item.dataKey])) {\n return item.payload[item.dataKey][1] - item.payload[item.dataKey][0];\n }\n return item.payload[item.name];\n}\n\nexport type ChartTooltipStylesNames =\n | 'tooltip'\n | 'tooltipItem'\n | 'tooltipItemBody'\n | 'tooltipItemColor'\n | 'tooltipItemName'\n | 'tooltipItemData'\n | 'tooltipLabel'\n | 'tooltipBody';\n\nexport interface ChartTooltipProps\n extends BoxProps, StylesApiProps<ChartTooltipFactory>, ElementProps<'div'> {\n /** Main tooltip label */\n label?: React.ReactNode;\n\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | Record<string, any>[] | undefined;\n\n /** Data units, provided by parent component */\n unit?: string;\n\n /** Tooltip type that determines the content and styles, `area` for LineChart, AreaChart and BarChart, `radial` for DonutChart and PieChart @default 'area' */\n type?: 'area' | 'radial' | 'scatter';\n\n /** Id of the segment to display data for. Only applicable when `type=\"radial\"`. If not set, all data is rendered. */\n segmentId?: string;\n\n /** Chart series data, applicable only for `area` type */\n series?: ChartSeries[];\n\n /** A function to format values */\n valueFormatter?: (value: number) => React.ReactNode;\n\n /** Determines whether the color swatch should be visible @default true */\n showColor?: boolean;\n}\n\nexport type ChartTooltipFactory = Factory<{\n props: ChartTooltipProps;\n ref: HTMLDivElement;\n stylesNames: ChartTooltipStylesNames;\n}>;\n\nconst defaultProps = {\n type: 'area',\n showColor: true,\n} satisfies Partial<ChartTooltipProps>;\n\nexport const ChartTooltip = factory<ChartTooltipFactory>((_props) => {\n const props = useProps('ChartTooltip', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n label,\n unit,\n type,\n segmentId,\n mod,\n series,\n valueFormatter,\n showColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<ChartTooltipFactory>({\n name: 'ChartTooltip',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartTooltipPayload(payload, segmentId);\n const scatterLabel = type === 'scatter' ? payload[0]?.payload?.name : null;\n const labels = getSeriesLabels(series);\n const _label = label || scatterLabel;\n\n const items = filteredPayload.map((item) => (\n <div key={item?.key ?? item.name} data-type={type} {...getStyles('tooltipItem')}>\n <div {...getStyles('tooltipItemBody')}>\n {showColor && (\n <svg {...getStyles('tooltipItemColor')}>\n <circle\n r={6}\n fill={getThemeColor(item.color, theme)}\n width={12}\n height={12}\n cx={6}\n cy={6}\n />\n </svg>\n )}\n <div {...getStyles('tooltipItemName')}>{labels[item.name] || item.name}</div>\n </div>\n <div {...getStyles('tooltipItemData')}>\n {typeof valueFormatter === 'function'\n ? valueFormatter(getData(item, type))\n : getData(item, type)}\n {unit || item.unit}\n </div>\n </div>\n ));\n\n return (\n <Box {...getStyles('tooltip')} mod={[{ type }, mod]} {...others}>\n {_label && <div {...getStyles('tooltipLabel')}>{_label}</div>}\n <div {...getStyles('tooltipBody')}>{items}</div>\n </Box>\n );\n});\n\nChartTooltip.displayName = '@mantine/charts/ChartTooltip';\n"],"mappings":";;;;;;;AAgBA,SAAS,0BAA0B,SAAuD;AACxF,QAAO,QAAQ,KAAK,SAAS;AAC3B,MAAI,CAAC,KAAK,WAAW,KAAK,QAAQ,KAAK,MACrC,QAAO;EAET,MAAM,aAAa,KAAK,KAAK,OAAO,KAAK;AACzC,MAAI,cAAc,GAAG;GACnB,MAAM,aAAa,KAAK,KAAK,UAAU,GAAG,WAAW;GACrD,MAAM,gBAAgB,EAAE,GAAG,KAAK,QAAQ,aAAa;GACrD,MAAM,iBAAiB,OAAO,QAAQ,KAAK,QAAQ,CAAC,QAAQ,KAAK,YAAY;IAC3E,MAAM,CAAC,GAAG,KAAK;AACf,WAAO,MAAM,aAAa,MAAM;KAAE,GAAG;MAAM,IAAI;KAAG;MACjD,EAAE,CAAC;AAEN,UAAO;IACL,GAAG;IACH,MAAM,KAAK,KAAK,UAAU,aAAa,EAAE;IACzC,SAAS;KACP,GAAG;KACH,GAAG;KACJ;IACF;;AAEH,SAAO;GACP;;AAGJ,SAAgB,+BACd,SACA,WACA;CACA,MAAM,mBAAmB,0BACvB,QAAQ,QAAQ,SAAS,KAAK,SAAS,UAAU,CAAC,KAAK,MAAM,CAC9D;AAED,KAAI,CAAC,UACH,QAAO;AAGT,QAAO,iBAAiB,QAAQ,SAAS,KAAK,SAAS,UAAU;;AAGnE,SAAS,QAAQ,MAA2B,MAAqC;AAC/E,KAAI,SAAS,YAAY,SAAS,WAAW;AAC3C,MAAI,MAAM,QAAQ,KAAK,MAAM,CAC3B,QAAO,KAAK,MAAM,KAAK,KAAK,MAAM;AAEpC,SAAO,KAAK;;AAGd,KAAI,MAAM,QAAQ,KAAK,QAAQ,KAAK,SAAS,CAC3C,QAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,KAAK,QAAQ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AI,UAAU,kBAAkB;aAArC,CACG,OAAO,mBAAmB,aACvB,eAAe,QAAQ,MAAM,KAAK,CAAC,GACnC,QAAQ,MAAM,KAAK,EACtB,QAAQ,KAAK,KACV;KACF;IAtBI,MAAM,OAAO,KAAK,KAsBtB,CACN;AAEF,QACE,iBAAA,GAAA,kBAAA,MAACC,cAAAA,KAAD;EAAK,GAAI,UAAU,UAAU;EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI;EAAE,GAAI;YAAzD,CACG,UAAU,iBAAA,GAAA,kBAAA,KAAC,OAAD;GAAK,GAAI,UAAU,eAAe;aAAG;GAAa,CAAA,EAC7D,iBAAA,GAAA,kBAAA,KAAC,OAAD;GAAK,GAAI,UAAU,cAAc;aAAG;GAAY,CAAA,CAC5C;;EAER;AAEF,aAAa,cAAc"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
3
|
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
3
4
|
const require_ChartLegend = require("../ChartLegend/ChartLegend.cjs");
|
|
4
5
|
const require_PointLabel = require("../PointLabel/PointLabel.cjs");
|