@mui/x-charts 8.8.0 → 8.9.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/BarChart/BarChart.d.ts +3 -2
- package/BarChart/BarChart.js +1 -1
- package/BarChart/barClasses.d.ts +1 -1
- package/BarChart/seriesConfig/seriesProcessor.js +5 -3
- package/BarChart/useBarPlotData.js +32 -5
- package/CHANGELOG.md +101 -24
- package/ChartsLabel/ChartsLabelMark.d.ts +2 -1
- package/ChartsLabel/index.d.ts +1 -0
- package/ChartsLabel/index.js +18 -0
- package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
- package/LineChart/LineChart.d.ts +3 -2
- package/LineChart/LineChart.js +1 -1
- package/PieChart/PieArcLabelPlot.js +3 -0
- package/PieChart/PieArcPlot.js +3 -0
- package/PieChart/PieChart.d.ts +3 -2
- package/PieChart/PieChart.js +1 -1
- package/PieChart/pieClasses.d.ts +1 -1
- package/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
- package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
- package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
- package/RadarChart/RadarChart.d.ts +2 -1
- package/RadarChart/RadarChart.js +23 -2
- package/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
- package/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
- package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
- package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
- package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
- package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +38 -0
- package/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
- package/RadarChart/index.d.ts +1 -1
- package/RadarChart/useRadarChartProps.d.ts +3 -0
- package/RadarChart/useRadarChartProps.js +15 -3
- package/ScatterChart/ScatterChart.d.ts +3 -2
- package/ScatterChart/ScatterChart.js +1 -1
- package/esm/BarChart/BarChart.d.ts +3 -2
- package/esm/BarChart/BarChart.js +1 -1
- package/esm/BarChart/barClasses.d.ts +1 -1
- package/esm/BarChart/seriesConfig/seriesProcessor.js +5 -3
- package/esm/BarChart/useBarPlotData.js +32 -5
- package/esm/ChartsLabel/ChartsLabelMark.d.ts +2 -1
- package/esm/ChartsLabel/index.d.ts +1 -0
- package/esm/ChartsLabel/index.js +1 -0
- package/esm/ChartsLegend/chartsLegendClasses.d.ts +1 -1
- package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
- package/esm/LineChart/LineChart.d.ts +3 -2
- package/esm/LineChart/LineChart.js +1 -1
- package/esm/PieChart/PieArcLabelPlot.js +3 -0
- package/esm/PieChart/PieArcPlot.js +3 -0
- package/esm/PieChart/PieChart.d.ts +3 -2
- package/esm/PieChart/PieChart.js +1 -1
- package/esm/PieChart/pieClasses.d.ts +1 -1
- package/esm/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
- package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
- package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
- package/esm/RadarChart/RadarChart.d.ts +2 -1
- package/esm/RadarChart/RadarChart.js +23 -2
- package/esm/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
- package/esm/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
- package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
- package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
- package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +32 -0
- package/esm/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
- package/esm/RadarChart/index.d.ts +1 -1
- package/esm/RadarChart/useRadarChartProps.d.ts +3 -0
- package/esm/RadarChart/useRadarChartProps.js +15 -3
- package/esm/ScatterChart/ScatterChart.d.ts +3 -2
- package/esm/ScatterChart/ScatterChart.js +1 -1
- package/esm/hooks/useTicks.d.ts +6 -1
- package/esm/hooks/useTicks.js +94 -58
- package/esm/index.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +19 -11
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +19 -11
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
- package/esm/models/axis.d.ts +27 -1
- package/esm/models/seriesType/bar.d.ts +11 -1
- package/esm/models/seriesType/common.d.ts +9 -3
- package/esm/models/seriesType/line.d.ts +3 -1
- package/esm/models/seriesType/scatter.d.ts +4 -1
- package/esm/tests/web-components.js +49 -0
- package/hooks/useTicks.d.ts +6 -1
- package/hooks/useTicks.js +95 -58
- package/index.js +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +20 -13
- package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +20 -13
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
- package/models/axis.d.ts +27 -1
- package/models/seriesType/bar.d.ts +11 -1
- package/models/seriesType/common.d.ts +9 -3
- package/models/seriesType/line.d.ts +3 -1
- package/models/seriesType/scatter.d.ts +4 -1
- package/package.json +4 -4
- package/tests/web-components.js +55 -0
package/esm/models/axis.d.ts
CHANGED
|
@@ -281,11 +281,37 @@ export type AxisValueFormatterContext<S extends ScaleName = ScaleName> = {
|
|
|
281
281
|
* - `'legend'` The value is displayed in the legend when using color legend.
|
|
282
282
|
* - `'zoom-slider-tooltip'` The value is displayed in the zoom slider tooltip.
|
|
283
283
|
*/
|
|
284
|
-
location: '
|
|
284
|
+
location: 'tooltip' | 'zoom-slider-tooltip';
|
|
285
285
|
/**
|
|
286
286
|
* The d3-scale instance associated to the axis.
|
|
287
287
|
*/
|
|
288
288
|
scale: AxisScaleConfig[S]['scale'];
|
|
289
|
+
} | {
|
|
290
|
+
/**
|
|
291
|
+
* Location indicates where the value will be displayed.
|
|
292
|
+
* - `'tick'` The value is displayed on the axis ticks.
|
|
293
|
+
* - `'tooltip'` The value is displayed in the tooltip when hovering the chart.
|
|
294
|
+
* - `'legend'` The value is displayed in the legend when using color legend.
|
|
295
|
+
* - `'zoom-slider-tooltip'` The value is displayed in the zoom slider tooltip.
|
|
296
|
+
*/
|
|
297
|
+
location: 'tick';
|
|
298
|
+
/**
|
|
299
|
+
* The d3-scale instance associated to the axis.
|
|
300
|
+
*/
|
|
301
|
+
scale: AxisScaleConfig[S]['scale'];
|
|
302
|
+
/**
|
|
303
|
+
* The tick label shown by default if the value isn't formatted.
|
|
304
|
+
* This value might be an empty string if no tick label should be displayed, which is particularly useful in log
|
|
305
|
+
* scales where we want to show ticks to demonstrate it's a log scale, but not labels to avoid them overlapping.
|
|
306
|
+
* @see See {@link https://d3js.org/d3-scale/log#log_tickFormat D3 log scale docs} for more details.
|
|
307
|
+
*/
|
|
308
|
+
defaultTickLabel: string;
|
|
309
|
+
/**
|
|
310
|
+
* A suggestion of the number of ticks to show.
|
|
311
|
+
* Can be provided to the scale's `ticks` method to compute the ticks, or to `tickFormat` to format the ticks.
|
|
312
|
+
* Can be `undefined` if the scale doesn't support it, e.g., band, point scales.
|
|
313
|
+
*/
|
|
314
|
+
tickNumber?: number;
|
|
289
315
|
};
|
|
290
316
|
/**
|
|
291
317
|
* Config that is shared between cartesian and polar axes.
|
|
@@ -25,6 +25,16 @@ export interface BarSeriesType extends CommonSeriesType<number | null>, Cartesia
|
|
|
25
25
|
* @default 'diverging'
|
|
26
26
|
*/
|
|
27
27
|
stackOffset?: StackOffsetType;
|
|
28
|
+
/**
|
|
29
|
+
* If provided, the value will be used as the minimum size of the bar in pixels.
|
|
30
|
+
* This is useful to avoid bars with a size of 0.
|
|
31
|
+
*
|
|
32
|
+
* The property is ignored if the series value is `null` or `0`.
|
|
33
|
+
* It also doesn't work with stacked series.
|
|
34
|
+
*
|
|
35
|
+
* @default 0px
|
|
36
|
+
*/
|
|
37
|
+
minBarSize?: number;
|
|
28
38
|
}
|
|
29
39
|
/**
|
|
30
40
|
* An object that allows to identify a single bar.
|
|
@@ -35,4 +45,4 @@ export type BarItemIdentifier = {
|
|
|
35
45
|
seriesId: SeriesId;
|
|
36
46
|
dataIndex: number;
|
|
37
47
|
};
|
|
38
|
-
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color' | 'layout'> {}
|
|
48
|
+
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color' | 'layout' | 'minBarSize'> {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ChartsLabelMarkProps } from "../../ChartsLabel/index.js";
|
|
2
1
|
import { HighlightScope } from "../../internals/plugins/featurePlugins/useChartHighlight/highlightConfig.types.js";
|
|
3
2
|
import type { StackOffsetType, StackOrderType } from "../stacking.js";
|
|
3
|
+
import type { ChartsLabelMarkType } from "../../ChartsLabel/ChartsLabelMark.js";
|
|
4
4
|
export type SeriesId = number | string;
|
|
5
5
|
export type SeriesValueFormatterContext = {
|
|
6
6
|
/**
|
|
@@ -10,7 +10,13 @@ export type SeriesValueFormatterContext = {
|
|
|
10
10
|
};
|
|
11
11
|
export type SeriesValueFormatter<TValue> = (value: TValue, context: SeriesValueFormatterContext) => string | null;
|
|
12
12
|
export type CommonSeriesType<TValue> = {
|
|
13
|
+
/**
|
|
14
|
+
* The id of this series.
|
|
15
|
+
*/
|
|
13
16
|
id?: SeriesId;
|
|
17
|
+
/**
|
|
18
|
+
* Color to use when displaying the series.
|
|
19
|
+
*/
|
|
14
20
|
color?: string;
|
|
15
21
|
/**
|
|
16
22
|
* Formatter used to render values in tooltip or other data display.
|
|
@@ -22,13 +28,13 @@ export type CommonSeriesType<TValue> = {
|
|
|
22
28
|
/**
|
|
23
29
|
* The scope to apply when the series is highlighted.
|
|
24
30
|
*/
|
|
25
|
-
highlightScope?:
|
|
31
|
+
highlightScope?: HighlightScope;
|
|
26
32
|
/**
|
|
27
33
|
* Defines the mark type for the series.
|
|
28
34
|
*
|
|
29
35
|
* There is a default mark type for each series type.
|
|
30
36
|
*/
|
|
31
|
-
labelMarkType?:
|
|
37
|
+
labelMarkType?: ChartsLabelMarkType;
|
|
32
38
|
};
|
|
33
39
|
export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
|
|
34
40
|
export type CartesianSeriesType = {
|
|
@@ -34,7 +34,9 @@ export interface LineSeriesType extends CommonSeriesType<number | null>, Cartesi
|
|
|
34
34
|
* The key used to retrieve data from the dataset.
|
|
35
35
|
*/
|
|
36
36
|
dataKey?: string;
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* If `true`, the series is rendered as an area instead of a line.
|
|
39
|
+
*/
|
|
38
40
|
area?: boolean;
|
|
39
41
|
/**
|
|
40
42
|
* The label to display on the tooltip or the legend. It can be a string or a function.
|
|
@@ -12,6 +12,9 @@ export type ScatterValueType = {
|
|
|
12
12
|
export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType | null>, CartesianSeriesType {
|
|
13
13
|
type: 'scatter';
|
|
14
14
|
data?: readonly ScatterValueType[];
|
|
15
|
+
/**
|
|
16
|
+
* Size of the markers in the scatter plot, in pixels.
|
|
17
|
+
*/
|
|
15
18
|
markerSize?: number;
|
|
16
19
|
/**
|
|
17
20
|
* The label to display on the tooltip or the legend. It can be a string or a function.
|
|
@@ -52,7 +55,7 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType | n
|
|
|
52
55
|
};
|
|
53
56
|
preview?: {
|
|
54
57
|
/**
|
|
55
|
-
* The size of the preview marker.
|
|
58
|
+
* The size of the preview marker in pixels.
|
|
56
59
|
* @default 1
|
|
57
60
|
*/
|
|
58
61
|
markerSize?: number;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const renderSymbol = Symbol.for('render');
|
|
2
|
+
const connectedSymbol = Symbol.for('connected');
|
|
3
|
+
const contextSymbol = Symbol.for('context');
|
|
4
|
+
const propsSymbol = Symbol.for('props');
|
|
5
|
+
|
|
6
|
+
// This function creates a custom web component that wraps a React component.
|
|
7
|
+
// Adapted from https://github.com/bitovi/react-to-web-component/blob/b1372bfd7bc67fe49920db840f1ed9cf736b2724/packages/core/src/core.ts
|
|
8
|
+
export function reactToWebComponent(ReactComponent, options, renderer) {
|
|
9
|
+
class ReactWebComponent extends HTMLElement {
|
|
10
|
+
static get observedAttributes() {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this[connectedSymbol] = true;
|
|
16
|
+
this[contextSymbol] = void 0;
|
|
17
|
+
this[propsSymbol] = {};
|
|
18
|
+
this.container = void 0;
|
|
19
|
+
if (options.shadow) {
|
|
20
|
+
this.container = this.attachShadow({
|
|
21
|
+
mode: options.shadow
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
this.container = this;
|
|
25
|
+
}
|
|
26
|
+
this[propsSymbol].container = this.container;
|
|
27
|
+
}
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
this[connectedSymbol] = true;
|
|
30
|
+
this[renderSymbol]();
|
|
31
|
+
}
|
|
32
|
+
disconnectedCallback() {
|
|
33
|
+
this[connectedSymbol] = false;
|
|
34
|
+
if (this[contextSymbol]) {
|
|
35
|
+
renderer.unmount(this[contextSymbol]);
|
|
36
|
+
}
|
|
37
|
+
delete this[contextSymbol];
|
|
38
|
+
}
|
|
39
|
+
[renderSymbol]() {
|
|
40
|
+
if (!this[connectedSymbol]) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!this[contextSymbol]) {
|
|
44
|
+
this[contextSymbol] = renderer.mount(this.container, ReactComponent, this[propsSymbol]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return ReactWebComponent;
|
|
49
|
+
}
|
package/hooks/useTicks.d.ts
CHANGED
|
@@ -49,8 +49,13 @@ export type TickItemType = {
|
|
|
49
49
|
offset: number;
|
|
50
50
|
labelOffset: number;
|
|
51
51
|
};
|
|
52
|
+
export declare function getTicks(options: {
|
|
53
|
+
scale: D3Scale;
|
|
54
|
+
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
|
+
isInside: (offset: number) => boolean;
|
|
56
|
+
} & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
|
|
52
57
|
export declare function useTicks(options: {
|
|
53
58
|
scale: D3Scale;
|
|
54
59
|
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
60
|
direction: 'x' | 'y';
|
|
56
|
-
} & Pick<TickParams, '
|
|
61
|
+
} & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
|
package/hooks/useTicks.js
CHANGED
|
@@ -5,6 +5,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.getTicks = getTicks;
|
|
8
9
|
exports.useTicks = useTicks;
|
|
9
10
|
var React = _interopRequireWildcard(require("react"));
|
|
10
11
|
var _ChartProvider = require("../context/ChartProvider");
|
|
@@ -16,7 +17,7 @@ const offsetRatio = {
|
|
|
16
17
|
end: 1,
|
|
17
18
|
middle: 0.5
|
|
18
19
|
};
|
|
19
|
-
function
|
|
20
|
+
function getTicks(options) {
|
|
20
21
|
const {
|
|
21
22
|
scale,
|
|
22
23
|
tickNumber,
|
|
@@ -24,75 +25,111 @@ function useTicks(options) {
|
|
|
24
25
|
tickInterval,
|
|
25
26
|
tickPlacement = 'extremities',
|
|
26
27
|
tickLabelPlacement: tickLabelPlacementProp,
|
|
27
|
-
|
|
28
|
+
isInside
|
|
28
29
|
} = options;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return [...filteredDomain.map(value => ({
|
|
30
|
+
|
|
31
|
+
// band scale
|
|
32
|
+
if ((0, _isBandScale.isBandScale)(scale)) {
|
|
33
|
+
const domain = scale.domain();
|
|
34
|
+
const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
|
|
35
|
+
if (scale.bandwidth() > 0) {
|
|
36
|
+
// scale type = 'band'
|
|
37
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
38
|
+
return [...filteredDomain.map(value => {
|
|
39
|
+
const defaultTickLabel = `${value}`;
|
|
40
|
+
return {
|
|
41
41
|
value,
|
|
42
42
|
formattedValue: valueFormatter?.(value, {
|
|
43
43
|
location: 'tick',
|
|
44
|
-
scale
|
|
45
|
-
|
|
44
|
+
scale,
|
|
45
|
+
tickNumber,
|
|
46
|
+
defaultTickLabel
|
|
47
|
+
}) ?? defaultTickLabel,
|
|
46
48
|
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step(),
|
|
47
49
|
labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
50
|
+
};
|
|
51
|
+
}), ...(tickPlacement === 'extremities' ? [{
|
|
52
|
+
formattedValue: undefined,
|
|
53
|
+
offset: scale.range()[1],
|
|
54
|
+
labelOffset: 0
|
|
55
|
+
}] : [])];
|
|
56
|
+
}
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
// scale type = 'point'
|
|
59
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
60
|
+
return filteredDomain.map(value => {
|
|
61
|
+
const defaultTickLabel = `${value}`;
|
|
62
|
+
return {
|
|
58
63
|
value,
|
|
59
64
|
formattedValue: valueFormatter?.(value, {
|
|
60
65
|
location: 'tick',
|
|
61
|
-
scale
|
|
62
|
-
|
|
66
|
+
scale,
|
|
67
|
+
tickNumber,
|
|
68
|
+
defaultTickLabel
|
|
69
|
+
}) ?? defaultTickLabel,
|
|
63
70
|
offset: scale(value),
|
|
64
71
|
labelOffset: 0
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const domain = scale.domain();
|
|
76
|
+
// Skip axis rendering if no data is available
|
|
77
|
+
// - The domains contains Infinity for continuous scales.
|
|
78
|
+
if (domain.some(_isInfinity.isInfinity)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const tickLabelPlacement = tickLabelPlacementProp;
|
|
82
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
75
83
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
// Ticks inside the drawing area
|
|
85
|
+
const visibleTicks = [];
|
|
86
|
+
for (let i = 0; i < ticks.length; i += 1) {
|
|
87
|
+
const value = ticks[i];
|
|
88
|
+
const offset = scale(value);
|
|
89
|
+
if (isInside(offset)) {
|
|
90
|
+
/* If d3 returns an empty string, it means that a tick should be shown, but its label shouldn't.
|
|
91
|
+
* This is especially useful in a log scale where we want to show ticks to demonstrate it's a log
|
|
92
|
+
* scale, but don't want to show labels because they would overlap.
|
|
93
|
+
* https://github.com/mui/mui-x/issues/18239 */
|
|
94
|
+
const defaultTickLabel = scale.tickFormat(tickNumber)(value);
|
|
95
|
+
visibleTicks.push({
|
|
96
|
+
value,
|
|
97
|
+
formattedValue: valueFormatter?.(value, {
|
|
98
|
+
location: 'tick',
|
|
99
|
+
scale,
|
|
100
|
+
tickNumber,
|
|
101
|
+
defaultTickLabel
|
|
102
|
+
}) ?? defaultTickLabel,
|
|
103
|
+
offset,
|
|
104
|
+
// Allowing the label to be placed in the middle of a continuous scale is weird.
|
|
105
|
+
// But it is useful in some cases, like funnel categories with a linear scale.
|
|
106
|
+
labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
|
|
107
|
+
});
|
|
95
108
|
}
|
|
96
|
-
|
|
97
|
-
|
|
109
|
+
}
|
|
110
|
+
return visibleTicks;
|
|
111
|
+
}
|
|
112
|
+
function useTicks(options) {
|
|
113
|
+
const {
|
|
114
|
+
scale,
|
|
115
|
+
tickNumber,
|
|
116
|
+
valueFormatter,
|
|
117
|
+
tickInterval,
|
|
118
|
+
tickPlacement = 'extremities',
|
|
119
|
+
tickLabelPlacement,
|
|
120
|
+
direction
|
|
121
|
+
} = options;
|
|
122
|
+
const {
|
|
123
|
+
instance
|
|
124
|
+
} = (0, _ChartProvider.useChartContext)();
|
|
125
|
+
const isInside = direction === 'x' ? instance.isXInside : instance.isYInside;
|
|
126
|
+
return React.useMemo(() => getTicks({
|
|
127
|
+
scale,
|
|
128
|
+
tickNumber,
|
|
129
|
+
tickPlacement,
|
|
130
|
+
tickInterval,
|
|
131
|
+
tickLabelPlacement,
|
|
132
|
+
valueFormatter,
|
|
133
|
+
isInside
|
|
134
|
+
}), [scale, tickNumber, tickPlacement, tickInterval, tickLabelPlacement, valueFormatter, isInside]);
|
|
98
135
|
}
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { HighlightScope } from "./highlightConfig.types.js";
|
|
2
2
|
import { HighlightItemData } from "./useChartHighlight.types.js";
|
|
3
|
-
export declare
|
|
3
|
+
export declare function createIsFaded(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
|
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createIsFaded =
|
|
7
|
-
|
|
8
|
-
if (!highlightScope || !highlightedItem || !item) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (highlightScope.fade === 'series') {
|
|
12
|
-
return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
|
|
13
|
-
}
|
|
14
|
-
if (highlightScope.fade === 'global') {
|
|
15
|
-
return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
|
|
16
|
-
}
|
|
6
|
+
exports.createIsFaded = createIsFaded;
|
|
7
|
+
function alwaysFalse() {
|
|
17
8
|
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
9
|
+
}
|
|
10
|
+
function createIsFaded(highlightScope, highlightedItem) {
|
|
11
|
+
if (!highlightScope || !highlightedItem) {
|
|
12
|
+
return alwaysFalse;
|
|
13
|
+
}
|
|
14
|
+
return function isFaded(item) {
|
|
15
|
+
if (!item) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (highlightScope.fade === 'series') {
|
|
19
|
+
return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
|
|
20
|
+
}
|
|
21
|
+
if (highlightScope.fade === 'global') {
|
|
22
|
+
return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { HighlightScope } from "./highlightConfig.types.js";
|
|
2
2
|
import { HighlightItemData } from "./useChartHighlight.types.js";
|
|
3
|
-
export declare
|
|
3
|
+
export declare function createIsHighlighted(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
|
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createIsHighlighted =
|
|
7
|
-
|
|
8
|
-
if (!highlightScope || !highlightedItem || !item) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (highlightScope.highlight === 'series') {
|
|
12
|
-
return item.seriesId === highlightedItem.seriesId;
|
|
13
|
-
}
|
|
14
|
-
if (highlightScope.highlight === 'item') {
|
|
15
|
-
return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
|
|
16
|
-
}
|
|
6
|
+
exports.createIsHighlighted = createIsHighlighted;
|
|
7
|
+
function alwaysFalse() {
|
|
17
8
|
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
9
|
+
}
|
|
10
|
+
function createIsHighlighted(highlightScope, highlightedItem) {
|
|
11
|
+
if (!highlightScope || !highlightedItem) {
|
|
12
|
+
return alwaysFalse;
|
|
13
|
+
}
|
|
14
|
+
return function isHighlighted(item) {
|
|
15
|
+
if (!item) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (highlightScope.highlight === 'series') {
|
|
19
|
+
return item.seriesId === highlightedItem.seriesId;
|
|
20
|
+
}
|
|
21
|
+
if (highlightScope.highlight === 'item') {
|
|
22
|
+
return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -20,8 +20,10 @@ const selectorChartsHighlightScopePerSeriesId = exports.selectorChartsHighlightS
|
|
|
20
20
|
});
|
|
21
21
|
return map;
|
|
22
22
|
});
|
|
23
|
-
const selectorChartsHighlightedItem = exports.selectorChartsHighlightedItem = (0, _selectors.createSelector)([selectHighlight],
|
|
24
|
-
|
|
23
|
+
const selectorChartsHighlightedItem = exports.selectorChartsHighlightedItem = (0, _selectors.createSelector)([selectHighlight], function selectorChartsHighlightedItem(highlight) {
|
|
24
|
+
return highlight.item;
|
|
25
|
+
});
|
|
26
|
+
const selectorChartsHighlightScope = exports.selectorChartsHighlightScope = (0, _selectors.createSelector)([selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem], function selectorChartsHighlightScope(seriesIdToHighlightScope, highlightedItem) {
|
|
25
27
|
if (!highlightedItem) {
|
|
26
28
|
return null;
|
|
27
29
|
}
|
|
@@ -33,5 +35,9 @@ const selectorChartsHighlightScope = exports.selectorChartsHighlightScope = (0,
|
|
|
33
35
|
});
|
|
34
36
|
const selectorChartsIsHighlightedCallback = exports.selectorChartsIsHighlightedCallback = (0, _selectors.createSelector)([selectorChartsHighlightScope, selectorChartsHighlightedItem], _createIsHighlighted.createIsHighlighted);
|
|
35
37
|
const selectorChartsIsFadedCallback = exports.selectorChartsIsFadedCallback = (0, _selectors.createSelector)([selectorChartsHighlightScope, selectorChartsHighlightedItem], _createIsFaded.createIsFaded);
|
|
36
|
-
const selectorChartsIsHighlighted = exports.selectorChartsIsHighlighted = (0, _selectors.createSelector)([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], (highlightScope, highlightedItem, item)
|
|
37
|
-
|
|
38
|
+
const selectorChartsIsHighlighted = exports.selectorChartsIsHighlighted = (0, _selectors.createSelector)([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsHighlighted(highlightScope, highlightedItem, item) {
|
|
39
|
+
return (0, _createIsHighlighted.createIsHighlighted)(highlightScope, highlightedItem)(item);
|
|
40
|
+
});
|
|
41
|
+
const selectorChartsIsFaded = exports.selectorChartsIsFaded = (0, _selectors.createSelector)([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsFaded(highlightScope, highlightedItem, item) {
|
|
42
|
+
return (0, _createIsFaded.createIsFaded)(highlightScope, highlightedItem)(item);
|
|
43
|
+
});
|
|
@@ -11,7 +11,7 @@ var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompa
|
|
|
11
11
|
const useChartInteraction = ({
|
|
12
12
|
store
|
|
13
13
|
}) => {
|
|
14
|
-
const cleanInteraction = (0, _useEventCallback.default)(()
|
|
14
|
+
const cleanInteraction = (0, _useEventCallback.default)(function cleanInteraction() {
|
|
15
15
|
store.update(prev => {
|
|
16
16
|
return (0, _extends2.default)({}, prev, {
|
|
17
17
|
interaction: {
|
|
@@ -21,7 +21,7 @@ const useChartInteraction = ({
|
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
-
const removeItemInteraction = (0, _useEventCallback.default)(itemToRemove
|
|
24
|
+
const removeItemInteraction = (0, _useEventCallback.default)(function removeItemInteraction(itemToRemove) {
|
|
25
25
|
store.update(prev => {
|
|
26
26
|
const prevItem = prev.interaction.item;
|
|
27
27
|
if (!itemToRemove) {
|
|
@@ -43,7 +43,7 @@ const useChartInteraction = ({
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
|
-
const setItemInteraction = (0, _useEventCallback.default)(newItem
|
|
46
|
+
const setItemInteraction = (0, _useEventCallback.default)(function setItemInteraction(newItem) {
|
|
47
47
|
store.update(prev => {
|
|
48
48
|
if ((0, _fastObjectShallowCompare.fastObjectShallowCompare)(prev.interaction.item, newItem)) {
|
|
49
49
|
return prev;
|
|
@@ -55,7 +55,7 @@ const useChartInteraction = ({
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
-
const setPointerCoordinate = (0, _useEventCallback.default)(coordinate
|
|
58
|
+
const setPointerCoordinate = (0, _useEventCallback.default)(function setPointerCoordinate(coordinate) {
|
|
59
59
|
store.update(prev => (0, _extends2.default)({}, prev, {
|
|
60
60
|
interaction: (0, _extends2.default)({}, prev.interaction, {
|
|
61
61
|
pointer: coordinate
|
|
@@ -17,6 +17,8 @@ var _useChartInteraction = require("../useChartInteraction");
|
|
|
17
17
|
var _useChartPolarAxis = require("./useChartPolarAxis.selectors");
|
|
18
18
|
var _getSVGPoint = require("../../../getSVGPoint");
|
|
19
19
|
var _coordinateTransformation = require("./coordinateTransformation");
|
|
20
|
+
var _getAxisIndex = require("./getAxisIndex");
|
|
21
|
+
var _useChartSeries = require("../../corePlugins/useChartSeries");
|
|
20
22
|
const useChartPolarAxis = ({
|
|
21
23
|
params,
|
|
22
24
|
store,
|
|
@@ -37,6 +39,7 @@ const useChartPolarAxis = ({
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
const drawingArea = (0, _useSelector.useSelector)(store, _useChartDimensions.selectorChartDrawingArea);
|
|
42
|
+
const processedSeries = (0, _useSelector.useSelector)(store, _useChartSeries.selectorChartSeriesProcessed);
|
|
40
43
|
const center = (0, _useSelector.useSelector)(store, _useChartPolarAxis.selectorChartPolarCenter);
|
|
41
44
|
const isInteractionEnabled = (0, _useSelector.useSelector)(store, _useChartInteraction.selectorChartsInteractionIsInitialized);
|
|
42
45
|
const {
|
|
@@ -163,6 +166,45 @@ const useChartPolarAxis = ({
|
|
|
163
166
|
pressEndHandler.cleanup();
|
|
164
167
|
};
|
|
165
168
|
}, [svgRef, store, center, radiusAxisWithScale, usedRadiusAxisId, rotationAxisWithScale, usedRotationAxisId, instance, params.disableAxisListener, isInteractionEnabled, svg2rotation]);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
const element = svgRef.current;
|
|
171
|
+
const onAxisClick = params.onAxisClick;
|
|
172
|
+
if (element === null || !onAxisClick) {
|
|
173
|
+
return () => {};
|
|
174
|
+
}
|
|
175
|
+
const axisClickHandler = instance.addInteractionListener('tap', event => {
|
|
176
|
+
let dataIndex = null;
|
|
177
|
+
let isRotationAxis = false;
|
|
178
|
+
const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, event.detail.srcEvent);
|
|
179
|
+
const rotation = (0, _coordinateTransformation.generateSvg2rotation)(center)(svgPoint.x, svgPoint.y);
|
|
180
|
+
const rotationIndex = (0, _getAxisIndex.getAxisIndex)(rotationAxisWithScale[usedRotationAxisId], rotation);
|
|
181
|
+
isRotationAxis = rotationIndex !== -1;
|
|
182
|
+
dataIndex = isRotationAxis ? rotationIndex : null; // radius index is not yet implemented.
|
|
183
|
+
|
|
184
|
+
const USED_AXIS_ID = isRotationAxis ? usedRotationAxisId : usedRadiusAxisId;
|
|
185
|
+
if (dataIndex == null || dataIndex === -1) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The .data exist because otherwise the dataIndex would be null or -1.
|
|
190
|
+
const axisValue = (isRotationAxis ? rotationAxisWithScale : radiusAxisWithScale)[USED_AXIS_ID].data[dataIndex];
|
|
191
|
+
const seriesValues = {};
|
|
192
|
+
Object.keys(processedSeries).filter(seriesType => seriesType === 'radar').forEach(seriesType => {
|
|
193
|
+
processedSeries[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
194
|
+
const seriesItem = processedSeries[seriesType].series[seriesId];
|
|
195
|
+
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
onAxisClick(event.detail.srcEvent, {
|
|
199
|
+
dataIndex,
|
|
200
|
+
axisValue,
|
|
201
|
+
seriesValues
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
return () => {
|
|
205
|
+
axisClickHandler.cleanup();
|
|
206
|
+
};
|
|
207
|
+
}, [center, instance, params.onAxisClick, processedSeries, radiusAxisWithScale, rotationAxisWithScale, svgRef, usedRadiusAxisId, usedRotationAxisId]);
|
|
166
208
|
return {
|
|
167
209
|
instance: {
|
|
168
210
|
svg2polar,
|
|
@@ -176,7 +218,8 @@ useChartPolarAxis.params = {
|
|
|
176
218
|
rotationAxis: true,
|
|
177
219
|
radiusAxis: true,
|
|
178
220
|
dataset: true,
|
|
179
|
-
disableAxisListener: true
|
|
221
|
+
disableAxisListener: true,
|
|
222
|
+
onAxisClick: true
|
|
180
223
|
};
|
|
181
224
|
useChartPolarAxis.getInitialState = params => ({
|
|
182
225
|
polarAxis: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChartPluginSignature } from "../../models/index.js";
|
|
2
2
|
import { ChartSeriesType, DatasetType } from "../../../../models/seriesType/config.js";
|
|
3
|
-
import { ScaleName, AxisConfig, ChartsRotationAxisProps, ChartsRadiusAxisProps, RadiusAxis, RotationAxis } from "../../../../models/axis.js";
|
|
3
|
+
import { ScaleName, AxisConfig, ChartsRotationAxisProps, ChartsRadiusAxisProps, RadiusAxis, RotationAxis, ChartsAxisData } from "../../../../models/axis.js";
|
|
4
4
|
import { UseChartSeriesSignature } from "../../corePlugins/useChartSeries/index.js";
|
|
5
5
|
import { UseChartInteractionSignature } from "../useChartInteraction/index.js";
|
|
6
6
|
export interface UseChartPolarAxisInstance {
|
|
@@ -49,6 +49,13 @@ export interface UseChartPolarAxisParameters {
|
|
|
49
49
|
* @default false
|
|
50
50
|
*/
|
|
51
51
|
disableAxisListener?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The function called for onClick events.
|
|
54
|
+
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
55
|
+
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
56
|
+
* @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
|
|
57
|
+
*/
|
|
58
|
+
onAxisClick?: (event: MouseEvent, data: null | ChartsAxisData) => void;
|
|
52
59
|
}
|
|
53
60
|
export type UseChartPolarAxisDefaultizedParameters = UseChartPolarAxisParameters & {};
|
|
54
61
|
export interface UseChartPolarAxisState {
|