@mui/x-charts 7.2.0 → 7.3.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.
Files changed (188) hide show
  1. package/BarChart/BarChart.js +32 -2
  2. package/BarChart/BarPlot.js +12 -5
  3. package/BarChart/getColor.d.ts +3 -0
  4. package/BarChart/getColor.js +33 -0
  5. package/CHANGELOG.md +125 -0
  6. package/ChartContainer/ChartContainer.js +35 -4
  7. package/ChartsAxis/ChartsAxis.js +4 -4
  8. package/ChartsClipPath/ChartsClipPath.js +2 -2
  9. package/ChartsLegend/ChartsLegend.js +2 -2
  10. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +4 -1
  11. package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  12. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +6 -0
  13. package/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  14. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  15. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  16. package/ChartsTooltip/utils.d.ts +5 -1
  17. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  18. package/ChartsXAxis/ChartsXAxis.js +2 -2
  19. package/ChartsYAxis/ChartsYAxis.js +2 -2
  20. package/Gauge/GaugeProvider.js +5 -5
  21. package/LineChart/AnimatedArea.js +6 -5
  22. package/LineChart/AnimatedLine.js +7 -5
  23. package/LineChart/AreaElement.d.ts +1 -0
  24. package/LineChart/AreaElement.js +4 -1
  25. package/LineChart/AreaPlot.js +7 -1
  26. package/LineChart/LineChart.js +32 -2
  27. package/LineChart/LineElement.d.ts +1 -0
  28. package/LineChart/LineElement.js +4 -1
  29. package/LineChart/LineHighlightPlot.js +4 -1
  30. package/LineChart/LinePlot.js +7 -1
  31. package/LineChart/MarkPlot.js +5 -5
  32. package/LineChart/getColor.d.ts +3 -0
  33. package/LineChart/getColor.js +31 -0
  34. package/PieChart/PieChart.js +32 -2
  35. package/PieChart/PiePlot.js +26 -6
  36. package/PieChart/formatter.js +4 -2
  37. package/PieChart/getColor.d.ts +2 -0
  38. package/PieChart/getColor.js +11 -0
  39. package/PieChart/getPieCoordinates.d.ts +7 -0
  40. package/PieChart/getPieCoordinates.js +25 -0
  41. package/PieChart/index.d.ts +1 -0
  42. package/PieChart/index.js +11 -0
  43. package/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  44. package/ScatterChart/Scatter.d.ts +1 -0
  45. package/ScatterChart/Scatter.js +6 -3
  46. package/ScatterChart/ScatterChart.js +32 -2
  47. package/ScatterChart/ScatterPlot.js +3 -0
  48. package/ScatterChart/getColor.d.ts +3 -0
  49. package/ScatterChart/getColor.js +31 -0
  50. package/SparkLineChart/SparkLineChart.js +15 -0
  51. package/context/CartesianContextProvider.d.ts +2 -2
  52. package/context/CartesianContextProvider.js +23 -8
  53. package/esm/BarChart/BarChart.js +32 -2
  54. package/esm/BarChart/BarPlot.js +13 -5
  55. package/esm/BarChart/getColor.js +27 -0
  56. package/esm/ChartContainer/ChartContainer.js +36 -4
  57. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  58. package/esm/ChartsClipPath/ChartsClipPath.js +2 -2
  59. package/esm/ChartsLegend/ChartsLegend.js +2 -2
  60. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  61. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  62. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  63. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  64. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  65. package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
  66. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  67. package/esm/Gauge/GaugeProvider.js +5 -5
  68. package/esm/LineChart/AnimatedArea.js +6 -5
  69. package/esm/LineChart/AnimatedLine.js +7 -5
  70. package/esm/LineChart/AreaElement.js +4 -1
  71. package/esm/LineChart/AreaPlot.js +7 -1
  72. package/esm/LineChart/LineChart.js +32 -2
  73. package/esm/LineChart/LineElement.js +4 -1
  74. package/esm/LineChart/LineHighlightPlot.js +4 -1
  75. package/esm/LineChart/LinePlot.js +7 -1
  76. package/esm/LineChart/MarkPlot.js +5 -5
  77. package/esm/LineChart/getColor.js +25 -0
  78. package/esm/PieChart/PieChart.js +32 -2
  79. package/esm/PieChart/PiePlot.js +26 -6
  80. package/esm/PieChart/formatter.js +4 -2
  81. package/esm/PieChart/getColor.js +5 -0
  82. package/esm/PieChart/getPieCoordinates.js +19 -0
  83. package/esm/PieChart/index.js +2 -1
  84. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  85. package/esm/ScatterChart/Scatter.js +6 -3
  86. package/esm/ScatterChart/ScatterChart.js +32 -2
  87. package/esm/ScatterChart/ScatterPlot.js +3 -0
  88. package/esm/ScatterChart/getColor.js +25 -0
  89. package/esm/SparkLineChart/SparkLineChart.js +15 -0
  90. package/esm/context/CartesianContextProvider.js +23 -8
  91. package/esm/hooks/index.js +4 -1
  92. package/esm/hooks/useAxisEvents.js +7 -6
  93. package/esm/hooks/useChartId.js +8 -0
  94. package/esm/hooks/useSeries.js +64 -0
  95. package/esm/hooks/useSvgRef.js +9 -0
  96. package/esm/internals/colorGetter.js +22 -0
  97. package/esm/internals/colorScale.js +16 -0
  98. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  99. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  100. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  101. package/esm/internals/components/ChartsAxesGradients/index.js +1 -0
  102. package/esm/models/colorMapping.js +1 -0
  103. package/esm/models/seriesType/index.js +6 -1
  104. package/hooks/index.d.ts +3 -0
  105. package/hooks/index.js +65 -1
  106. package/hooks/useAxisEvents.js +7 -6
  107. package/hooks/useChartId.d.ts +1 -0
  108. package/hooks/useChartId.js +16 -0
  109. package/hooks/useSeries.d.ts +45 -0
  110. package/hooks/useSeries.js +75 -0
  111. package/hooks/useSvgRef.d.ts +2 -0
  112. package/hooks/useSvgRef.js +17 -0
  113. package/index.js +1 -1
  114. package/internals/colorGetter.d.ts +5 -0
  115. package/internals/colorGetter.js +29 -0
  116. package/internals/colorScale.d.ts +5 -0
  117. package/internals/colorScale.js +24 -0
  118. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +3 -0
  119. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +105 -0
  120. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +13 -0
  121. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +63 -0
  122. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +12 -0
  123. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +48 -0
  124. package/internals/components/ChartsAxesGradients/index.d.ts +1 -0
  125. package/internals/components/ChartsAxesGradients/index.js +16 -0
  126. package/internals/defaultizeColor.d.ts +4 -4
  127. package/internals/defaultizeValueFormatter.d.ts +5 -5
  128. package/internals/getScale.d.ts +2 -2
  129. package/models/axis.d.ts +44 -4
  130. package/models/colorMapping.d.ts +45 -0
  131. package/models/colorMapping.js +5 -0
  132. package/models/index.d.ts +1 -1
  133. package/models/seriesType/common.d.ts +10 -2
  134. package/models/seriesType/index.d.ts +2 -0
  135. package/models/seriesType/index.js +17 -1
  136. package/modern/BarChart/BarChart.js +32 -2
  137. package/modern/BarChart/BarPlot.js +13 -5
  138. package/modern/BarChart/getColor.js +27 -0
  139. package/modern/ChartContainer/ChartContainer.js +36 -4
  140. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  141. package/modern/ChartsClipPath/ChartsClipPath.js +2 -2
  142. package/modern/ChartsLegend/ChartsLegend.js +2 -2
  143. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -2
  144. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -1
  145. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -3
  146. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +13 -4
  147. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
  148. package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
  149. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  150. package/modern/Gauge/GaugeProvider.js +5 -5
  151. package/modern/LineChart/AnimatedArea.js +6 -5
  152. package/modern/LineChart/AnimatedLine.js +7 -5
  153. package/modern/LineChart/AreaElement.js +4 -1
  154. package/modern/LineChart/AreaPlot.js +7 -1
  155. package/modern/LineChart/LineChart.js +32 -2
  156. package/modern/LineChart/LineElement.js +4 -1
  157. package/modern/LineChart/LineHighlightPlot.js +4 -1
  158. package/modern/LineChart/LinePlot.js +7 -1
  159. package/modern/LineChart/MarkPlot.js +5 -5
  160. package/modern/LineChart/getColor.js +25 -0
  161. package/modern/PieChart/PieChart.js +32 -2
  162. package/modern/PieChart/PiePlot.js +26 -6
  163. package/modern/PieChart/formatter.js +4 -2
  164. package/modern/PieChart/getColor.js +5 -0
  165. package/modern/PieChart/getPieCoordinates.js +19 -0
  166. package/modern/PieChart/index.js +2 -1
  167. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +32 -2
  168. package/modern/ScatterChart/Scatter.js +6 -3
  169. package/modern/ScatterChart/ScatterChart.js +32 -2
  170. package/modern/ScatterChart/ScatterPlot.js +3 -0
  171. package/modern/ScatterChart/getColor.js +25 -0
  172. package/modern/SparkLineChart/SparkLineChart.js +15 -0
  173. package/modern/context/CartesianContextProvider.js +23 -8
  174. package/modern/hooks/index.js +4 -1
  175. package/modern/hooks/useAxisEvents.js +7 -6
  176. package/modern/hooks/useChartId.js +8 -0
  177. package/modern/hooks/useSeries.js +64 -0
  178. package/modern/hooks/useSvgRef.js +9 -0
  179. package/modern/index.js +1 -1
  180. package/modern/internals/colorGetter.js +22 -0
  181. package/modern/internals/colorScale.js +16 -0
  182. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +96 -0
  183. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +55 -0
  184. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +41 -0
  185. package/modern/internals/components/ChartsAxesGradients/index.js +1 -0
  186. package/modern/models/colorMapping.js +1 -0
  187. package/modern/models/seriesType/index.js +6 -1
  188. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ import { DefaultizedBarSeriesType, DefaultizedLineSeriesType, DefaultizedPieSeriesType, DefaultizedScatterSeriesType } from '../models';
