@mui/x-charts 6.0.0-alpha.13 → 6.0.0-alpha.15

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 (139) hide show
  1. package/BarChart/BarChart.d.ts +6 -3
  2. package/BarChart/BarChart.js +7 -10
  3. package/BarChart/BarElement.js +2 -4
  4. package/BarChart/formatter.js +1 -2
  5. package/BarChart/legend.js +1 -2
  6. package/CHANGELOG.md +165 -1
  7. package/ChartContainer/index.js +2 -3
  8. package/ChartsAxis/axisClasses.js +1 -2
  9. package/ChartsLegend/ChartsLegend.d.ts +43 -24
  10. package/ChartsLegend/ChartsLegend.js +186 -148
  11. package/ChartsLegend/chartsLegendClasses.js +1 -2
  12. package/ChartsLegend/utils.d.ts +1 -6
  13. package/ChartsSurface.js +5 -14
  14. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
  15. package/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
  16. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
  17. package/ChartsTooltip/ChartsItemTooltipContent.js +16 -6
  18. package/ChartsTooltip/ChartsTooltip.d.ts +23 -0
  19. package/ChartsTooltip/ChartsTooltip.js +47 -13
  20. package/ChartsTooltip/ChartsTooltipTable.js +6 -11
  21. package/ChartsTooltip/tooltipClasses.js +1 -2
  22. package/ChartsXAxis/ChartsXAxis.js +48 -25
  23. package/ChartsYAxis/ChartsYAxis.js +47 -26
  24. package/LineChart/AreaElement.js +2 -4
  25. package/LineChart/LineChart.d.ts +6 -3
  26. package/LineChart/LineChart.js +11 -11
  27. package/LineChart/LineElement.js +2 -4
  28. package/LineChart/LineHighlightElement.js +1 -2
  29. package/LineChart/MarkElement.js +1 -2
  30. package/LineChart/formatter.js +1 -2
  31. package/LineChart/legend.js +1 -2
  32. package/PieChart/PieArc.d.ts +1 -0
  33. package/PieChart/PieArc.js +6 -4
  34. package/PieChart/PieArcLabel.js +1 -2
  35. package/PieChart/PieChart.d.ts +8 -4
  36. package/PieChart/PieChart.js +11 -10
  37. package/PieChart/PiePlot.d.ts +8 -0
  38. package/PieChart/PiePlot.js +21 -5
  39. package/PieChart/formatter.js +1 -2
  40. package/PieChart/legend.js +1 -2
  41. package/ResponsiveChartContainer/index.js +2 -3
  42. package/ScatterChart/ScatterChart.d.ts +6 -3
  43. package/ScatterChart/ScatterChart.js +7 -10
  44. package/ScatterChart/formatter.js +1 -2
  45. package/ScatterChart/legend.js +1 -2
  46. package/SparkLineChart/SparkLineChart.d.ts +3 -3
  47. package/SparkLineChart/SparkLineChart.js +7 -3
  48. package/colorPalettes/colorPalettes.js +6 -12
  49. package/constants.js +5 -8
  50. package/context/CartesianContextProvider.js +11 -12
  51. package/context/DrawingProvider.d.ts +2 -0
  52. package/context/DrawingProvider.js +4 -4
  53. package/context/HighlightProvider.js +1 -2
  54. package/context/InteractionProvider.js +1 -2
  55. package/context/SeriesContextProvider.js +1 -2
  56. package/esm/BarChart/BarChart.js +6 -8
  57. package/esm/ChartsLegend/ChartsLegend.js +184 -142
  58. package/esm/ChartsSurface.js +3 -11
  59. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
  60. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
  61. package/esm/ChartsTooltip/ChartsTooltip.js +47 -12
  62. package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
  63. package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
  64. package/esm/LineChart/LineChart.js +10 -9
  65. package/esm/PieChart/PieArc.js +5 -2
  66. package/esm/PieChart/PieChart.js +11 -10
  67. package/esm/PieChart/PiePlot.js +17 -2
  68. package/esm/ScatterChart/ScatterChart.js +6 -8
  69. package/esm/SparkLineChart/SparkLineChart.js +6 -1
  70. package/esm/constants.js +1 -1
  71. package/esm/context/CartesianContextProvider.js +11 -11
  72. package/esm/context/DrawingProvider.js +2 -0
  73. package/esm/hooks/useChartDimensions.js +2 -0
  74. package/esm/hooks/useTicks.js +5 -5
  75. package/esm/internals/components/AxisSharedComponents.js +15 -70
  76. package/esm/internals/components/ChartsText.js +71 -0
  77. package/esm/internals/domUtils.js +113 -0
  78. package/hooks/useChartDimensions.d.ts +2 -0
  79. package/hooks/useChartDimensions.js +3 -2
  80. package/hooks/useTicks.d.ts +2 -3
  81. package/hooks/useTicks.js +7 -8
  82. package/index.js +1 -1
  83. package/internals/components/AxisSharedComponents.d.ts +0 -4
  84. package/internals/components/AxisSharedComponents.js +18 -78
  85. package/internals/components/ChartsText.d.ts +32 -0
  86. package/internals/components/ChartsText.js +81 -0
  87. package/internals/defaultizeValueFormatter.js +1 -2
  88. package/internals/domUtils.d.ts +14 -0
  89. package/internals/domUtils.js +122 -0
  90. package/internals/stackSeries.js +2 -4
  91. package/legacy/BarChart/BarChart.js +6 -8
  92. package/legacy/ChartsLegend/ChartsLegend.js +196 -140
  93. package/legacy/ChartsSurface.js +2 -11
  94. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
  95. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
  96. package/legacy/ChartsTooltip/ChartsTooltip.js +50 -12
  97. package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
  98. package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
  99. package/legacy/LineChart/LineChart.js +10 -9
  100. package/legacy/PieChart/PieArc.js +4 -1
  101. package/legacy/PieChart/PieChart.js +11 -10
  102. package/legacy/PieChart/PiePlot.js +17 -2
  103. package/legacy/ScatterChart/ScatterChart.js +6 -8
  104. package/legacy/SparkLineChart/SparkLineChart.js +6 -1
  105. package/legacy/constants.js +1 -1
  106. package/legacy/context/CartesianContextProvider.js +11 -11
  107. package/legacy/context/DrawingProvider.js +2 -0
  108. package/legacy/hooks/useChartDimensions.js +2 -0
  109. package/legacy/hooks/useTicks.js +5 -5
  110. package/legacy/index.js +1 -1
  111. package/legacy/internals/components/AxisSharedComponents.js +9 -63
  112. package/legacy/internals/components/ChartsText.js +77 -0
  113. package/legacy/internals/domUtils.js +121 -0
  114. package/models/axis.d.ts +6 -5
  115. package/models/layout.d.ts +7 -6
  116. package/modern/BarChart/BarChart.js +6 -8
  117. package/modern/ChartsLegend/ChartsLegend.js +184 -142
  118. package/modern/ChartsSurface.js +3 -11
  119. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
  120. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
  121. package/modern/ChartsTooltip/ChartsTooltip.js +46 -12
  122. package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
  123. package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
  124. package/modern/LineChart/LineChart.js +10 -9
  125. package/modern/PieChart/PieArc.js +5 -2
  126. package/modern/PieChart/PieChart.js +11 -10
  127. package/modern/PieChart/PiePlot.js +17 -2
  128. package/modern/ScatterChart/ScatterChart.js +6 -8
  129. package/modern/SparkLineChart/SparkLineChart.js +6 -1
  130. package/modern/constants.js +1 -1
  131. package/modern/context/CartesianContextProvider.js +11 -11
  132. package/modern/context/DrawingProvider.js +2 -0
  133. package/modern/hooks/useChartDimensions.js +2 -0
  134. package/modern/hooks/useTicks.js +5 -5
  135. package/modern/index.js +1 -1
  136. package/modern/internals/components/AxisSharedComponents.js +15 -70
  137. package/modern/internals/components/ChartsText.js +71 -0
  138. package/modern/internals/domUtils.js +113 -0
  139. package/package.json +3 -3
