@mui/x-charts 6.0.0-alpha.14 → 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.
- package/BarChart/BarChart.d.ts +3 -0
- package/BarChart/BarChart.js +4 -8
- package/CHANGELOG.md +104 -0
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +185 -143
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +3 -11
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/LineChart.d.ts +3 -0
- package/LineChart/LineChart.js +4 -8
- package/PieChart/PieChart.d.ts +3 -0
- package/PieChart/PieChart.js +4 -8
- package/ScatterChart/ScatterChart.d.ts +3 -0
- package/ScatterChart/ScatterChart.js +4 -8
- package/constants.js +1 -1
- package/context/CartesianContextProvider.js +10 -10
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +2 -0
- package/esm/BarChart/BarChart.js +4 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +4 -8
- package/esm/PieChart/PieChart.js +4 -8
- package/esm/ScatterChart/ScatterChart.js +4 -8
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +11 -11
- package/esm/context/DrawingProvider.js +2 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useTicks.js +5 -5
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +71 -0
- package/esm/internals/domUtils.js +113 -0
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +2 -0
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +6 -6
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +16 -71
- package/internals/components/ChartsText.d.ts +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/legacy/BarChart/BarChart.js +4 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +4 -8
- package/legacy/PieChart/PieChart.js +4 -8
- package/legacy/ScatterChart/ScatterChart.js +4 -8
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +11 -11
- package/legacy/context/DrawingProvider.js +2 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useTicks.js +5 -5
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +9 -63
- package/legacy/internals/components/ChartsText.js +77 -0
- package/legacy/internals/domUtils.js +121 -0
- package/models/axis.d.ts +6 -5
- package/models/layout.d.ts +7 -6
- package/modern/BarChart/BarChart.js +4 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +4 -8
- package/modern/PieChart/PieChart.js +4 -8
- package/modern/ScatterChart/ScatterChart.js +4 -8
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +11 -11
- package/modern/context/DrawingProvider.js +2 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useTicks.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +71 -0
- package/modern/internals/domUtils.js +113 -0
- package/package.json +1 -1
package/BarChart/BarChart.d.ts
CHANGED
|
@@ -16,6 +16,9 @@ export interface BarChartProps extends Omit<ResponsiveChartContainerProps, 'seri
|
|
|
16
16
|
series: MakeOptional<BarSeriesType, 'type'>[];
|
|
17
17
|
tooltip?: ChartsTooltipProps;
|
|
18
18
|
axisHighlight?: ChartsAxisHighlightProps;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
21
|
+
*/
|
|
19
22
|
legend?: ChartsLegendProps;
|
|
20
23
|
/**
|
|
21
24
|
* Overridable component slots.
|
package/BarChart/BarChart.js
CHANGED
|
@@ -167,23 +167,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
167
167
|
tickNumber: _propTypes.default.number,
|
|
168
168
|
tickSize: _propTypes.default.number
|
|
169
169
|
}), _propTypes.default.string]),
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
172
|
+
*/
|
|
170
173
|
legend: _propTypes.default.shape({
|
|
171
174
|
classes: _propTypes.default.object,
|
|
172
175
|
direction: _propTypes.default.oneOf(['column', 'row']),
|
|
173
176
|
hidden: _propTypes.default.bool,
|
|
174
|
-
itemWidth: _propTypes.default.number,
|
|
175
|
-
markSize: _propTypes.default.number,
|
|
176
|
-
offset: _propTypes.default.shape({
|
|
177
|
-
x: _propTypes.default.number,
|
|
178
|
-
y: _propTypes.default.number
|
|
179
|
-
}),
|
|
180
177
|
position: _propTypes.default.shape({
|
|
181
178
|
horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
|
|
182
179
|
vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
183
180
|
}),
|
|
184
181
|
slotProps: _propTypes.default.object,
|
|
185
|
-
slots: _propTypes.default.object
|
|
186
|
-
spacing: _propTypes.default.number
|
|
182
|
+
slots: _propTypes.default.object
|
|
187
183
|
}),
|
|
188
184
|
margin: _propTypes.default.shape({
|
|
189
185
|
bottom: _propTypes.default.number,
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,110 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 6.16.2
|
|
7
|
+
|
|
8
|
+
_Oct 12, 2023_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 12 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 📊 Chart's legend text management has been reworked and contains breaking changes (#10138) @alexfauquette
|
|
13
|
+
- 📝 Add [Bulk editing](https://mui.com/x/react-data-grid/recipes-editing/#bulk-editing) demo (#10333) @cherniavskii
|
|
14
|
+
- 🚀 Column grouping now works smoothly with column pinning (#10518) @MBilalShafi
|
|
15
|
+
- 🌍 Improve Arabic (ar-SD) and Spanish (es-ES) locales
|
|
16
|
+
- 🐞 Bugfixes
|
|
17
|
+
- 📚 Documentation improvements
|
|
18
|
+
|
|
19
|
+
### Data Grid
|
|
20
|
+
|
|
21
|
+
#### `@mui/x-data-grid@6.16.2`
|
|
22
|
+
|
|
23
|
+
- [DataGrid] Fix `LazyLoading` demo crash (#10621) @MBilalShafi
|
|
24
|
+
- [DataGrid] Fix cells overlapping the scrollbar in iOS Safari (#10633) @cherniavskii
|
|
25
|
+
- [DataGrid] Fix `getRowId is not defined` error (#10613) @romgrk
|
|
26
|
+
- [DataGrid] Get quick filter to work OOTB with `date` and `dateTime` fields (#10636) @MBilalShafi
|
|
27
|
+
- [DataGrid] Make cursor for selectable cells to be `default` unless editable (#9997) @gitstart
|
|
28
|
+
- [DataGrid] Remove unnecessary syntax in JSDoc (#10567) @Lev-Shapiro
|
|
29
|
+
- [DataGrid] Update row hover behavior to match native hover (#10623) @cherniavskii
|
|
30
|
+
- [l10n] Improve Arabic (ar-SD) locale (#10625) @alabenyahia
|
|
31
|
+
|
|
32
|
+
#### `@mui/x-data-grid-pro@6.16.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
33
|
+
|
|
34
|
+
Same changes as in `@mui/x-data-grid@6.16.2`, plus:
|
|
35
|
+
|
|
36
|
+
- [DataGridPro] Improve column grouping and column pinning friendship (#10518) @MBilalShafi
|
|
37
|
+
|
|
38
|
+
#### `@mui/x-data-grid-premium@6.16.2` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
39
|
+
|
|
40
|
+
Same changes as in `@mui/x-data-grid-pro@6.16.2`.
|
|
41
|
+
|
|
42
|
+
### Date Pickers
|
|
43
|
+
|
|
44
|
+
#### `@mui/x-date-pickers@6.16.2`
|
|
45
|
+
|
|
46
|
+
- [DateTimePicker] Add support for `DigitalClock` view renderer (#10624) @LukasTy
|
|
47
|
+
- [fields] Bootstrap the multi-HTML input component (#10638) @flaviendelangle
|
|
48
|
+
- [pickers] Fix timezone `UTC` false positive (#10586) @alexfauquette
|
|
49
|
+
- [l10n] Improve Spanish (es-ES) locale (#10588) @eduardodallmann
|
|
50
|
+
|
|
51
|
+
#### `@mui/x-date-pickers-pro@6.16.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
52
|
+
|
|
53
|
+
Same changes as in `@mui/x-date-pickers@6.16.2`.
|
|
54
|
+
|
|
55
|
+
### Charts / `@mui/x-charts@6.0.0-alpha.15`
|
|
56
|
+
|
|
57
|
+
#### Breaking changes
|
|
58
|
+
|
|
59
|
+
The charts have a new text display mechanism.
|
|
60
|
+
It adds line break support and avoids overlapping text in the legend.
|
|
61
|
+
This comes with some breaking changes.
|
|
62
|
+
|
|
63
|
+
- The DOM structure is modified. An intermediary `<tspan />` element has been added. This can impact how your style is applied.
|
|
64
|
+
```diff
|
|
65
|
+
- <text>The label</text>
|
|
66
|
+
+ <text><tspan>The label</tspan></text>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- The top margin has been reduced from 100 to 50 to benefit from the denser legend.
|
|
70
|
+
|
|
71
|
+
- To accurately compute the text size and then place it, styling should be provided as a JS object. For example, to set the legend font size, you should do:
|
|
72
|
+
```jsx
|
|
73
|
+
<PieChart
|
|
74
|
+
{/** ... */}
|
|
75
|
+
slotProps={{
|
|
76
|
+
legend: {
|
|
77
|
+
labelStyle: {
|
|
78
|
+
fontSize: 16,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
```
|
|
84
|
+
Support for other text elements (axis labels and tick labels) will be implemented in follow-up PR.
|
|
85
|
+
|
|
86
|
+
#### Changes
|
|
87
|
+
|
|
88
|
+
- [charts] Fix typo between internal/external variable (#10640) @alexfauquette
|
|
89
|
+
- [charts] Improve the management of the text (#10138) @alexfauquette
|
|
90
|
+
|
|
91
|
+
### Docs
|
|
92
|
+
|
|
93
|
+
- [docs] Add bulk editing demo (#10333) @cherniavskii
|
|
94
|
+
- [docs] Add reference links to DateRangePicker components (#10629) @michelengelen
|
|
95
|
+
- [docs] Add reference links to DateTimePicker components (#10628) @michelengelen
|
|
96
|
+
- [docs] Add reference links to picker field components (#10631) @michelengelen
|
|
97
|
+
- [docs] Added reference links to TimePicker components (#10627) @michelengelen
|
|
98
|
+
- [docs] Avoid Pickers playground error due to empty views (#10654) @LukasTy
|
|
99
|
+
- [docs] Fix DataGrid[Pro/Premium] reference links (#10620) @michelengelen
|
|
100
|
+
|
|
101
|
+
### Core
|
|
102
|
+
|
|
103
|
+
- [core] Bump monorepo (#10619) @alexfauquette
|
|
104
|
+
- [core] Update `no-response` workflow (#10491) @MBilalShafi
|
|
105
|
+
- [core] Update the issue templates to reflect the new support workflow (#10651) @MBilalShafi
|
|
106
|
+
- [test] Fix `testEval` not invoking test assertions (#10587) @cherniavskii
|
|
107
|
+
- [test] Fix dev mode warning (#10610) @oliviertassinari
|
|
108
|
+
- [test] Set UUID chance seed in visual tests (#10609) @oliviertassinari
|
|
109
|
+
|
|
6
110
|
## 6.16.1
|
|
7
111
|
|
|
8
112
|
_Oct 6, 2023_
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Theme } from '@mui/material/styles';
|
|
3
3
|
import { DrawingArea } from '../context/DrawingProvider';
|
|
4
|
-
import { AnchorPosition,
|
|
4
|
+
import { AnchorPosition, Direction } from './utils';
|
|
5
5
|
import { FormattedSeries } from '../context/SeriesContextProvider';
|
|
6
6
|
import { ChartsLegendClasses } from './chartsLegendClasses';
|
|
7
7
|
import { DefaultizedProps } from '../models/helpers';
|
|
8
|
-
import {
|
|
8
|
+
import { LegendParams } from '../models/seriesType/config';
|
|
9
|
+
import { CardinalDirections } from '../models/layout';
|
|
9
10
|
export interface ChartsLegendSlotsComponent {
|
|
10
11
|
legend?: React.JSXElementConstructor<LegendRendererProps>;
|
|
11
12
|
}
|
|
@@ -14,10 +15,6 @@ export interface ChartsLegendSlotComponentProps {
|
|
|
14
15
|
}
|
|
15
16
|
export type ChartsLegendProps = {
|
|
16
17
|
position?: AnchorPosition;
|
|
17
|
-
offset?: Partial<{
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
}>;
|
|
21
18
|
/**
|
|
22
19
|
* Override or extend the styles applied to the component.
|
|
23
20
|
*/
|
|
@@ -26,6 +23,11 @@ export type ChartsLegendProps = {
|
|
|
26
23
|
* Set to true to hide the legend.
|
|
27
24
|
*/
|
|
28
25
|
hidden?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The direction of the legend layout.
|
|
28
|
+
* The default depends on the chart.
|
|
29
|
+
*/
|
|
30
|
+
direction?: Direction;
|
|
29
31
|
/**
|
|
30
32
|
* Overridable component slots.
|
|
31
33
|
* @default {}
|
|
@@ -36,36 +38,53 @@ export type ChartsLegendProps = {
|
|
|
36
38
|
* @default {}
|
|
37
39
|
*/
|
|
38
40
|
slotProps?: ChartsLegendSlotComponentProps;
|
|
39
|
-
} & SizingParams;
|
|
40
|
-
type DefaultizedChartsLegendProps = DefaultizedProps<ChartsLegendProps, 'direction' | 'position'>;
|
|
41
|
-
type SeriesLegendOwnerState = ChartSeriesDefaultized<any> & Pick<DefaultizedChartsLegendProps, 'direction'> & {
|
|
42
|
-
seriesIndex: number;
|
|
43
41
|
};
|
|
42
|
+
type DefaultizedChartsLegendProps = DefaultizedProps<ChartsLegendProps, 'direction' | 'position'>;
|
|
44
43
|
export type ChartsLegendRootOwnerState = {
|
|
45
44
|
position: AnchorPosition;
|
|
46
|
-
direction:
|
|
45
|
+
direction: Direction;
|
|
47
46
|
drawingArea: DrawingArea;
|
|
48
47
|
offsetX?: number;
|
|
49
48
|
offsetY?: number;
|
|
50
49
|
seriesNumber: number;
|
|
51
50
|
};
|
|
52
|
-
export declare const ChartsLegendRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme
|
|
53
|
-
ownerState: ChartsLegendRootOwnerState;
|
|
54
|
-
}, Pick<React.SVGProps<SVGGElement>, keyof React.SVGProps<SVGGElement>>, {}>;
|
|
55
|
-
export declare const ChartsSeriesLegendGroup: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
56
|
-
ownerState: SeriesLegendOwnerState;
|
|
57
|
-
}, Pick<React.SVGProps<SVGGElement>, keyof React.SVGProps<SVGGElement>>, {}>;
|
|
58
|
-
export declare const ChartsLegendMark: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme> & {
|
|
59
|
-
ownerState: {
|
|
60
|
-
color: string;
|
|
61
|
-
};
|
|
62
|
-
}, Pick<React.SVGProps<SVGRectElement>, keyof React.SVGProps<SVGRectElement>>, {}>;
|
|
63
|
-
export declare const ChartsLegendLabel: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme>, Pick<React.SVGTextElementAttributes<SVGTextElement>, keyof React.SVGTextElementAttributes<SVGTextElement>>, {}>;
|
|
51
|
+
export declare const ChartsLegendRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme>, Pick<React.SVGProps<SVGGElement>, keyof React.SVGProps<SVGGElement>>, {}>;
|
|
64
52
|
export interface LegendRendererProps extends Omit<DefaultizedChartsLegendProps, 'slots' | 'slotProps'> {
|
|
65
53
|
series: FormattedSeries;
|
|
66
54
|
seriesToDisplay: LegendParams[];
|
|
67
55
|
drawingArea: DrawingArea;
|
|
68
|
-
classes: Record<'
|
|
56
|
+
classes: Record<'mark' | 'series' | 'root', string>;
|
|
57
|
+
/**
|
|
58
|
+
* Style applied to legend labels.
|
|
59
|
+
* @default theme.typography.subtitle1
|
|
60
|
+
*/
|
|
61
|
+
labelStyle?: React.CSSProperties;
|
|
62
|
+
/**
|
|
63
|
+
* Width of the item mark (in px).
|
|
64
|
+
* @default 20
|
|
65
|
+
*/
|
|
66
|
+
itemMarkWidth?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Height of the item mark (in px).
|
|
69
|
+
* @default 20
|
|
70
|
+
*/
|
|
71
|
+
itemMarkHeight?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Space between the mark and the label (in px).
|
|
74
|
+
* @default 5
|
|
75
|
+
*/
|
|
76
|
+
markGap?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Space between two legend items (in px).
|
|
79
|
+
* @default 10
|
|
80
|
+
*/
|
|
81
|
+
itemGap?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Legend padding (in px).
|
|
84
|
+
* Can either be a single number, or an object with top, left, bottom, right properties.
|
|
85
|
+
* @default 0
|
|
86
|
+
*/
|
|
87
|
+
padding?: number | Partial<CardinalDirections<number>>;
|
|
69
88
|
}
|
|
70
89
|
export declare function ChartsLegend(inProps: ChartsLegendProps): React.JSX.Element;
|
|
71
90
|
export {};
|
|
@@ -5,17 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.ChartsLegend = ChartsLegend;
|
|
8
|
-
exports.
|
|
8
|
+
exports.ChartsLegendRoot = void 0;
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var React = _interopRequireWildcard(require("react"));
|
|
11
12
|
var _utils = require("@mui/base/utils");
|
|
13
|
+
var _NoSsr = require("@mui/base/NoSsr");
|
|
12
14
|
var _utils2 = require("@mui/utils");
|
|
13
15
|
var _styles = require("@mui/material/styles");
|
|
14
16
|
var _DrawingProvider = require("../context/DrawingProvider");
|
|
15
17
|
var _utils3 = require("./utils");
|
|
16
18
|
var _SeriesContextProvider = require("../context/SeriesContextProvider");
|
|
17
19
|
var _chartsLegendClasses = require("./chartsLegendClasses");
|
|
20
|
+
var _ChartsText = require("../internals/components/ChartsText");
|
|
18
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _excluded = ["label"];
|
|
19
23
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
25
|
const useUtilityClasses = ownerState => {
|
|
@@ -31,167 +35,207 @@ const useUtilityClasses = ownerState => {
|
|
|
31
35
|
};
|
|
32
36
|
return (0, _utils2.unstable_composeClasses)(slots, _chartsLegendClasses.getChartsLegendUtilityClass, classes);
|
|
33
37
|
};
|
|
34
|
-
function getTranslePosition({
|
|
35
|
-
position,
|
|
36
|
-
drawingArea
|
|
37
|
-
}) {
|
|
38
|
-
let xValue;
|
|
39
|
-
switch (position.horizontal) {
|
|
40
|
-
case 'left':
|
|
41
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left}px - var(--ChartsLegend-rootWidth))`;
|
|
42
|
-
break;
|
|
43
|
-
case 'middle':
|
|
44
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width / 2}px - 0.5 * var(--ChartsLegend-rootWidth))`;
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
xValue = `calc(var(--ChartsLegend-rootOffsetX, 0px) + ${drawingArea.left + drawingArea.width}px)`;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
let yValue;
|
|
51
|
-
switch (position.vertical) {
|
|
52
|
-
case 'top':
|
|
53
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top}px - var(--ChartsLegend-rootHeight))`;
|
|
54
|
-
break;
|
|
55
|
-
case 'middle':
|
|
56
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height / 2}px - 0.5 * var(--ChartsLegend-rootHeight))`;
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
yValue = `calc(var(--ChartsLegend-rootOffsetY, 0px) + ${drawingArea.top + drawingArea.height}px)`;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
transform: `translate(${xValue}, ${yValue})`
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
38
|
const ChartsLegendRoot = exports.ChartsLegendRoot = (0, _styles.styled)('g', {
|
|
67
39
|
name: 'MuiChartsLegend',
|
|
68
40
|
slot: 'Root',
|
|
69
41
|
overridesResolver: (props, styles) => styles.root
|
|
70
|
-
})(
|
|
71
|
-
ownerState
|
|
72
|
-
}) => {
|
|
73
|
-
const {
|
|
74
|
-
direction,
|
|
75
|
-
drawingArea,
|
|
76
|
-
offsetX,
|
|
77
|
-
offsetY,
|
|
78
|
-
seriesNumber,
|
|
79
|
-
position
|
|
80
|
-
} = ownerState;
|
|
81
|
-
return (0, _extends2.default)({
|
|
82
|
-
'--ChartsLegend-rootOffsetX': typeof offsetX === 'number' ? `${offsetX}px` : undefined,
|
|
83
|
-
'--ChartsLegend-rootOffsetY': typeof offsetY === 'number' ? `${offsetY}px` : undefined,
|
|
84
|
-
'--ChartsLegend-rootWidth': direction === 'row' ? `calc(var(--ChartsLegend-itemWidth) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )` : 'var(--ChartsLegend-itemWidth)',
|
|
85
|
-
'--ChartsLegend-rootHeight': direction === 'row' ? 'var(--ChartsLegend-itemMarkSize)' : `calc(var(--ChartsLegend-itemMarkSize) * ${seriesNumber} + var(--ChartsLegend-rootSpacing) * ${seriesNumber - 1} )`
|
|
86
|
-
}, getTranslePosition({
|
|
87
|
-
position,
|
|
88
|
-
drawingArea,
|
|
89
|
-
offsetX,
|
|
90
|
-
offsetY
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
const ChartsSeriesLegendGroup = exports.ChartsSeriesLegendGroup = (0, _styles.styled)('g', {
|
|
94
|
-
name: 'MuiChartsLegend',
|
|
95
|
-
slot: 'ChartsSeriesLegendGroup',
|
|
96
|
-
overridesResolver: (props, styles) => styles.series
|
|
97
|
-
})(({
|
|
98
|
-
ownerState
|
|
99
|
-
}) => {
|
|
100
|
-
const {
|
|
101
|
-
direction,
|
|
102
|
-
seriesIndex
|
|
103
|
-
} = ownerState;
|
|
104
|
-
if (direction === 'row') {
|
|
105
|
-
return {
|
|
106
|
-
transform: `translate(calc(${seriesIndex} * (var(--ChartsLegend-itemWidth) + var(--ChartsLegend-rootSpacing))), 0)`
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
transform: `translate(0, calc(${seriesIndex} * (var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-rootSpacing))))`
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
const ChartsLegendMark = exports.ChartsLegendMark = (0, _styles.styled)('rect', {
|
|
114
|
-
name: 'MuiChartsLegend',
|
|
115
|
-
slot: 'Mark',
|
|
116
|
-
overridesResolver: (props, styles) => styles.mark
|
|
117
|
-
})(({
|
|
118
|
-
ownerState
|
|
119
|
-
}) => ({
|
|
120
|
-
x: 0,
|
|
121
|
-
y: 0,
|
|
122
|
-
width: 'var(--ChartsLegend-itemMarkSize)',
|
|
123
|
-
height: 'var(--ChartsLegend-itemMarkSize)',
|
|
124
|
-
fill: ownerState.color
|
|
125
|
-
}));
|
|
126
|
-
const ChartsLegendLabel = exports.ChartsLegendLabel = (0, _styles.styled)('text', {
|
|
127
|
-
name: 'MuiChartsLegend',
|
|
128
|
-
slot: 'Label',
|
|
129
|
-
overridesResolver: (props, styles) => styles.label
|
|
130
|
-
})(({
|
|
131
|
-
theme
|
|
132
|
-
}) => (0, _extends2.default)({}, theme.typography.body1, {
|
|
133
|
-
color: 'inherit',
|
|
134
|
-
transform: `translate(
|
|
135
|
-
calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),
|
|
136
|
-
calc(0.5 * var(--ChartsLegend-itemMarkSize))
|
|
137
|
-
)`,
|
|
138
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
139
|
-
dominantBaseline: 'central'
|
|
140
|
-
}));
|
|
42
|
+
})({});
|
|
141
43
|
const defaultProps = {
|
|
142
44
|
position: {
|
|
143
45
|
horizontal: 'middle',
|
|
144
46
|
vertical: 'top'
|
|
145
47
|
},
|
|
146
|
-
direction: 'row'
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
48
|
+
direction: 'row'
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
52
|
+
*/
|
|
53
|
+
const getStandardizedPadding = padding => {
|
|
54
|
+
if (typeof padding === 'number') {
|
|
55
|
+
return {
|
|
56
|
+
left: padding,
|
|
57
|
+
right: padding,
|
|
58
|
+
top: padding,
|
|
59
|
+
bottom: padding
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return (0, _extends2.default)({
|
|
63
|
+
left: 0,
|
|
64
|
+
right: 0,
|
|
65
|
+
top: 0,
|
|
66
|
+
bottom: 0
|
|
67
|
+
}, padding);
|
|
150
68
|
};
|
|
151
69
|
function DefaultChartsLegend(props) {
|
|
152
70
|
const {
|
|
153
71
|
hidden,
|
|
154
72
|
position,
|
|
155
73
|
direction,
|
|
156
|
-
offset,
|
|
157
|
-
series,
|
|
158
74
|
seriesToDisplay,
|
|
159
75
|
drawingArea,
|
|
160
|
-
classes
|
|
76
|
+
classes,
|
|
77
|
+
itemMarkWidth = 20,
|
|
78
|
+
itemMarkHeight = 20,
|
|
79
|
+
markGap = 5,
|
|
80
|
+
itemGap = 10,
|
|
81
|
+
padding: paddingProps = 10,
|
|
82
|
+
labelStyle: inLabelStyle
|
|
161
83
|
} = props;
|
|
84
|
+
const theme = (0, _styles.useTheme)();
|
|
85
|
+
const labelStyle = React.useMemo(() => (0, _extends2.default)({}, theme.typography.subtitle1, {
|
|
86
|
+
color: 'inherit',
|
|
87
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
88
|
+
lineHeight: 1
|
|
89
|
+
}, inLabelStyle), [inLabelStyle, theme]);
|
|
90
|
+
const padding = React.useMemo(() => getStandardizedPadding(paddingProps), [paddingProps]);
|
|
91
|
+
const getItemSpace = React.useCallback((label, style) => {
|
|
92
|
+
const linesSize = (0, _ChartsText.getWordsByLines)({
|
|
93
|
+
style,
|
|
94
|
+
needsComputation: true,
|
|
95
|
+
text: label
|
|
96
|
+
});
|
|
97
|
+
const innerSize = {
|
|
98
|
+
innerWidth: itemMarkWidth + markGap + Math.max(...linesSize.map(size => size.width)),
|
|
99
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
100
|
+
};
|
|
101
|
+
return (0, _extends2.default)({}, innerSize, {
|
|
102
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
103
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
104
|
+
});
|
|
105
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
106
|
+
const totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
107
|
+
const totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
108
|
+
const availableWidth = totalWidth - padding.left - padding.right;
|
|
109
|
+
const availableHeight = totalHeight - padding.top - padding.bottom;
|
|
110
|
+
const seriesWithPosition = React.useMemo(() => {
|
|
111
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
112
|
+
let x = 0;
|
|
113
|
+
let y = 0;
|
|
114
|
+
|
|
115
|
+
// total values used to align legend later.
|
|
116
|
+
let totalWidthUsed = 0;
|
|
117
|
+
let totalHeightUsed = 0;
|
|
118
|
+
let rowIndex = 0;
|
|
119
|
+
const rowMaxHeight = [0];
|
|
120
|
+
const seriesWithRawPosition = seriesToDisplay.map(_ref => {
|
|
121
|
+
let {
|
|
122
|
+
label
|
|
123
|
+
} = _ref,
|
|
124
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
|
|
125
|
+
const itemSpace = getItemSpace(label, labelStyle);
|
|
126
|
+
const rep = (0, _extends2.default)({}, other, {
|
|
127
|
+
label,
|
|
128
|
+
positionX: x,
|
|
129
|
+
positionY: y,
|
|
130
|
+
innerHeight: itemSpace.innerHeight,
|
|
131
|
+
innerWidth: itemSpace.innerWidth,
|
|
132
|
+
outerHeight: itemSpace.outerHeight,
|
|
133
|
+
outerWidth: itemSpace.outerWidth,
|
|
134
|
+
rowIndex
|
|
135
|
+
});
|
|
136
|
+
if (direction === 'row') {
|
|
137
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
138
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
139
|
+
x = 0;
|
|
140
|
+
y += rowMaxHeight[rowIndex];
|
|
141
|
+
rowIndex += 1;
|
|
142
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
143
|
+
rowMaxHeight.push(0);
|
|
144
|
+
}
|
|
145
|
+
rep.positionX = x;
|
|
146
|
+
rep.positionY = y;
|
|
147
|
+
rep.rowIndex = rowIndex;
|
|
148
|
+
}
|
|
149
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
150
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
151
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
152
|
+
x += itemSpace.outerWidth;
|
|
153
|
+
}
|
|
154
|
+
if (direction === 'column') {
|
|
155
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
156
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
157
|
+
x = totalWidthUsed + itemGap;
|
|
158
|
+
y = 0;
|
|
159
|
+
rowIndex = 0;
|
|
160
|
+
rep.positionX = x;
|
|
161
|
+
rep.positionY = y;
|
|
162
|
+
rep.rowIndex = rowIndex;
|
|
163
|
+
}
|
|
164
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
165
|
+
rowMaxHeight.push(0);
|
|
166
|
+
}
|
|
167
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
168
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
169
|
+
rowIndex += 1;
|
|
170
|
+
y += itemSpace.outerHeight;
|
|
171
|
+
}
|
|
172
|
+
return rep;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Move the legend according to padding and position
|
|
176
|
+
let gapX = 0;
|
|
177
|
+
let gapY = 0;
|
|
178
|
+
switch (position.horizontal) {
|
|
179
|
+
case 'left':
|
|
180
|
+
gapX = padding.left;
|
|
181
|
+
break;
|
|
182
|
+
case 'right':
|
|
183
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
switch (position.vertical) {
|
|
190
|
+
case 'top':
|
|
191
|
+
gapY = padding.top;
|
|
192
|
+
break;
|
|
193
|
+
case 'bottom':
|
|
194
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
195
|
+
break;
|
|
196
|
+
default:
|
|
197
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
return seriesWithRawPosition.map(item => (0, _extends2.default)({}, item, {
|
|
201
|
+
// Add the gap due to the position
|
|
202
|
+
positionX: item.positionX + gapX,
|
|
203
|
+
// Add the gap due to the position
|
|
204
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
205
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
206
|
+
}));
|
|
207
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
162
208
|
if (hidden) {
|
|
163
209
|
return null;
|
|
164
210
|
}
|
|
165
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})]
|
|
194
|
-
}, id))
|
|
211
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NoSsr.NoSsr, {
|
|
212
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ChartsLegendRoot, {
|
|
213
|
+
className: classes.root,
|
|
214
|
+
children: seriesWithPosition.map(({
|
|
215
|
+
id,
|
|
216
|
+
label,
|
|
217
|
+
color,
|
|
218
|
+
positionX,
|
|
219
|
+
positionY
|
|
220
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
|
|
221
|
+
className: classes.series,
|
|
222
|
+
transform: `translate(${positionX} ${positionY})`,
|
|
223
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("rect", {
|
|
224
|
+
className: classes.mark,
|
|
225
|
+
y: -itemMarkHeight / 2,
|
|
226
|
+
width: itemMarkWidth,
|
|
227
|
+
height: itemMarkHeight,
|
|
228
|
+
fill: color
|
|
229
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
|
|
230
|
+
style: labelStyle,
|
|
231
|
+
dominantBaseline: "central",
|
|
232
|
+
textAnchor: "start",
|
|
233
|
+
text: label,
|
|
234
|
+
x: itemMarkWidth + markGap,
|
|
235
|
+
y: 0
|
|
236
|
+
})]
|
|
237
|
+
}, id))
|
|
238
|
+
})
|
|
195
239
|
});
|
|
196
240
|
}
|
|
197
241
|
function ChartsLegend(inProps) {
|
|
@@ -202,7 +246,6 @@ function ChartsLegend(inProps) {
|
|
|
202
246
|
const {
|
|
203
247
|
position,
|
|
204
248
|
direction,
|
|
205
|
-
offset,
|
|
206
249
|
hidden,
|
|
207
250
|
slots,
|
|
208
251
|
slotProps
|
|
@@ -221,7 +264,6 @@ function ChartsLegend(inProps) {
|
|
|
221
264
|
additionalProps: {
|
|
222
265
|
position,
|
|
223
266
|
direction,
|
|
224
|
-
offset,
|
|
225
267
|
classes,
|
|
226
268
|
drawingArea,
|
|
227
269
|
series,
|
package/ChartsLegend/utils.d.ts
CHANGED
|
@@ -5,10 +5,5 @@ export type AnchorPosition = {
|
|
|
5
5
|
horizontal: AnchorX;
|
|
6
6
|
vertical: AnchorY;
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
9
|
-
direction?: 'row' | 'column';
|
|
10
|
-
markSize?: number;
|
|
11
|
-
itemWidth?: number;
|
|
12
|
-
spacing?: number;
|
|
13
|
-
};
|
|
8
|
+
export type Direction = 'row' | 'column';
|
|
14
9
|
export declare function getSeriesToDisplay(series: FormattedSeries): import("../models/seriesType/config").LegendParams[];
|