@mantine/charts 9.4.3-alpha.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/AreaChart/AreaChart.cjs +12 -3
- package/cjs/AreaChart/AreaChart.cjs.map +1 -1
- package/cjs/BarChart/BarChart.cjs +12 -3
- package/cjs/BarChart/BarChart.cjs.map +1 -1
- package/cjs/BubbleChart/BubbleChart.cjs +70 -66
- package/cjs/BubbleChart/BubbleChart.cjs.map +1 -1
- package/cjs/BulletChart/BulletChart.cjs +137 -0
- package/cjs/BulletChart/BulletChart.cjs.map +1 -0
- package/cjs/BulletChart/BulletChart.module.cjs +18 -0
- package/cjs/BulletChart/BulletChart.module.cjs.map +1 -0
- package/cjs/ChartBrush/ChartBrush.cjs +35 -0
- package/cjs/ChartBrush/ChartBrush.cjs.map +1 -0
- package/cjs/ChartBrush/ChartBrush.module.cjs +7 -0
- package/cjs/ChartBrush/ChartBrush.module.cjs.map +1 -0
- package/cjs/CompositeChart/CompositeChart.cjs +12 -3
- package/cjs/CompositeChart/CompositeChart.cjs.map +1 -1
- package/cjs/DonutChart/DonutChart.cjs +5 -3
- package/cjs/DonutChart/DonutChart.cjs.map +1 -1
- package/cjs/DonutChart/DonutChart.module.cjs.map +1 -1
- package/cjs/FunnelChart/FunnelChart.cjs +5 -3
- package/cjs/FunnelChart/FunnelChart.cjs.map +1 -1
- package/cjs/FunnelChart/FunnelChart.module.cjs.map +1 -1
- package/cjs/Heatmap/Heatmap.cjs +12 -5
- package/cjs/Heatmap/Heatmap.cjs.map +1 -1
- package/cjs/LineChart/LineChart.cjs +12 -3
- package/cjs/LineChart/LineChart.cjs.map +1 -1
- package/cjs/PieChart/PieChart.cjs +5 -3
- package/cjs/PieChart/PieChart.cjs.map +1 -1
- package/cjs/PieChart/PieChart.module.cjs.map +1 -1
- package/cjs/RadarChart/RadarChart.cjs +5 -3
- package/cjs/RadarChart/RadarChart.cjs.map +1 -1
- package/cjs/RadarChart/RadarChart.module.cjs.map +1 -1
- package/cjs/RadialBarChart/RadialBarChart.cjs +5 -3
- package/cjs/RadialBarChart/RadialBarChart.cjs.map +1 -1
- package/cjs/RadialBarChart/RadialBarChart.module.cjs.map +1 -1
- package/cjs/SankeyChart/SankeyChart.cjs +1 -1
- package/cjs/ScatterChart/ScatterChart.cjs +5 -3
- package/cjs/ScatterChart/ScatterChart.cjs.map +1 -1
- package/cjs/Sparkline/Sparkline.cjs +1 -1
- package/cjs/SunburstChart/SunburstChart.cjs +129 -0
- package/cjs/SunburstChart/SunburstChart.cjs.map +1 -0
- package/cjs/SunburstChart/SunburstChart.module.cjs +7 -0
- package/cjs/SunburstChart/SunburstChart.module.cjs.map +1 -0
- package/cjs/Treemap/Treemap.cjs +1 -1
- package/cjs/grid-chart.module.cjs.map +1 -1
- package/cjs/index.cjs +6 -0
- package/esm/AreaChart/AreaChart.mjs +12 -3
- package/esm/AreaChart/AreaChart.mjs.map +1 -1
- package/esm/BarChart/BarChart.mjs +12 -3
- package/esm/BarChart/BarChart.mjs.map +1 -1
- package/esm/BubbleChart/BubbleChart.mjs +70 -66
- package/esm/BubbleChart/BubbleChart.mjs.map +1 -1
- package/esm/BulletChart/BulletChart.mjs +137 -0
- package/esm/BulletChart/BulletChart.mjs.map +1 -0
- package/esm/BulletChart/BulletChart.module.mjs +18 -0
- package/esm/BulletChart/BulletChart.module.mjs.map +1 -0
- package/esm/ChartBrush/ChartBrush.mjs +35 -0
- package/esm/ChartBrush/ChartBrush.mjs.map +1 -0
- package/esm/ChartBrush/ChartBrush.module.mjs +7 -0
- package/esm/ChartBrush/ChartBrush.module.mjs.map +1 -0
- package/esm/CompositeChart/CompositeChart.mjs +12 -3
- package/esm/CompositeChart/CompositeChart.mjs.map +1 -1
- package/esm/DonutChart/DonutChart.mjs +5 -3
- package/esm/DonutChart/DonutChart.mjs.map +1 -1
- package/esm/DonutChart/DonutChart.module.mjs.map +1 -1
- package/esm/FunnelChart/FunnelChart.mjs +5 -3
- package/esm/FunnelChart/FunnelChart.mjs.map +1 -1
- package/esm/FunnelChart/FunnelChart.module.mjs.map +1 -1
- package/esm/Heatmap/Heatmap.mjs +12 -5
- package/esm/Heatmap/Heatmap.mjs.map +1 -1
- package/esm/LineChart/LineChart.mjs +12 -3
- package/esm/LineChart/LineChart.mjs.map +1 -1
- package/esm/PieChart/PieChart.mjs +5 -3
- package/esm/PieChart/PieChart.mjs.map +1 -1
- package/esm/PieChart/PieChart.module.mjs.map +1 -1
- package/esm/RadarChart/RadarChart.mjs +5 -3
- package/esm/RadarChart/RadarChart.mjs.map +1 -1
- package/esm/RadarChart/RadarChart.module.mjs.map +1 -1
- package/esm/RadialBarChart/RadialBarChart.mjs +5 -3
- package/esm/RadialBarChart/RadialBarChart.mjs.map +1 -1
- package/esm/RadialBarChart/RadialBarChart.module.mjs.map +1 -1
- package/esm/SankeyChart/SankeyChart.mjs +1 -1
- package/esm/ScatterChart/ScatterChart.mjs +5 -3
- package/esm/ScatterChart/ScatterChart.mjs.map +1 -1
- package/esm/Sparkline/Sparkline.mjs +1 -1
- package/esm/SunburstChart/SunburstChart.mjs +129 -0
- package/esm/SunburstChart/SunburstChart.mjs.map +1 -0
- package/esm/SunburstChart/SunburstChart.module.mjs +7 -0
- package/esm/SunburstChart/SunburstChart.module.mjs.map +1 -0
- package/esm/Treemap/Treemap.mjs +1 -1
- package/esm/grid-chart.module.mjs.map +1 -1
- package/esm/index.mjs +4 -1
- package/lib/BubbleChart/BubbleChart.d.ts +2 -0
- package/lib/BulletChart/BulletChart.d.ts +58 -0
- package/lib/BulletChart/index.d.ts +9 -0
- package/lib/ChartBrush/ChartBrush.d.ts +15 -0
- package/lib/ChartBrush/index.d.ts +2 -0
- package/lib/DonutChart/DonutChart.d.ts +2 -0
- package/lib/FunnelChart/FunnelChart.d.ts +2 -0
- package/lib/Heatmap/Heatmap.d.ts +2 -0
- package/lib/PieChart/PieChart.d.ts +2 -0
- package/lib/RadarChart/RadarChart.d.ts +2 -0
- package/lib/RadialBarChart/RadialBarChart.d.ts +2 -0
- package/lib/ScatterChart/ScatterChart.d.ts +2 -2
- package/lib/SunburstChart/SunburstChart.d.ts +58 -0
- package/lib/SunburstChart/index.d.ts +10 -0
- package/lib/index.d.mts +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/types.d.ts +8 -2
- package/package.json +3 -3
- package/styles.css +218 -2
- package/styles.layer.css +218 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunnelChart.cjs","names":["Box","ResponsiveContainer","RechartsFunnelChart","Funnel","LabelList","Tooltip","ChartTooltip","Legend","ChartLegend","classes"],"sources":["../../src/FunnelChart/FunnelChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n Funnel,\n FunnelProps,\n LabelList,\n Legend,\n LegendProps,\n FunnelChart as RechartsFunnelChart,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './FunnelChart.module.css';\n\nexport interface FunnelChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type FunnelChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;\nexport type FunnelChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface FunnelChartProps\n extends BoxProps, StylesApiProps<FunnelChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: FunnelChartCell[];\n\n /** Determines whether the tooltip should be displayed when a section is hovered @default true */\n withTooltip?: boolean;\n\n /** Determines whether the legend should be displayed @default false */\n withLegend?: boolean;\n\n /** Props passed down to recharts `Legend` component */\n legendProps?: Omit<LegendProps, 'ref'>;\n\n /** Tooltip animation duration in ms @default 0 */\n tooltipAnimationDuration?: number;\n\n /** Props passed down to `Tooltip` recharts component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to recharts `Pie` component */\n funnelProps?: Partial<Omit<FunnelProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels @default 'white' */\n labelColor?: MantineColor;\n\n /** Controls chart width and height @default 300 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Controls labels position relative to the segment @default 'right' */\n labelsPosition?: 'right' | 'left' | 'inside';\n\n /** A function to format values inside the tooltip and labels */\n valueFormatter?: (value: number) => string;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `FunnelChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `FunnelChart` component */\n funnelChartProps?: React.ComponentProps<typeof RechartsFunnelChart>;\n}\n\nexport type FunnelChartFactory = Factory<{\n props: FunnelChartProps;\n ref: HTMLDivElement;\n stylesNames: FunnelChartStylesNames;\n vars: FunnelChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: true,\n size: 300,\n strokeWidth: 1,\n withLabels: false,\n labelsPosition: 'right',\n tooltipDataSource: 'all',\n} satisfies Partial<FunnelChartProps>;\n\nconst varsResolver = createVarsResolver<FunnelChartFactory>(\n (theme, { strokeColor, labelColor, size }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': rem(size),\n },\n })\n);\n\nexport const FunnelChart = factory<FunnelChartFactory>((_props) => {\n const props = useProps('FunnelChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n withLegend,\n legendProps,\n tooltipAnimationDuration,\n tooltipProps,\n strokeWidth,\n withLabels,\n size,\n valueFormatter,\n children,\n funnelChartProps,\n funnelProps,\n labelsPosition,\n tooltipDataSource,\n strokeColor,\n labelColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);\n\n const getStyles = useStyles<FunnelChartFactory>({\n name: 'FunnelChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<FunnelChartFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <RechartsFunnelChart {...funnelChartProps}>\n <Funnel\n data={data.map((entry, index) => ({\n ...entry,\n __segmentIndex: index,\n fill: getThemeColor(entry.color, theme),\n fillOpacity: highlightedIndex !== null ? (highlightedIndex === index ? 1 : 0.2) : 1,\n }))}\n dataKey=\"value\"\n isAnimationActive={false}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={strokeWidth}\n {...funnelProps}\n >\n {withLabels && (\n <LabelList\n position={labelsPosition}\n fill={\n labelsPosition === 'inside'\n ? 'var(--chart-labels-color, var(--mantine-color-white))'\n : 'var(--chart-labels-color, var(--mantine-color-dimmed))'\n }\n stroke=\"none\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n dataKey={(entry) => {\n return typeof valueFormatter === 'function'\n ? valueFormatter(entry.value as number)\n : entry.value;\n }}\n />\n )}\n </Funnel>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment'\n ? (payload?.[0]?.payload?.__segmentIndex as number)\n : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {withLegend && (\n <Legend\n verticalAlign=\"bottom\"\n content={() => (\n <ChartLegend\n payload={data.map((item, index) => ({\n value: item.name,\n color: getThemeColor(item.color, theme),\n dataKey: item.name,\n highlightKey: index,\n }))}\n onHighlight={(value) =>\n setHighlightedIndex(typeof value === 'number' ? value : null)\n }\n legendPosition={legendProps?.verticalAlign || 'bottom'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n centered\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n {children}\n </RechartsFunnelChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nFunnelChart.displayName = '@mantine/charts/FunnelChart';\nFunnelChart.classes = classes;\nFunnelChart.varsResolver = varsResolver;\n\nexport namespace FunnelChart {\n export type Props = FunnelChartProps;\n export type StylesNames = FunnelChartStylesNames;\n export type Factory = FunnelChartFactory;\n export type CssVariables = FunnelChartCssVariables;\n export type Cell = FunnelChartCell;\n}\n"],"mappings":";;;;;;;;;AAyGA,MAAM,eAAe;CACnB,aAAa;CACb,MAAM;CACN,aAAa;CACb,YAAY;CACZ,gBAAgB;CAChB,mBAAmB;AACrB;AAEA,MAAM,gBAAA,GAAA,cAAA,mBAAA,EACH,OAAO,EAAE,aAAa,YAAY,YAAY,EAC7C,MAAM;CACJ,wBAAwB,eAAA,GAAA,cAAA,cAAA,CAA4B,aAAa,KAAK,IAAI,KAAA;CAC1E,wBAAwB,cAAA,GAAA,cAAA,cAAA,CAA2B,YAAY,KAAK,IAAI,KAAA;CACxE,iBAAA,GAAA,cAAA,IAAA,CAAoB,IAAI;AAC1B,EACF,EACF;AAEA,MAAa,eAAA,GAAA,cAAA,QAAA,EAA2C,WAAW;CACjE,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,eAAe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A;IAEG,CAAA;IAEP,eACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,SAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YACjB,UAAU,EAAE,EAAE,SAAS,iBACxB,KAAA;MAEU;MACJ;KACb,CAAA;KAEH,GAAI;IACL,CAAA;IAGF,cACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,QAAD;KACE,eAAc;KACd,eACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,oBAAAA,aAAD;MACE,SAAS,KAAK,KAAK,MAAM,WAAW;OAClC,OAAO,KAAK;OACZ,QAAA,GAAA,cAAA,cAAA,CAAqB,KAAK,OAAO,KAAK;OACtC,SAAS,KAAK;OACd,cAAc;MAChB,EAAE;MACF,cAAc,UACZ,oBAAoB,OAAO,UAAU,WAAW,QAAQ,IAAI;MAE9D,gBAAgB,aAAa,iBAAiB;MAC9C,YAAY;MACZ,QAAQ;MACR,UAAA;MACY;KACb,CAAA;KAEH,GAAI;IACL,CAAA;IAGF;GACkB;KACF,CAAA;CAClB,CAAA;AAET,CAAC;AAED,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA;AACtB,YAAY,eAAe"}
|
|
1
|
+
{"version":3,"file":"FunnelChart.cjs","names":["Box","ResponsiveContainer","RechartsFunnelChart","Funnel","LabelList","Tooltip","ChartTooltip","Legend","ChartLegend","classes"],"sources":["../../src/FunnelChart/FunnelChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n Funnel,\n FunnelProps,\n LabelList,\n Legend,\n LegendProps,\n FunnelChart as RechartsFunnelChart,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport classes from './FunnelChart.module.css';\n\nexport interface FunnelChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type FunnelChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;\nexport type FunnelChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface FunnelChartProps\n extends BoxProps, StylesApiProps<FunnelChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: FunnelChartCell[];\n\n /** Determines whether the tooltip should be displayed when a section is hovered @default true */\n withTooltip?: boolean;\n\n /** Determines whether the legend should be displayed @default false */\n withLegend?: boolean;\n\n /** Props passed down to recharts `Legend` component */\n legendProps?: Omit<LegendProps, 'ref'>;\n\n /** Tooltip animation duration in ms @default 0 */\n tooltipAnimationDuration?: number;\n\n /** Props passed down to `Tooltip` recharts component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to recharts `Pie` component */\n funnelProps?: Partial<Omit<FunnelProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels @default 'white' */\n labelColor?: MantineColor;\n\n /** Controls chart width and height @default 300 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Controls labels position relative to the segment @default 'right' */\n labelsPosition?: 'right' | 'left' | 'inside';\n\n /** A function to format values inside the tooltip and labels */\n valueFormatter?: (value: number) => string;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `FunnelChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `FunnelChart` component */\n funnelChartProps?: React.ComponentProps<typeof RechartsFunnelChart>;\n\n /** Determines whether the chart should be keyboard-navigable with the recharts accessibility layer, `true` by default */\n accessibilityLayer?: boolean;\n}\n\nexport type FunnelChartFactory = Factory<{\n props: FunnelChartProps;\n ref: HTMLDivElement;\n stylesNames: FunnelChartStylesNames;\n vars: FunnelChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: true,\n size: 300,\n strokeWidth: 1,\n withLabels: false,\n labelsPosition: 'right',\n tooltipDataSource: 'all',\n accessibilityLayer: true,\n} satisfies Partial<FunnelChartProps>;\n\nconst varsResolver = createVarsResolver<FunnelChartFactory>(\n (theme, { strokeColor, labelColor, size }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': rem(size),\n },\n })\n);\n\nexport const FunnelChart = factory<FunnelChartFactory>((_props) => {\n const props = useProps('FunnelChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n withLegend,\n legendProps,\n tooltipAnimationDuration,\n tooltipProps,\n strokeWidth,\n withLabels,\n size,\n valueFormatter,\n children,\n funnelChartProps,\n funnelProps,\n labelsPosition,\n tooltipDataSource,\n strokeColor,\n labelColor,\n attributes,\n accessibilityLayer,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);\n\n const getStyles = useStyles<FunnelChartFactory>({\n name: 'FunnelChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<FunnelChartFactory>({\n classNames,\n styles,\n props,\n });\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <RechartsFunnelChart accessibilityLayer={accessibilityLayer} {...funnelChartProps}>\n <Funnel\n data={data.map((entry, index) => ({\n ...entry,\n __segmentIndex: index,\n fill: getThemeColor(entry.color, theme),\n fillOpacity: highlightedIndex !== null ? (highlightedIndex === index ? 1 : 0.2) : 1,\n }))}\n dataKey=\"value\"\n isAnimationActive={false}\n stroke=\"var(--chart-stroke-color, var(--mantine-color-body))\"\n strokeWidth={strokeWidth}\n {...funnelProps}\n >\n {withLabels && (\n <LabelList\n position={labelsPosition}\n fill={\n labelsPosition === 'inside'\n ? 'var(--chart-labels-color, var(--mantine-color-white))'\n : 'var(--chart-labels-color, var(--mantine-color-dimmed))'\n }\n stroke=\"none\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n dataKey={(entry) => {\n return typeof valueFormatter === 'function'\n ? valueFormatter(entry.value as number)\n : entry.value;\n }}\n />\n )}\n </Funnel>\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment'\n ? (payload?.[0]?.payload?.__segmentIndex as number)\n : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {withLegend && (\n <Legend\n verticalAlign=\"bottom\"\n content={() => (\n <ChartLegend\n payload={data.map((item, index) => ({\n value: item.name,\n color: getThemeColor(item.color, theme),\n dataKey: item.name,\n highlightKey: index,\n }))}\n onHighlight={(value) =>\n setHighlightedIndex(typeof value === 'number' ? value : null)\n }\n legendPosition={legendProps?.verticalAlign || 'bottom'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n centered\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n {children}\n </RechartsFunnelChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nFunnelChart.displayName = '@mantine/charts/FunnelChart';\nFunnelChart.classes = classes;\nFunnelChart.varsResolver = varsResolver;\n\nexport namespace FunnelChart {\n export type Props = FunnelChartProps;\n export type StylesNames = FunnelChartStylesNames;\n export type Factory = FunnelChartFactory;\n export type CssVariables = FunnelChartCssVariables;\n export type Cell = FunnelChartCell;\n}\n"],"mappings":";;;;;;;;;AA4GA,MAAM,eAAe;CACnB,aAAa;CACb,MAAM;CACN,aAAa;CACb,YAAY;CACZ,gBAAgB;CAChB,mBAAmB;CACnB,oBAAoB;AACtB;AAEA,MAAM,gBAAA,GAAA,cAAA,mBAAA,EACH,OAAO,EAAE,aAAa,YAAY,YAAY,EAC7C,MAAM;CACJ,wBAAwB,eAAA,GAAA,cAAA,cAAA,CAA4B,aAAa,KAAK,IAAI,KAAA;CAC1E,wBAAwB,cAAA,GAAA,cAAA,cAAA,CAA2B,YAAY,KAAK,IAAI,KAAA;CACxE,iBAAA,GAAA,cAAA,IAAA,CAAoB,IAAI;AAC1B,EACF,EACF;AAEA,MAAa,eAAA,GAAA,cAAA,QAAA,EAA2C,WAAW;CACjE,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,eAAe,cAAc,MAAM;CAC1D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,aACA,YACA,aACA,0BACA,cACA,aACA,YACA,MACA,gBACA,UACA,kBACA,aACA,gBACA,mBACA,aACA,YACA,YACA,oBACA,GAAG,WACD;CAEJ,MAAM,SAAA,GAAA,cAAA,gBAAA,CAAwB;CAC9B,MAAM,CAAC,kBAAkB,wBAAA,GAAA,MAAA,SAAA,CAA+C,IAAI;CAE5E,MAAM,aAAA,GAAA,cAAA,UAAA,CAA0C;EAC9C,MAAM;EACN,SAAA,2BAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,EAAE,oBAAoB,oBAAA,GAAA,cAAA,qBAAA,CAA4D;EACtF;EACA;EACA;CACF,CAAC;CAED,OACE,iBAA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ACZ,QAAA,GAAA,cAAA,cAAA,CAAqB,KAAK,OAAO,KAAK;OACtC,SAAS,KAAK;OACd,cAAc;MAChB,EAAE;MACF,cAAc,UACZ,oBAAoB,OAAO,UAAU,WAAW,QAAQ,IAAI;MAE9D,gBAAgB,aAAa,iBAAiB;MAC9C,YAAY;MACZ,QAAQ;MACR,UAAA;MACY;KACb,CAAA;KAEH,GAAI;IACL,CAAA;IAGF;GACkB;KACF,CAAA;CAClB,CAAA;AAET,CAAC;AAED,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA;AACtB,YAAY,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunnelChart.module.cjs","names":[],"sources":["../../src/FunnelChart/FunnelChart.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-size, auto);\n height: var(--chart-size, auto);\n width: var(--chart-size, auto);\n min-width: var(--chart-size, auto);\n\n & :where(*) {\n outline: 0;\n }\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"FunnelChart.module.cjs","names":[],"sources":["../../src/FunnelChart/FunnelChart.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-size, auto);\n height: var(--chart-size, auto);\n width: var(--chart-size, auto);\n min-width: var(--chart-size, auto);\n\n & :where(*) {\n outline: 0;\n }\n\n svg:focus-visible {\n outline: 2px solid var(--mantine-primary-color-filled);\n outline-offset: 2px;\n }\n}\n"],"mappings":""}
|
package/cjs/Heatmap/Heatmap.cjs
CHANGED
|
@@ -35,6 +35,7 @@ const defaultProps = {
|
|
|
35
35
|
"Fri",
|
|
36
36
|
""
|
|
37
37
|
],
|
|
38
|
+
monthLabelsPosition: "top",
|
|
38
39
|
withOutsideDates: true,
|
|
39
40
|
firstDayOfWeek: 1,
|
|
40
41
|
rectSize: 10,
|
|
@@ -53,7 +54,7 @@ const defaultProps = {
|
|
|
53
54
|
};
|
|
54
55
|
const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
55
56
|
const props = (0, _mantine_core.useProps)("Heatmap", defaultProps, _props);
|
|
56
|
-
const { classNames, className, style, styles, unstyled, vars, data, startDate, endDate, withMonthLabels, withWeekdayLabels, weekdayLabels, withOutsideDates, monthLabels, firstDayOfWeek, rectSize = 10, gap = 1, rectRadius, domain, colors, weekdaysLabelsWidth, monthsLabelsHeight, fontSize, getTooltipLabel, withTooltip, tooltipProps, getRectProps, splitMonths, withLegend, legendLabels, attributes, ...others } = props;
|
|
57
|
+
const { classNames, className, style, styles, unstyled, vars, data, startDate, endDate, withMonthLabels, monthLabelsPosition, withWeekdayLabels, weekdayLabels, withOutsideDates, monthLabels, firstDayOfWeek, rectSize = 10, gap = 1, rectRadius, domain, colors, weekdaysLabelsWidth, monthsLabelsHeight, fontSize, getTooltipLabel, withTooltip, tooltipProps, getRectProps, splitMonths, withLegend, legendLabels, attributes, ...others } = props;
|
|
57
58
|
const getStyles = (0, _mantine_core.useStyles)({
|
|
58
59
|
name: "Heatmap",
|
|
59
60
|
classes: require_Heatmap_module.default,
|
|
@@ -69,7 +70,10 @@ const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
|
69
70
|
const [hoveredRect, setHoveredRect] = (0, react.useState)(null);
|
|
70
71
|
const rectSizeWithGap = rectSize + gap;
|
|
71
72
|
const weekdaysOffset = withWeekdayLabels ? weekdaysLabelsWidth : 0;
|
|
72
|
-
const
|
|
73
|
+
const monthsLabelAtTop = withMonthLabels && monthLabelsPosition === "top";
|
|
74
|
+
const monthsLabelAtBottom = withMonthLabels && monthLabelsPosition === "bottom";
|
|
75
|
+
const monthsOffset = monthsLabelAtTop ? monthsLabelsHeight : 0;
|
|
76
|
+
const monthsBottomHeight = monthsLabelAtBottom ? monthsLabelsHeight : 0;
|
|
73
77
|
const [min, max] = require_get_boundaries.getBoundaries({
|
|
74
78
|
data,
|
|
75
79
|
domain
|
|
@@ -108,9 +112,10 @@ const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
|
108
112
|
const minSize = splitMonths ? 2 : 3;
|
|
109
113
|
if (month.size < minSize) return null;
|
|
110
114
|
const monthLabel = monthLabels[month.month];
|
|
115
|
+
const monthLabelY = monthsLabelAtBottom ? rectSizeWithGap * 7 + gap + monthsLabelsHeight - 4 : monthsLabelsHeight - 4;
|
|
111
116
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
|
|
112
117
|
x: computeMonthLabelX(month.position, monthIndex),
|
|
113
|
-
y:
|
|
118
|
+
y: monthLabelY,
|
|
114
119
|
width: month.size * rectSizeWithGap,
|
|
115
120
|
fontSize,
|
|
116
121
|
...getStyles("monthLabel"),
|
|
@@ -129,6 +134,7 @@ const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
|
129
134
|
const legendPadding = 10;
|
|
130
135
|
const legendHeight = withLegend ? legendPadding + rectSize : 0;
|
|
131
136
|
const svgWidth = rectSizeWithGap * totalColumns + gap + weekdaysOffset;
|
|
137
|
+
const svgHeight = rectSizeWithGap * 7 + gap + monthsOffset + monthsBottomHeight + legendHeight;
|
|
132
138
|
const legendNode = withLegend ? (() => {
|
|
133
139
|
const lessLabel = legendLabels[0];
|
|
134
140
|
const moreLabel = legendLabels[1];
|
|
@@ -138,8 +144,9 @@ const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
|
138
144
|
const allColors = [void 0, ...colors || []];
|
|
139
145
|
const rectsWidth = allColors.length * rectSize + (allColors.length - 1) * gap;
|
|
140
146
|
const moreWidth = moreLabel.length * charWidth;
|
|
147
|
+
const totalLegendWidth = lessWidth + textGap + rectsWidth + textGap + moreWidth;
|
|
141
148
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", {
|
|
142
|
-
transform: `translate(${svgWidth -
|
|
149
|
+
transform: `translate(${svgWidth - totalLegendWidth}, ${rectSizeWithGap * 7 + gap + monthsOffset + monthsBottomHeight + legendPadding})`,
|
|
143
150
|
"data-id": "legend",
|
|
144
151
|
...getStyles("legend"),
|
|
145
152
|
children: [
|
|
@@ -175,7 +182,7 @@ const Heatmap = (0, _mantine_core.factory)((_props) => {
|
|
|
175
182
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_mantine_core.Box, {
|
|
176
183
|
component: "svg",
|
|
177
184
|
width: svgWidth,
|
|
178
|
-
height:
|
|
185
|
+
height: svgHeight,
|
|
179
186
|
...getStyles("root"),
|
|
180
187
|
...others,
|
|
181
188
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Heatmap.cjs","names":["getBoundaries","rotateWeekdaysNames","getDatesRange","getMonthsRange","HeatmapSplitWeeks","HeatmapWeeks","getColumns","getFirstMonthColumnIndex","Box","Tooltip","classes"],"sources":["../../src/Heatmap/Heatmap.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n Tooltip,\n TooltipFloatingProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { getBoundaries } from './get-boundaries/get-boundaries';\nimport { getColumns, getFirstMonthColumnIndex, HeatmapColumn } from './get-columns/get-columns';\nimport { getDatesRange } from './get-dates-range/get-dates-range';\nimport { getMonthsRange } from './get-months-range/get-months-range';\nimport { HeatmapSplitWeeks } from './HeatmapSplitWeeks';\nimport { HeatmapWeeks } from './HeatmapWeeks';\nimport { rotateWeekdaysNames } from './rotate-weekdays-names/rotate-weekdays-names';\nimport classes from './Heatmap.module.css';\n\nexport type HeatmapStylesNames =\n | 'root'\n | 'rect'\n | 'weekdayLabel'\n | 'monthLabel'\n | 'legend'\n | 'legendLabel'\n | 'legendRect';\n\ninterface HeatmapRectData {\n date: string;\n value: number | null;\n}\n\nexport interface HeatmapProps\n extends\n BoxProps,\n StylesApiProps<HeatmapFactory>,\n ElementProps<'svg', 'display' | 'opacity' | 'viewBox' | 'width' | 'height'> {\n /** Heatmap data, key is date in `YYYY-MM-DD` format (interpreted as a UTC calendar day) */\n data: Record<string, number>;\n\n /** Heatmap domain, array of 2 numbers, min and max values, calculated from data by default */\n domain?: [number, number];\n\n /** Heatmap start date. Current date - 1 year by default. Date is normalized to UTC midnight of the intended calendar day. */\n startDate?: Date | string;\n\n /** Heatmap end date. Current date by default. Date is normalized to UTC midnight of the intended calendar day. */\n endDate?: Date | string;\n\n /** If set, month labels are displayed @default false */\n withMonthLabels?: boolean;\n\n /** Month labels, array of 12 elements, can be used for localization */\n monthLabels?: string[];\n\n /** If set, weekday labels are displayed @default false */\n withWeekdayLabels?: boolean;\n\n /** Weekday labels, array of 7 elements, can be used for localization */\n weekdayLabels?: string[];\n\n /** If set, trailing dates that do not fall into the given `startDate` – `endDate` range are displayed to fill empty space. @default true */\n withOutsideDates?: boolean;\n\n /** First day of week, 0 – Sunday, 1 – Monday. @default 1 – Monday */\n firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n /** Size of day rect in px @default 10 */\n rectSize?: number;\n\n /** Gap between rects in px @default 1 */\n gap?: number;\n\n /** Rect radius in px @default 2 */\n rectRadius?: number;\n\n /** Colors array, used to calculate color for each value, by default 4 shades of green colors are used */\n colors?: string[];\n\n /** Width of weekday labels column @default 30 */\n weekdaysLabelsWidth?: number;\n\n /** Height of month labels row @default 30 */\n monthsLabelsHeight?: number;\n\n /** Font size of month and weekday labels @default 12 */\n fontSize?: number;\n\n /** A function to generate tooltip label based on the hovered rect date and value, required for the tooltip to be visible */\n getTooltipLabel?: (input: HeatmapRectData) => React.ReactNode;\n\n /** If set, tooltip is displayed on rect hover @default false */\n withTooltip?: boolean;\n\n /** Props passed down to the `Tooltip.Floating` component */\n tooltipProps?: Partial<TooltipFloatingProps>;\n\n /** Props passed down to each rect depending on its date and associated value */\n getRectProps?: (input: HeatmapRectData) => React.ComponentProps<'rect'>;\n\n /** If set, inserts a spacer column between months @default false */\n splitMonths?: boolean;\n\n /** If set, legend with color levels is displayed below the heatmap @default false */\n withLegend?: boolean;\n\n /** Legend labels, array of 2 elements: [min label, max label] @default ['Less', 'More'] */\n legendLabels?: [string, string];\n}\n\nexport type HeatmapFactory = Factory<{\n props: HeatmapProps;\n ref: SVGSVGElement;\n stylesNames: HeatmapStylesNames;\n}>;\n\nconst defaultProps = {\n monthLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n weekdayLabels: ['Sun', 'Mon', '', 'Wed', '', 'Fri', ''],\n withOutsideDates: true,\n firstDayOfWeek: 1,\n rectSize: 10,\n weekdaysLabelsWidth: 30,\n monthsLabelsHeight: 14,\n gap: 1,\n rectRadius: 2,\n fontSize: 12,\n colors: [\n 'var(--heatmap-level-1)',\n 'var(--heatmap-level-2)',\n 'var(--heatmap-level-3)',\n 'var(--heatmap-level-4)',\n ],\n legendLabels: ['Less', 'More'] as [string, string],\n} satisfies Partial<HeatmapProps>;\n\nexport const Heatmap = factory<HeatmapFactory>((_props) => {\n const props = useProps('Heatmap', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n startDate,\n endDate,\n withMonthLabels,\n withWeekdayLabels,\n weekdayLabels,\n withOutsideDates,\n monthLabels,\n firstDayOfWeek,\n rectSize = 10,\n gap = 1,\n rectRadius,\n domain,\n colors,\n weekdaysLabelsWidth,\n monthsLabelsHeight,\n fontSize,\n getTooltipLabel,\n withTooltip,\n tooltipProps,\n getRectProps,\n splitMonths,\n withLegend,\n legendLabels,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<HeatmapFactory>({\n name: 'Heatmap',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n });\n\n const [hoveredRect, setHoveredRect] = useState<HeatmapRectData | null>(null);\n const rectSizeWithGap = rectSize + gap;\n const weekdaysOffset = withWeekdayLabels ? weekdaysLabelsWidth : 0;\n const monthsOffset = withMonthLabels ? monthsLabelsHeight : 0;\n const [min, max] = getBoundaries({ data, domain });\n const rotatedWeekdayLabels = useMemo(\n () => rotateWeekdaysNames(weekdayLabels, firstDayOfWeek),\n [weekdayLabels, firstDayOfWeek]\n );\n\n const datesRange = getDatesRange({\n startDate,\n endDate,\n withOutsideDates,\n firstDayOfWeek,\n });\n\n // Calculate months range for labels and optional split between months\n const monthsRange = withMonthLabels || splitMonths ? getMonthsRange(datesRange) : [];\n\n // Shared props for weeks rendering components\n const weeksProps = {\n data,\n datesRange,\n rectSize,\n gap,\n rectRadius,\n min,\n max,\n colors,\n withTooltip,\n setHoveredRect,\n getRectProps,\n getStyles,\n };\n\n // Use different rendering logic based on splitMonths\n const weeks = splitMonths ? (\n <HeatmapSplitWeeks {...weeksProps} />\n ) : (\n <HeatmapWeeks {...weeksProps} />\n );\n\n // Calculate total columns based on whether splitMonths is enabled\n const totalColumns = splitMonths ? getColumns(datesRange, splitMonths).length : datesRange.length;\n\n const computeMonthLabelX = (monthPosition: number, monthIndex: number) => {\n if (!splitMonths) {\n return monthPosition * rectSizeWithGap + gap + weekdaysOffset;\n }\n\n // For split months, find the first column index that has this month and shift label by 1 column\n const firstMonth = monthsRange[monthIndex];\n const columns: HeatmapColumn[] = getColumns(datesRange, splitMonths);\n const i = getFirstMonthColumnIndex(columns, firstMonth.month);\n const base = i >= 0 ? i : monthPosition;\n // shift right by one column\n return (base + 1) * rectSizeWithGap + gap + weekdaysOffset;\n };\n\n const monthsLabelsNodes =\n withMonthLabels && monthLabels\n ? monthsRange.map((month, monthIndex) => {\n // For non-split months, use original logic with minimum size of 3\n // For split months, use minimum size of 2\n const minSize = splitMonths ? 2 : 3;\n if (month.size < minSize) {\n return null;\n }\n\n const monthLabel = monthLabels[month.month];\n\n return (\n <text\n key={monthIndex}\n x={computeMonthLabelX(month.position, monthIndex)}\n y={monthsLabelsHeight - 4}\n width={month.size * rectSizeWithGap}\n fontSize={fontSize}\n {...getStyles('monthLabel')}\n >\n {monthLabel}\n </text>\n );\n })\n : null;\n\n const weekdayLabelsNodes =\n withWeekdayLabels && weekdayLabels\n ? rotatedWeekdayLabels.map((weekdayLabel, dayIndex) => (\n <text\n key={dayIndex}\n x={0}\n y={(dayIndex + 1) * rectSizeWithGap - gap + monthsOffset}\n width={weekdaysLabelsWidth}\n fontSize={fontSize}\n {...getStyles('weekdayLabel')}\n >\n {weekdayLabel}\n </text>\n ))\n : null;\n\n const label = getTooltipLabel && hoveredRect && withTooltip ? getTooltipLabel(hoveredRect) : null;\n\n const legendPadding = 10;\n const legendHeight = withLegend ? legendPadding + rectSize : 0;\n const svgWidth = rectSizeWithGap * totalColumns + gap + weekdaysOffset;\n\n const legendNode = withLegend\n ? (() => {\n const lessLabel = legendLabels![0];\n const moreLabel = legendLabels![1];\n const textGap = 6;\n const charWidth = fontSize! * 0.6;\n const lessWidth = lessLabel.length * charWidth;\n const allColors = [undefined, ...(colors || [])];\n const rectsWidth = allColors.length * rectSize + (allColors.length - 1) * gap;\n const moreWidth = moreLabel.length * charWidth;\n const totalLegendWidth = lessWidth + textGap + rectsWidth + textGap + moreWidth;\n\n const legendX = svgWidth - totalLegendWidth;\n const legendY = rectSizeWithGap * 7 + gap + monthsOffset + legendPadding;\n\n return (\n <g\n transform={`translate(${legendX}, ${legendY})`}\n data-id=\"legend\"\n {...getStyles('legend')}\n >\n <text\n x={0}\n y={rectSize / 2}\n fontSize={fontSize}\n dominantBaseline=\"central\"\n {...getStyles('legendLabel')}\n >\n {lessLabel}\n </text>\n {allColors.map((color, i) => (\n <rect\n key={i}\n x={lessWidth + textGap + i * (rectSize + gap)}\n y={0}\n width={rectSize}\n height={rectSize}\n rx={rectRadius}\n fill={color}\n data-empty={color === undefined || undefined}\n {...getStyles('legendRect')}\n />\n ))}\n <text\n x={lessWidth + textGap + rectsWidth + textGap}\n y={rectSize / 2}\n fontSize={fontSize}\n dominantBaseline=\"central\"\n {...getStyles('legendLabel')}\n >\n {moreLabel}\n </text>\n </g>\n );\n })()\n : null;\n\n return (\n <Box\n component=\"svg\"\n width={svgWidth}\n height={rectSizeWithGap * 7 + gap + monthsOffset + legendHeight}\n {...getStyles('root')}\n {...others}\n >\n <Tooltip.Floating\n label={label}\n disabled={!withTooltip || !label}\n position=\"top\"\n {...tooltipProps}\n >\n <g transform={`translate(${weekdaysOffset}, ${monthsOffset})`} data-id=\"all-weeks\">\n {/* Required for tooltip to remain visible while gaps between rects are hovered */}\n {withTooltip && (\n <rect\n fill=\"transparent\"\n width={rectSizeWithGap * totalColumns + gap}\n height={rectSizeWithGap * 7 + gap}\n />\n )}\n {weeks}\n </g>\n </Tooltip.Floating>\n {weekdayLabelsNodes}\n {monthsLabelsNodes}\n {legendNode}\n </Box>\n );\n});\n\nHeatmap.displayName = '@mantine/charts/Heatmap';\nHeatmap.classes = classes;\n\nexport namespace Heatmap {\n export type Props = HeatmapProps;\n export type StylesNames = HeatmapStylesNames;\n export type Factory = HeatmapFactory;\n}\n"],"mappings":";;;;;;;;;;;;;AAwHA,MAAM,eAAe;CACnB,aAAa;EAAC;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;CAAK;CAChG,eAAe;EAAC;EAAO;EAAO;EAAI;EAAO;EAAI;EAAO;CAAE;CACtD,kBAAkB;CAClB,gBAAgB;CAChB,UAAU;CACV,qBAAqB;CACrB,oBAAoB;CACpB,KAAK;CACL,YAAY;CACZ,UAAU;CACV,QAAQ;EACN;EACA;EACA;EACA;CACF;CACA,cAAc,CAAC,QAAQ,MAAM;AAC/B;AAEA,MAAa,WAAA,GAAA,cAAA,QAAA,EAAmC,WAAW;CACzD,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,WAAW,cAAc,MAAM;CACtD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,WACA,SACA,iBACA,mBACA,eACA,kBACA,aACA,gBACA,WAAW,IACX,MAAM,GACN,YACA,QACA,QACA,qBACA,oBACA,UACA,iBACA,aACA,cACA,cACA,aACA,YACA,cACA,YACA,GAAG,WACD;CAEJ,MAAM,aAAA,GAAA,cAAA,UAAA,CAAsC;EAC1C,MAAM;EACN,SAAA,u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AA;IACL,UAAU,KAAK,OAAO,MACrB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAEE,GAAG,YAAY,UAAU,KAAK,WAAW;KACzC,GAAG;KACH,OAAO;KACP,QAAQ;KACR,IAAI;KACJ,MAAM;KACN,cAAY,UAAU,KAAA,KAAa,KAAA;KACnC,GAAI,UAAU,YAAY;IAC3B,GATM,CASN,CACF;IACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KACE,GAAG,YAAY,UAAU,aAAa;KACtC,GAAG,WAAW;KACJ;KACV,kBAAiB;KACjB,GAAI,UAAU,aAAa;eAE1B;IACG,CAAA;GACL;;CAEP,EAAA,CAAG,IACH;CAEJ,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACE,cAAAA,KAAD;EACE,WAAU;EACV,OAAO;EACP,QAAQ,kBAAkB,IAAI,MAAM,eAAe;EACnD,GAAI,UAAU,MAAM;EACpB,GAAI;YALN;GAOE,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,QAAQ,UAAT;IACS;IACP,UAAU,CAAC,eAAe,CAAC;IAC3B,UAAS;IACT,GAAI;cAEJ,iBAAA,GAAA,kBAAA,KAAA,CAAC,KAAD;KAAG,WAAW,aAAa,eAAe,IAAI,aAAa;KAAI,WAAQ;eAAvE,CAEG,eACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MACE,MAAK;MACL,OAAO,kBAAkB,eAAe;MACxC,QAAQ,kBAAkB,IAAI;KAC/B,CAAA,GAEF,KACA;;GACa,CAAA;GACjB;GACA;GACA;EACE;;AAET,CAAC;AAED,QAAQ,cAAc;AACtB,QAAQ,UAAUC,uBAAAA"}
|
|
1
|
+
{"version":3,"file":"Heatmap.cjs","names":["getBoundaries","rotateWeekdaysNames","getDatesRange","getMonthsRange","HeatmapSplitWeeks","HeatmapWeeks","getColumns","getFirstMonthColumnIndex","Box","Tooltip","classes"],"sources":["../../src/Heatmap/Heatmap.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n Tooltip,\n TooltipFloatingProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { getBoundaries } from './get-boundaries/get-boundaries';\nimport { getColumns, getFirstMonthColumnIndex, HeatmapColumn } from './get-columns/get-columns';\nimport { getDatesRange } from './get-dates-range/get-dates-range';\nimport { getMonthsRange } from './get-months-range/get-months-range';\nimport { HeatmapSplitWeeks } from './HeatmapSplitWeeks';\nimport { HeatmapWeeks } from './HeatmapWeeks';\nimport { rotateWeekdaysNames } from './rotate-weekdays-names/rotate-weekdays-names';\nimport classes from './Heatmap.module.css';\n\nexport type HeatmapStylesNames =\n | 'root'\n | 'rect'\n | 'weekdayLabel'\n | 'monthLabel'\n | 'legend'\n | 'legendLabel'\n | 'legendRect';\n\ninterface HeatmapRectData {\n date: string;\n value: number | null;\n}\n\nexport interface HeatmapProps\n extends\n BoxProps,\n StylesApiProps<HeatmapFactory>,\n ElementProps<'svg', 'display' | 'opacity' | 'viewBox' | 'width' | 'height'> {\n /** Heatmap data, key is date in `YYYY-MM-DD` format (interpreted as a UTC calendar day) */\n data: Record<string, number>;\n\n /** Heatmap domain, array of 2 numbers, min and max values, calculated from data by default */\n domain?: [number, number];\n\n /** Heatmap start date. Current date - 1 year by default. Date is normalized to UTC midnight of the intended calendar day. */\n startDate?: Date | string;\n\n /** Heatmap end date. Current date by default. Date is normalized to UTC midnight of the intended calendar day. */\n endDate?: Date | string;\n\n /** If set, month labels are displayed @default false */\n withMonthLabels?: boolean;\n\n /** Month labels position relative to the heatmap @default 'top' */\n monthLabelsPosition?: 'top' | 'bottom';\n\n /** Month labels, array of 12 elements, can be used for localization */\n monthLabels?: string[];\n\n /** If set, weekday labels are displayed @default false */\n withWeekdayLabels?: boolean;\n\n /** Weekday labels, array of 7 elements, can be used for localization */\n weekdayLabels?: string[];\n\n /** If set, trailing dates that do not fall into the given `startDate` – `endDate` range are displayed to fill empty space. @default true */\n withOutsideDates?: boolean;\n\n /** First day of week, 0 – Sunday, 1 – Monday. @default 1 – Monday */\n firstDayOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n /** Size of day rect in px @default 10 */\n rectSize?: number;\n\n /** Gap between rects in px @default 1 */\n gap?: number;\n\n /** Rect radius in px @default 2 */\n rectRadius?: number;\n\n /** Colors array, used to calculate color for each value, by default 4 shades of green colors are used */\n colors?: string[];\n\n /** Width of weekday labels column @default 30 */\n weekdaysLabelsWidth?: number;\n\n /** Height of month labels row @default 30 */\n monthsLabelsHeight?: number;\n\n /** Font size of month and weekday labels @default 12 */\n fontSize?: number;\n\n /** A function to generate tooltip label based on the hovered rect date and value, required for the tooltip to be visible */\n getTooltipLabel?: (input: HeatmapRectData) => React.ReactNode;\n\n /** If set, tooltip is displayed on rect hover @default false */\n withTooltip?: boolean;\n\n /** Props passed down to the `Tooltip.Floating` component */\n tooltipProps?: Partial<TooltipFloatingProps>;\n\n /** Props passed down to each rect depending on its date and associated value */\n getRectProps?: (input: HeatmapRectData) => React.ComponentProps<'rect'>;\n\n /** If set, inserts a spacer column between months @default false */\n splitMonths?: boolean;\n\n /** If set, legend with color levels is displayed below the heatmap @default false */\n withLegend?: boolean;\n\n /** Legend labels, array of 2 elements: [min label, max label] @default ['Less', 'More'] */\n legendLabels?: [string, string];\n}\n\nexport type HeatmapFactory = Factory<{\n props: HeatmapProps;\n ref: SVGSVGElement;\n stylesNames: HeatmapStylesNames;\n}>;\n\nconst defaultProps = {\n monthLabels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],\n weekdayLabels: ['Sun', 'Mon', '', 'Wed', '', 'Fri', ''],\n monthLabelsPosition: 'top',\n withOutsideDates: true,\n firstDayOfWeek: 1,\n rectSize: 10,\n weekdaysLabelsWidth: 30,\n monthsLabelsHeight: 14,\n gap: 1,\n rectRadius: 2,\n fontSize: 12,\n colors: [\n 'var(--heatmap-level-1)',\n 'var(--heatmap-level-2)',\n 'var(--heatmap-level-3)',\n 'var(--heatmap-level-4)',\n ],\n legendLabels: ['Less', 'More'] as [string, string],\n} satisfies Partial<HeatmapProps>;\n\nexport const Heatmap = factory<HeatmapFactory>((_props) => {\n const props = useProps('Heatmap', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n startDate,\n endDate,\n withMonthLabels,\n monthLabelsPosition,\n withWeekdayLabels,\n weekdayLabels,\n withOutsideDates,\n monthLabels,\n firstDayOfWeek,\n rectSize = 10,\n gap = 1,\n rectRadius,\n domain,\n colors,\n weekdaysLabelsWidth,\n monthsLabelsHeight,\n fontSize,\n getTooltipLabel,\n withTooltip,\n tooltipProps,\n getRectProps,\n splitMonths,\n withLegend,\n legendLabels,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<HeatmapFactory>({\n name: 'Heatmap',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n });\n\n const [hoveredRect, setHoveredRect] = useState<HeatmapRectData | null>(null);\n const rectSizeWithGap = rectSize + gap;\n const weekdaysOffset = withWeekdayLabels ? weekdaysLabelsWidth : 0;\n const monthsLabelAtTop = withMonthLabels && monthLabelsPosition === 'top';\n const monthsLabelAtBottom = withMonthLabels && monthLabelsPosition === 'bottom';\n const monthsOffset = monthsLabelAtTop ? monthsLabelsHeight : 0;\n const monthsBottomHeight = monthsLabelAtBottom ? monthsLabelsHeight : 0;\n const [min, max] = getBoundaries({ data, domain });\n const rotatedWeekdayLabels = useMemo(\n () => rotateWeekdaysNames(weekdayLabels, firstDayOfWeek),\n [weekdayLabels, firstDayOfWeek]\n );\n\n const datesRange = getDatesRange({\n startDate,\n endDate,\n withOutsideDates,\n firstDayOfWeek,\n });\n\n // Calculate months range for labels and optional split between months\n const monthsRange = withMonthLabels || splitMonths ? getMonthsRange(datesRange) : [];\n\n // Shared props for weeks rendering components\n const weeksProps = {\n data,\n datesRange,\n rectSize,\n gap,\n rectRadius,\n min,\n max,\n colors,\n withTooltip,\n setHoveredRect,\n getRectProps,\n getStyles,\n };\n\n // Use different rendering logic based on splitMonths\n const weeks = splitMonths ? (\n <HeatmapSplitWeeks {...weeksProps} />\n ) : (\n <HeatmapWeeks {...weeksProps} />\n );\n\n // Calculate total columns based on whether splitMonths is enabled\n const totalColumns = splitMonths ? getColumns(datesRange, splitMonths).length : datesRange.length;\n\n const computeMonthLabelX = (monthPosition: number, monthIndex: number) => {\n if (!splitMonths) {\n return monthPosition * rectSizeWithGap + gap + weekdaysOffset;\n }\n\n // For split months, find the first column index that has this month and shift label by 1 column\n const firstMonth = monthsRange[monthIndex];\n const columns: HeatmapColumn[] = getColumns(datesRange, splitMonths);\n const i = getFirstMonthColumnIndex(columns, firstMonth.month);\n const base = i >= 0 ? i : monthPosition;\n // shift right by one column\n return (base + 1) * rectSizeWithGap + gap + weekdaysOffset;\n };\n\n const monthsLabelsNodes =\n withMonthLabels && monthLabels\n ? monthsRange.map((month, monthIndex) => {\n // For non-split months, use original logic with minimum size of 3\n // For split months, use minimum size of 2\n const minSize = splitMonths ? 2 : 3;\n if (month.size < minSize) {\n return null;\n }\n\n const monthLabel = monthLabels[month.month];\n\n const monthLabelY = monthsLabelAtBottom\n ? rectSizeWithGap * 7 + gap + monthsLabelsHeight - 4\n : monthsLabelsHeight - 4;\n\n return (\n <text\n key={monthIndex}\n x={computeMonthLabelX(month.position, monthIndex)}\n y={monthLabelY}\n width={month.size * rectSizeWithGap}\n fontSize={fontSize}\n {...getStyles('monthLabel')}\n >\n {monthLabel}\n </text>\n );\n })\n : null;\n\n const weekdayLabelsNodes =\n withWeekdayLabels && weekdayLabels\n ? rotatedWeekdayLabels.map((weekdayLabel, dayIndex) => (\n <text\n key={dayIndex}\n x={0}\n y={(dayIndex + 1) * rectSizeWithGap - gap + monthsOffset}\n width={weekdaysLabelsWidth}\n fontSize={fontSize}\n {...getStyles('weekdayLabel')}\n >\n {weekdayLabel}\n </text>\n ))\n : null;\n\n const label = getTooltipLabel && hoveredRect && withTooltip ? getTooltipLabel(hoveredRect) : null;\n\n const legendPadding = 10;\n const legendHeight = withLegend ? legendPadding + rectSize : 0;\n const svgWidth = rectSizeWithGap * totalColumns + gap + weekdaysOffset;\n const svgHeight = rectSizeWithGap * 7 + gap + monthsOffset + monthsBottomHeight + legendHeight;\n\n const legendNode = withLegend\n ? (() => {\n const lessLabel = legendLabels![0];\n const moreLabel = legendLabels![1];\n const textGap = 6;\n const charWidth = fontSize! * 0.6;\n const lessWidth = lessLabel.length * charWidth;\n const allColors = [undefined, ...(colors || [])];\n const rectsWidth = allColors.length * rectSize + (allColors.length - 1) * gap;\n const moreWidth = moreLabel.length * charWidth;\n const totalLegendWidth = lessWidth + textGap + rectsWidth + textGap + moreWidth;\n\n const legendX = svgWidth - totalLegendWidth;\n const legendY =\n rectSizeWithGap * 7 + gap + monthsOffset + monthsBottomHeight + legendPadding;\n\n return (\n <g\n transform={`translate(${legendX}, ${legendY})`}\n data-id=\"legend\"\n {...getStyles('legend')}\n >\n <text\n x={0}\n y={rectSize / 2}\n fontSize={fontSize}\n dominantBaseline=\"central\"\n {...getStyles('legendLabel')}\n >\n {lessLabel}\n </text>\n {allColors.map((color, i) => (\n <rect\n key={i}\n x={lessWidth + textGap + i * (rectSize + gap)}\n y={0}\n width={rectSize}\n height={rectSize}\n rx={rectRadius}\n fill={color}\n data-empty={color === undefined || undefined}\n {...getStyles('legendRect')}\n />\n ))}\n <text\n x={lessWidth + textGap + rectsWidth + textGap}\n y={rectSize / 2}\n fontSize={fontSize}\n dominantBaseline=\"central\"\n {...getStyles('legendLabel')}\n >\n {moreLabel}\n </text>\n </g>\n );\n })()\n : null;\n\n return (\n <Box component=\"svg\" width={svgWidth} height={svgHeight} {...getStyles('root')} {...others}>\n <Tooltip.Floating\n label={label}\n disabled={!withTooltip || !label}\n position=\"top\"\n {...tooltipProps}\n >\n <g transform={`translate(${weekdaysOffset}, ${monthsOffset})`} data-id=\"all-weeks\">\n {/* Required for tooltip to remain visible while gaps between rects are hovered */}\n {withTooltip && (\n <rect\n fill=\"transparent\"\n width={rectSizeWithGap * totalColumns + gap}\n height={rectSizeWithGap * 7 + gap}\n />\n )}\n {weeks}\n </g>\n </Tooltip.Floating>\n {weekdayLabelsNodes}\n {monthsLabelsNodes}\n {legendNode}\n </Box>\n );\n});\n\nHeatmap.displayName = '@mantine/charts/Heatmap';\nHeatmap.classes = classes;\n\nexport namespace Heatmap {\n export type Props = HeatmapProps;\n export type StylesNames = HeatmapStylesNames;\n export type Factory = HeatmapFactory;\n}\n"],"mappings":";;;;;;;;;;;;;AA2HA,MAAM,eAAe;CACnB,aAAa;EAAC;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;EAAO;CAAK;CAChG,eAAe;EAAC;EAAO;EAAO;EAAI;EAAO;EAAI;EAAO;CAAE;CACtD,qBAAqB;CACrB,kBAAkB;CAClB,gBAAgB;CAChB,UAAU;CACV,qBAAqB;CACrB,oBAAoB;CACpB,KAAK;CACL,YAAY;CACZ,UAAU;CACV,QAAQ;EACN;EACA;EACA;EACA;CACF;CACA,cAAc,CAAC,QAAQ,MAAM;AAC/B;AAEA,MAAa,WAAA,GAAA,cAAA,QAAA,EAAmC,WAAW;CACzD,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,WAAW,cAAc,MAAM;CACtD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,WACA,SACA,iBACA,qBACA,mBACA,eACA,kBACA,aACA,gBACA,WAAW,IACX,MAAM,GACN,YACA,QACA,QACA,qBACA,oBACA,UACA,iBACA,aACA,cACA,cACA,aACA,YACA,cACA,YACA,GAAG,WACD;CAEJ,MAAM,aAAA,GAAA,cAAA,UAAA,CAAsC;EAC1C,MAAM;EACN,SAAA,uBAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,CAAC,aAAa,mBA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|
2
2
|
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
3
3
|
const require_ChartLegend = require("../ChartLegend/ChartLegend.cjs");
|
|
4
|
+
const require_ChartBrush = require("../ChartBrush/ChartBrush.cjs");
|
|
4
5
|
const require_PointLabel = require("../PointLabel/PointLabel.cjs");
|
|
5
6
|
const require_grid_chart_module = require("../grid-chart.module.cjs");
|
|
6
7
|
let _mantine_core = require("@mantine/core");
|
|
7
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
let react = require("react");
|
|
9
9
|
let recharts = require("recharts");
|
|
10
|
+
let react = require("react");
|
|
10
11
|
let _mantine_hooks = require("@mantine/hooks");
|
|
11
12
|
//#region packages/@mantine/charts/src/LineChart/LineChart.tsx
|
|
12
13
|
const defaultProps = {
|
|
@@ -28,7 +29,8 @@ const defaultProps = {
|
|
|
28
29
|
}, {
|
|
29
30
|
offset: 100,
|
|
30
31
|
color: "blue"
|
|
31
|
-
}]
|
|
32
|
+
}],
|
|
33
|
+
accessibilityLayer: true
|
|
32
34
|
};
|
|
33
35
|
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { textColor, gridColor }) => ({ root: {
|
|
34
36
|
"--chart-text-color": textColor ? (0, _mantine_core.getThemeColor)(textColor, theme) : void 0,
|
|
@@ -36,7 +38,7 @@ const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { textColor,
|
|
|
36
38
|
} }));
|
|
37
39
|
const LineChart = (0, _mantine_core.factory)((_props) => {
|
|
38
40
|
const props = (0, _mantine_core.useProps)("LineChart", defaultProps, _props);
|
|
39
|
-
const { classNames, className, style, styles, unstyled, vars, data, withLegend, legendProps, series, onMouseLeave, dataKey, withTooltip, withXAxis, withYAxis, gridAxis, tickLine, xAxisProps, yAxisProps, unit, tooltipAnimationDuration, strokeDasharray, gridProps, tooltipProps, referenceLines, withDots, dotProps, activeDotProps, strokeWidth, lineChartProps, connectNulls, fillOpacity, curveType, orientation, dir, valueFormatter, children, lineProps, xAxisLabel, yAxisLabel, type, gradientStops, withRightYAxis, rightYAxisLabel, rightYAxisProps, withPointLabels, attributes, gridColor, ...others } = props;
|
|
41
|
+
const { classNames, className, style, styles, unstyled, vars, data, withLegend, legendProps, series, onMouseLeave, dataKey, withTooltip, withXAxis, withYAxis, gridAxis, tickLine, xAxisProps, yAxisProps, unit, tooltipAnimationDuration, strokeDasharray, gridProps, tooltipProps, referenceLines, withDots, dotProps, activeDotProps, strokeWidth, lineChartProps, connectNulls, fillOpacity, curveType, orientation, dir, valueFormatter, children, lineProps, xAxisLabel, yAxisLabel, type, gradientStops, withRightYAxis, rightYAxisLabel, rightYAxisProps, withPointLabels, attributes, gridColor, accessibilityLayer, withBrush, brushProps, ...others } = props;
|
|
40
42
|
const theme = (0, _mantine_core.useMantineTheme)();
|
|
41
43
|
const withXTickLine = gridAxis !== "none" && (tickLine === "x" || tickLine === "xy");
|
|
42
44
|
const withYTickLine = gridAxis !== "none" && (tickLine === "y" || tickLine === "xy");
|
|
@@ -147,6 +149,7 @@ const LineChart = (0, _mantine_core.factory)((_props) => {
|
|
|
147
149
|
left: yAxisLabel ? 10 : void 0,
|
|
148
150
|
right: yAxisLabel ? 5 : void 0
|
|
149
151
|
},
|
|
152
|
+
accessibilityLayer,
|
|
150
153
|
...lineChartProps,
|
|
151
154
|
children: [
|
|
152
155
|
type === "gradient" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("linearGradient", {
|
|
@@ -265,6 +268,12 @@ const LineChart = (0, _mantine_core.factory)((_props) => {
|
|
|
265
268
|
}),
|
|
266
269
|
lines,
|
|
267
270
|
referenceLinesItems,
|
|
271
|
+
withBrush && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartBrush.ChartBrush, {
|
|
272
|
+
dataKey,
|
|
273
|
+
classNames: resolvedClassNames,
|
|
274
|
+
styles: resolvedStyles,
|
|
275
|
+
...brushProps
|
|
276
|
+
}),
|
|
268
277
|
children
|
|
269
278
|
]
|
|
270
279
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.cjs","names":["Line","PointLabel","ReferenceLine","Box","ResponsiveContainer","ReChartsLineChart","Legend","ChartLegend","XAxis","Label","YAxis","CartesianGrid","Tooltip","ChartTooltip","classes"],"sources":["../../src/LineChart/LineChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n CartesianGrid,\n Label,\n Legend,\n Line,\n LineProps,\n LineChart as ReChartsLineChart,\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 { useId } from '@mantine/hooks';\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 classes from '../grid-chart.module.css';\n\nexport type LineChartType = 'default' | 'gradient';\n\nexport interface LineChartGradientStop {\n offset: number;\n color: MantineColor;\n}\n\nexport type LineChartCurveType =\n | 'bump'\n | 'linear'\n | 'natural'\n | 'monotone'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\nexport interface LineChartSeries extends ChartSeries {\n strokeDasharray?: string | number;\n curveType?: LineChartCurveType;\n}\n\nexport type LineChartStylesNames =\n | 'line'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type LineChartCssVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface LineChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<LineChartFactory>, 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: LineChartSeries[];\n\n /** Controls styles of the line @default 'default' */\n type?: LineChartType;\n\n /** Data used to generate gradient stops @default [{ offset: 0, color: 'red' }, { offset: 100, color: 'blue' }] */\n gradientStops?: LineChartGradientStop[];\n\n /** Type of the curve @default 'monotone' */\n curveType?: LineChartCurveType;\n\n /** Controls fill opacity of all lines @default 1 */\n fillOpacity?: number;\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 lines @default 2 */\n strokeWidth?: number;\n\n /** Props passed down to recharts `LineChart` component */\n lineChartProps?: React.ComponentProps<typeof ReChartsLineChart>;\n\n /** Determines whether points with `null` values should be connected @default true */\n connectNulls?: boolean;\n\n /** Additional components that are rendered inside recharts `LineChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Line` component */\n lineProps?:\n | ((series: LineChartSeries) => Partial<Omit<LineProps, 'ref'>>)\n | Partial<Omit<LineProps, 'ref'>>;\n\n /** Determines whether each point should have associated label @default false */\n withPointLabels?: boolean;\n}\n\nexport type LineChartFactory = Factory<{\n props: LineChartProps;\n ref: HTMLDivElement;\n stylesNames: LineChartStylesNames;\n vars: LineChartCssVariables;\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 withDots: true,\n connectNulls: true,\n strokeWidth: 2,\n curveType: 'monotone',\n gradientStops: [\n { offset: 0, color: 'red' },\n { offset: 100, color: 'blue' },\n ],\n} satisfies Partial<LineChartProps>;\n\nconst varsResolver = createVarsResolver<LineChartFactory>((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 LineChart = factory<LineChartFactory>((_props) => {\n const props = useProps('LineChart', 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 withDots,\n dotProps,\n activeDotProps,\n strokeWidth,\n lineChartProps,\n connectNulls,\n fillOpacity,\n curveType,\n orientation,\n dir,\n valueFormatter,\n children,\n lineProps,\n xAxisLabel,\n yAxisLabel,\n type,\n gradientStops,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n withPointLabels,\n attributes,\n gridColor,\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 | number | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<LineChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const getStyles = useStyles<LineChartFactory>({\n name: 'LineChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const id = useId();\n const gradientId = `line-chart-gradient-${id}`;\n const stops = gradientStops?.map((stop) => (\n <stop\n key={stop.color}\n offset={`${stop.offset}%`}\n stopColor={getThemeColor(stop.color, theme)}\n />\n ));\n\n const lines = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n\n return (\n <Line\n {...getStyles('line')}\n key={item.name}\n name={item.name}\n dataKey={item.name}\n dot={\n withDots\n ? {\n fillOpacity: dimmed ? 0 : 1,\n strokeOpacity: dimmed ? 0 : 1,\n strokeWidth: 1,\n fill: type === 'gradient' ? 'var(--mantine-color-gray-7)' : color,\n stroke: type === 'gradient' ? 'white' : color,\n ...dotProps,\n }\n : false\n }\n activeDot={\n withDots\n ? {\n fill: type === 'gradient' ? 'var(--mantine-color-gray-7)' : color,\n stroke: type === 'gradient' ? 'white' : color,\n ...activeDotProps,\n }\n : false\n }\n fill={color}\n stroke={type === 'gradient' ? `url(#${gradientId})` : color}\n strokeWidth={strokeWidth}\n isAnimationActive={false}\n fillOpacity={dimmed ? 0 : fillOpacity}\n strokeOpacity={dimmed ? 0.5 : fillOpacity}\n connectNulls={connectNulls}\n type={item.curveType ?? curveType}\n strokeDasharray={item.strokeDasharray}\n yAxisId={item.yAxisId || undefined}\n label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}\n {...(typeof lineProps === 'function' ? lineProps(item) : lineProps)}\n />\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 fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n ...(typeof line.label === 'object' ? line.label : { value: line.label }),\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 : valueFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box {...getStyles('root')} onMouseLeave={handleMouseLeave} dir={dir || 'ltr'} {...others}>\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsLineChart\n data={data}\n layout={orientation}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n {...lineChartProps}\n >\n {type === 'gradient' && (\n <defs>\n <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n {stops}\n </linearGradient>\n </defs>\n )}\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 !== 'gradient'}\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' ? valueFormatter : 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 // yAxisId=\"left\"\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 }}\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 showColor={type !== 'gradient'}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {lines}\n {referenceLinesItems}\n {children}\n </ReChartsLineChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nLineChart.displayName = '@mantine/charts/LineChart';\nLineChart.classes = classes;\nLineChart.varsResolver = varsResolver;\n\nexport namespace LineChart {\n export type Props = LineChartProps;\n export type CssVariables = LineChartCssVariables;\n export type Factory = LineChartFactory;\n export type Series = LineChartSeries;\n export type StylesNames = LineChartStylesNames;\n export type CurveType = LineChartCurveType;\n}\n"],"mappings":";;;;;;;;;;;AAiIA,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,aAAa;CACb,0B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,GAAA,kBAAA,KAAA,CAACC,SAAAA,OAAD;MACE,SAAQ;MACR,aAAY;MACZ,MAAM;OAAE,WAAW;OAAoB,UAAU;OAAI,MAAM;MAAe;MAC1E,MAAM,CAAC;MACP,GAAI;MACJ,GAAI;gBANN,CAQG,mBACC,iBAAA,GAAA,kBAAA,IAAA,CAACD,SAAAA,OAAD;OACE,UAAS;OACT,OAAO;OACP,YAAW;OACX,UAAU;OACV,QAAQ;OACR,GAAI,UAAU,WAAW;iBAExB;MACI,CAAA,GAER,YAAY,QACR;;KAEP,iBAAA,GAAA,kBAAA,IAAA,CAACE,SAAAA,eAAD;MACmB;MACjB,UAAU,aAAa,OAAO,aAAa;MAC3C,YAAY,aAAa,OAAO,aAAa;MAC7C,GAAI,UAAU,MAAM;MACpB,GAAI;KACL,CAAA;KAEA,eACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,SAAD;MACE,mBAAmB;MACnB,mBAAmB,6BAA6B;MAChD,UAAU,gBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE;MACnD,QAAQ;OACN,QAAQ;OACR,aAAa;OACb;MACF;MACA,UAAU,EAAE,OAAO,SAAS,qBAC1B,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,cAAD;OACE,OAAO,kBAAkB,UAAU,eAAe,OAAO,OAAO,IAAI;OAC3D;OACH;OACN,YAAY;OACZ,QAAQ;OACA;OACQ;OAChB,WAAW,SAAS;OACR;MACb,CAAA;MAEH,GAAI;KACL,CAAA;KAGF;KACA;KACA;IACgB;;EACA,CAAA;CAClB,CAAA;AAET,CAAC;AAED,UAAU,cAAc;AACxB,UAAU,UAAUC,0BAAAA;AACpB,UAAU,eAAe"}
|
|
1
|
+
{"version":3,"file":"LineChart.cjs","names":["Line","PointLabel","ReferenceLine","Box","ResponsiveContainer","ReChartsLineChart","Legend","ChartLegend","XAxis","Label","YAxis","CartesianGrid","Tooltip","ChartTooltip","ChartBrush","classes"],"sources":["../../src/LineChart/LineChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n CartesianGrid,\n Label,\n Legend,\n Line,\n LineProps,\n LineChart as ReChartsLineChart,\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 { useId } from '@mantine/hooks';\nimport { ChartBrush } from '../ChartBrush';\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 classes from '../grid-chart.module.css';\n\nexport type LineChartType = 'default' | 'gradient';\n\nexport interface LineChartGradientStop {\n offset: number;\n color: MantineColor;\n}\n\nexport type LineChartCurveType =\n | 'bump'\n | 'linear'\n | 'natural'\n | 'monotone'\n | 'step'\n | 'stepBefore'\n | 'stepAfter';\n\nexport interface LineChartSeries extends ChartSeries {\n strokeDasharray?: string | number;\n curveType?: LineChartCurveType;\n}\n\nexport type LineChartStylesNames =\n | 'line'\n | BaseChartStylesNames\n | ChartLegendStylesNames\n | ChartTooltipStylesNames;\n\nexport type LineChartCssVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface LineChartProps\n extends BoxProps, GridChartBaseProps, StylesApiProps<LineChartFactory>, 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: LineChartSeries[];\n\n /** Controls styles of the line @default 'default' */\n type?: LineChartType;\n\n /** Data used to generate gradient stops @default [{ offset: 0, color: 'red' }, { offset: 100, color: 'blue' }] */\n gradientStops?: LineChartGradientStop[];\n\n /** Type of the curve @default 'monotone' */\n curveType?: LineChartCurveType;\n\n /** Controls fill opacity of all lines @default 1 */\n fillOpacity?: number;\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 lines @default 2 */\n strokeWidth?: number;\n\n /** Props passed down to recharts `LineChart` component */\n lineChartProps?: React.ComponentProps<typeof ReChartsLineChart>;\n\n /** Determines whether points with `null` values should be connected @default true */\n connectNulls?: boolean;\n\n /** Additional components that are rendered inside recharts `LineChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `Line` component */\n lineProps?:\n | ((series: LineChartSeries) => Partial<Omit<LineProps, 'ref'>>)\n | Partial<Omit<LineProps, 'ref'>>;\n\n /** Determines whether each point should have associated label @default false */\n withPointLabels?: boolean;\n}\n\nexport type LineChartFactory = Factory<{\n props: LineChartProps;\n ref: HTMLDivElement;\n stylesNames: LineChartStylesNames;\n vars: LineChartCssVariables;\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 withDots: true,\n connectNulls: true,\n strokeWidth: 2,\n curveType: 'monotone',\n gradientStops: [\n { offset: 0, color: 'red' },\n { offset: 100, color: 'blue' },\n ],\n accessibilityLayer: true,\n} satisfies Partial<LineChartProps>;\n\nconst varsResolver = createVarsResolver<LineChartFactory>((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 LineChart = factory<LineChartFactory>((_props) => {\n const props = useProps('LineChart', 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 withDots,\n dotProps,\n activeDotProps,\n strokeWidth,\n lineChartProps,\n connectNulls,\n fillOpacity,\n curveType,\n orientation,\n dir,\n valueFormatter,\n children,\n lineProps,\n xAxisLabel,\n yAxisLabel,\n type,\n gradientStops,\n withRightYAxis,\n rightYAxisLabel,\n rightYAxisProps,\n withPointLabels,\n attributes,\n gridColor,\n accessibilityLayer,\n withBrush,\n brushProps,\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 | number | null>(null);\n const shouldHighlight = highlightedArea !== null;\n const handleMouseLeave = (event: React.MouseEvent<HTMLDivElement>) => {\n setHighlightedArea(null);\n onMouseLeave?.(event);\n };\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<LineChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const getStyles = useStyles<LineChartFactory>({\n name: 'LineChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const id = useId();\n const gradientId = `line-chart-gradient-${id}`;\n const stops = gradientStops?.map((stop) => (\n <stop\n key={stop.color}\n offset={`${stop.offset}%`}\n stopColor={getThemeColor(stop.color, theme)}\n />\n ));\n\n const lines = series.map((item) => {\n const color = getThemeColor(item.color, theme);\n const dimmed = shouldHighlight && highlightedArea !== item.name;\n\n return (\n <Line\n {...getStyles('line')}\n key={item.name}\n name={item.name}\n dataKey={item.name}\n dot={\n withDots\n ? {\n fillOpacity: dimmed ? 0 : 1,\n strokeOpacity: dimmed ? 0 : 1,\n strokeWidth: 1,\n fill: type === 'gradient' ? 'var(--mantine-color-gray-7)' : color,\n stroke: type === 'gradient' ? 'white' : color,\n ...dotProps,\n }\n : false\n }\n activeDot={\n withDots\n ? {\n fill: type === 'gradient' ? 'var(--mantine-color-gray-7)' : color,\n stroke: type === 'gradient' ? 'white' : color,\n ...activeDotProps,\n }\n : false\n }\n fill={color}\n stroke={type === 'gradient' ? `url(#${gradientId})` : color}\n strokeWidth={strokeWidth}\n isAnimationActive={false}\n fillOpacity={dimmed ? 0 : fillOpacity}\n strokeOpacity={dimmed ? 0.5 : fillOpacity}\n connectNulls={connectNulls}\n type={item.curveType ?? curveType}\n strokeDasharray={item.strokeDasharray}\n yAxisId={item.yAxisId || undefined}\n label={withPointLabels ? <PointLabel valueFormatter={valueFormatter} /> : undefined}\n {...(typeof lineProps === 'function' ? lineProps(item) : lineProps)}\n />\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 fill: line.color ? color : 'currentColor',\n fontSize: 12,\n position: line.labelPosition ?? 'insideBottomLeft',\n ...(typeof line.label === 'object' ? line.label : { value: line.label }),\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 : valueFormatter,\n ...getStyles('axis'),\n };\n\n return (\n <Box {...getStyles('root')} onMouseLeave={handleMouseLeave} dir={dir || 'ltr'} {...others}>\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsLineChart\n data={data}\n layout={orientation}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n accessibilityLayer={accessibilityLayer}\n {...lineChartProps}\n >\n {type === 'gradient' && (\n <defs>\n <linearGradient id={gradientId} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n {stops}\n </linearGradient>\n </defs>\n )}\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 !== 'gradient'}\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' ? valueFormatter : 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 // yAxisId=\"left\"\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 }}\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 showColor={type !== 'gradient'}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {lines}\n {referenceLinesItems}\n {withBrush && (\n <ChartBrush\n dataKey={dataKey}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n {...brushProps}\n />\n )}\n {children}\n </ReChartsLineChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nLineChart.displayName = '@mantine/charts/LineChart';\nLineChart.classes = classes;\nLineChart.varsResolver = varsResolver;\n\nexport namespace LineChart {\n export type Props = LineChartProps;\n export type CssVariables = LineChartCssVariables;\n export type Factory = LineChartFactory;\n export type Series = LineChartSeries;\n export type StylesNames = LineChartStylesNames;\n export type CurveType = LineChartCurveType;\n}\n"],"mappings":";;;;;;;;;;;;AAkIA,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,aAAa;CACb,0BAA0B;CAC1B,aAAa;CACb,UAAU;CACV,iBAAiB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
5
|
const require_PieChart_module = require("./PieChart.module.cjs");
|
|
6
6
|
let _mantine_core = require("@mantine/core");
|
|
7
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
let react = require("react");
|
|
9
8
|
let recharts = require("recharts");
|
|
9
|
+
let react = require("react");
|
|
10
10
|
//#region packages/@mantine/charts/src/PieChart/PieChart.tsx
|
|
11
11
|
const defaultProps = {
|
|
12
12
|
withTooltip: false,
|
|
@@ -18,7 +18,8 @@ const defaultProps = {
|
|
|
18
18
|
endAngle: 360,
|
|
19
19
|
tooltipDataSource: "all",
|
|
20
20
|
labelsPosition: "outside",
|
|
21
|
-
labelsType: "value"
|
|
21
|
+
labelsType: "value",
|
|
22
|
+
accessibilityLayer: true
|
|
22
23
|
};
|
|
23
24
|
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { strokeColor, labelColor, withLabels, withLegend, size, labelsPosition }) => ({ root: {
|
|
24
25
|
"--chart-stroke-color": strokeColor ? (0, _mantine_core.getThemeColor)(strokeColor, theme) : void 0,
|
|
@@ -60,7 +61,7 @@ const getOutsideLabel = (labelsType, valueFormatter) => ({ x, y, cx, cy, percent
|
|
|
60
61
|
});
|
|
61
62
|
const PieChart = (0, _mantine_core.factory)((_props) => {
|
|
62
63
|
const props = (0, _mantine_core.useProps)("PieChart", defaultProps, _props);
|
|
63
|
-
const { classNames, className, style, styles, unstyled, vars, data, withTooltip, withLegend, legendProps, tooltipAnimationDuration, tooltipProps, pieProps, paddingAngle, withLabels, withLabelsLine, size, strokeWidth, startAngle, endAngle, tooltipDataSource, children, pieChartProps, labelsPosition, valueFormatter, labelsType, strokeColor, attributes, cellProps, ...others } = props;
|
|
64
|
+
const { classNames, className, style, styles, unstyled, vars, data, withTooltip, withLegend, legendProps, tooltipAnimationDuration, tooltipProps, pieProps, paddingAngle, withLabels, withLabelsLine, size, strokeWidth, startAngle, endAngle, tooltipDataSource, children, pieChartProps, labelsPosition, valueFormatter, labelsType, strokeColor, attributes, cellProps, accessibilityLayer, ...others } = props;
|
|
64
65
|
const theme = (0, _mantine_core.useMantineTheme)();
|
|
65
66
|
const [highlightedIndex, setHighlightedIndex] = (0, react.useState)(null);
|
|
66
67
|
const getStyles = (0, _mantine_core.useStyles)({
|
|
@@ -93,6 +94,7 @@ const PieChart = (0, _mantine_core.factory)((_props) => {
|
|
|
93
94
|
...getStyles("root"),
|
|
94
95
|
...others,
|
|
95
96
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ResponsiveContainer, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.PieChart, {
|
|
97
|
+
accessibilityLayer,
|
|
96
98
|
...pieChartProps,
|
|
97
99
|
children: [
|
|
98
100
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Pie, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChart.cjs","names":["classes","getPieChartData","Box","ResponsiveContainer","ReChartsPieChart","Pie","Tooltip","ChartTooltip","Legend","ChartLegend"],"sources":["../../src/PieChart/PieChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n Legend,\n LegendProps,\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport { getPieChartData } from '../utils';\nimport classes from './PieChart.module.css';\n\nexport interface PieChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type PieChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;\nexport type PieChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface PieChartProps\n extends BoxProps, StylesApiProps<PieChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: PieChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section is hovered @default true */\n withTooltip?: boolean;\n\n /** Determines whether the legend should be displayed @default false */\n withLegend?: boolean;\n\n /** Props passed down to recharts `Legend` component */\n legendProps?: Omit<LegendProps, 'ref'>;\n\n /** Tooltip animation duration in ms @default 0 */\n tooltipAnimationDuration?: number;\n\n /** Props passed down to `Tooltip` recharts component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to recharts `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, white by default */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Controls labels position relative to the segment @default 'outside' */\n labelsPosition?: 'inside' | 'outside';\n\n /** Type of labels to display @default 'value' */\n labelsType?: 'value' | 'percent' | 'name';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to each segment of the chart */\n cellProps?:\n | ((series: PieChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>)\n | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;\n}\n\nexport type PieChartFactory = Factory<{\n props: PieChartProps;\n ref: HTMLDivElement;\n stylesNames: PieChartStylesNames;\n vars: PieChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: false,\n withLabelsLine: true,\n paddingAngle: 0,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n tooltipDataSource: 'all',\n labelsPosition: 'outside',\n labelsType: 'value',\n} satisfies Partial<PieChartProps>;\n\nconst varsResolver = createVarsResolver<PieChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, withLegend, size, labelsPosition }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': rem(\n size! + (withLabels && labelsPosition === 'outside' ? 80 : 0) + (withLegend ? 80 : 0)\n ),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: PieChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n name: string | undefined,\n valueFormatter?: PieChartProps['valueFormatter']\n) => {\n if (labelsType === 'name') {\n return name;\n }\n\n if (labelsType === 'percent' && typeof percent === 'number') {\n return `${(percent * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function' && typeof value === 'number') {\n return valueFormatter(value);\n }\n\n return value;\n};\n\nconst getInsideLabel =\n (\n labelsType: 'value' | 'percent' | 'name',\n valueFormatter?: PieChartProps['valueFormatter']\n ): PieLabel =>\n ({ cx, cy, midAngle, innerRadius, outerRadius, value, percent, name }) => {\n const RADIAN = Math.PI / 180;\n const radius = Number(innerRadius) + (Number(outerRadius) - Number(innerRadius)) * 0.5;\n const x = Number(cx) + radius * Math.cos(-(midAngle || 0) * RADIAN);\n const y = Number(cy) + radius * Math.sin(-(midAngle || 0) * RADIAN);\n\n return (\n <text\n x={x}\n y={y}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n dominantBaseline=\"central\"\n className={classes.label}\n >\n {getLabelValue(labelsType, Number(value), Number(percent), name as string, valueFormatter)}\n </text>\n );\n };\n\nconst getOutsideLabel =\n (\n labelsType: 'value' | 'percent' | 'name',\n valueFormatter?: PieChartProps['valueFormatter']\n ): PieLabel =>\n ({ x, y, cx, cy, percent, value, name }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), name as string, valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const PieChart = factory<PieChartFactory>((_props) => {\n const props = useProps('PieChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n withLegend,\n legendProps,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n children,\n pieChartProps,\n labelsPosition,\n valueFormatter,\n labelsType,\n strokeColor,\n attributes,\n cellProps,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);\n\n const getStyles = useStyles<PieChartFactory>({\n name: 'PieChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<PieChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const pieData = getPieChartData({ data, theme, strokeWidth, highlightedIndex, cellProps });\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart {...pieChartProps}>\n <Pie\n data={pieData as any}\n innerRadius={0}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={\n withLabels\n ? labelsPosition === 'inside'\n ? getInsideLabel(labelsType || 'value', valueFormatter)\n : getOutsideLabel(labelsType || 'value', valueFormatter)\n : false\n }\n labelLine={\n withLabelsLine && labelsPosition === 'outside'\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment'\n ? (payload?.[0]?.payload?.__segmentIndex as number)\n : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {withLegend && (\n <Legend\n verticalAlign=\"bottom\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload?.map((item) => ({\n ...item,\n dataKey: (item.payload as any)?.name,\n highlightKey: (item.payload as any)?.__segmentIndex,\n }))}\n onHighlight={(value) =>\n setHighlightedIndex(typeof value === 'number' ? value : null)\n }\n legendPosition={legendProps?.verticalAlign || 'bottom'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n centered\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nPieChart.displayName = '@mantine/charts/PieChart';\nPieChart.classes = classes;\nPieChart.varsResolver = varsResolver;\n\nexport namespace PieChart {\n export type Props = PieChartProps;\n export type StylesNames = PieChartStylesNames;\n export type CssVariables = PieChartCssVariables;\n export type Factory = PieChartFactory;\n export type Cell = PieCh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cAAc;AACvB,SAAS,UAAUT,wBAAAA;AACnB,SAAS,eAAe"}
|
|
1
|
+
{"version":3,"file":"PieChart.cjs","names":["classes","getPieChartData","Box","ResponsiveContainer","ReChartsPieChart","Pie","Tooltip","ChartTooltip","Legend","ChartLegend"],"sources":["../../src/PieChart/PieChart.tsx"],"sourcesContent":["import { useState } from 'react';\nimport {\n Legend,\n LegendProps,\n Pie,\n PieLabel,\n PieProps,\n PieChart as ReChartsPieChart,\n ResponsiveContainer,\n Tooltip,\n TooltipProps,\n} from 'recharts';\nimport {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useResolvedStylesApi,\n useStyles,\n} from '@mantine/core';\nimport { ChartLegend, ChartLegendStylesNames } from '../ChartLegend';\nimport { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip/ChartTooltip';\nimport { getPieChartData } from '../utils';\nimport classes from './PieChart.module.css';\n\nexport interface PieChartCell {\n key?: string | number;\n name: string;\n value: number;\n color: MantineColor;\n}\n\nexport type PieChartStylesNames = 'root' | ChartTooltipStylesNames | ChartLegendStylesNames;\nexport type PieChartCssVariables = {\n root: '--chart-stroke-color' | '--chart-labels-color' | '--chart-size';\n};\n\nexport interface PieChartProps\n extends BoxProps, StylesApiProps<PieChartFactory>, ElementProps<'div'> {\n /** Data used to render chart */\n data: PieChartCell[];\n\n /** Determines whether the tooltip should be displayed when one of the section is hovered @default true */\n withTooltip?: boolean;\n\n /** Determines whether the legend should be displayed @default false */\n withLegend?: boolean;\n\n /** Props passed down to recharts `Legend` component */\n legendProps?: Omit<LegendProps, 'ref'>;\n\n /** Tooltip animation duration in ms @default 0 */\n tooltipAnimationDuration?: number;\n\n /** Props passed down to `Tooltip` recharts component */\n tooltipProps?: Omit<TooltipProps<any, any>, 'ref'>;\n\n /** Props passed down to recharts `Pie` component */\n pieProps?: Partial<Omit<PieProps, 'ref'>>;\n\n /** Controls color of the segments stroke, by default depends on color scheme */\n strokeColor?: MantineColor;\n\n /** Controls text color of all labels, white by default */\n labelColor?: MantineColor;\n\n /** Controls padding between segments @default 0 */\n paddingAngle?: number;\n\n /** Determines whether each segment should have associated label @default false */\n withLabels?: boolean;\n\n /** Determines whether segments labels should have lines that connect the segment with the label @default true */\n withLabelsLine?: boolean;\n\n /** Controls chart width and height, height is increased by 40 if `withLabels` prop is set. Cannot be less than `thickness`. @default 80 */\n size?: number;\n\n /** Controls width of segments stroke @default 1 */\n strokeWidth?: number;\n\n /** Controls angle at which chart starts. Set to `180` to render the chart as semicircle. @default 0 */\n startAngle?: number;\n\n /** Controls angle at which charts ends. Set to `0` to render the chart as semicircle. @default 360 */\n endAngle?: number;\n\n /** Determines which data is displayed in the tooltip. `'all'` – display all values, `'segment'` – display only hovered segment. @default 'all' */\n tooltipDataSource?: 'segment' | 'all';\n\n /** Additional elements rendered inside `PieChart` component */\n children?: React.ReactNode;\n\n /** Props passed down to recharts `PieChart` component */\n pieChartProps?: React.ComponentProps<typeof ReChartsPieChart>;\n\n /** Controls labels position relative to the segment @default 'outside' */\n labelsPosition?: 'inside' | 'outside';\n\n /** Type of labels to display @default 'value' */\n labelsType?: 'value' | 'percent' | 'name';\n\n /** A function to format values inside the tooltip */\n valueFormatter?: (value: number) => string;\n\n /** Props passed down to each segment of the chart */\n cellProps?:\n | ((series: PieChartCell) => Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>)\n | Partial<Omit<React.SVGProps<SVGElement>, 'ref'>>;\n\n /** Determines whether the chart should be keyboard-navigable with the recharts accessibility layer, `true` by default */\n accessibilityLayer?: boolean;\n}\n\nexport type PieChartFactory = Factory<{\n props: PieChartProps;\n ref: HTMLDivElement;\n stylesNames: PieChartStylesNames;\n vars: PieChartCssVariables;\n}>;\n\nconst defaultProps = {\n withTooltip: false,\n withLabelsLine: true,\n paddingAngle: 0,\n size: 160,\n strokeWidth: 1,\n startAngle: 0,\n endAngle: 360,\n tooltipDataSource: 'all',\n labelsPosition: 'outside',\n labelsType: 'value',\n accessibilityLayer: true,\n} satisfies Partial<PieChartProps>;\n\nconst varsResolver = createVarsResolver<PieChartFactory>(\n (theme, { strokeColor, labelColor, withLabels, withLegend, size, labelsPosition }) => ({\n root: {\n '--chart-stroke-color': strokeColor ? getThemeColor(strokeColor, theme) : undefined,\n '--chart-labels-color': labelColor ? getThemeColor(labelColor, theme) : undefined,\n '--chart-size': rem(\n size! + (withLabels && labelsPosition === 'outside' ? 80 : 0) + (withLegend ? 80 : 0)\n ),\n },\n })\n);\n\nconst getLabelValue = (\n labelsType: PieChartProps['labelsType'],\n value: number | undefined,\n percent: number | undefined,\n name: string | undefined,\n valueFormatter?: PieChartProps['valueFormatter']\n) => {\n if (labelsType === 'name') {\n return name;\n }\n\n if (labelsType === 'percent' && typeof percent === 'number') {\n return `${(percent * 100).toFixed(0)}%`;\n }\n\n if (typeof valueFormatter === 'function' && typeof value === 'number') {\n return valueFormatter(value);\n }\n\n return value;\n};\n\nconst getInsideLabel =\n (\n labelsType: 'value' | 'percent' | 'name',\n valueFormatter?: PieChartProps['valueFormatter']\n ): PieLabel =>\n ({ cx, cy, midAngle, innerRadius, outerRadius, value, percent, name }) => {\n const RADIAN = Math.PI / 180;\n const radius = Number(innerRadius) + (Number(outerRadius) - Number(innerRadius)) * 0.5;\n const x = Number(cx) + radius * Math.cos(-(midAngle || 0) * RADIAN);\n const y = Number(cy) + radius * Math.sin(-(midAngle || 0) * RADIAN);\n\n return (\n <text\n x={x}\n y={y}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n dominantBaseline=\"central\"\n className={classes.label}\n >\n {getLabelValue(labelsType, Number(value), Number(percent), name as string, valueFormatter)}\n </text>\n );\n };\n\nconst getOutsideLabel =\n (\n labelsType: 'value' | 'percent' | 'name',\n valueFormatter?: PieChartProps['valueFormatter']\n ): PieLabel =>\n ({ x, y, cx, cy, percent, value, name }) => (\n <text\n x={x}\n y={y}\n cx={cx}\n cy={cy}\n textAnchor={x > Number(cx) ? 'start' : 'end'}\n fill=\"var(--chart-labels-color, var(--mantine-color-dimmed))\"\n fontFamily=\"var(--mantine-font-family)\"\n fontSize={12}\n >\n <tspan x={x}>\n {getLabelValue(labelsType, Number(value), Number(percent), name as string, valueFormatter)}\n </tspan>\n </text>\n );\n\nexport const PieChart = factory<PieChartFactory>((_props) => {\n const props = useProps('PieChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n withTooltip,\n withLegend,\n legendProps,\n tooltipAnimationDuration,\n tooltipProps,\n pieProps,\n paddingAngle,\n withLabels,\n withLabelsLine,\n size,\n strokeWidth,\n startAngle,\n endAngle,\n tooltipDataSource,\n children,\n pieChartProps,\n labelsPosition,\n valueFormatter,\n labelsType,\n strokeColor,\n attributes,\n cellProps,\n accessibilityLayer,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const [highlightedIndex, setHighlightedIndex] = useState<number | null>(null);\n\n const getStyles = useStyles<PieChartFactory>({\n name: 'PieChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<PieChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const pieData = getPieChartData({ data, theme, strokeWidth, highlightedIndex, cellProps });\n\n return (\n <Box size={size} {...getStyles('root')} {...others}>\n <ResponsiveContainer>\n <ReChartsPieChart accessibilityLayer={accessibilityLayer} {...pieChartProps}>\n <Pie\n data={pieData as any}\n innerRadius={0}\n outerRadius={size / 2}\n dataKey=\"value\"\n isAnimationActive={false}\n paddingAngle={paddingAngle}\n startAngle={startAngle}\n endAngle={endAngle}\n label={\n withLabels\n ? labelsPosition === 'inside'\n ? getInsideLabel(labelsType || 'value', valueFormatter)\n : getOutsideLabel(labelsType || 'value', valueFormatter)\n : false\n }\n labelLine={\n withLabelsLine && labelsPosition === 'outside'\n ? {\n stroke: 'var(--chart-label-color, var(--mantine-color-dimmed))',\n strokeWidth: 1,\n }\n : false\n }\n {...pieProps}\n />\n\n {withTooltip && (\n <Tooltip\n animationDuration={tooltipAnimationDuration}\n isAnimationActive={false}\n content={({ payload }) => (\n <ChartTooltip\n payload={data}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n type=\"radial\"\n segmentId={\n tooltipDataSource === 'segment'\n ? (payload?.[0]?.payload?.__segmentIndex as number)\n : undefined\n }\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n )}\n {...tooltipProps}\n />\n )}\n\n {withLegend && (\n <Legend\n verticalAlign=\"bottom\"\n content={(payload) => (\n <ChartLegend\n payload={payload.payload?.map((item) => ({\n ...item,\n dataKey: (item.payload as any)?.name,\n highlightKey: (item.payload as any)?.__segmentIndex,\n }))}\n onHighlight={(value) =>\n setHighlightedIndex(typeof value === 'number' ? value : null)\n }\n legendPosition={legendProps?.verticalAlign || 'bottom'}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n centered\n attributes={attributes}\n />\n )}\n {...legendProps}\n />\n )}\n\n {children}\n </ReChartsPieChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nPieChart.displayName = '@mantine/charts/PieChart';\nPieChart.classes = classes;\nPieChart.varsResolver = varsResolver;\n\nexport namespace PieChart {\n export type Props = PieChartProps;\n export type StylesNames = PieChartStylesNames;\n export type CssVariables = PieChartCssVariables;\n export type Factory = PieChartFactory;\n export type Cell = PieChartCell;\n}\n"],"mappings":";;;;;;;;;;AAiIA,MAAM,eAAe;CACnB,aAAa;CACb,gBAAgB;CAChB,cAAc;CACd,MAAM;CACN,aAAa;CACb,YAAY;CACZ,UAAU;CACV,mBAAmB;CACnB,gBAAgB;CAChB,YAAY;CACZ,oBAAoB;AACtB;AAEA,MAAM,gBAAA,GAAA,cAAA,mBAAA,EACH,OAAO,EAAE,aAAa,YAAY,YAAY,YAAY,MAAM,sBAAsB,EACrF,MAAM;CACJ,wBAAwB,eAAA,GAAA,cAAA,cAAA,CA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WACjB,eAAe,cAAc,SAAS,cAAc,IACpD,gBAAgB,cAAc,SAAS,cAAc,IACvD;KAEN,WACE,kBAAkB,mBAAmB,YACjC;MACE,QAAQ;MACR,aAAa;KACf,IACA;KAEN,GAAI;IACL,CAAA;IAEA,eACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,SAAD;KACE,mBAAmB;KACnB,mBAAmB;KACnB,UAAU,EAAE,cACV,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,cAAD;MACE,SAAS;MACT,YAAY;MACZ,QAAQ;MACR,MAAK;MACL,WACE,sBAAsB,YACjB,UAAU,EAAE,EAAE,SAAS,iBACxB,KAAA;MAEU;MACJ;KACb,CAAA;KAEH,GAAI;IACL,CAAA;IAGF,cACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,QAAD;KACE,eAAc;KACd,UAAU,YACR,iBAAA,GAAA,kBAAA,IAAA,CAACC,oBAAAA,aAAD;MACE,SAAS,QAAQ,SAAS,KAAK,UAAU;OACvC,GAAG;OACH,SAAU,KAAK,SAAiB;OAChC,cAAe,KAAK,SAAiB;MACvC,EAAE;MACF,cAAc,UACZ,oBAAoB,OAAO,UAAU,WAAW,QAAQ,IAAI;MAE9D,gBAAgB,aAAa,iBAAiB;MAC9C,YAAY;MACZ,QAAQ;MACR,UAAA;MACY;KACb,CAAA;KAEH,GAAI;IACL,CAAA;IAGF;GACe;KACC,CAAA;CAClB,CAAA;AAET,CAAC;AAED,SAAS,cAAc;AACvB,SAAS,UAAUT,wBAAAA;AACnB,SAAS,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChart.module.cjs","names":[],"sources":["../../src/PieChart/PieChart.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-size, auto);\n height: var(--chart-size, auto);\n width: var(--chart-size, auto);\n min-width: var(--chart-size, auto);\n\n & :where(*) {\n outline: 0;\n }\n\n & :where(:global(.recharts-surface)) {\n overflow: visible;\n }\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"PieChart.module.cjs","names":[],"sources":["../../src/PieChart/PieChart.module.css"],"sourcesContent":[".root {\n min-height: var(--chart-size, auto);\n height: var(--chart-size, auto);\n width: var(--chart-size, auto);\n min-width: var(--chart-size, auto);\n\n & :where(*) {\n outline: 0;\n }\n\n & :where(:global(.recharts-surface)) {\n overflow: visible;\n }\n\n svg:focus-visible {\n outline: 2px solid var(--mantine-primary-color-filled);\n outline-offset: 2px;\n }\n}\n"],"mappings":""}
|
|
@@ -4,8 +4,8 @@ const require_ChartLegend = require("../ChartLegend/ChartLegend.cjs");
|
|
|
4
4
|
const require_RadarChart_module = require("./RadarChart.module.cjs");
|
|
5
5
|
let _mantine_core = require("@mantine/core");
|
|
6
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let react = require("react");
|
|
8
7
|
let recharts = require("recharts");
|
|
8
|
+
let react = require("react");
|
|
9
9
|
//#region packages/@mantine/charts/src/RadarChart/RadarChart.tsx
|
|
10
10
|
const defaultProps = {
|
|
11
11
|
withPolarGrid: true,
|
|
@@ -13,7 +13,8 @@ const defaultProps = {
|
|
|
13
13
|
withPolarRadiusAxis: false,
|
|
14
14
|
withTooltip: false,
|
|
15
15
|
withDots: false,
|
|
16
|
-
tooltipAnimationDuration: 0
|
|
16
|
+
tooltipAnimationDuration: 0,
|
|
17
|
+
accessibilityLayer: true
|
|
17
18
|
};
|
|
18
19
|
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { gridColor, textColor }) => ({ root: {
|
|
19
20
|
"--chart-grid-color": gridColor ? (0, _mantine_core.getThemeColor)(gridColor, theme) : void 0,
|
|
@@ -21,7 +22,7 @@ const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { gridColor,
|
|
|
21
22
|
} }));
|
|
22
23
|
const RadarChart = (0, _mantine_core.factory)((_props) => {
|
|
23
24
|
const props = (0, _mantine_core.useProps)("RadarChart", defaultProps, _props);
|
|
24
|
-
const { classNames, className, style, styles, unstyled, vars, data, series, dataKey, gridColor, textColor, radarProps, radarChartProps, polarGridProps, polarAngleAxisProps, polarRadiusAxisProps, tooltipProps, withPolarGrid, withPolarAngleAxis, withPolarRadiusAxis, withTooltip, tooltipAnimationDuration, children, withLegend, withDots, dotProps, activeDotProps, legendProps, attributes, ...others } = props;
|
|
25
|
+
const { classNames, className, style, styles, unstyled, vars, data, series, dataKey, gridColor, textColor, radarProps, radarChartProps, polarGridProps, polarAngleAxisProps, polarRadiusAxisProps, tooltipProps, withPolarGrid, withPolarAngleAxis, withPolarRadiusAxis, withTooltip, tooltipAnimationDuration, children, withLegend, withDots, dotProps, activeDotProps, legendProps, attributes, accessibilityLayer, ...others } = props;
|
|
25
26
|
const theme = (0, _mantine_core.useMantineTheme)();
|
|
26
27
|
const getStyles = (0, _mantine_core.useStyles)({
|
|
27
28
|
name: "RadarChart",
|
|
@@ -72,6 +73,7 @@ const RadarChart = (0, _mantine_core.factory)((_props) => {
|
|
|
72
73
|
...getStyles("container"),
|
|
73
74
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.RadarChart, {
|
|
74
75
|
data,
|
|
76
|
+
accessibilityLayer,
|
|
75
77
|
...radarChartProps,
|
|
76
78
|
children: [
|
|
77
79
|
withPolarGrid && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.PolarGrid, {
|