2
+ import { AxisDefaultized } from '../models/axis';
3
+ declare function getColor(series: DefaultizedPieSeriesType): (dataIndex: number) => string;
4
+ declare function getColor(series: DefaultizedBarSeriesType | DefaultizedLineSeriesType | DefaultizedScatterSeriesType | DefaultizedPieSeriesType, xAxis: AxisDefaultized, yAxis: AxisDefaultized): (dataIndex: number) => string;
5
+ export default getColor;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _getColor = _interopRequireDefault(require("../BarChart/getColor"));
9
+ var _getColor2 = _interopRequireDefault(require("../LineChart/getColor"));
10
+ var _getColor3 = _interopRequireDefault(require("../ScatterChart/getColor"));
11
+ var _getColor4 = _interopRequireDefault(require("../PieChart/getColor"));
12
+ function getColor(series, xAxis, yAxis) {
13
+ if (xAxis !== undefined && yAxis !== undefined) {
14
+ if (series.type === 'bar') {
15
+ return (0, _getColor.default)(series, xAxis, yAxis);
16
+ }
17
+ if (series.type === 'line') {
18
+ return (0, _getColor2.default)(series, xAxis, yAxis);
19
+ }
20
+ if (series.type === 'scatter') {
21
+ return (0, _getColor3.default)(series, xAxis, yAxis);
22
+ }
23
+ }
24
+ if (series.type === 'pie') {
25
+ return (0, _getColor4.default)(series);
26
+ }
27
+ throw Error(`MUI X Charts: getColor called with unexpected arguments for series with id "${series.id}"`);
28
+ }
29
+ var _default = exports.default = getColor;
@@ -0,0 +1,5 @@
1
+ import { ScaleOrdinal } from 'd3-scale';
2
+ import { ContinuousColorConfig, PiecewiseColorConfig, OrdinalColorConfig } from '../models/colorMapping';
3
+ export declare function getSequentialColorScale<Value extends number | Date>(config: ContinuousColorConfig<Value> | PiecewiseColorConfig<Value>): import("d3-scale").ScaleThreshold<Value, string, never> | import("d3-scale").ScaleSequential<string, never>;
4
+ export declare function getOrdinalColorScale<Value extends number | Date | string>(config: OrdinalColorConfig<Value>): ScaleOrdinal<Value, string, null | string> | ScaleOrdinal<number, string, null | string>;
5
+ export declare function getColorScale(config: ContinuousColorConfig | PiecewiseColorConfig | OrdinalColorConfig): ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | import("d3-scale").ScaleSequential<string, never> | import("d3-scale").ScaleThreshold<number | Date, string, never>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getColorScale = getColorScale;
7
+ exports.getOrdinalColorScale = getOrdinalColorScale;
8
+ exports.getSequentialColorScale = getSequentialColorScale;
9
+ var _d3Scale = require("d3-scale");
10
+ function getSequentialColorScale(config) {
11
+ if (config.type === 'piecewise') {
12
+ return (0, _d3Scale.scaleThreshold)(config.thresholds, config.colors);
13
+ }
14
+ return (0, _d3Scale.scaleSequential)([config.min ?? 0, config.max ?? 100], config.color);
15
+ }
16
+ function getOrdinalColorScale(config) {
17
+ if (config.values) {
18
+ return (0, _d3Scale.scaleOrdinal)(config.values, config.colors).unknown(config.unknownColor ?? null);
19
+ }
20
+ return (0, _d3Scale.scaleOrdinal)(config.colors.map((_, index) => index), config.colors).unknown(config.unknownColor ?? null);
21
+ }
22
+ function getColorScale(config) {
23
+ return config.type === 'ordinal' ? getOrdinalColorScale(config) : getSequentialColorScale(config);
24
+ }
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ export declare function useChartGradient(): (axisId: string, direction: 'x' | 'y') => string;
3
+ export declare function ChartsAxesGradients(): React.JSX.Element;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ChartsAxesGradients = ChartsAxesGradients;
8
+ exports.useChartGradient = useChartGradient;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _CartesianContextProvider = require("../../../context/CartesianContextProvider");
11
+ var _DrawingProvider = require("../../../context/DrawingProvider");
12
+ var _hooks = require("../../../hooks");
13
+ var _ChartsPiecewiseGradient = _interopRequireDefault(require("./ChartsPiecewiseGradient"));
14
+ var _ChartsContinuousGradient = _interopRequireDefault(require("./ChartsContinuousGradient"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ function useChartGradient() {
19
+ const {
20
+ chartId
21
+ } = React.useContext(_DrawingProvider.DrawingContext);
22
+ return React.useCallback((axisId, direction) => `${chartId}-graient-${direction}-${axisId}`, [chartId]);
23
+ }
24
+ function ChartsAxesGradients() {
25
+ const {
26
+ top,
27
+ height,
28
+ bottom,
29
+ left,
30
+ width,
31
+ right
32
+ } = (0, _hooks.useDrawingArea)();
33
+ const svgHeight = top + height + bottom;
34
+ const svgWidth = left + width + right;
35
+ const getGradientId = useChartGradient();
36
+ const {
37
+ xAxisIds,
38
+ xAxis,
39
+ yAxisIds,
40
+ yAxis
41
+ } = React.useContext(_CartesianContextProvider.CartesianContext);
42
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("defs", {
43
+ children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
44
+ const gradientId = getGradientId(axisId, 'y');
45
+ const {
46
+ colorMap,
47
+ scale,
48
+ colorScale,
49
+ reverse
50
+ } = yAxis[axisId];
51
+ if (colorMap?.type === 'piecewise') {
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsPiecewiseGradient.default, {
53
+ isReveresed: !reverse,
54
+ scale: scale,
55
+ colorMap: colorMap,
56
+ size: svgHeight,
57
+ gradientId: gradientId,
58
+ direction: "y"
59
+ }, gradientId);
60
+ }
61
+ if (colorMap?.type === 'continuous') {
62
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
63
+ isReveresed: !reverse,
64
+ scale: scale,
65
+ colorScale: colorScale,
66
+ colorMap: colorMap,
67
+ size: svgHeight,
68
+ gradientId: gradientId,
69
+ direction: "y"
70
+ }, gradientId);
71
+ }
72
+ return null;
73
+ }), xAxisIds.filter(axisId => xAxis[axisId].colorMap !== undefined).map(axisId => {
74
+ const gradientId = getGradientId(axisId, 'x');
75
+ const {
76
+ colorMap,
77
+ scale,
78
+ reverse,
79
+ colorScale
80
+ } = xAxis[axisId];
81
+ if (colorMap?.type === 'piecewise') {
82
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsPiecewiseGradient.default, {
83
+ isReveresed: reverse,
84
+ scale: scale,
85
+ colorMap: colorMap,
86
+ size: svgWidth,
87
+ gradientId: gradientId,
88
+ direction: "x"
89
+ }, gradientId);
90
+ }
91
+ if (colorMap?.type === 'continuous') {
92
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
93
+ isReveresed: reverse,
94
+ scale: scale,
95
+ colorScale: colorScale,
96
+ colorMap: colorMap,
97
+ size: svgWidth,
98
+ gradientId: gradientId,
99
+ direction: "x"
100
+ }, gradientId);
101
+ }
102
+ return null;
103
+ })]
104
+ });
105
+ }
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { ContinuousColorConfig } from '../../../models/colorMapping';
3
+ type ChartsContinuousGradientProps = {
4
+ isReveresed?: boolean;
5
+ gradientId: string;
6
+ size: number;
7
+ direction: 'x' | 'y';
8
+ scale: (value: any) => number | undefined;
9
+ colorMap: ContinuousColorConfig;
10
+ colorScale: (value: any) => string | null;
11
+ };
12
+ export default function ChartsContinuousGradient(props: ChartsContinuousGradientProps): React.JSX.Element | null;
13
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ChartsContinuousGradient;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _d3Interpolate = require("d3-interpolate");
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ const PX_PRECISION = 10;
13
+ function ChartsContinuousGradient(props) {
14
+ const {
15
+ isReveresed,
16
+ gradientId,
17
+ size,
18
+ direction,
19
+ scale,
20
+ colorScale,
21
+ colorMap
22
+ } = props;
23
+ const extremValues = [colorMap.min ?? 0, colorMap.max ?? 100];
24
+ const extremPositions = extremValues.map(scale).filter(p => p !== undefined);
25
+ if (extremPositions.length !== 2) {
26
+ return null;
27
+ }
28
+ const interpolator = typeof extremValues[0] === 'number' ? (0, _d3Interpolate.interpolateNumber)(extremValues[0], extremValues[1]) : (0, _d3Interpolate.interpolateDate)(extremValues[0], extremValues[1]);
29
+ const numberOfPoints = Math.round((Math.max(...extremPositions) - Math.min(...extremPositions)) / PX_PRECISION);
30
+ const keyPrefix = `${extremValues[0]}-${extremValues[1]}-`;
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("linearGradient", {
32
+ id: gradientId,
33
+ x1: "0",
34
+ x2: "0",
35
+ y1: "0",
36
+ y2: "0",
37
+ [`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
38
+ gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
39
+ ,
40
+ children: Array.from({
41
+ length: numberOfPoints + 1
42
+ }, (_, index) => {
43
+ const value = interpolator(index / numberOfPoints);
44
+ if (value === undefined) {
45
+ return null;
46
+ }
47
+ const x = scale(value);
48
+ if (x === undefined) {
49
+ return null;
50
+ }
51
+ const offset = isReveresed ? 1 - x / size : x / size;
52
+ const color = colorScale(value);
53
+ if (color === null) {
54
+ return null;
55
+ }
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("stop", {
57
+ offset: offset,
58
+ stopColor: color,
59
+ stopOpacity: 1
60
+ }, keyPrefix + index);
61
+ })
62
+ });
63
+ }
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { PiecewiseColorConfig } from '../../../models/colorMapping';
3
+ type ChartsPiecewiseGradientProps = {
4
+ isReveresed?: boolean;
5
+ gradientId: string;
6
+ size: number;
7
+ direction: 'x' | 'y';
8
+ scale: (value: any) => number | undefined;
9
+ colorMap: PiecewiseColorConfig;
10
+ };
11
+ export default function ChartsPiecewiseGradient(props: ChartsPiecewiseGradientProps): React.JSX.Element;
12
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ChartsPiecewiseGradient;
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ function ChartsPiecewiseGradient(props) {
12
+ const {
13
+ isReveresed,
14
+ gradientId,
15
+ size,
16
+ direction,
17
+ scale,
18
+ colorMap
19
+ } = props;
20
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("linearGradient", {
21
+ id: gradientId,
22
+ x1: "0",
23
+ x2: "0",
24
+ y1: "0",
25
+ y2: "0",
26
+ [`${direction}${isReveresed ? 1 : 2}`]: `${size}px`,
27
+ gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
28
+ ,
29
+ children: colorMap.thresholds.map((threshold, index) => {
30
+ const x = scale(threshold);
31
+ if (x === undefined) {
32
+ return null;
33
+ }
34
+ const offset = isReveresed ? 1 - x / size : x / size;
35
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
36
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("stop", {
37
+ offset: offset,
38
+ stopColor: colorMap.colors[index],
39
+ stopOpacity: 1
40
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("stop", {
41
+ offset: offset,
42
+ stopColor: colorMap.colors[index + 1],
43
+ stopOpacity: 1
44
+ })]
45
+ }, threshold.toString() + index);
46
+ })
47
+ });
48
+ }
@@ -0,0 +1 @@
1
+ export * from './ChartsAxesGradients';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ChartsAxesGradients = require("./ChartsAxesGradients");
7
+ Object.keys(_ChartsAxesGradients).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ChartsAxesGradients[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ChartsAxesGradients[key];
14
+ }
15
+ });
16
+ });
@@ -39,7 +39,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
39
39
  } | undefined;
40
40
  id?: import("../models/seriesType/common").SeriesId | undefined;
41
41
  color?: string | undefined;
42
- valueFormatter?: (<V extends import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">>(value: V) => string) | undefined;
42
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">> | undefined;
43
43
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
44
44
  } | {
45
45
  type: "bar";
@@ -50,7 +50,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
50
50
  stackOffset?: import("..").StackOffsetType | undefined;
51
51
  id?: import("../models/seriesType/common").SeriesId | undefined;
52
52
  color: string;
53
- valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
53
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<number | null> | undefined;
54
54
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
55
55
  xAxisKey?: string | undefined;
56
56
  yAxisKey?: string | undefined;
@@ -64,7 +64,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
64
64
  disableHover?: boolean | undefined;
65
65
  id?: import("../models/seriesType/common").SeriesId | undefined;
66
66
  color: string;
67
- valueFormatter?: (<V_2 extends import("../models/seriesType").ScatterValueType>(value: V_2) => string) | undefined;
67
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
68
68
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
69
69
  xAxisKey?: string | undefined;
70
70
  yAxisKey?: string | undefined;
@@ -82,7 +82,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
82
82
  stackOffset?: import("..").StackOffsetType | undefined;
83
83
  id?: import("../models/seriesType/common").SeriesId | undefined;
84
84
  color: string;
85
- valueFormatter?: (<V_1 extends number | null>(value: V_1) => string) | undefined;
85
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<number | null> | undefined;
86
86
  highlightScope?: Partial<import("..").HighlightScope> | undefined;
87
87
  xAxisKey?: string | undefined;
88
88
  yAxisKey?: string | undefined;
@@ -1,7 +1,7 @@
1
- import { SeriesId } from '../models/seriesType/common';
2
- declare function defaultizeValueFormatter<ISeries extends {
3
- valueFormatter?: IFormatter;
4
- }, IFormatter extends (v: any) => string>(series: Record<SeriesId, ISeries>, defaultValueFormatter: IFormatter): Record<SeriesId, ISeries & {
5
- valueFormatter: IFormatter;
1
+ import { SeriesId, SeriesValueFormatter } from '../models/seriesType/common';
2
+ declare function defaultizeValueFormatter<TValue, ISeries extends {
3
+ valueFormatter?: SeriesValueFormatter<TValue>;
4
+ }>(series: Record<SeriesId, ISeries>, defaultValueFormatter: SeriesValueFormatter<TValue>): Record<SeriesId, ISeries & {
5
+ valueFormatter: SeriesValueFormatter<TValue>;
6
6
  }>;
7
7
  export default defaultizeValueFormatter;
@@ -1,2 +1,2 @@
1
- import { ContinuouseScaleName, D3ContinuouseScale } from '../models/axis';
2
- export declare function getScale(scaleType: ContinuouseScaleName, domain: any[], range: any[]): D3ContinuouseScale;
1
+ import { ContinuousScaleName, D3ContinuousScale } from '../models/axis';
2
+ export declare function getScale(scaleType: ContinuousScaleName, domain: any[], range: any[]): D3ContinuousScale;
package/models/axis.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /// <reference types="react" />
2
- import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
2
+ import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint, ScaleOrdinal, ScaleSequential, ScaleThreshold } from 'd3-scale';
3
3
  import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
4
4
  import type { TickParams } from '../hooks/useTicks';
5
5
  import { ChartsTextProps } from '../ChartsText';
6
+ import { ContinuousColorConfig, OrdinalColorConfig, PiecewiseColorConfig } from './colorMapping';
6
7
  export type AxisId = string | number;
7
8
  export type D3Scale<Domain extends {
8
9
  toString(): string;
9
10
  } = number | Date | string, Range = number, Output = number> = ScaleBand<Domain> | ScaleLogarithmic<Range, Output> | ScalePoint<Domain> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
10
- export type D3ContinuouseScale<Range = number, Output = number> = ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
11
+ export type D3ContinuousScale<Range = number, Output = number> = ScaleLogarithmic<Range, Output> | ScalePower<Range, Output> | ScaleTime<Range, Output> | ScaleLinear<Range, Output>;
11
12
  export interface ChartsAxisSlots {
12
13
  /**
13
14
  * Custom component for the axis main line.
@@ -126,7 +127,7 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
126
127
  position?: 'top' | 'bottom';
127
128
  }
128
129
  export type ScaleName = 'linear' | 'band' | 'point' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
129
- export type ContinuouseScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
130
+ export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
130
131
  interface AxisScaleConfig {
131
132
  band: {
132
133
  scaleType: 'band';
@@ -143,37 +144,76 @@ interface AxisScaleConfig {
143
144
  * @default 0.1
144
145
  */
145
146
  barGapRatio: number;
147
+ colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
146
148
  } & Pick<TickParams, 'tickPlacement' | 'tickLabelPlacement'>;
147
149
  point: {
148
150
  scaleType: 'point';
149
151
  scale: ScalePoint<number | Date | string>;
152
+ colorMap?: OrdinalColorConfig | ContinuousColorConfig | PiecewiseColorConfig;
150
153
  };
151
154
  log: {
152
155
  scaleType: 'log';
153
156
  scale: ScaleLogarithmic<number, number>;
157
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
154
158
  };
155
159
  pow: {
156
160
  scaleType: 'pow';
157
161
  scale: ScalePower<number, number>;
162
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
158
163
  };
159
164
  sqrt: {
160
165
  scaleType: 'sqrt';
161
166
  scale: ScalePower<number, number>;
167
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
162
168
  };
163
169
  time: {
164
170
  scaleType: 'time';
165
171
  scale: ScaleTime<number, number>;
172
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
166
173
  };
167
174
  utc: {
168
175
  scaleType: 'utc';
169
176
  scale: ScaleTime<number, number>;
177
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
170
178
  };
171
179
  linear: {
172
180
  scaleType: 'linear';
173
181
  scale: ScaleLinear<number, number>;
182
+ colorMap?: ContinuousColorConfig | PiecewiseColorConfig;
183
+ };
184
+ }
185
+ interface AxisScaleComputedConfig {
186
+ band: {
187
+ colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
188
+ };
189
+ point: {
190
+ colorScale?: ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
191
+ };
192
+ log: {
193
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
194
+ };
195
+ pow: {
196
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
197
+ };
198
+ sqrt: {
199
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
200
+ };
201
+ time: {
202
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
203
+ };
204
+ utc: {
205
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number | Date, string | null>;
206
+ };
207
+ linear: {
208
+ colorScale?: ScaleSequential<string, string | null> | ScaleThreshold<number, string | null>;
174
209
  };
175
210
  }
176
211
  export type AxisValueFormatterContext = {
212
+ /**
213
+ * Location indicates where the value will be displayed.
214
+ * - `'tick'` The value is displayed on the axis ticks.
215
+ * - `'tooltip'` The value is displayed in the tooltip when hovering the chart.
216
+ */
177
217
  location: 'tick' | 'tooltip';
178
218
  };
179
219
  export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
@@ -215,7 +255,7 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
215
255
  */
216
256
  reverse?: boolean;
217
257
  } & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
218
- export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
258
+ export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & AxisScaleComputedConfig[S] & {
219
259
  /**
220
260
  * An indication of the expected number of ticks.
221
261
  */
@@ -0,0 +1,45 @@
1
+ export interface ContinuousColorConfig<Value = number | Date> {
2
+ type: 'continuous';
3
+ /**
4
+ * The minimal value of the color scale.
5
+ * @default 0
6
+ */
7
+ min?: Value;
8
+ /**
9
+ * The maximal value of the color scale.
10
+ * @default 100
11
+ */
12
+ max?: Value;
13
+ /**
14
+ * The colors to render. Can either be and array with the extrem colors, or an interpolation function.
15
+ */
16
+ color: [string, string] | ((t: number) => string);
17
+ }
18
+ export interface PiecewiseColorConfig<Value = number | Date> {
19
+ type: 'piecewise';
20
+ /**
21
+ * The thresholds where color should change from one category to another.
22
+ */
23
+ thresholds: Value[];
24
+ /**
25
+ * The colors used for each band defined by `thresholds`.
26
+ * Should contain N+1 colors with N the number of thresholds.
27
+ */
28
+ colors: string[];
29
+ }
30
+ export interface OrdinalColorConfig<Value = number | Date | string> {
31
+ type: 'ordinal';
32
+ /**
33
+ * The value to map.
34
+ * If undefined, it will be integers from 0 to the number of colors.
35
+ */
36
+ values?: Value[];
37
+ /**
38
+ * The color palette.
39
+ */
40
+ colors: string[];
41
+ /**
42
+ * The color to use when an element is not part of the values.
43
+ */
44
+ unknownColor?: string;
45
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/models/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
3
  export * from './stacking';
4
- export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuouseScaleName, } from './axis';
4
+ export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuousScaleName, } from './axis';
@@ -1,15 +1,23 @@
1
1
  import type { HighlightScope } from '../../context/HighlightProvider';
2
2
  import type { StackOffsetType, StackOrderType } from '../stacking';
3
3
  export type SeriesId = number | string;
4
+ export type SeriesValueFormatterContext = {
5
+ /**
6
+ * The index of the value in the data array.
7
+ */
8
+ dataIndex: number;
9
+ };
10
+ export type SeriesValueFormatter<TValue> = (value: TValue, context: SeriesValueFormatterContext) => string;
4
11
  export type CommonSeriesType<TValue> = {
5
12
  id?: SeriesId;
6
13
  color?: string;
7
14
  /**
8
15
  * Formatter used to render values in tooltip or other data display.
9
16
  * @param {TValue} value The series' value to render.
10
- * @returns {string} The string to dispaly.
17
+ * @param {SeriesValueFormatterContext} context The rendering context of the value.
18
+ * @returns {string} The string to display.
11
19
  */
12
- valueFormatter?: <V extends TValue>(value: V) => string;
20
+ valueFormatter?: SeriesValueFormatter<TValue>;
13
21
  highlightScope?: Partial<HighlightScope>;
14
22
  };
15
23
  export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
@@ -14,3 +14,5 @@ export * from './bar';
14
14
  export * from './scatter';
15
15
  export * from './pie';
16
16
  export type { AllSeriesType, CartesianSeriesType, DefaultizedSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
17
+ export declare function isDefaultizedBarSeries(series: DefaultizedSeriesType): series is DefaultizedBarSeriesType;
18
+ export declare function isBarSeries(series: AllSeriesType): series is BarSeriesType;
@@ -3,9 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ isDefaultizedBarSeries: true,
8
+ isBarSeries: true
9
+ };
10
+ exports.isBarSeries = isBarSeries;
11
+ exports.isDefaultizedBarSeries = isDefaultizedBarSeries;
6
12
  var _line = require("./line");
7
13
  Object.keys(_line).forEach(function (key) {
8
14
  if (key === "default" || key === "__esModule") return;
15
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
16
  if (key in exports && exports[key] === _line[key]) return;
10
17
  Object.defineProperty(exports, key, {
11
18
  enumerable: true,
@@ -17,6 +24,7 @@ Object.keys(_line).forEach(function (key) {
17
24
  var _bar = require("./bar");
18
25
  Object.keys(_bar).forEach(function (key) {
19
26
  if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
28
  if (key in exports && exports[key] === _bar[key]) return;
21
29
  Object.defineProperty(exports, key, {
22
30
  enumerable: true,
@@ -28,6 +36,7 @@ Object.keys(_bar).forEach(function (key) {
28
36
  var _scatter = require("./scatter");
29
37
  Object.keys(_scatter).forEach(function (key) {
30
38
  if (key === "default" || key === "__esModule") return;
39
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
40
  if (key in exports && exports[key] === _scatter[key]) return;
32
41
  Object.defineProperty(exports, key, {
33
42
  enumerable: true,
@@ -39,6 +48,7 @@ Object.keys(_scatter).forEach(function (key) {
39
48
  var _pie = require("./pie");
40
49
  Object.keys(_pie).forEach(function (key) {
41
50
  if (key === "default" || key === "__esModule") return;
51
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
52
  if (key in exports && exports[key] === _pie[key]) return;
43
53
  Object.defineProperty(exports, key, {
44
54
  enumerable: true,
@@ -46,4 +56,10 @@ Object.keys(_pie).forEach(function (key) {
46
56
  return _pie[key];
47
57
  }
48
58
  });
49
- });
59
+ });
60
+ function isDefaultizedBarSeries(series) {
61
+ return series.type === 'bar';
62
+ }
63
+ function isBarSeries(series) {
64
+ return series.type === 'bar';
65
+ }