@@ -5,77 +5,22 @@ export const AxisRoot = styled('g', {
5
5
  name: 'MuiChartsAxis',
6
6
  slot: 'Root',
7
7
  overridesResolver: (props, styles) => styles.root
8
- })({
9
- [`&.${axisClasses.directionY}`]: {
10
- [`.${axisClasses.tickLabel}`]: {
11
- dominantBaseline: 'middle'
12
- },
13
- [`.${axisClasses.label}`]: {
14
- dominantBaseline: 'auto',
15
- textAnchor: 'middle'
16
- }
17
- },
18
- [`&.${axisClasses.left}`]: {
19
- [`.${axisClasses.tickLabel}`]: {
20
- dominantBaseline: 'central',
21
- textAnchor: 'end'
22
- }
23
- },
24
- [`&.${axisClasses.right}`]: {
25
- [`.${axisClasses.tickLabel}`]: {
26
- dominantBaseline: 'central',
27
- textAnchor: 'start'
28
- }
29
- },
30
- [`&.${axisClasses.bottom}`]: {
31
- [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
32
- dominantBaseline: 'hanging',
33
- textAnchor: 'middle'
34
- }
35
- },
36
- [`&.${axisClasses.top}`]: {
37
- [`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
38
- dominantBaseline: 'baseline',
39
- textAnchor: 'middle'
40
- }
41
- }
42
- });
43
- export const ChartsLine = styled('line', {
44
- name: 'MuiChartsAxis',
45
- slot: 'Line',
46
- overridesResolver: (props, styles) => styles.line
47
- })(({
48
- theme
49
- }) => ({
50
- stroke: (theme.vars || theme).palette.text.primary,
51
- shapeRendering: 'crispEdges',
52
- strokeWidth: 1
53
- }));
54
- export const ChartsTick = styled('line', {
55
- name: 'MuiChartsAxis',
56
- slot: 'Tick',
57
- overridesResolver: (props, styles) => styles.tick
58
8
  })(({
59
9
  theme
60
10
  }) => ({
61
- stroke: (theme.vars || theme).palette.text.primary,
62
- shapeRendering: 'crispEdges'
63
- }));
64
- export const ChartsTickLabel = styled('text', {
65
- name: 'MuiChartsAxis',
66
- slot: 'TickLabel',
67
- overridesResolver: (props, styles) => styles.tickLabel
68
- })(({
69
- theme
70
- }) => _extends({}, theme.typography.caption, {
71
- fill: (theme.vars || theme).palette.text.primary
72
- }));
73
- export const ChartsLabel = styled('text', {
74
- name: 'MuiChartsAxis',
75
- slot: 'Label',
76
- overridesResolver: (props, styles) => styles.label
77
- })(({
78
- theme
79
- }) => _extends({}, theme.typography.body1, {
80
- fill: (theme.vars || theme).palette.text.primary
11
+ [`& .${axisClasses.tickLabel}`]: _extends({}, theme.typography.caption, {
12
+ fill: (theme.vars || theme).palette.text.primary
13
+ }),
14
+ [`& .${axisClasses.label}`]: _extends({}, theme.typography.body1, {
15
+ fill: (theme.vars || theme).palette.text.primary
16
+ }),
17
+ [`& .${axisClasses.line}`]: {
18
+ stroke: (theme.vars || theme).palette.text.primary,
19
+ shapeRendering: 'crispEdges',
20
+ strokeWidth: 1
21
+ },
22
+ [`& .${axisClasses.tick}`]: {
23
+ stroke: (theme.vars || theme).palette.text.primary,
24
+ shapeRendering: 'crispEdges'
25
+ }
81
26
  }));
@@ -0,0 +1,71 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["x", "y", "textAnchor", "dominantBaseline", "style", "text", "ownerState"];
4
+ import * as React from 'react';
5
+ import { getStringSize } from '../domUtils';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export function getWordsByLines({
8
+ style,
9
+ needsComputation,
10
+ text
11
+ }) {
12
+ return text.split('\n').map(subText => _extends({
13
+ text: subText
14
+ }, needsComputation ? getStringSize(subText, style) : {
15
+ width: 0,
16
+ height: 0
17
+ }));
18
+ }
19
+ export function ChartsText(props) {
20
+ const {
21
+ x,
22
+ y,
23
+ textAnchor = 'start',
24
+ dominantBaseline = 'central',
25
+ style,
26
+ text
27
+ } = props,
28
+ textProps = _objectWithoutPropertiesLoose(props, _excluded);
29
+ const wordsByLines = React.useMemo(() => getWordsByLines({
30
+ style,
31
+ needsComputation: text.includes('\n'),
32
+ text
33
+ }), [style, text]);
34
+ let startDy;
35
+ switch (dominantBaseline) {
36
+ case 'hanging':
37
+ startDy = 0;
38
+ break;
39
+ case 'central':
40
+ startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
41
+ break;
42
+ default:
43
+ startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
44
+ break;
45
+ }
46
+
47
+ // const transforms = [];
48
+ // if (scaleToFit) {
49
+ // const lineWidth = wordsByLines[0].width;
50
+ // transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
51
+ // }
52
+ // if (angle) {
53
+ // transforms.push(`rotate(${angle}, ${x}, ${y})`);
54
+ // }
55
+ // if (transforms.length) {
56
+ // textProps.transform = transforms.join(' ');
57
+ // }
58
+
59
+ return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
60
+ x: x,
61
+ y: y,
62
+ textAnchor: textAnchor,
63
+ dominantBaseline: dominantBaseline,
64
+ style: style,
65
+ children: wordsByLines.map((line, index) => /*#__PURE__*/_jsx("tspan", {
66
+ x: x,
67
+ dy: `${index === 0 ? startDy : wordsByLines[0].height}px`,
68
+ children: line.text
69
+ }, index))
70
+ }));
71
+ }
@@ -0,0 +1,113 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ // DOM utils taken from
3
+ // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
4
+
5
+ const isSsr = () => !(typeof window !== 'undefined' && window.document && window.setTimeout);
6
+ const stringCache = {
7
+ widthCache: {},
8
+ cacheCount: 0
9
+ };
10
+ const MAX_CACHE_NUM = 2000;
11
+ const SPAN_STYLE = {
12
+ position: 'absolute',
13
+ top: '-20000px',
14
+ left: 0,
15
+ padding: 0,
16
+ margin: 0,
17
+ border: 'none',
18
+ whiteSpace: 'pre'
19
+ };
20
+ const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
21
+ const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
22
+
23
+ /**
24
+ *
25
+ * @param name CSS property name
26
+ * @param value
27
+ * @returns add 'px' for distance properties
28
+ */
29
+ function autoCompleteStyle(name, value) {
30
+ if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
31
+ return `${value}px`;
32
+ }
33
+ return value;
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param text camelcase css property
39
+ * @returns css property
40
+ */
41
+ function camelToMiddleLine(text) {
42
+ const strs = text.split('');
43
+ const formatStrs = strs.reduce((result, entry) => {
44
+ if (entry === entry.toUpperCase()) {
45
+ return [...result, '-', entry.toLowerCase()];
46
+ }
47
+ return [...result, entry];
48
+ }, []);
49
+ return formatStrs.join('');
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @param style React style object
55
+ * @returns CSS styling string
56
+ */
57
+ export const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
58
+
59
+ /**
60
+ *
61
+ * @param text The string to estimate
62
+ * @param style The style applied
63
+ * @returns width and height of the text
64
+ */
65
+ export const getStringSize = (text, style = {}) => {
66
+ if (text === undefined || text === null || isSsr()) {
67
+ return {
68
+ width: 0,
69
+ height: 0
70
+ };
71
+ }
72
+ const str = `${text}`;
73
+ const styleString = getStyleString(style);
74
+ const cacheKey = `${str}-${styleString}`;
75
+ if (stringCache.widthCache[cacheKey]) {
76
+ return stringCache.widthCache[cacheKey];
77
+ }
78
+ try {
79
+ let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
80
+ if (measurementSpan === null) {
81
+ measurementSpan = document.createElement('span');
82
+ measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
83
+ measurementSpan.setAttribute('aria-hidden', 'true');
84
+ document.body.appendChild(measurementSpan);
85
+ }
86
+ // Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
87
+ // https://en.wikipedia.org/wiki/Content_Security_Policy
88
+ const measurementSpanStyle = _extends({}, SPAN_STYLE, style);
89
+ Object.keys(measurementSpanStyle).map(styleKey => {
90
+ measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
91
+ return styleKey;
92
+ });
93
+ measurementSpan.textContent = str;
94
+ const rect = measurementSpan.getBoundingClientRect();
95
+ const result = {
96
+ width: rect.width,
97
+ height: rect.height
98
+ };
99
+ stringCache.widthCache[cacheKey] = result;
100
+ if (stringCache.cacheCount + 1 > MAX_CACHE_NUM) {
101
+ stringCache.cacheCount = 0;
102
+ stringCache.widthCache = {};
103
+ } else {
104
+ stringCache.cacheCount += 1;
105
+ }
106
+ return result;
107
+ } catch (e) {
108
+ return {
109
+ width: 0,
110
+ height: 0
111
+ };
112
+ }
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.13",
3
+ "version": "6.0.0-alpha.15",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",
@@ -27,8 +27,8 @@
27
27
  "directory": "packages/x-charts"
28
28
  },
29
29
  "dependencies": {
30
- "@babel/runtime": "^7.22.15",
31
- "@mui/base": "^5.0.0-beta.14",
30
+ "@babel/runtime": "^7.23.1",
31
+ "@mui/base": "^5.0.0-beta.17",
32
32
  "clsx": "^2.0.0",
33
33
  "d3-color": "^3.1.0",
34
34
  "d3-scale": "^4.0.2",