Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobelchior committed Feb 7, 2025
1 parent 95a0bcd commit ee4ca2e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 45 deletions.
31 changes: 9 additions & 22 deletions docs/data/charts/scatter/CustomScatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { useScatterSeries, useXScale, useYScale } from '@mui/x-charts/hooks';

const data1 = [
{ x: 100, y: 200, id: 1 },
{ x: 95, y: 200, id: 1 },
{ x: 120, y: 100, id: 2 },
{ x: 170, y: 300, id: 3 },
{ x: 140, y: 250, id: 4 },
Expand All @@ -19,17 +19,20 @@ const data2 = [
{ x: 420, y: 280, id: 5 },
];

const series = [
{ id: 's1', data: data1, label: 'Open' },
{ id: 's2', data: data2, label: 'Closed' },
];

function LinkPoints({ seriesId, close }) {
const scatter = useScatterSeries();
const xScale = useXScale();
const yScale = useYScale();

if (!scatter) {
if (!scatter || !scatter.series[seriesId]) {
return null;
}

const color = scatter.series[seriesId]?.color;
const data = scatter.series[seriesId]?.data;
const { color, data } = scatter.series[seriesId];

if (!data) {
return null;
Expand All @@ -49,23 +52,7 @@ function LinkPoints({ seriesId, close }) {

export default function CustomScatter() {
return (
<ScatterChart
series={[
{
id: 's1',
data: data1,
label: 'Open',
},
{
data: data2,
id: 's2',
label: 'Closed',
},
]}
xAxis={[{ min: 0 }]}
width={500}
height={300}
>
<ScatterChart series={series} width={500} height={300}>
<LinkPoints seriesId="s1" />
<LinkPoints seriesId="s2" close />
</ScatterChart>
Expand Down
30 changes: 8 additions & 22 deletions docs/data/charts/scatter/CustomScatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { useScatterSeries, useXScale, useYScale } from '@mui/x-charts/hooks';

const data1 = [
{ x: 100, y: 200, id: 1 },
{ x: 95, y: 200, id: 1 },
{ x: 120, y: 100, id: 2 },
{ x: 170, y: 300, id: 3 },
{ x: 140, y: 250, id: 4 },
Expand All @@ -17,18 +17,20 @@ const data2 = [
{ x: 340, y: 350, id: 4 },
{ x: 420, y: 280, id: 5 },
];
const series = [
{ id: 's1', data: data1, label: 'Open' },
{ id: 's2', data: data2, label: 'Closed' },
];

function LinkPoints({ seriesId, close }: { seriesId: string; close?: boolean }) {
const scatter = useScatterSeries();
const xScale = useXScale();
const yScale = useYScale();

if (!scatter) {
if (!scatter || !scatter.series[seriesId]) {
return null;
}

const color = scatter.series[seriesId]?.color;
const data = scatter.series[seriesId]?.data;
const { color, data } = scatter.series[seriesId];

if (!data) {
return null;
Expand All @@ -48,23 +50,7 @@ function LinkPoints({ seriesId, close }: { seriesId: string; close?: boolean })

export default function CustomScatter() {
return (
<ScatterChart
series={[
{
id: 's1',
data: data1,
label: 'Open',
},
{
data: data2,
id: 's2',
label: 'Closed',
},
]}
xAxis={[{ min: 0 }]}
width={500}
height={300}
>
<ScatterChart series={series} width={500} height={300}>
<LinkPoints seriesId="s1" />
<LinkPoints seriesId="s2" close />
</ScatterChart>
Expand Down
4 changes: 4 additions & 0 deletions docs/data/charts/scatter/CustomScatter.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ScatterChart series={series} width={500} height={300}>
<LinkPoints seriesId="s1" />
<LinkPoints seriesId="s2" close />
</ScatterChart>
3 changes: 2 additions & 1 deletion docs/data/charts/scatter/scatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ See [Axis—Grid](/x/react-charts/axis/#grid) documentation for more information

You can customize the plotting of the data in a scatter chart by providing custom components as `children` of the `ScatterChart` component.

A scatter chart's series can be accessed through the `useScatterSeries` hook. This hook returns the order of the series and information about the series themselves, including their data points, color, etc.
A scatter chart's series can be accessed through the `useScatterSeries` hook.
This hook returns the order of the series and information about the series themselves, including their data points, color, etc.

See [Custom components](/x/react-charts/components/) to learn how to further customize your charts.

Expand Down

0 comments on commit ee4ca2e

Please sign in to comment.