@mantine/charts 9.5.1 → 9.6.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 +49 -11
- package/cjs/AreaChart/AreaChart.cjs.map +1 -1
- package/cjs/AreaChart/AreaGradient.cjs.map +1 -1
- package/cjs/AreaChart/AreaSplit.cjs.map +1 -1
- package/cjs/BarChart/BarChart.cjs +44 -6
- package/cjs/BarChart/BarChart.cjs.map +1 -1
- package/cjs/BarsList/BarsList.cjs.map +1 -1
- package/cjs/BubbleChart/BubbleChart.cjs.map +1 -1
- package/cjs/BulletChart/BulletChart.cjs +7 -5
- package/cjs/BulletChart/BulletChart.cjs.map +1 -1
- package/cjs/CandlestickChart/CandlestickChart.cjs +340 -0
- package/cjs/CandlestickChart/CandlestickChart.cjs.map +1 -0
- package/cjs/CandlestickChart/get-candle-geometry/get-candle-geometry.cjs +30 -0
- package/cjs/CandlestickChart/get-candle-geometry/get-candle-geometry.cjs.map +1 -0
- package/cjs/CandlestickChart/get-candlestick-domain/get-candlestick-domain.cjs +40 -0
- package/cjs/CandlestickChart/get-candlestick-domain/get-candlestick-domain.cjs.map +1 -0
- package/cjs/ChartBrush/ChartBrush.cjs.map +1 -1
- package/cjs/ChartLegend/ChartLegend.cjs.map +1 -1
- package/cjs/ChartTooltip/ChartTooltip.cjs.map +1 -1
- package/cjs/CompositeChart/CompositeChart.cjs +44 -6
- package/cjs/CompositeChart/CompositeChart.cjs.map +1 -1
- package/cjs/DonutChart/DonutChart.cjs.map +1 -1
- package/cjs/FunnelChart/FunnelChart.cjs.map +1 -1
- package/cjs/GaugeChart/GaugeChart.cjs +208 -0
- package/cjs/GaugeChart/GaugeChart.cjs.map +1 -0
- package/cjs/GaugeChart/GaugeChart.module.cjs +10 -0
- package/cjs/GaugeChart/GaugeChart.module.cjs.map +1 -0
- package/cjs/Heatmap/Heatmap.cjs +5 -2
- package/cjs/Heatmap/Heatmap.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs +2 -1
- package/cjs/Heatmap/HeatmapSplitWeeks.cjs.map +1 -1
- package/cjs/Heatmap/HeatmapWeeks.cjs.map +1 -1
- package/cjs/LineChart/LineChart.cjs +44 -6
- package/cjs/LineChart/LineChart.cjs.map +1 -1
- package/cjs/MatrixChart/MatrixChart.cjs +211 -0
- package/cjs/MatrixChart/MatrixChart.cjs.map +1 -0
- package/cjs/MatrixChart/MatrixChart.module.cjs +14 -0
- package/cjs/MatrixChart/MatrixChart.module.cjs.map +1 -0
- package/cjs/MatrixChart/build-cell-map/build-cell-map.cjs +17 -0
- package/cjs/MatrixChart/build-cell-map/build-cell-map.cjs.map +1 -0
- package/cjs/MatrixChart/get-domain/get-domain.cjs +28 -0
- package/cjs/MatrixChart/get-domain/get-domain.cjs.map +1 -0
- package/cjs/MatrixChart/get-legend-width/get-legend-width.cjs +15 -0
- package/cjs/MatrixChart/get-legend-width/get-legend-width.cjs.map +1 -0
- package/cjs/MatrixChart/get-unique-values/get-unique-values.cjs +19 -0
- package/cjs/MatrixChart/get-unique-values/get-unique-values.cjs.map +1 -0
- package/cjs/PieChart/PieChart.cjs +2 -1
- package/cjs/PieChart/PieChart.cjs.map +1 -1
- package/cjs/PointLabel/PointLabel.cjs.map +1 -1
- package/cjs/RadarChart/RadarChart.cjs.map +1 -1
- package/cjs/RadialBarChart/RadialBarChart.cjs.map +1 -1
- package/cjs/SankeyChart/SankeyChart.cjs.map +1 -1
- package/cjs/ScatterChart/ScatterChart.cjs +43 -7
- package/cjs/ScatterChart/ScatterChart.cjs.map +1 -1
- package/cjs/Sparkline/Sparkline.cjs.map +1 -1
- package/cjs/SunburstChart/SunburstChart.cjs.map +1 -1
- package/cjs/Treemap/Treemap.cjs.map +1 -1
- package/cjs/WaffleChart/WaffleChart.cjs +189 -0
- package/cjs/WaffleChart/WaffleChart.cjs.map +1 -0
- package/cjs/WaffleChart/WaffleChart.module.cjs +14 -0
- package/cjs/WaffleChart/WaffleChart.module.cjs.map +1 -0
- package/cjs/_virtual/_rolldown/runtime.cjs +1 -1
- package/cjs/index.cjs +8 -0
- package/cjs/utils/get-pie-chart-data/get-pie-chart-data.cjs.map +1 -1
- package/esm/AreaChart/AreaChart.mjs +50 -12
- package/esm/AreaChart/AreaChart.mjs.map +1 -1
- package/esm/AreaChart/AreaGradient.mjs.map +1 -1
- package/esm/AreaChart/AreaSplit.mjs.map +1 -1
- package/esm/BarChart/BarChart.mjs +45 -7
- package/esm/BarChart/BarChart.mjs.map +1 -1
- package/esm/BarsList/BarsList.mjs.map +1 -1
- package/esm/BubbleChart/BubbleChart.mjs.map +1 -1
- package/esm/BulletChart/BulletChart.mjs +7 -5
- package/esm/BulletChart/BulletChart.mjs.map +1 -1
- package/esm/CandlestickChart/CandlestickChart.mjs +340 -0
- package/esm/CandlestickChart/CandlestickChart.mjs.map +1 -0
- package/esm/CandlestickChart/get-candle-geometry/get-candle-geometry.mjs +30 -0
- package/esm/CandlestickChart/get-candle-geometry/get-candle-geometry.mjs.map +1 -0
- package/esm/CandlestickChart/get-candlestick-domain/get-candlestick-domain.mjs +39 -0
- package/esm/CandlestickChart/get-candlestick-domain/get-candlestick-domain.mjs.map +1 -0
- package/esm/ChartLegend/ChartLegend.mjs.map +1 -1
- package/esm/ChartTooltip/ChartTooltip.mjs.map +1 -1
- package/esm/CompositeChart/CompositeChart.mjs +45 -7
- package/esm/CompositeChart/CompositeChart.mjs.map +1 -1
- package/esm/DonutChart/DonutChart.mjs.map +1 -1
- package/esm/FunnelChart/FunnelChart.mjs.map +1 -1
- package/esm/GaugeChart/GaugeChart.mjs +208 -0
- package/esm/GaugeChart/GaugeChart.mjs.map +1 -0
- package/esm/GaugeChart/GaugeChart.module.mjs +10 -0
- package/esm/GaugeChart/GaugeChart.module.mjs.map +1 -0
- package/esm/Heatmap/Heatmap.mjs +5 -2
- package/esm/Heatmap/Heatmap.mjs.map +1 -1
- package/esm/Heatmap/HeatmapSplitWeeks.mjs +2 -1
- package/esm/Heatmap/HeatmapSplitWeeks.mjs.map +1 -1
- package/esm/Heatmap/HeatmapWeeks.mjs.map +1 -1
- package/esm/LineChart/LineChart.mjs +45 -7
- package/esm/LineChart/LineChart.mjs.map +1 -1
- package/esm/MatrixChart/MatrixChart.mjs +211 -0
- package/esm/MatrixChart/MatrixChart.mjs.map +1 -0
- package/esm/MatrixChart/MatrixChart.module.mjs +14 -0
- package/esm/MatrixChart/MatrixChart.module.mjs.map +1 -0
- package/esm/MatrixChart/build-cell-map/build-cell-map.mjs +16 -0
- package/esm/MatrixChart/build-cell-map/build-cell-map.mjs.map +1 -0
- package/esm/MatrixChart/get-domain/get-domain.mjs +28 -0
- package/esm/MatrixChart/get-domain/get-domain.mjs.map +1 -0
- package/esm/MatrixChart/get-legend-width/get-legend-width.mjs +15 -0
- package/esm/MatrixChart/get-legend-width/get-legend-width.mjs.map +1 -0
- package/esm/MatrixChart/get-unique-values/get-unique-values.mjs +19 -0
- package/esm/MatrixChart/get-unique-values/get-unique-values.mjs.map +1 -0
- package/esm/PieChart/PieChart.mjs +2 -1
- package/esm/PieChart/PieChart.mjs.map +1 -1
- package/esm/PointLabel/PointLabel.mjs.map +1 -1
- package/esm/RadarChart/RadarChart.mjs.map +1 -1
- package/esm/RadialBarChart/RadialBarChart.mjs.map +1 -1
- package/esm/SankeyChart/SankeyChart.mjs.map +1 -1
- package/esm/ScatterChart/ScatterChart.mjs +44 -8
- package/esm/ScatterChart/ScatterChart.mjs.map +1 -1
- package/esm/Sparkline/Sparkline.mjs.map +1 -1
- package/esm/SunburstChart/SunburstChart.mjs.map +1 -1
- package/esm/Treemap/Treemap.mjs.map +1 -1
- package/esm/WaffleChart/WaffleChart.mjs +189 -0
- package/esm/WaffleChart/WaffleChart.mjs.map +1 -0
- package/esm/WaffleChart/WaffleChart.module.mjs +14 -0
- package/esm/WaffleChart/WaffleChart.module.mjs.map +1 -0
- package/esm/index.mjs +5 -1
- package/lib/AreaChart/AreaChart.d.ts +7 -3
- package/lib/AreaChart/AreaGradient.d.ts +1 -1
- package/lib/AreaChart/AreaSplit.d.ts +1 -1
- package/lib/CandlestickChart/CandlestickChart.d.ts +68 -0
- package/lib/CandlestickChart/get-candle-geometry/get-candle-geometry.d.ts +30 -0
- package/lib/CandlestickChart/get-candlestick-domain/get-candlestick-domain.d.ts +21 -0
- package/lib/CandlestickChart/index.d.ts +3 -0
- package/lib/GaugeChart/GaugeChart.d.ts +57 -0
- package/lib/GaugeChart/index.d.ts +10 -0
- package/lib/Heatmap/HeatmapSplitWeeks.d.ts +1 -1
- package/lib/Heatmap/HeatmapWeeks.d.ts +1 -1
- package/lib/MatrixChart/MatrixChart.d.ts +64 -0
- package/lib/MatrixChart/build-cell-map/build-cell-map.d.ts +3 -0
- package/lib/MatrixChart/get-domain/get-domain.d.ts +10 -0
- package/lib/MatrixChart/get-legend-width/get-legend-width.d.ts +9 -0
- package/lib/MatrixChart/get-unique-values/get-unique-values.d.ts +2 -0
- package/lib/MatrixChart/index.d.ts +8 -0
- package/lib/PointLabel/PointLabel.d.ts +1 -1
- package/lib/WaffleChart/WaffleChart.d.ts +57 -0
- package/lib/WaffleChart/index.d.ts +10 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.d.ts +4 -0
- package/lib/types.d.ts +16 -2
- package/package.json +5 -5
- package/styles.css +109 -0
- package/styles.layer.css +109 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BulletChart.cjs","names":["Box","Tooltip","classes"],"sources":["../../src/BulletChart/BulletChart.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n Tooltip,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from './BulletChart.module.css';\n\nexport interface BulletChartRange {\n /** Upper bound value for this range */\n value: number;\n\n /** Background color of the range band */\n color: MantineColor;\n\n /** Optional label for the range */\n label?: string;\n}\n\nexport type BulletChartStylesNames =\n | 'root'\n | 'label'\n | 'trackWrapper'\n | 'track'\n | 'range'\n | 'bar'\n | 'target'\n | 'rangeLabel'\n | 'barLabel'\n | 'targetLabel';\n\nexport type BulletChartCssVariables = {\n root: '--bullet-size' | '--bullet-bar-size';\n};\n\nexport interface BulletChartProps\n extends BoxProps, StylesApiProps<BulletChartFactory>, ElementProps<'div'> {\n /** Current actual value */\n value: number;\n\n /** Target value, displayed as a marker line */\n target?: number;\n\n /** Qualitative ranges displayed as background bands */\n ranges: BulletChartRange[];\n\n /** Orientation, @default 'horizontal' */\n orientation?: 'horizontal' | 'vertical';\n\n /** Label displayed next to the chart */\n label?: React.ReactNode;\n\n /** Value formatter for tooltip/display and labels */\n valueFormatter?: (value: number) => string;\n\n /** Color of the actual value bar, @default 'white' */\n barColor?: MantineColor;\n\n /** Color of the target marker, @default 'dark' for light, 'white' for dark */\n targetColor?: MantineColor;\n\n /** Height of the chart track area (ranges), @default 32 */\n size?: number | string;\n\n /** Height of the actual value bar, @default 16 */\n barSize?: number | string;\n\n /** Target marker size relative to chart size, @default 0.7 */\n targetRatio?: number;\n\n /** Target marker thickness, @default 2 */\n targetSize?: number | string;\n\n /** Whether to show tooltip on hover, @default false */\n withTooltip?: boolean;\n\n /** Custom tooltip content */\n getTooltipLabel?: (data: { value: number; target?: number }) => React.ReactNode;\n}\n\nexport type BulletChartFactory = Factory<{\n props: BulletChartProps;\n ref: HTMLDivElement;\n stylesNames: BulletChartStylesNames;\n vars: BulletChartCssVariables;\n}>;\n\nconst defaultProps = {\n orientation: 'horizontal',\n size: 32,\n barSize: 16,\n targetRatio: 0.7,\n targetSize: 2,\n withTooltip: false,\n} satisfies Partial<BulletChartProps>;\n\nconst varsResolver = createVarsResolver<BulletChartFactory>((_theme, { size, barSize }) => ({\n root: {\n '--bullet-size': rem(size),\n '--bullet-bar-size': rem(barSize),\n },\n}));\n\nexport const BulletChart = factory<BulletChartFactory>((_props) => {\n const props = useProps('BulletChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n value,\n target,\n ranges,\n orientation,\n label,\n valueFormatter,\n barColor,\n targetColor,\n size,\n barSize,\n targetRatio,\n targetSize,\n withTooltip,\n getTooltipLabel,\n variant,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BulletChartFactory>({\n name: 'BulletChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const isVertical = orientation === 'vertical';\n const maxRange = Math.max(...ranges.map((r) => r.value), 0);\n const formatValue = (v: number) => (valueFormatter ? valueFormatter(v) : v.toString());\n\n // Clamp positions/sizes to the track so out-of-range values and targets never overflow it\n const toPercentage = (v: number) =>\n maxRange > 0 ? Math.max(0, Math.min((v / maxRange) * 100, 100)) : 0;\n\n const resolvedBarColor = barColor ? getThemeColor(barColor, theme) : 'var(--mantine-color-white)';\n\n const resolvedTargetColor = targetColor ? getThemeColor(targetColor, theme) : undefined;\n\n const sortedRanges = [...ranges].sort((a, b) => b.value - a.value);\n\n const rangeBands = sortedRanges.map((range, index) => {\n const percentage = toPercentage(range.value);\n const sizeStyle = isVertical\n ? { height: `${percentage}%`, bottom: 0 }\n : { width: `${percentage}%` };\n\n return (\n <div\n key={index}\n {...getStyles('range', {\n style: {\n ...sizeStyle,\n backgroundColor: getThemeColor(range.color, theme),\n },\n })}\n />\n );\n });\n\n const rangeLabels = sortedRanges.map((range, index) => {\n const percentage = toPercentage(range.value);\n const positionStyle = isVertical ? { bottom: `${percentage}%` } : { left: `${percentage}%` };\n\n return (\n <div key={index} {...getStyles('rangeLabel', { style: positionStyle })}>\n {formatValue(range.value)}\n </div>\n );\n });\n\n const barPercentage = toPercentage(value);\n const barSizeStyle = isVertical\n ? { height: `${barPercentage}%`, bottom: 0 }\n : { width: `${barPercentage}%` };\n\n const barElement = (\n <div\n {...getStyles('bar', {\n style: {\n ...barSizeStyle,\n backgroundColor: resolvedBarColor,\n },\n })}\n />\n );\n\n const barLabelPosition = isVertical\n ? { bottom: `${barPercentage}%` }\n : { left: `${barPercentage}%` };\n\n const barLabelElement = (\n <div {...getStyles('barLabel', { style: barLabelPosition })}>{formatValue(value)}</div>\n );\n\n const targetPercentage = target != null ? toPercentage(target) : 0;\n\n const targetElement =\n target != null ? (\n <div\n {...getStyles('target', {\n style: isVertical\n ? {\n bottom: `${targetPercentage}%`,\n width: `${targetRatio! * 100}%`,\n height: rem(targetSize),\n backgroundColor: resolvedTargetColor,\n }\n : {\n left: `${targetPercentage}%`,\n height: `${targetRatio! * 100}%`,\n width: rem(targetSize),\n backgroundColor: resolvedTargetColor,\n },\n })}\n />\n ) : null;\n\n const targetLabelElement =\n target != null ? (\n <div\n {...getStyles('targetLabel', {\n style: isVertical ? { bottom: `${targetPercentage}%` } : { left: `${targetPercentage}%` },\n })}\n >\n {formatValue(target)}\n </div>\n ) : null;\n\n const getDefaultTooltipLabel = () => {\n const parts = [`Value: ${formatValue(value)}`];\n if (target != null) {\n parts.push(`Target: ${formatValue(target)}`);\n }\n return parts.join(' / ');\n };\n\n const tooltipLabel = getTooltipLabel\n ? getTooltipLabel({ value, target })\n : getDefaultTooltipLabel();\n\n const trackWrapper = (\n <div {...getStyles('trackWrapper')} data-orientation={orientation}>\n {rangeLabels}\n {targetLabelElement}\n <div {...getStyles('track')} data-orientation={orientation}>\n {rangeBands}\n {barElement}\n {targetElement}\n </div>\n {barLabelElement}\n </div>\n );\n\n return (\n <Box {...getStyles('root')} variant={variant} mod={{ orientation }} {...others}>\n {label && <div {...getStyles('label')}>{label}</div>}\n {withTooltip ? (\n <Tooltip label={tooltipLabel} position={isVertical ? 'right' : 'top'}>\n {trackWrapper}\n </Tooltip>\n ) : (\n trackWrapper\n )}\n </Box>\n );\n});\n\nBulletChart.displayName = '@mantine/charts/BulletChart';\nBulletChart.classes = classes;\nBulletChart.varsResolver = varsResolver;\n"],"mappings":";;;;;AAiGA,MAA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,CAAC,OAAD;GAAK,GAAI,UAAU,OAAO;aAAI;EAAW,CAAA,GAClD,cACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,SAAD;GAAS,OAAO;GAAc,UAAU,aAAa,UAAU;aAC5D;EACM,CAAA,IAET,YAEC;;AAET,CAAC;AAED,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA;AACtB,YAAY,eAAe"}
|
|
1
|
+
{"version":3,"file":"BulletChart.cjs","names":["createVarsResolver","rem","factory","useProps","useMantineTheme","useStyles","getThemeColor","Box","Tooltip","classes"],"sources":["../../src/BulletChart/BulletChart.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n MantineColor,\n rem,\n StylesApiProps,\n Tooltip,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport classes from './BulletChart.module.css';\n\nexport interface BulletChartRange {\n /** Upper bound value for this range */\n value: number;\n\n /** Background color of the range band */\n color: MantineColor;\n\n /** Optional label for the range */\n label?: string;\n}\n\nexport type BulletChartStylesNames =\n | 'root'\n | 'label'\n | 'trackWrapper'\n | 'track'\n | 'range'\n | 'bar'\n | 'target'\n | 'rangeLabel'\n | 'barLabel'\n | 'targetLabel';\n\nexport type BulletChartCssVariables = {\n root: '--bullet-size' | '--bullet-bar-size';\n};\n\nexport interface BulletChartProps\n extends BoxProps, StylesApiProps<BulletChartFactory>, ElementProps<'div'> {\n /** Current actual value */\n value: number;\n\n /** Target value, displayed as a marker line */\n target?: number;\n\n /** Qualitative ranges displayed as background bands */\n ranges: BulletChartRange[];\n\n /** Orientation, @default 'horizontal' */\n orientation?: 'horizontal' | 'vertical';\n\n /** Label displayed next to the chart */\n label?: React.ReactNode;\n\n /** Value formatter for tooltip/display and labels */\n valueFormatter?: (value: number) => string;\n\n /** Color of the actual value bar, @default 'white' */\n barColor?: MantineColor;\n\n /** Color of the target marker, @default 'dark' for light, 'white' for dark */\n targetColor?: MantineColor;\n\n /** Height of the chart track area (ranges), @default 32 */\n size?: number | string;\n\n /** Height of the actual value bar, @default 16 */\n barSize?: number | string;\n\n /** Target marker size relative to chart size, @default 0.7 */\n targetRatio?: number;\n\n /** Target marker thickness, @default 2 */\n targetSize?: number | string;\n\n /** Whether to show tooltip on hover, @default false */\n withTooltip?: boolean;\n\n /** Custom tooltip content */\n getTooltipLabel?: (data: { value: number; target?: number }) => React.ReactNode;\n}\n\nexport type BulletChartFactory = Factory<{\n props: BulletChartProps;\n ref: HTMLDivElement;\n stylesNames: BulletChartStylesNames;\n vars: BulletChartCssVariables;\n}>;\n\nconst defaultProps = {\n orientation: 'horizontal',\n size: 32,\n barSize: 16,\n targetRatio: 0.7,\n targetSize: 2,\n withTooltip: false,\n} satisfies Partial<BulletChartProps>;\n\nconst varsResolver = createVarsResolver<BulletChartFactory>((_theme, { size, barSize }) => ({\n root: {\n '--bullet-size': rem(size),\n '--bullet-bar-size': rem(barSize),\n },\n}));\n\nexport const BulletChart = factory<BulletChartFactory>((_props) => {\n const props = useProps('BulletChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n attributes,\n value,\n target,\n ranges,\n orientation,\n label,\n valueFormatter,\n barColor,\n targetColor,\n size,\n barSize,\n targetRatio,\n targetSize,\n withTooltip,\n getTooltipLabel,\n variant,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<BulletChartFactory>({\n name: 'BulletChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const isVertical = orientation === 'vertical';\n const maxRange = Math.max(...ranges.map((r) => r.value), 0);\n const formatValue = (v: number) => (valueFormatter ? valueFormatter(v) : v.toString());\n\n // Clamp positions/sizes to the track so out-of-range values and targets never overflow it\n const toPercentage = (v: number) =>\n maxRange > 0 ? Math.max(0, Math.min((v / maxRange) * 100, 100)) : 0;\n\n const resolvedBarColor = barColor ? getThemeColor(barColor, theme) : 'var(--mantine-color-white)';\n\n const resolvedTargetColor = targetColor ? getThemeColor(targetColor, theme) : undefined;\n\n const sortedRanges = [...ranges].sort((a, b) => b.value - a.value);\n\n const rangeBands = sortedRanges.map((range, index) => {\n const percentage = toPercentage(range.value);\n const sizeStyle = isVertical\n ? { height: `${percentage}%`, bottom: 0 }\n : { width: `${percentage}%` };\n\n return (\n <div\n key={index}\n {...getStyles('range', {\n style: {\n ...sizeStyle,\n backgroundColor: getThemeColor(range.color, theme),\n },\n })}\n />\n );\n });\n\n const rangeLabels = sortedRanges.map((range, index) => {\n const percentage = toPercentage(range.value);\n const positionStyle = isVertical ? { bottom: `${percentage}%` } : { left: `${percentage}%` };\n\n return (\n <div key={index} {...getStyles('rangeLabel', { style: positionStyle })}>\n {formatValue(range.value)}\n </div>\n );\n });\n\n const barPercentage = toPercentage(value);\n const barSizeStyle = isVertical\n ? { height: `${barPercentage}%`, bottom: 0 }\n : { width: `${barPercentage}%` };\n\n const barElement = (\n <div\n {...getStyles('bar', {\n style: {\n ...barSizeStyle,\n backgroundColor: resolvedBarColor,\n },\n })}\n />\n );\n\n const barLabelPosition = isVertical\n ? { bottom: `${barPercentage}%` }\n : { left: `${barPercentage}%` };\n\n const barLabelElement = (\n <div {...getStyles('barLabel', { style: barLabelPosition })}>{formatValue(value)}</div>\n );\n\n const targetPercentage = target != null ? toPercentage(target) : 0;\n\n const targetElement =\n target != null ? (\n <div\n {...getStyles('target', {\n style: isVertical\n ? {\n bottom: `${targetPercentage}%`,\n width: `${targetRatio! * 100}%`,\n height: rem(targetSize),\n backgroundColor: resolvedTargetColor,\n }\n : {\n left: `${targetPercentage}%`,\n height: `${targetRatio! * 100}%`,\n width: rem(targetSize),\n backgroundColor: resolvedTargetColor,\n },\n })}\n />\n ) : null;\n\n const targetLabelElement =\n target != null ? (\n <div\n {...getStyles('targetLabel', {\n style: isVertical ? { bottom: `${targetPercentage}%` } : { left: `${targetPercentage}%` },\n })}\n >\n {formatValue(target)}\n </div>\n ) : null;\n\n const getDefaultTooltipLabel = () => {\n const parts = [`Value: ${formatValue(value)}`];\n if (target != null) {\n parts.push(`Target: ${formatValue(target)}`);\n }\n return parts.join(' / ');\n };\n\n const tooltipLabel = getTooltipLabel\n ? getTooltipLabel({ value, target })\n : getDefaultTooltipLabel();\n\n const trackWrapper = (\n <div {...getStyles('trackWrapper')} data-orientation={orientation}>\n {rangeLabels}\n {targetLabelElement}\n <div {...getStyles('track')} data-orientation={orientation}>\n {rangeBands}\n {barElement}\n {targetElement}\n </div>\n {barLabelElement}\n </div>\n );\n\n return (\n <Box {...getStyles('root')} variant={variant} mod={{ orientation }} {...others}>\n {label && <div {...getStyles('label')}>{label}</div>}\n {withTooltip ? (\n <Tooltip label={tooltipLabel} position={isVertical ? 'right' : 'top'}>\n {trackWrapper}\n </Tooltip>\n ) : (\n trackWrapper\n )}\n </Box>\n );\n});\n\nBulletChart.displayName = '@mantine/charts/BulletChart';\nBulletChart.classes = classes;\nBulletChart.varsResolver = varsResolver;\n"],"mappings":";;;;;AAiGA,MAAM,eAAe;CACnB,aAAa;CACb,MAAM;CACN,SAAS;CACT,aAAa;CACb,YAAY;CACZ,aAAa;AACf;AAEA,MAAM,gBAAA,GAAeA,cAAAA,mBAAAA,EAAwC,QAAQ,EAAE,MAAM,eAAe,EAC1F,MAAM;CACJ,kBAAA,GAAiBC,cAAAA,IAAAA,CAAI,IAAI;CACzB,sBAAA,GAAqBA,cAAAA,IAAAA,CAAI,OAAO;AAClC,EACF,EAAE;AAEF,MAAa,eAAA,GAAcC,cAAAA,QAAAA,EAA6B,WAAW;CACjE,MAAM,SAAA,GAAQC,cAAAA,SAAAA,CAAS,eAAe,cAAc,MAAM;CAC1D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,YACA,OACA,QACA,QACA,aACA,OACA,gBACA,UACA,aACA,MACA,SACA,aACA,YACA,aACA,iBACA,SACA,GAAG,WACD;CAEJ,MAAM,SAAA,GAAQC,cAAAA,gBA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,GAAG,iBAAiB,GAAG,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,EAC1F,CAAC;EAEA,UAAA,YAAY,MAAM;CAChB,CAAA,IACH;CAEN,MAAM,+BAA+B;EACnC,MAAM,QAAQ,CAAC,UAAU,YAAY,KAAK,GAAG;EAC7C,IAAI,UAAU,MACZ,MAAM,KAAK,WAAW,YAAY,MAAM,GAAG;EAE7C,OAAO,MAAM,KAAK,KAAK;CACzB;CAEA,MAAM,eAAe,kBACjB,gBAAgB;EAAE;EAAO;CAAO,CAAC,IACjC,uBAAuB;CAE3B,MAAM,eACJ,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,GAAI,UAAU,cAAc;EAAG,oBAAkB;EAAtD,UAAA;GACG;GACA;GACD,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;IAAK,GAAI,UAAU,OAAO;IAAG,oBAAkB;IAA/C,UAAA;KACG;KACA;KACA;IACE;;GACJ;EACE;;CAGP,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACM,cAAAA,KAAD;EAAK,GAAI,UAAU,MAAM;EAAY;EAAS,KAAK,EAAE,YAAY;EAAG,GAAI;EAAxE,UAAA,CACG,SAAS,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;GAAK,GAAI,UAAU,OAAO;GAAI,UAAA;EAAW,CAAA,GAClD,cACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,SAAD;GAAS,OAAO;GAAc,UAAU,aAAa,UAAU;GAC5D,UAAA;EACM,CAAA,IAET,YAEC;;AAET,CAAC;AAED,YAAY,cAAc;AAC1B,YAAY,UAAUC,2BAAAA;AACtB,YAAY,eAAe"}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_ChartTooltip = require("../ChartTooltip/ChartTooltip.cjs");
|
|
3
|
+
const require_grid_chart_module = require("../grid-chart.module.cjs");
|
|
4
|
+
const require_get_candlestick_domain = require("./get-candlestick-domain/get-candlestick-domain.cjs");
|
|
5
|
+
const require_get_candle_geometry = require("./get-candle-geometry/get-candle-geometry.cjs");
|
|
6
|
+
let _mantine_core = require("@mantine/core");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
let recharts = require("recharts");
|
|
9
|
+
//#region packages/@mantine/charts/src/CandlestickChart/CandlestickChart.tsx
|
|
10
|
+
const defaultProps = {
|
|
11
|
+
withXAxis: true,
|
|
12
|
+
withYAxis: true,
|
|
13
|
+
withTooltip: true,
|
|
14
|
+
tooltipAnimationDuration: 0,
|
|
15
|
+
tickLine: "y",
|
|
16
|
+
strokeDasharray: "5 5",
|
|
17
|
+
gridAxis: "x",
|
|
18
|
+
upColor: "teal.6",
|
|
19
|
+
downColor: "red.6",
|
|
20
|
+
candleStrokeWidth: 1,
|
|
21
|
+
dataKeys: {
|
|
22
|
+
open: "open",
|
|
23
|
+
high: "high",
|
|
24
|
+
low: "low",
|
|
25
|
+
close: "close"
|
|
26
|
+
},
|
|
27
|
+
labels: {
|
|
28
|
+
open: "Open",
|
|
29
|
+
high: "High",
|
|
30
|
+
low: "Low",
|
|
31
|
+
close: "Close"
|
|
32
|
+
},
|
|
33
|
+
accessibilityLayer: true
|
|
34
|
+
};
|
|
35
|
+
const varsResolver = (0, _mantine_core.createVarsResolver)((theme, { textColor, gridColor }) => ({ root: {
|
|
36
|
+
"--chart-text-color": textColor ? (0, _mantine_core.getThemeColor)(textColor, theme) : void 0,
|
|
37
|
+
"--chart-grid-color": gridColor ? (0, _mantine_core.getThemeColor)(gridColor, theme) : void 0
|
|
38
|
+
} }));
|
|
39
|
+
const CandlestickChart = (0, _mantine_core.factory)((_props) => {
|
|
40
|
+
const props = (0, _mantine_core.useProps)("CandlestickChart", defaultProps, _props);
|
|
41
|
+
const { classNames, className, style, styles, unstyled, vars, data, dataKeys: dataKeysProp, labels, dataKey, withTooltip, withXAxis, withYAxis, gridAxis, tickLine, xAxisProps, yAxisProps, unit, tooltipAnimationDuration, strokeDasharray, gridProps, tooltipProps, referenceLines, referenceAreas, referenceDots, upColor, downColor, maxCandleWidth, candleStrokeWidth, dir, valueFormatter, children, xAxisLabel, yAxisLabel, composedChartProps, textColor, gridColor, mod, attributes, accessibilityLayer, ...others } = props;
|
|
42
|
+
const theme = (0, _mantine_core.useMantineTheme)();
|
|
43
|
+
const seriesKeys = dataKeysProp;
|
|
44
|
+
const seriesLabels = {
|
|
45
|
+
open: "Open",
|
|
46
|
+
high: "High",
|
|
47
|
+
low: "Low",
|
|
48
|
+
close: "Close",
|
|
49
|
+
...labels
|
|
50
|
+
};
|
|
51
|
+
const tooltipSeries = [
|
|
52
|
+
{
|
|
53
|
+
name: "open",
|
|
54
|
+
label: seriesLabels.open
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "high",
|
|
58
|
+
label: seriesLabels.high
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "low",
|
|
62
|
+
label: seriesLabels.low
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "close",
|
|
66
|
+
label: seriesLabels.close
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
const withXTickLine = gridAxis !== "none" && (tickLine === "x" || tickLine === "xy");
|
|
70
|
+
const withYTickLine = gridAxis !== "none" && (tickLine === "y" || tickLine === "xy");
|
|
71
|
+
const { resolvedClassNames, resolvedStyles } = (0, _mantine_core.useResolvedStylesApi)({
|
|
72
|
+
classNames,
|
|
73
|
+
styles,
|
|
74
|
+
props
|
|
75
|
+
});
|
|
76
|
+
const getStyles = (0, _mantine_core.useStyles)({
|
|
77
|
+
name: "CandlestickChart",
|
|
78
|
+
classes: require_grid_chart_module.default,
|
|
79
|
+
props,
|
|
80
|
+
className,
|
|
81
|
+
style,
|
|
82
|
+
classNames,
|
|
83
|
+
styles,
|
|
84
|
+
unstyled,
|
|
85
|
+
attributes,
|
|
86
|
+
vars,
|
|
87
|
+
varsResolver
|
|
88
|
+
});
|
|
89
|
+
const upColorResolved = (0, _mantine_core.getThemeColor)(upColor, theme);
|
|
90
|
+
const downColorResolved = (0, _mantine_core.getThemeColor)(downColor, theme);
|
|
91
|
+
const candleStyles = getStyles("candle");
|
|
92
|
+
const renderCandle = (shapeProps) => {
|
|
93
|
+
const { x, y, width, height, payload } = shapeProps;
|
|
94
|
+
const geometry = require_get_candle_geometry.getCandleGeometry({
|
|
95
|
+
x,
|
|
96
|
+
y,
|
|
97
|
+
width,
|
|
98
|
+
height,
|
|
99
|
+
open: payload[seriesKeys.open],
|
|
100
|
+
high: payload[seriesKeys.high],
|
|
101
|
+
low: payload[seriesKeys.low],
|
|
102
|
+
close: payload[seriesKeys.close]
|
|
103
|
+
});
|
|
104
|
+
if (geometry === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("g", {});
|
|
105
|
+
const { centerX, bodyY, bodyHeight, isUp } = geometry;
|
|
106
|
+
const color = isUp ? upColorResolved : downColorResolved;
|
|
107
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", {
|
|
108
|
+
...candleStyles,
|
|
109
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
110
|
+
x1: centerX,
|
|
111
|
+
y1: y,
|
|
112
|
+
x2: centerX,
|
|
113
|
+
y2: y + height,
|
|
114
|
+
stroke: color,
|
|
115
|
+
strokeWidth: candleStrokeWidth
|
|
116
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
|
|
117
|
+
x,
|
|
118
|
+
y: bodyY,
|
|
119
|
+
width,
|
|
120
|
+
height: bodyHeight,
|
|
121
|
+
fill: color,
|
|
122
|
+
stroke: color,
|
|
123
|
+
strokeWidth: candleStrokeWidth
|
|
124
|
+
})]
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const domain = require_get_candlestick_domain.getCandlestickDomain({
|
|
128
|
+
data,
|
|
129
|
+
openKey: seriesKeys.open,
|
|
130
|
+
highKey: seriesKeys.high,
|
|
131
|
+
lowKey: seriesKeys.low,
|
|
132
|
+
closeKey: seriesKeys.close
|
|
133
|
+
});
|
|
134
|
+
const referenceLinesItems = referenceLines?.map(({ color: lineColor, labelPosition, ...line }, index) => {
|
|
135
|
+
const color = (0, _mantine_core.getThemeColor)(lineColor, theme);
|
|
136
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ReferenceLine, {
|
|
137
|
+
stroke: lineColor ? color : "var(--chart-grid-color)",
|
|
138
|
+
strokeWidth: 1,
|
|
139
|
+
...line,
|
|
140
|
+
label: {
|
|
141
|
+
fill: lineColor ? color : "currentColor",
|
|
142
|
+
fontSize: 12,
|
|
143
|
+
position: labelPosition ?? "insideBottomLeft",
|
|
144
|
+
...typeof line.label === "object" ? line.label : { value: line.label }
|
|
145
|
+
},
|
|
146
|
+
...getStyles("referenceLine")
|
|
147
|
+
}, index);
|
|
148
|
+
});
|
|
149
|
+
const referenceAreasItems = referenceAreas?.map(({ color: areaColor, labelPosition, ...area }, index) => {
|
|
150
|
+
const color = (0, _mantine_core.getThemeColor)(areaColor, theme);
|
|
151
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ReferenceArea, {
|
|
152
|
+
fill: areaColor ? color : "var(--chart-grid-color)",
|
|
153
|
+
fillOpacity: .2,
|
|
154
|
+
stroke: areaColor ? color : "var(--chart-grid-color)",
|
|
155
|
+
strokeOpacity: .6,
|
|
156
|
+
...area,
|
|
157
|
+
label: {
|
|
158
|
+
fill: areaColor ? color : "currentColor",
|
|
159
|
+
fontSize: 12,
|
|
160
|
+
position: labelPosition ?? "insideTop",
|
|
161
|
+
...typeof area.label === "object" ? area.label : { value: area.label }
|
|
162
|
+
},
|
|
163
|
+
...getStyles("referenceArea")
|
|
164
|
+
}, index);
|
|
165
|
+
});
|
|
166
|
+
const referenceDotsItems = referenceDots?.map(({ color: dotColor, labelPosition, ...dot }, index) => {
|
|
167
|
+
const color = (0, _mantine_core.getThemeColor)(dotColor, theme);
|
|
168
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ReferenceDot, {
|
|
169
|
+
r: 5,
|
|
170
|
+
fill: dotColor ? color : "var(--chart-grid-color)",
|
|
171
|
+
stroke: "var(--mantine-color-body)",
|
|
172
|
+
strokeWidth: 2,
|
|
173
|
+
...dot,
|
|
174
|
+
label: {
|
|
175
|
+
fill: dotColor ? color : "currentColor",
|
|
176
|
+
fontSize: 12,
|
|
177
|
+
position: labelPosition ?? "top",
|
|
178
|
+
...typeof dot.label === "object" ? dot.label : { value: dot.label }
|
|
179
|
+
},
|
|
180
|
+
...getStyles("referenceDot")
|
|
181
|
+
}, index);
|
|
182
|
+
});
|
|
183
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_mantine_core.Box, {
|
|
184
|
+
...getStyles("root"),
|
|
185
|
+
dir: dir || "ltr",
|
|
186
|
+
mod,
|
|
187
|
+
...others,
|
|
188
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.ResponsiveContainer, {
|
|
189
|
+
...getStyles("container"),
|
|
190
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.ComposedChart, {
|
|
191
|
+
data,
|
|
192
|
+
maxBarSize: maxCandleWidth,
|
|
193
|
+
margin: {
|
|
194
|
+
bottom: xAxisLabel ? 30 : void 0,
|
|
195
|
+
left: yAxisLabel ? 10 : void 0,
|
|
196
|
+
right: yAxisLabel ? 5 : void 0
|
|
197
|
+
},
|
|
198
|
+
accessibilityLayer,
|
|
199
|
+
...composedChartProps,
|
|
200
|
+
children: [
|
|
201
|
+
referenceAreasItems,
|
|
202
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.XAxis, {
|
|
203
|
+
hide: !withXAxis,
|
|
204
|
+
dataKey,
|
|
205
|
+
tick: {
|
|
206
|
+
transform: "translate(0, 10)",
|
|
207
|
+
fontSize: 12,
|
|
208
|
+
fill: "currentColor"
|
|
209
|
+
},
|
|
210
|
+
stroke: "",
|
|
211
|
+
interval: "preserveStartEnd",
|
|
212
|
+
tickLine: withXTickLine ? { stroke: "currentColor" } : false,
|
|
213
|
+
minTickGap: 5,
|
|
214
|
+
...getStyles("axis"),
|
|
215
|
+
...xAxisProps,
|
|
216
|
+
children: [xAxisLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Label, {
|
|
217
|
+
position: "insideBottom",
|
|
218
|
+
offset: -20,
|
|
219
|
+
fontSize: 12,
|
|
220
|
+
...getStyles("axisLabel"),
|
|
221
|
+
children: xAxisLabel
|
|
222
|
+
}), xAxisProps?.children]
|
|
223
|
+
}),
|
|
224
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(recharts.YAxis, {
|
|
225
|
+
orientation: "left",
|
|
226
|
+
type: "number",
|
|
227
|
+
domain,
|
|
228
|
+
axisLine: false,
|
|
229
|
+
tick: {
|
|
230
|
+
transform: "translate(-10, 0)",
|
|
231
|
+
fontSize: 12,
|
|
232
|
+
fill: "currentColor"
|
|
233
|
+
},
|
|
234
|
+
hide: !withYAxis,
|
|
235
|
+
tickLine: withYTickLine ? { stroke: "currentColor" } : false,
|
|
236
|
+
allowDecimals: true,
|
|
237
|
+
unit,
|
|
238
|
+
tickFormatter: valueFormatter,
|
|
239
|
+
...getStyles("axis"),
|
|
240
|
+
...yAxisProps,
|
|
241
|
+
children: [yAxisLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Label, {
|
|
242
|
+
position: "insideLeft",
|
|
243
|
+
angle: -90,
|
|
244
|
+
textAnchor: "middle",
|
|
245
|
+
fontSize: 12,
|
|
246
|
+
offset: -5,
|
|
247
|
+
...getStyles("axisLabel"),
|
|
248
|
+
children: yAxisLabel
|
|
249
|
+
}), yAxisProps?.children]
|
|
250
|
+
}),
|
|
251
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.CartesianGrid, {
|
|
252
|
+
strokeDasharray,
|
|
253
|
+
vertical: gridAxis === "y" || gridAxis === "xy",
|
|
254
|
+
horizontal: gridAxis === "x" || gridAxis === "xy",
|
|
255
|
+
...getStyles("grid"),
|
|
256
|
+
...gridProps
|
|
257
|
+
}),
|
|
258
|
+
withTooltip && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Tooltip, {
|
|
259
|
+
animationDuration: tooltipAnimationDuration,
|
|
260
|
+
isAnimationActive: tooltipAnimationDuration !== 0,
|
|
261
|
+
position: { y: 0 },
|
|
262
|
+
cursor: {
|
|
263
|
+
stroke: "var(--chart-grid-color)",
|
|
264
|
+
strokeWidth: 1,
|
|
265
|
+
strokeDasharray,
|
|
266
|
+
fill: "var(--chart-cursor-fill)"
|
|
267
|
+
},
|
|
268
|
+
content: ({ label, payload, labelFormatter }) => {
|
|
269
|
+
const entry = payload?.[0]?.payload;
|
|
270
|
+
if (!entry) return null;
|
|
271
|
+
const open = entry[seriesKeys.open];
|
|
272
|
+
const close = entry[seriesKeys.close];
|
|
273
|
+
if (![
|
|
274
|
+
open,
|
|
275
|
+
close,
|
|
276
|
+
entry[seriesKeys.high],
|
|
277
|
+
entry[seriesKeys.low]
|
|
278
|
+
].every(require_get_candlestick_domain.isRenderableValue)) return null;
|
|
279
|
+
const color = (0, _mantine_core.getThemeColor)(close >= open ? upColor : downColor, theme);
|
|
280
|
+
const ohlcPayload = [
|
|
281
|
+
{
|
|
282
|
+
name: "open",
|
|
283
|
+
color,
|
|
284
|
+
payload: { open }
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "high",
|
|
288
|
+
color,
|
|
289
|
+
payload: { high: entry[seriesKeys.high] }
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
name: "low",
|
|
293
|
+
color,
|
|
294
|
+
payload: { low: entry[seriesKeys.low] }
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: "close",
|
|
298
|
+
color,
|
|
299
|
+
payload: { close }
|
|
300
|
+
}
|
|
301
|
+
];
|
|
302
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChartTooltip.ChartTooltip, {
|
|
303
|
+
label: labelFormatter && payload ? labelFormatter(label, payload) : label,
|
|
304
|
+
payload: ohlcPayload,
|
|
305
|
+
series: tooltipSeries,
|
|
306
|
+
unit,
|
|
307
|
+
showColor: false,
|
|
308
|
+
classNames: resolvedClassNames,
|
|
309
|
+
styles: resolvedStyles,
|
|
310
|
+
valueFormatter,
|
|
311
|
+
attributes
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
...tooltipProps
|
|
315
|
+
}),
|
|
316
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(recharts.Bar, {
|
|
317
|
+
dataKey: (entry) => {
|
|
318
|
+
const low = entry[seriesKeys.low];
|
|
319
|
+
const high = entry[seriesKeys.high];
|
|
320
|
+
return require_get_candlestick_domain.isRenderableValue(low) && require_get_candlestick_domain.isRenderableValue(high) ? [low, high] : null;
|
|
321
|
+
},
|
|
322
|
+
isAnimationActive: false,
|
|
323
|
+
legendType: "none",
|
|
324
|
+
shape: renderCandle
|
|
325
|
+
}),
|
|
326
|
+
referenceLinesItems,
|
|
327
|
+
referenceDotsItems,
|
|
328
|
+
children
|
|
329
|
+
]
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
CandlestickChart.displayName = "@mantine/charts/CandlestickChart";
|
|
335
|
+
CandlestickChart.classes = require_grid_chart_module.default;
|
|
336
|
+
CandlestickChart.varsResolver = varsResolver;
|
|
337
|
+
//#endregion
|
|
338
|
+
exports.CandlestickChart = CandlestickChart;
|
|
339
|
+
|
|
340
|
+
//# sourceMappingURL=CandlestickChart.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CandlestickChart.cjs","names":["createVarsResolver","getThemeColor","factory","useProps","useMantineTheme","useResolvedStylesApi","useStyles","getCandleGeometry","getCandlestickDomain","ReferenceLine","ReferenceArea","ReferenceDot","Box","ResponsiveContainer","ReChartsComposedChart","XAxis","Label","YAxis","CartesianGrid","Tooltip","isRenderableValue","ChartTooltip","Bar","classes"],"sources":["../../src/CandlestickChart/CandlestickChart.tsx"],"sourcesContent":["import {\n Bar,\n BarShapeProps,\n CartesianGrid,\n Label,\n ComposedChart as ReChartsComposedChart,\n ReferenceArea,\n ReferenceDot,\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 { ChartTooltip, ChartTooltipStylesNames } from '../ChartTooltip';\nimport type { BaseChartStylesNames, GridChartBaseProps } from '../types';\nimport { getCandleGeometry } from './get-candle-geometry/get-candle-geometry';\nimport {\n getCandlestickDomain,\n isRenderableValue,\n} from './get-candlestick-domain/get-candlestick-domain';\nimport classes from '../grid-chart.module.css';\n\nexport interface CandlestickChartDataKeys {\n /** Key of the data object for the open value */\n open: string;\n\n /** Key of the data object for the high value */\n high: string;\n\n /** Key of the data object for the low value */\n low: string;\n\n /** Key of the data object for the close value */\n close: string;\n}\n\nexport interface CandlestickChartLabels {\n /** Label of the open value displayed in the tooltip */\n open: string;\n\n /** Label of the high value displayed in the tooltip */\n high: string;\n\n /** Label of the low value displayed in the tooltip */\n low: string;\n\n /** Label of the close value displayed in the tooltip */\n close: string;\n}\n\nexport type CandlestickChartStylesNames =\n | 'candle'\n | Exclude<BaseChartStylesNames, 'brush'>\n | ChartTooltipStylesNames;\n\nexport type CandlestickChartCssVariables = {\n root: '--chart-text-color' | '--chart-grid-color';\n};\n\nexport interface CandlestickChartProps\n extends\n BoxProps,\n Pick<\n GridChartBaseProps,\n | 'dataKey'\n | 'withXAxis'\n | 'withYAxis'\n | 'xAxisProps'\n | 'yAxisProps'\n | 'gridProps'\n | 'tickLine'\n | 'strokeDasharray'\n | 'gridAxis'\n | 'unit'\n | 'tooltipAnimationDuration'\n | 'tooltipProps'\n | 'withTooltip'\n | 'textColor'\n | 'gridColor'\n | 'valueFormatter'\n | 'xAxisLabel'\n | 'yAxisLabel'\n | 'referenceLines'\n | 'referenceAreas'\n | 'referenceDots'\n | 'accessibilityLayer'\n >,\n StylesApiProps<CandlestickChartFactory>,\n ElementProps<'div'> {\n /** Data used to display chart */\n data: Record<string, any>[];\n\n /** Keys of the `data` object used to read open, high, low and close values @default `{ open: 'open', high: 'high', low: 'low', close: 'close' }` */\n dataKeys?: CandlestickChartDataKeys;\n\n /** Labels of open, high, low and close values displayed in the tooltip @default `{ open: 'Open', high: 'High', low: 'Low', close: 'Close' }` */\n labels?: Partial<CandlestickChartLabels>;\n\n /** Color of candles with `close >= open`, key of `theme.colors` or any valid CSS color @default 'teal.6' */\n upColor?: MantineColor;\n\n /** Color of candles with `close < open`, key of `theme.colors` or any valid CSS color @default 'red.6' */\n downColor?: MantineColor;\n\n /** Maximum candle width in px */\n maxCandleWidth?: number;\n\n /** Stroke width of the candle wick and body outline @default 1 */\n candleStrokeWidth?: number;\n\n /** Props passed down to recharts `ComposedChart` component */\n composedChartProps?: React.ComponentProps<typeof ReChartsComposedChart>;\n\n /** Additional components that are rendered inside recharts `ComposedChart` component */\n children?: React.ReactNode;\n}\n\nexport type CandlestickChartFactory = Factory<{\n props: CandlestickChartProps;\n ref: HTMLDivElement;\n stylesNames: CandlestickChartStylesNames;\n vars: CandlestickChartCssVariables;\n}>;\n\nconst defaultProps = {\n withXAxis: true,\n withYAxis: true,\n withTooltip: true,\n tooltipAnimationDuration: 0,\n tickLine: 'y',\n strokeDasharray: '5 5',\n gridAxis: 'x',\n upColor: 'teal.6',\n downColor: 'red.6',\n candleStrokeWidth: 1,\n dataKeys: { open: 'open', high: 'high', low: 'low', close: 'close' },\n labels: { open: 'Open', high: 'High', low: 'Low', close: 'Close' },\n accessibilityLayer: true,\n} satisfies Partial<CandlestickChartProps>;\n\nconst varsResolver = createVarsResolver<CandlestickChartFactory>(\n (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);\n\nexport const CandlestickChart = factory<CandlestickChartFactory>((_props) => {\n const props = useProps('CandlestickChart', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n data,\n dataKeys: dataKeysProp,\n labels,\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 referenceAreas,\n referenceDots,\n upColor,\n downColor,\n maxCandleWidth,\n candleStrokeWidth,\n dir,\n valueFormatter,\n children,\n xAxisLabel,\n yAxisLabel,\n composedChartProps,\n textColor,\n gridColor,\n mod,\n attributes,\n accessibilityLayer,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n const seriesKeys = dataKeysProp!;\n const seriesLabels = { open: 'Open', high: 'High', low: 'Low', close: 'Close', ...labels };\n const tooltipSeries = [\n { name: 'open', label: seriesLabels.open },\n { name: 'high', label: seriesLabels.high },\n { name: 'low', label: seriesLabels.low },\n { name: 'close', label: seriesLabels.close },\n ];\n const withXTickLine = gridAxis !== 'none' && (tickLine === 'x' || tickLine === 'xy');\n const withYTickLine = gridAxis !== 'none' && (tickLine === 'y' || tickLine === 'xy');\n\n const { resolvedClassNames, resolvedStyles } = useResolvedStylesApi<CandlestickChartFactory>({\n classNames,\n styles,\n props,\n });\n\n const getStyles = useStyles<CandlestickChartFactory>({\n name: 'CandlestickChart',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n const upColorResolved = getThemeColor(upColor, theme);\n const downColorResolved = getThemeColor(downColor, theme);\n\n const candleStyles = getStyles('candle');\n\n const renderCandle = (shapeProps: BarShapeProps) => {\n const { x, y, width, height, payload } = shapeProps as BarShapeProps & {\n x: number;\n y: number;\n width: number;\n height: number;\n payload: Record<string, any>;\n };\n\n const geometry = getCandleGeometry({\n x,\n y,\n width,\n height,\n open: payload[seriesKeys.open],\n high: payload[seriesKeys.high],\n low: payload[seriesKeys.low],\n close: payload[seriesKeys.close],\n });\n\n if (geometry === null) {\n return <g />;\n }\n\n const { centerX, bodyY, bodyHeight, isUp } = geometry;\n const color = isUp ? upColorResolved : downColorResolved;\n\n return (\n <g {...candleStyles}>\n <line\n x1={centerX}\n y1={y}\n x2={centerX}\n y2={y + height}\n stroke={color}\n strokeWidth={candleStrokeWidth}\n />\n <rect\n x={x}\n y={bodyY}\n width={width}\n height={bodyHeight}\n fill={color}\n stroke={color}\n strokeWidth={candleStrokeWidth}\n />\n </g>\n );\n };\n\n const domain = getCandlestickDomain({\n data,\n openKey: seriesKeys.open,\n highKey: seriesKeys.high,\n lowKey: seriesKeys.low,\n closeKey: seriesKeys.close,\n });\n\n const referenceLinesItems = referenceLines?.map(\n ({ color: lineColor, labelPosition, ...line }, index) => {\n const color = getThemeColor(lineColor, theme);\n return (\n <ReferenceLine\n key={index}\n stroke={lineColor ? color : 'var(--chart-grid-color)'}\n strokeWidth={1}\n {...line}\n label={{\n fill: lineColor ? color : 'currentColor',\n fontSize: 12,\n position: labelPosition ?? 'insideBottomLeft',\n ...(typeof line.label === 'object' ? line.label : { value: line.label }),\n }}\n {...getStyles('referenceLine')}\n />\n );\n }\n );\n\n const referenceAreasItems = referenceAreas?.map(\n ({ color: areaColor, labelPosition, ...area }, index) => {\n const color = getThemeColor(areaColor, theme);\n return (\n <ReferenceArea\n key={index}\n fill={areaColor ? color : 'var(--chart-grid-color)'}\n fillOpacity={0.2}\n stroke={areaColor ? color : 'var(--chart-grid-color)'}\n strokeOpacity={0.6}\n {...area}\n label={{\n fill: areaColor ? color : 'currentColor',\n fontSize: 12,\n position: labelPosition ?? 'insideTop',\n ...(typeof area.label === 'object' ? area.label : { value: area.label }),\n }}\n {...getStyles('referenceArea')}\n />\n );\n }\n );\n\n const referenceDotsItems = referenceDots?.map(\n ({ color: dotColor, labelPosition, ...dot }, index) => {\n const color = getThemeColor(dotColor, theme);\n return (\n <ReferenceDot\n key={index}\n r={5}\n fill={dotColor ? color : 'var(--chart-grid-color)'}\n stroke=\"var(--mantine-color-body)\"\n strokeWidth={2}\n {...dot}\n label={{\n fill: dotColor ? color : 'currentColor',\n fontSize: 12,\n position: labelPosition ?? 'top',\n ...(typeof dot.label === 'object' ? dot.label : { value: dot.label }),\n }}\n {...getStyles('referenceDot')}\n />\n );\n }\n );\n\n return (\n <Box {...getStyles('root')} dir={dir || 'ltr'} mod={mod} {...others}>\n <ResponsiveContainer {...getStyles('container')}>\n <ReChartsComposedChart\n data={data}\n maxBarSize={maxCandleWidth}\n margin={{\n bottom: xAxisLabel ? 30 : undefined,\n left: yAxisLabel ? 10 : undefined,\n right: yAxisLabel ? 5 : undefined,\n }}\n accessibilityLayer={accessibilityLayer}\n {...composedChartProps}\n >\n {referenceAreasItems}\n\n <XAxis\n hide={!withXAxis}\n dataKey={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 {...getStyles('axis')}\n {...xAxisProps}\n >\n {xAxisLabel && (\n <Label position=\"insideBottom\" offset={-20} fontSize={12} {...getStyles('axisLabel')}>\n {xAxisLabel}\n </Label>\n )}\n {xAxisProps?.children}\n </XAxis>\n\n <YAxis\n orientation=\"left\"\n type=\"number\"\n domain={domain}\n axisLine={false}\n tick={{ transform: 'translate(-10, 0)', fontSize: 12, fill: 'currentColor' }}\n hide={!withYAxis}\n tickLine={withYTickLine ? { stroke: 'currentColor' } : false}\n allowDecimals\n unit={unit}\n tickFormatter={valueFormatter}\n {...getStyles('axis')}\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 <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={{ y: 0 }}\n cursor={{\n stroke: 'var(--chart-grid-color)',\n strokeWidth: 1,\n strokeDasharray,\n fill: 'var(--chart-cursor-fill)',\n }}\n content={({ label, payload, labelFormatter }) => {\n const entry = payload?.[0]?.payload as Record<string, any> | undefined;\n\n if (!entry) {\n return null;\n }\n\n const open = entry[seriesKeys.open];\n const close = entry[seriesKeys.close];\n\n // Rows the candle renderer skipped must not produce a tooltip either,\n // otherwise `valueFormatter` is handed undefined or a string.\n if (\n ![open, close, entry[seriesKeys.high], entry[seriesKeys.low]].every(\n isRenderableValue\n )\n ) {\n return null;\n }\n\n const color = getThemeColor(close >= open ? upColor : downColor, theme);\n\n const ohlcPayload = [\n { name: 'open', color, payload: { open } },\n { name: 'high', color, payload: { high: entry[seriesKeys.high] } },\n { name: 'low', color, payload: { low: entry[seriesKeys.low] } },\n { name: 'close', color, payload: { close } },\n ];\n\n return (\n <ChartTooltip\n label={labelFormatter && payload ? labelFormatter(label, payload) : label}\n payload={ohlcPayload}\n series={tooltipSeries}\n unit={unit}\n showColor={false}\n classNames={resolvedClassNames}\n styles={resolvedStyles}\n valueFormatter={valueFormatter}\n attributes={attributes}\n />\n );\n }}\n {...tooltipProps}\n />\n )}\n\n <Bar\n dataKey={(entry: Record<string, any>) => {\n const low = entry[seriesKeys.low];\n const high = entry[seriesKeys.high];\n\n // Recharts derives its own data domain from these values, so a row the\n // candle renderer would skip must not be handed to it either.\n return isRenderableValue(low) && isRenderableValue(high) ? [low, high] : null;\n }}\n isAnimationActive={false}\n legendType=\"none\"\n shape={renderCandle}\n />\n\n {referenceLinesItems}\n {referenceDotsItems}\n {children}\n </ReChartsComposedChart>\n </ResponsiveContainer>\n </Box>\n );\n});\n\nCandlestickChart.displayName = '@mantine/charts/CandlestickChart';\nCandlestickChart.classes = classes;\nCandlestickChart.varsResolver = varsResolver;\n\nexport namespace CandlestickChart {\n export type Props = CandlestickChartProps;\n export type CssVariables = CandlestickChartCssVariables;\n export type Factory = CandlestickChartFactory;\n export type Labels = CandlestickChartLabels;\n export type DataKeys = CandlestickChartDataKeys;\n export type StylesNames = CandlestickChartStylesNames;\n}\n"],"mappings":";;;;;;;;;AA4IA,MAAM,eAAe;CACnB,WAAW;CACX,WAAW;CACX,aAAa;CACb,0BAA0B;CAC1B,UAAU;CACV,iBAAiB;CACjB,UAAU;CACV,SAAS;CACT,WAAW;CACX,mBAAmB;CACnB,UAAU;EAAE,MAAM;EAAQ,MAAM;EAAQ,KAAK;EAAO,OAAO;CAAQ;CACnE,QAAQ;EAAE,MAAM;EAAQ,MAAM;EAAQ,KAAK;EAAO,OAAO;CAAQ;CACjE,oBAAoB;AACtB;AAEA,MAAM,gBAAA,GAAeA,cAAAA,mBAAAA,EAClB,OAAO,EAAE,WAAW,iBAAiB,EACpC,MAAM;CACJ,sBAAsB,aAAA,GAAYC,cAAAA,cAAAA,CAAc,WAAW,KAAK,IAAI,KAAA;CACpE,sBAAsB,aAAA,GAAYA,cAAAA,cAAAA,CAAc,WAAW,KAAK,IAAI,KAAA;AACtE,EACF,EACF;AAEA,MAAa,oBAAA,GAAmBC,cAAAA,QAAAA,EAAkC,WAAW;CAC3E,MAAM,SAAA,GAAQC,cAAAA,SAAAA,CAAS,oBAAoB,cAAc,MAAM;CAC/D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,MACA,UAAU,cACV,QACA,SACA,aACA,WACA,WACA,UACA,UACA,YACA,YACA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1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_get_candlestick_domain = require("../get-candlestick-domain/get-candlestick-domain.cjs");
|
|
3
|
+
//#region packages/@mantine/charts/src/CandlestickChart/get-candle-geometry/get-candle-geometry.ts
|
|
4
|
+
/**
|
|
5
|
+
* Maps one OHLC row onto the slot recharts allocated for it. Returns `null` when the row
|
|
6
|
+
* cannot be drawn – the same condition `getCandlestickDomain` uses to decide which rows
|
|
7
|
+
* contribute to the axis, so the two never disagree about what is on the chart.
|
|
8
|
+
*/
|
|
9
|
+
function getCandleGeometry({ x, y, width, height, open, high, low, close }) {
|
|
10
|
+
if (![
|
|
11
|
+
open,
|
|
12
|
+
high,
|
|
13
|
+
low,
|
|
14
|
+
close
|
|
15
|
+
].every(require_get_candlestick_domain.isRenderableValue)) return null;
|
|
16
|
+
const range = high - low;
|
|
17
|
+
const ratio = range === 0 ? 0 : height / range;
|
|
18
|
+
const openY = y + (high - open) * ratio;
|
|
19
|
+
const closeY = y + (high - close) * ratio;
|
|
20
|
+
return {
|
|
21
|
+
centerX: x + width / 2,
|
|
22
|
+
bodyY: Math.min(openY, closeY),
|
|
23
|
+
bodyHeight: Math.max(Math.abs(closeY - openY), 1),
|
|
24
|
+
isUp: close >= open
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.getCandleGeometry = getCandleGeometry;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=get-candle-geometry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-candle-geometry.cjs","names":["isRenderableValue"],"sources":["../../../src/CandlestickChart/get-candle-geometry/get-candle-geometry.ts"],"sourcesContent":["import { isRenderableValue } from '../get-candlestick-domain/get-candlestick-domain';\n\nexport interface GetCandleGeometryInput {\n /** Left edge of the slot recharts allocated to the candle */\n x: number;\n\n /** Top edge of the slot, corresponding to `high` */\n y: number;\n\n /** Width of the slot */\n width: number;\n\n /** Height of the slot, spanning `high` to `low` */\n height: number;\n\n open: unknown;\n high: unknown;\n low: unknown;\n close: unknown;\n}\n\nexport interface CandleGeometry {\n /** Horizontal center of the slot, where the wick is drawn */\n centerX: number;\n\n /** Top of the open/close body */\n bodyY: number;\n\n /** Height of the open/close body, never less than 1px so a doji stays visible */\n bodyHeight: number;\n\n /** `true` when the candle closed at or above its open */\n isUp: boolean;\n}\n\n/**\n * Maps one OHLC row onto the slot recharts allocated for it. Returns `null` when the row\n * cannot be drawn – the same condition `getCandlestickDomain` uses to decide which rows\n * contribute to the axis, so the two never disagree about what is on the chart.\n */\nexport function getCandleGeometry({\n x,\n y,\n width,\n height,\n open,\n high,\n low,\n close,\n}: GetCandleGeometryInput): CandleGeometry | null {\n if (![open, high, low, close].every(isRenderableValue)) {\n return null;\n }\n\n const range = (high as number) - (low as number);\n const ratio = range === 0 ? 0 : height / range;\n const openY = y + ((high as number) - (open as number)) * ratio;\n const closeY = y + ((high as number) - (close as number)) * ratio;\n\n return {\n centerX: x + width / 2,\n bodyY: Math.min(openY, closeY),\n bodyHeight: Math.max(Math.abs(closeY - openY), 1),\n isUp: (close as number) >= (open as number),\n };\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgB,kBAAkB,EAChC,GACA,GACA,OACA,QACA,MACA,MACA,KACA,SACgD;CAChD,IAAI,CAAC;EAAC;EAAM;EAAM;EAAK;CAAK,CAAC,CAAC,MAAMA,+BAAAA,iBAAiB,GACnD,OAAO;CAGT,MAAM,QAAS,OAAmB;CAClC,MAAM,QAAQ,UAAU,IAAI,IAAI,SAAS;CACzC,MAAM,QAAQ,KAAM,OAAmB,QAAmB;CAC1D,MAAM,SAAS,KAAM,OAAmB,SAAoB;CAE5D,OAAO;EACL,SAAS,IAAI,QAAQ;EACrB,OAAO,KAAK,IAAI,OAAO,MAAM;EAC7B,YAAY,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,GAAG,CAAC;EAChD,MAAO,SAAqB;CAC9B;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region packages/@mantine/charts/src/CandlestickChart/get-candlestick-domain/get-candlestick-domain.ts
|
|
3
|
+
function isRenderableValue(value) {
|
|
4
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Calculates an explicit y-axis domain padded by 5% of the range. Rows with missing or
|
|
8
|
+
* non-finite values are ignored – `NaN` and `Infinity` are numbers, and letting either
|
|
9
|
+
* reach the bounds produces a `NaN` domain that blanks the entire chart instead of just
|
|
10
|
+
* the offending row. Bounds are reduced iteratively rather than spread into
|
|
11
|
+
* `Math.min`/`Math.max`, which throws on large datasets.
|
|
12
|
+
*
|
|
13
|
+
* A row counts only when all four OHLC values are renderable, which is the same condition
|
|
14
|
+
* the candle shape uses. Taking `low`/`high` independently would let a half-filled row
|
|
15
|
+
* stretch the domain toward a candle that is never drawn, squashing the real ones.
|
|
16
|
+
*/
|
|
17
|
+
function getCandlestickDomain({ data, openKey, highKey, lowKey, closeKey }) {
|
|
18
|
+
let dataMin = Infinity;
|
|
19
|
+
let dataMax = -Infinity;
|
|
20
|
+
for (const item of data) {
|
|
21
|
+
const low = item[lowKey];
|
|
22
|
+
const high = item[highKey];
|
|
23
|
+
if (![
|
|
24
|
+
item[openKey],
|
|
25
|
+
high,
|
|
26
|
+
low,
|
|
27
|
+
item[closeKey]
|
|
28
|
+
].every(isRenderableValue)) continue;
|
|
29
|
+
if (low < dataMin) dataMin = low;
|
|
30
|
+
if (high > dataMax) dataMax = high;
|
|
31
|
+
}
|
|
32
|
+
if (dataMin === Infinity || dataMax === -Infinity) return;
|
|
33
|
+
const padding = (dataMax - dataMin) * .05 || 1;
|
|
34
|
+
return [dataMin - padding, dataMax + padding];
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.getCandlestickDomain = getCandlestickDomain;
|
|
38
|
+
exports.isRenderableValue = isRenderableValue;
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=get-candlestick-domain.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-candlestick-domain.cjs","names":[],"sources":["../../../src/CandlestickChart/get-candlestick-domain/get-candlestick-domain.ts"],"sourcesContent":["export function isRenderableValue(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\ninterface GetCandlestickDomainInput {\n data: Record<string, any>[];\n openKey: string;\n highKey: string;\n lowKey: string;\n closeKey: string;\n}\n\n/**\n * Calculates an explicit y-axis domain padded by 5% of the range. Rows with missing or\n * non-finite values are ignored – `NaN` and `Infinity` are numbers, and letting either\n * reach the bounds produces a `NaN` domain that blanks the entire chart instead of just\n * the offending row. Bounds are reduced iteratively rather than spread into\n * `Math.min`/`Math.max`, which throws on large datasets.\n *\n * A row counts only when all four OHLC values are renderable, which is the same condition\n * the candle shape uses. Taking `low`/`high` independently would let a half-filled row\n * stretch the domain toward a candle that is never drawn, squashing the real ones.\n */\nexport function getCandlestickDomain({\n data,\n openKey,\n highKey,\n lowKey,\n closeKey,\n}: GetCandlestickDomainInput): [number, number] | undefined {\n let dataMin = Infinity;\n let dataMax = -Infinity;\n\n for (const item of data) {\n const low = item[lowKey];\n const high = item[highKey];\n\n if (![item[openKey], high, low, item[closeKey]].every(isRenderableValue)) {\n continue;\n }\n\n if (low < dataMin) {\n dataMin = low;\n }\n\n if (high > dataMax) {\n dataMax = high;\n }\n }\n\n if (dataMin === Infinity || dataMax === -Infinity) {\n return undefined;\n }\n\n const padding = (dataMax - dataMin) * 0.05 || 1;\n\n return [dataMin - padding, dataMax + padding];\n}\n"],"mappings":";;AAAA,SAAgB,kBAAkB,OAAiC;CACjE,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAC3D;;;;;;;;;;;;AAqBA,SAAgB,qBAAqB,EACnC,MACA,SACA,SACA,QACA,YAC0D;CAC1D,IAAI,UAAU;CACd,IAAI,UAAU;CAEd,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK;EAElB,IAAI,CAAC;GAAC,KAAK;GAAU;GAAM;GAAK,KAAK;EAAS,CAAC,CAAC,MAAM,iBAAiB,GACrE;EAGF,IAAI,MAAM,SACR,UAAU;EAGZ,IAAI,OAAO,SACT,UAAU;CAEd;CAEA,IAAI,YAAY,YAAY,YAAY,WACtC;CAGF,MAAM,WAAW,UAAU,WAAW,OAAQ;CAE9C,OAAO,CAAC,UAAU,SAAS,UAAU,OAAO;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartBrush.cjs","names":["Brush","classes"],"sources":["../../src/ChartBrush/ChartBrush.tsx"],"sourcesContent":["import { Brush, BrushProps } from 'recharts';\nimport { factory, Factory, StylesApiProps, useProps, useStyles } from '@mantine/core';\nimport classes from './ChartBrush.module.css';\n\nexport type ChartBrushStylesNames = 'brush';\n\nexport interface ChartBrushProps\n extends Omit<BrushProps, 'ref'>, StylesApiProps<ChartBrushFactory> {}\n\nexport type ChartBrushFactory = Factory<{\n props: ChartBrushProps;\n ref: SVGElement;\n stylesNames: ChartBrushStylesNames;\n}>;\n\nconst defaultProps = {} satisfies Partial<ChartBrushProps>;\n\nexport const ChartBrush = factory<ChartBrushFactory>((_props) => {\n const props = useProps('ChartBrush', defaultProps, _props);\n const { classNames, className, style, styles, unstyled, vars, attributes, ...others } = props;\n\n const getStyles = useStyles<ChartBrushFactory>({\n name: 'ChartBrush',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n return (\n <Brush\n dy={8}\n stroke=\"var(--chart-grid-color)\"\n fill=\"var(--mantine-color-body)\"\n {...others}\n {...getStyles('brush')}\n />\n );\n});\n\nChartBrush.classes = classes;\nChartBrush.displayName = '@mantine/charts/ChartBrush';\n"],"mappings":";;;;;;AAeA,MAAM,eAAe,CAAC;AAEtB,MAAa,cAAA,
|
|
1
|
+
{"version":3,"file":"ChartBrush.cjs","names":["factory","useProps","useStyles","Brush","classes"],"sources":["../../src/ChartBrush/ChartBrush.tsx"],"sourcesContent":["import { Brush, BrushProps } from 'recharts';\nimport { factory, Factory, StylesApiProps, useProps, useStyles } from '@mantine/core';\nimport classes from './ChartBrush.module.css';\n\nexport type ChartBrushStylesNames = 'brush';\n\nexport interface ChartBrushProps\n extends Omit<BrushProps, 'ref'>, StylesApiProps<ChartBrushFactory> {}\n\nexport type ChartBrushFactory = Factory<{\n props: ChartBrushProps;\n ref: SVGElement;\n stylesNames: ChartBrushStylesNames;\n}>;\n\nconst defaultProps = {} satisfies Partial<ChartBrushProps>;\n\nexport const ChartBrush = factory<ChartBrushFactory>((_props) => {\n const props = useProps('ChartBrush', defaultProps, _props);\n const { classNames, className, style, styles, unstyled, vars, attributes, ...others } = props;\n\n const getStyles = useStyles<ChartBrushFactory>({\n name: 'ChartBrush',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n return (\n <Brush\n dy={8}\n stroke=\"var(--chart-grid-color)\"\n fill=\"var(--mantine-color-body)\"\n {...others}\n {...getStyles('brush')}\n />\n );\n});\n\nChartBrush.classes = classes;\nChartBrush.displayName = '@mantine/charts/ChartBrush';\n"],"mappings":";;;;;;AAeA,MAAM,eAAe,CAAC;AAEtB,MAAa,cAAA,GAAaA,cAAAA,QAAAA,EAA4B,WAAW;CAC/D,MAAM,SAAA,GAAQC,cAAAA,SAAAA,CAAS,cAAc,cAAc,MAAM;CACzD,MAAM,EAAE,YAAY,WAAW,OAAO,QAAQ,UAAU,MAAM,YAAY,GAAG,WAAW;CAExF,MAAM,aAAA,GAAYC,cAAAA,UAAAA,CAA6B;EAC7C,MAAM;EACN,SAAA,0BAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,SAAAA,OAAD;EACE,IAAI;EACJ,QAAO;EACP,MAAK;EACL,GAAI;EACJ,GAAI,UAAU,OAAO;CACtB,CAAA;AAEL,CAAC;AAED,WAAW,UAAUC,0BAAAA;AACrB,WAAW,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartLegend.cjs","names":["getSeriesLabels","ColorSwatch","Box","classes"],"sources":["../../src/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ColorSwatch,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartLegend.module.css';\n\nfunction updateChartLegendPayload(\n payload: Record<string, any>[],\n splitNestedKeys: boolean\n): Record<string, any>[] {\n return payload.map((item) => {\n const newDataKey = splitNestedKeys ? item.dataKey?.split('.').pop() : item.dataKey;\n return {\n ...item,\n dataKey: newDataKey,\n payload: {\n ...item.payload,\n name: newDataKey,\n dataKey: newDataKey,\n },\n };\n });\n}\n\nexport function getFilteredChartLegendPayload(\n payload: readonly Record<string, any>[],\n splitNestedKeys = true\n) {\n return updateChartLegendPayload(\n payload.filter((item) => item.color !== 'none'),\n splitNestedKeys\n );\n}\n\nexport type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';\n\nexport interface ChartLegendProps\n extends BoxProps, StylesApiProps<ChartLegendFactory>, ElementProps<'div'> {\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | undefined;\n\n /** Function called when mouse enters/leaves one of the legend items */\n onHighlight: (area: string | number | null) => void;\n\n /** Position of the legend relative to the chart, used to apply margin on the corresponding side */\n legendPosition: 'top' | 'bottom' | 'middle';\n\n /** Data used for labels, only applicable for area charts: AreaChart, LineChart, BarChart */\n series?: ChartSeries[];\n\n /** Determines whether color swatch should be shown next to the label @default true */\n showColor?: boolean;\n\n /** Determines whether the legend should be centered @default false */\n centered?: boolean;\n}\n\nexport type ChartLegendFactory = Factory<{\n props: ChartLegendProps;\n ref: HTMLDivElement;\n stylesNames: ChartLegendStylesNames;\n}>;\n\nexport const ChartLegend = factory<ChartLegendFactory>((_props) => {\n const props = useProps('ChartLegend', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n onHighlight,\n legendPosition,\n mod,\n series,\n showColor,\n centered,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<ChartLegendFactory>({\n name: 'ChartLegend',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'legend',\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartLegendPayload(payload, series != null);\n const labels = getSeriesLabels(series);\n\n const items = filteredPayload.map((item, index) => (\n <div\n key={index}\n {...getStyles('legendItem')}\n onMouseEnter={() => onHighlight(item.highlightKey ?? item.dataKey)}\n data-without-color={showColor === false || undefined}\n >\n <ColorSwatch\n color={item.color}\n size={12}\n {...getStyles('legendItemColor')}\n withShadow={false}\n />\n <p {...getStyles('legendItemName')}>{labels[item.dataKey] || item.dataKey}</p>\n </div>\n ));\n\n return (\n <Box\n mod={[{ position: legendPosition, centered }, mod]}\n {...getStyles('legend')}\n {...others}\n onMouseLeave={(event) => {\n others.onMouseLeave?.(event);\n onHighlight(null);\n }}\n >\n {items}\n </Box>\n );\n});\n\nChartLegend.displayName = '@mantine/charts/ChartLegend';\nChartLegend.classes = classes;\n"],"mappings":";;;;;;AAeA,SAAS,yBACP,SACA,iBACuB;CACvB,OAAO,QAAQ,KAAK,SAAS;EAC3B,MAAM,aAAa,kBAAkB,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,KAAK;EAC3E,OAAO;GACL,GAAG;GACH,SAAS;GACT,SAAS;IACP,GAAG,KAAK;IACR,MAAM;IACN,SAAS;GACX;EACF;CACF,CAAC;AACH;AAEA,SAAgB,8BACd,SACA,kBAAkB,MAClB;CACA,OAAO,yBACL,QAAQ,QAAQ,SAAS,KAAK,UAAU,MAAM,GAC9C,eACF;AACF;AA+BA,MAAa,eAAA,
|
|
1
|
+
{"version":3,"file":"ChartLegend.cjs","names":["factory","useProps","useStyles","getSeriesLabels","ColorSwatch","Box","classes"],"sources":["../../src/ChartLegend/ChartLegend.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ColorSwatch,\n ElementProps,\n factory,\n Factory,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartLegend.module.css';\n\nfunction updateChartLegendPayload(\n payload: Record<string, any>[],\n splitNestedKeys: boolean\n): Record<string, any>[] {\n return payload.map((item) => {\n const newDataKey = splitNestedKeys ? item.dataKey?.split('.').pop() : item.dataKey;\n return {\n ...item,\n dataKey: newDataKey,\n payload: {\n ...item.payload,\n name: newDataKey,\n dataKey: newDataKey,\n },\n };\n });\n}\n\nexport function getFilteredChartLegendPayload(\n payload: readonly Record<string, any>[],\n splitNestedKeys = true\n) {\n return updateChartLegendPayload(\n payload.filter((item) => item.color !== 'none'),\n splitNestedKeys\n );\n}\n\nexport type ChartLegendStylesNames = 'legendItem' | 'legendItemColor' | 'legendItemName' | 'legend';\n\nexport interface ChartLegendProps\n extends BoxProps, StylesApiProps<ChartLegendFactory>, ElementProps<'div'> {\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | undefined;\n\n /** Function called when mouse enters/leaves one of the legend items */\n onHighlight: (area: string | number | null) => void;\n\n /** Position of the legend relative to the chart, used to apply margin on the corresponding side */\n legendPosition: 'top' | 'bottom' | 'middle';\n\n /** Data used for labels, only applicable for area charts: AreaChart, LineChart, BarChart */\n series?: ChartSeries[];\n\n /** Determines whether color swatch should be shown next to the label @default true */\n showColor?: boolean;\n\n /** Determines whether the legend should be centered @default false */\n centered?: boolean;\n}\n\nexport type ChartLegendFactory = Factory<{\n props: ChartLegendProps;\n ref: HTMLDivElement;\n stylesNames: ChartLegendStylesNames;\n}>;\n\nexport const ChartLegend = factory<ChartLegendFactory>((_props) => {\n const props = useProps('ChartLegend', null, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n onHighlight,\n legendPosition,\n mod,\n series,\n showColor,\n centered,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<ChartLegendFactory>({\n name: 'ChartLegend',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n rootSelector: 'legend',\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartLegendPayload(payload, series != null);\n const labels = getSeriesLabels(series);\n\n const items = filteredPayload.map((item, index) => (\n <div\n key={index}\n {...getStyles('legendItem')}\n onMouseEnter={() => onHighlight(item.highlightKey ?? item.dataKey)}\n data-without-color={showColor === false || undefined}\n >\n <ColorSwatch\n color={item.color}\n size={12}\n {...getStyles('legendItemColor')}\n withShadow={false}\n />\n <p {...getStyles('legendItemName')}>{labels[item.dataKey] || item.dataKey}</p>\n </div>\n ));\n\n return (\n <Box\n mod={[{ position: legendPosition, centered }, mod]}\n {...getStyles('legend')}\n {...others}\n onMouseLeave={(event) => {\n others.onMouseLeave?.(event);\n onHighlight(null);\n }}\n >\n {items}\n </Box>\n );\n});\n\nChartLegend.displayName = '@mantine/charts/ChartLegend';\nChartLegend.classes = classes;\n"],"mappings":";;;;;;AAeA,SAAS,yBACP,SACA,iBACuB;CACvB,OAAO,QAAQ,KAAK,SAAS;EAC3B,MAAM,aAAa,kBAAkB,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,KAAK;EAC3E,OAAO;GACL,GAAG;GACH,SAAS;GACT,SAAS;IACP,GAAG,KAAK;IACR,MAAM;IACN,SAAS;GACX;EACF;CACF,CAAC;AACH;AAEA,SAAgB,8BACd,SACA,kBAAkB,MAClB;CACA,OAAO,yBACL,QAAQ,QAAQ,SAAS,KAAK,UAAU,MAAM,GAC9C,eACF;AACF;AA+BA,MAAa,eAAA,GAAcA,cAAAA,QAAAA,EAA6B,WAAW;CACjE,MAAM,SAA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s","names":["getSeriesLabels","Box"],"sources":["../../src/ChartTooltip/ChartTooltip.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartTooltip.module.css';\n\nfunction updateChartTooltipPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n if (!item.payload || item.payload[item.name]) {\n return item;\n }\n const matchFound = item.name.search(/\\./);\n if (matchFound >= 0) {\n const newDataKey = item.name.substring(0, matchFound);\n const nestedPayload = { ...item.payload[newDataKey] };\n const shallowPayload = Object.entries(item.payload).reduce((acc, current) => {\n const [k, v] = current;\n return k === newDataKey ? acc : { ...acc, [k]: v };\n }, {});\n\n return {\n ...item,\n name: item.name.substring(matchFound + 1),\n payload: {\n ...shallowPayload,\n ...nestedPayload,\n },\n };\n }\n return item;\n });\n}\n\nexport function getFilteredChartTooltipPayload(\n payload: readonly Record<string, any>[] | Record<string, any>[],\n segmentId?: string | number\n) {\n const duplicatesFilter = updateChartTooltipPayload(\n payload.filter((item) => item.fill !== 'none' || !item.color)\n );\n\n if (segmentId === undefined || segmentId === null) {\n return duplicatesFilter;\n }\n\n if (typeof segmentId === 'number') {\n const item = duplicatesFilter[segmentId];\n return item ? [item] : [];\n }\n\n return duplicatesFilter.filter((item) => item.name === segmentId);\n}\n\nfunction getData(item: Record<string, any>, type: 'area' | 'radial' | 'scatter') {\n if (type === 'radial' || type === 'scatter') {\n if (Array.isArray(item.value)) {\n return item.value[1] - item.value[0];\n }\n return item.value;\n }\n\n if (Array.isArray(item.payload[item.dataKey])) {\n return item.payload[item.dataKey][1] - item.payload[item.dataKey][0];\n }\n return item.payload[item.name];\n}\n\nexport type ChartTooltipStylesNames =\n | 'tooltip'\n | 'tooltipItem'\n | 'tooltipItemBody'\n | 'tooltipItemColor'\n | 'tooltipItemName'\n | 'tooltipItemData'\n | 'tooltipLabel'\n | 'tooltipBody';\n\nexport interface ChartTooltipProps\n extends BoxProps, StylesApiProps<ChartTooltipFactory>, ElementProps<'div'> {\n /** Main tooltip label */\n label?: React.ReactNode;\n\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | Record<string, any>[] | undefined;\n\n /** Data units, provided by parent component */\n unit?: string;\n\n /** Tooltip type that determines the content and styles, `area` for LineChart, AreaChart and BarChart, `radial` for DonutChart and PieChart @default 'area' */\n type?: 'area' | 'radial' | 'scatter';\n\n /** Segment to display data for, identified by its index in the data array (preferred, isolates duplicate names) or by its name. Only applicable when `type=\"radial\"`. If not set, all data is rendered. */\n segmentId?: string | number;\n\n /** Chart series data, applicable only for `area` type */\n series?: ChartSeries[];\n\n /** A function to format values */\n valueFormatter?: (value: number) => React.ReactNode;\n\n /** Determines whether the color swatch should be visible @default true */\n showColor?: boolean;\n}\n\nexport type ChartTooltipFactory = Factory<{\n props: ChartTooltipProps;\n ref: HTMLDivElement;\n stylesNames: ChartTooltipStylesNames;\n}>;\n\nconst defaultProps = {\n type: 'area',\n showColor: true,\n} satisfies Partial<ChartTooltipProps>;\n\nexport const ChartTooltip = factory<ChartTooltipFactory>((_props) => {\n const props = useProps('ChartTooltip', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n label,\n unit,\n type,\n segmentId,\n mod,\n series,\n valueFormatter,\n showColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<ChartTooltipFactory>({\n name: 'ChartTooltip',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartTooltipPayload(payload, segmentId);\n const scatterLabel = type === 'scatter' ? payload[0]?.payload?.name : null;\n const labels = getSeriesLabels(series);\n const _label = label || scatterLabel;\n\n const items = filteredPayload.map((item, index) => (\n <div key={item?.key ?? `${item.name}-${index}`} data-type={type} {...getStyles('tooltipItem')}>\n <div {...getStyles('tooltipItemBody')}>\n {showColor && (\n <svg {...getStyles('tooltipItemColor')}>\n <circle\n r={6}\n fill={getThemeColor(item.color, theme)}\n width={12}\n height={12}\n cx={6}\n cy={6}\n />\n </svg>\n )}\n <div {...getStyles('tooltipItemName')}>{labels[item.name] || item.name}</div>\n </div>\n <div {...getStyles('tooltipItemData')}>\n {typeof valueFormatter === 'function'\n ? valueFormatter(getData(item, type))\n : getData(item, type)}\n {unit || item.unit}\n </div>\n </div>\n ));\n\n return (\n <Box {...getStyles('tooltip')} mod={[{ type }, mod]} {...others}>\n {_label && <div {...getStyles('tooltipLabel')}>{_label}</div>}\n <div {...getStyles('tooltipBody')}>{items}</div>\n </Box>\n );\n});\n\nChartTooltip.displayName = '@mantine/charts/ChartTooltip';\n"],"mappings":";;;;;;AAgBA,SAAS,0BAA0B,SAAuD;CACxF,OAAO,QAAQ,KAAK,SAAS;EAC3B,IAAI,CAAC,KAAK,WAAW,KAAK,QAAQ,KAAK,OACrC,OAAO;EAET,MAAM,aAAa,KAAK,KAAK,OAAO,IAAI;EACxC,IAAI,cAAc,GAAG;GACnB,MAAM,aAAa,KAAK,KAAK,UAAU,GAAG,UAAU;GACpD,MAAM,gBAAgB,EAAE,GAAG,KAAK,QAAQ,YAAY;GACpD,MAAM,iBAAiB,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,QAAQ,KAAK,YAAY;IAC3E,MAAM,CAAC,GAAG,KAAK;IACf,OAAO,MAAM,aAAa,MAAM;KAAE,GAAG;MAAM,IAAI;IAAE;GACnD,GAAG,CAAC,CAAC;GAEL,OAAO;IACL,GAAG;IACH,MAAM,KAAK,KAAK,UAAU,aAAa,CAAC;IACxC,SAAS;KACP,GAAG;KACH,GAAG;IACL;GACF;EACF;EACA,OAAO;CACT,CAAC;AACH;AAEA,SAAgB,+BACd,SACA,WACA;CACA,MAAM,mBAAmB,0BACvB,QAAQ,QAAQ,SAAS,KAAK,SAAS,UAAU,CAAC,KAAK,KAAK,CAC9D;CAEA,IAAI,cAAc,KAAA,KAAa,cAAc,MAC3C,OAAO;CAGT,IAAI,OAAO,cAAc,UAAU;EACjC,MAAM,OAAO,iBAAiB;EAC9B,OAAO,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B;CAEA,OAAO,iBAAiB,QAAQ,SAAS,KAAK,SAAS,SAAS;AAClE;AAEA,SAAS,QAAQ,MAA2B,MAAqC;CAC/E,IAAI,SAAS,YAAY,SAAS,WAAW;EAC3C,IAAI,MAAM,QAAQ,KAAK,KAAK,GAC1B,OAAO,KAAK,MAAM,KAAK,KAAK,MAAM;EAEpC,OAAO,KAAK;CACd;CAEA,IAAI,MAAM,QAAQ,KAAK,QAAQ,KAAK,QAAQ,GAC1C,OAAO,KAAK,QAAQ,KAAK,QAAQ,CAAC,KAAK,KAAK,QAAQ,KAAK,QAAQ,CAAC;CAEpE,OAAO,KAAK,QAAQ,KAAK;AAC3B;AA6CA,MAAM,eAAe;CACnB,MAAM;CACN,WAAW;AACb;AAEA,MAAa,gBAAA,
|
|
1
|
+
{"version":3,"file":"ChartTooltip.cjs","names":["factory","useProps","useMantineTheme","useStyles","getSeriesLabels","getThemeColor","Box"],"sources":["../../src/ChartTooltip/ChartTooltip.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n ElementProps,\n factory,\n Factory,\n getThemeColor,\n StylesApiProps,\n useMantineTheme,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { ChartSeries } from '../types';\nimport { getSeriesLabels } from '../utils';\nimport classes from './ChartTooltip.module.css';\n\nfunction updateChartTooltipPayload(payload: Record<string, any>[]): Record<string, any>[] {\n return payload.map((item) => {\n if (!item.payload || item.payload[item.name]) {\n return item;\n }\n const matchFound = item.name.search(/\\./);\n if (matchFound >= 0) {\n const newDataKey = item.name.substring(0, matchFound);\n const nestedPayload = { ...item.payload[newDataKey] };\n const shallowPayload = Object.entries(item.payload).reduce((acc, current) => {\n const [k, v] = current;\n return k === newDataKey ? acc : { ...acc, [k]: v };\n }, {});\n\n return {\n ...item,\n name: item.name.substring(matchFound + 1),\n payload: {\n ...shallowPayload,\n ...nestedPayload,\n },\n };\n }\n return item;\n });\n}\n\nexport function getFilteredChartTooltipPayload(\n payload: readonly Record<string, any>[] | Record<string, any>[],\n segmentId?: string | number\n) {\n const duplicatesFilter = updateChartTooltipPayload(\n payload.filter((item) => item.fill !== 'none' || !item.color)\n );\n\n if (segmentId === undefined || segmentId === null) {\n return duplicatesFilter;\n }\n\n if (typeof segmentId === 'number') {\n const item = duplicatesFilter[segmentId];\n return item ? [item] : [];\n }\n\n return duplicatesFilter.filter((item) => item.name === segmentId);\n}\n\nfunction getData(item: Record<string, any>, type: 'area' | 'radial' | 'scatter') {\n if (type === 'radial' || type === 'scatter') {\n if (Array.isArray(item.value)) {\n return item.value[1] - item.value[0];\n }\n return item.value;\n }\n\n if (Array.isArray(item.payload[item.dataKey])) {\n return item.payload[item.dataKey][1] - item.payload[item.dataKey][0];\n }\n return item.payload[item.name];\n}\n\nexport type ChartTooltipStylesNames =\n | 'tooltip'\n | 'tooltipItem'\n | 'tooltipItemBody'\n | 'tooltipItemColor'\n | 'tooltipItemName'\n | 'tooltipItemData'\n | 'tooltipLabel'\n | 'tooltipBody';\n\nexport interface ChartTooltipProps\n extends BoxProps, StylesApiProps<ChartTooltipFactory>, ElementProps<'div'> {\n /** Main tooltip label */\n label?: React.ReactNode;\n\n /** Chart data provided by recharts */\n payload: readonly Record<string, any>[] | Record<string, any>[] | undefined;\n\n /** Data units, provided by parent component */\n unit?: string;\n\n /** Tooltip type that determines the content and styles, `area` for LineChart, AreaChart and BarChart, `radial` for DonutChart and PieChart @default 'area' */\n type?: 'area' | 'radial' | 'scatter';\n\n /** Segment to display data for, identified by its index in the data array (preferred, isolates duplicate names) or by its name. Only applicable when `type=\"radial\"`. If not set, all data is rendered. */\n segmentId?: string | number;\n\n /** Chart series data, applicable only for `area` type */\n series?: ChartSeries[];\n\n /** A function to format values */\n valueFormatter?: (value: number) => React.ReactNode;\n\n /** Determines whether the color swatch should be visible @default true */\n showColor?: boolean;\n}\n\nexport type ChartTooltipFactory = Factory<{\n props: ChartTooltipProps;\n ref: HTMLDivElement;\n stylesNames: ChartTooltipStylesNames;\n}>;\n\nconst defaultProps = {\n type: 'area',\n showColor: true,\n} satisfies Partial<ChartTooltipProps>;\n\nexport const ChartTooltip = factory<ChartTooltipFactory>((_props) => {\n const props = useProps('ChartTooltip', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n payload,\n label,\n unit,\n type,\n segmentId,\n mod,\n series,\n valueFormatter,\n showColor,\n attributes,\n ...others\n } = props;\n\n const theme = useMantineTheme();\n\n const getStyles = useStyles<ChartTooltipFactory>({\n name: 'ChartTooltip',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n });\n\n if (!payload) {\n return null;\n }\n\n const filteredPayload = getFilteredChartTooltipPayload(payload, segmentId);\n const scatterLabel = type === 'scatter' ? payload[0]?.payload?.name : null;\n const labels = getSeriesLabels(series);\n const _label = label || scatterLabel;\n\n const items = filteredPayload.map((item, index) => (\n <div key={item?.key ?? `${item.name}-${index}`} data-type={type} {...getStyles('tooltipItem')}>\n <div {...getStyles('tooltipItemBody')}>\n {showColor && (\n <svg {...getStyles('tooltipItemColor')}>\n <circle\n r={6}\n fill={getThemeColor(item.color, theme)}\n width={12}\n height={12}\n cx={6}\n cy={6}\n />\n </svg>\n )}\n <div {...getStyles('tooltipItemName')}>{labels[item.name] || item.name}</div>\n </div>\n <div {...getStyles('tooltipItemData')}>\n {typeof valueFormatter === 'function'\n ? valueFormatter(getData(item, type))\n : getData(item, type)}\n {unit || item.unit}\n </div>\n </div>\n ));\n\n return (\n <Box {...getStyles('tooltip')} mod={[{ type }, mod]} {...others}>\n {_label && <div {...getStyles('tooltipLabel')}>{_label}</div>}\n <div {...getStyles('tooltipBody')}>{items}</div>\n </Box>\n );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