@mui/x-charts
Version:
The community edition of the Charts components (MUI X).
382 lines • 15.1 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import { ScatterPlot } from './ScatterPlot';
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
import { ChartsAxis } from '../ChartsAxis';
import { ChartsTooltip } from '../ChartsTooltip';
import { ChartsLegend } from '../ChartsLegend';
import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
import { ChartsGrid } from '../ChartsGrid';
import { ZAxisContextProvider } from '../context/ZAxisContextProvider';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Demos:
*
* - [Scatter](https://mui.com/x/react-charts/scatter/)
* - [Scatter demonstration](https://mui.com/x/react-charts/scatter-demo/)
*
* API:
*
* - [ScatterChart API](https://mui.com/x/api/charts/scatter-chart/)
*/
const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
const {
xAxis,
yAxis,
zAxis,
series,
tooltip,
axisHighlight,
voronoiMaxRadius,
disableVoronoi,
legend,
width,
height,
margin,
colors,
sx,
grid,
topAxis,
leftAxis,
rightAxis,
bottomAxis,
onItemClick,
children,
slots,
slotProps,
loading
} = props;
return /*#__PURE__*/_jsx(ResponsiveChartContainer, {
ref: ref,
series: series.map(s => _extends({
type: 'scatter'
}, s)),
width: width,
height: height,
margin: margin,
colors: colors,
xAxis: xAxis,
yAxis: yAxis,
sx: sx,
children: /*#__PURE__*/_jsxs(ZAxisContextProvider, {
zAxis: zAxis,
children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
voronoiMaxRadius: voronoiMaxRadius,
onItemClick: onItemClick
}), /*#__PURE__*/_jsx(ChartsAxis, {
topAxis: topAxis,
leftAxis: leftAxis,
rightAxis: rightAxis,
bottomAxis: bottomAxis,
slots: slots,
slotProps: slotProps
}), grid && /*#__PURE__*/_jsx(ChartsGrid, {
vertical: grid.vertical,
horizontal: grid.horizontal
}), /*#__PURE__*/_jsx(ScatterPlot, {
slots: slots,
slotProps: slotProps,
onItemClick: disableVoronoi ? onItemClick : undefined
}), /*#__PURE__*/_jsx(ChartsOverlay, {
loading: loading,
slots: slots,
slotProps: slotProps
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
slots: slots,
slotProps: slotProps
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
x: "none",
y: "none"
}, axisHighlight)), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({
trigger: "item"
}, tooltip)), children]
})
});
});
process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* The configuration of axes highlight.
* @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
* @default { x: 'none', y: 'none' }
*/
axisHighlight: PropTypes.shape({
x: PropTypes.oneOf(['band', 'line', 'none']),
y: PropTypes.oneOf(['band', 'line', 'none'])
}),
/**
* Indicate which axis to display the bottom of the charts.
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
* @default xAxisIds[0] The id of the first provided axis
*/
bottomAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
children: PropTypes.node,
className: PropTypes.string,
/**
* Color palette used to colorize multiple series.
* @default blueberryTwilightPalette
*/
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
/**
* An array of objects that can be used to populate series and axes data using their `dataKey` property.
*/
dataset: PropTypes.arrayOf(PropTypes.object),
desc: PropTypes.string,
/**
* If `true`, the charts will not listen to the mouse move event.
* It might break interactive features, but will improve performance.
* @default false
*/
disableAxisListener: PropTypes.bool,
/**
* If true, the interaction will not use the Voronoi cell and fall back to hover events.
* @default false
*/
disableVoronoi: PropTypes.bool,
/**
* Option to display a cartesian grid in the background.
*/
grid: PropTypes.shape({
horizontal: PropTypes.bool,
vertical: PropTypes.bool
}),
/**
* The height of the chart in px. If not defined, it takes the height of the parent element.
*/
height: PropTypes.number,
/**
* Indicate which axis to display the left of the charts.
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
* @default yAxisIds[0] The id of the first provided axis
*/
leftAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
/**
* @deprecated Consider using `slotProps.legend` instead.
*/
legend: PropTypes.shape({
classes: PropTypes.object,
direction: PropTypes.oneOf(['column', 'row']),
hidden: PropTypes.bool,
position: PropTypes.shape({
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
}),
slotProps: PropTypes.object,
slots: PropTypes.object
}),
/**
* If `true`, a loading overlay is displayed.
*/
loading: PropTypes.bool,
/**
* The margin between the SVG and the drawing area.
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
* Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
* @default object Depends on the charts type.
*/
margin: PropTypes.shape({
bottom: PropTypes.number,
left: PropTypes.number,
right: PropTypes.number,
top: PropTypes.number
}),
/**
* Callback fired when clicking on a scatter item.
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element if using Voronoi cells. Or the Mouse event from the scatter element, when `disableVoronoi=true`.
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
*/
onItemClick: PropTypes.func,
/**
* Indicate which axis to display the right of the charts.
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
* @default null
*/
rightAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
/**
* The series to display in the scatter chart.
* An array of [[ScatterSeriesType]] objects.
*/
series: PropTypes.arrayOf(PropTypes.object).isRequired,
/**
* The props used for each component slot.
* @default {}
*/
slotProps: PropTypes.object,
/**
* Overridable component slots.
* @default {}
*/
slots: PropTypes.object,
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
title: PropTypes.string,
/**
* The configuration of the tooltip.
* @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
* @default { trigger: 'item' }
*/
tooltip: PropTypes.shape({
axisContent: PropTypes.elementType,
classes: PropTypes.object,
itemContent: PropTypes.elementType,
slotProps: PropTypes.object,
slots: PropTypes.object,
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
}),
/**
* Indicate which axis to display the top of the charts.
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
* @default null
*/
topAxis: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
viewBox: PropTypes.shape({
height: PropTypes.number,
width: PropTypes.number,
x: PropTypes.number,
y: PropTypes.number
}),
/**
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
* If `undefined`, the radius is assumed to be infinite.
*/
voronoiMaxRadius: PropTypes.number,
/**
* The width of the chart in px. If not defined, it takes the width of the parent element.
*/
width: PropTypes.number,
/**
* The configuration of the x-axes.
* If not provided, a default axis config is used.
* An array of [[AxisConfig]] objects.
*/
xAxis: PropTypes.arrayOf(PropTypes.shape({
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
classes: PropTypes.object,
colorMap: PropTypes.oneOfType([PropTypes.shape({
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
type: PropTypes.oneOf(['continuous']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
type: PropTypes.oneOf(['piecewise']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
type: PropTypes.oneOf(['ordinal']).isRequired,
unknownColor: PropTypes.string,
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
})]),
data: PropTypes.array,
dataKey: PropTypes.string,
disableLine: PropTypes.bool,
disableTicks: PropTypes.bool,
fill: PropTypes.string,
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
reverse: PropTypes.bool,
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
slotProps: PropTypes.object,
slots: PropTypes.object,
stroke: PropTypes.string,
tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
tickLabelStyle: PropTypes.object,
tickMaxStep: PropTypes.number,
tickMinStep: PropTypes.number,
tickNumber: PropTypes.number,
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
tickSize: PropTypes.number,
valueFormatter: PropTypes.func
})),
/**
* The configuration of the y-axes.
* If not provided, a default axis config is used.
* An array of [[AxisConfig]] objects.
*/
yAxis: PropTypes.arrayOf(PropTypes.shape({
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
classes: PropTypes.object,
colorMap: PropTypes.oneOfType([PropTypes.shape({
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
type: PropTypes.oneOf(['continuous']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
type: PropTypes.oneOf(['piecewise']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
type: PropTypes.oneOf(['ordinal']).isRequired,
unknownColor: PropTypes.string,
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
})]),
data: PropTypes.array,
dataKey: PropTypes.string,
disableLine: PropTypes.bool,
disableTicks: PropTypes.bool,
fill: PropTypes.string,
hideTooltip: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
label: PropTypes.string,
labelFontSize: PropTypes.number,
labelStyle: PropTypes.object,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
reverse: PropTypes.bool,
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
slotProps: PropTypes.object,
slots: PropTypes.object,
stroke: PropTypes.string,
tickFontSize: PropTypes.number,
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
tickLabelStyle: PropTypes.object,
tickMaxStep: PropTypes.number,
tickMinStep: PropTypes.number,
tickNumber: PropTypes.number,
tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
tickSize: PropTypes.number,
valueFormatter: PropTypes.func
})),
/**
* The configuration of the z-axes.
*/
zAxis: PropTypes.arrayOf(PropTypes.shape({
colorMap: PropTypes.oneOfType([PropTypes.shape({
color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
type: PropTypes.oneOf(['continuous']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
type: PropTypes.oneOf(['piecewise']).isRequired
}), PropTypes.shape({
colors: PropTypes.arrayOf(PropTypes.string).isRequired,
type: PropTypes.oneOf(['ordinal']).isRequired,
unknownColor: PropTypes.string,
values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
})]),
data: PropTypes.array,
dataKey: PropTypes.string,
id: PropTypes.string
}))
} : void 0;
export { ScatterChart };