Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(declarative-chart): Create Scatter plot #33843

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
resolve comments
  • Loading branch information
Anush2303 committed Feb 19, 2025
commit 24f7e8b82d7d27339e31014ab5eedbbe9e33ccf2
Original file line number Diff line number Diff line change
@@ -228,7 +228,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
if (plotlyInput.data[0].mode === 'markers' && !isNumberArray(plotlyInput.data[0].y!)) {
throw new Error(
`Unsupported chart - type :${plotlyInput.data[0]?.type}, mode: ${plotlyInput.data[0]?.mode}
, xAxisType: String`,
, xAxisType: String or Date`,
);
}
const isAreaChart = plotlyInput.data.some(
@@ -239,7 +239,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
if (isAreaChart) {
return <AreaChart {...chartProps} />;
}
return <LineChart {...chartProps} scatterMarkersMode={isScatterMarkers} />;
return <LineChart {...chartProps} mode={isScatterMarkers ? 'scatter' : 'default'} />;
};
return checkAndRenderChart(renderChartJsx, isAreaChart);
case 'heatmap':
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ export const transformPlotlyJsonToScatterChartProps = (
data: xValues.map((x, i: number) => ({
x: isString ? (isXDate ? new Date(x as string) : isXNumber ? parseFloat(x as string) : x) : x,
y: series.y[i],
markerSize: Array.isArray(series.marker?.size) ? series.marker.size[i] : undefined,
...(Array.isArray(series.marker?.size) ? { markerSize: series.marker.size[i] } : {}),
})),
color: lineColor,
} as ILineChartPoints;
Original file line number Diff line number Diff line change
@@ -820,7 +820,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt

const currentPointHidden = this._points[i].hideNonActiveDots && activePoint !== circleId;
pointsForLine.push(
this.props.scatterMarkersMode ? (
this.props.mode === 'scatter' ? (
<circle
id={circleId}
key={circleId}
@@ -913,7 +913,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
} = this._points[i].data[j];
pointsForLine.push(
<React.Fragment key={`${lastCircleId}_container`}>
{this.props.scatterMarkersMode ? (
{this.props.mode === 'scatter' ? (
<circle
id={lastCircleId}
key={lastCircleId}
@@ -1039,7 +1039,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
);
}

if (!this.props.scatterMarkersMode) {
if (this.props.mode !== 'scatter') {
if (isLegendSelected) {
// don't draw line if it is in a gap
if (!isInGap) {
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ export interface ILineChartProps extends ICartesianChartProps {
* @default false
* The prop used to handle scatter plot
*/
scatterMarkersMode?: boolean;
mode?: 'default' | 'scatter';
}

/**
16 changes: 8 additions & 8 deletions packages/charts/react-charting/src/utilities/utilities.ts
Original file line number Diff line number Diff line change
@@ -446,15 +446,15 @@ export function createNumericYAxis(
: yMinMaxValues.startValue < yMinValue
? 0
: yMinValue!;
const maxMarkerSizeInPixelsForYAxis = maxMarkerSize
const maxMarkerSizeForYAxis = maxMarkerSize
? Math.abs(
(maxMarkerSize * (finalYmin - finalYmax)) /
(margins.top! - containerHeight + margins.bottom! + 2 * maxMarkerSize),
)
: 0;
const domainValues = prepareDatapoints(
finalYmax + maxMarkerSizeInPixelsForYAxis,
finalYmin - maxMarkerSizeInPixelsForYAxis,
finalYmax + maxMarkerSizeForYAxis,
finalYmin - maxMarkerSizeForYAxis,
yAxisTickCount,
isIntegralDataset,
roundedTicks,
@@ -924,22 +924,22 @@ export function domainRangeOfNumericForAreaChart(
return item.markerSize as number;
});
})!;
const maxMarkerSizeInPixelsForXAxis = maxMarkerSize
const maxMarkerSizeForXAxis = maxMarkerSize
? Math.abs((maxMarkerSize * (xMax - xMin)) / (width - margins.right! - margins.left! - 2 * maxMarkerSize))
: 0;
const rStartValue = margins.left!;
const rEndValue = width - margins.right!;

return isRTL
? {
dStartValue: xMax + maxMarkerSizeInPixelsForXAxis,
dEndValue: xMin - maxMarkerSizeInPixelsForXAxis,
dStartValue: xMax + maxMarkerSizeForXAxis,
dEndValue: xMin - maxMarkerSizeForXAxis,
rStartValue,
rEndValue,
}
: {
dStartValue: xMin - maxMarkerSizeInPixelsForXAxis,
dEndValue: xMax + maxMarkerSizeInPixelsForXAxis,
dStartValue: xMin - maxMarkerSizeForXAxis,
dEndValue: xMax + maxMarkerSizeForXAxis,
rStartValue,
rEndValue,
};
Loading
Oops, something went wrong.