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 28, 2025
commit 8959fb1c182a2ed5e36f631ca5fba47a1fd6fb21
Original file line number Diff line number Diff line change
@@ -225,7 +225,7 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
);
}
case 'scatter':
if (plotlyInput.data[0].mode === 'markers' && !isNumberArray(plotlyInput.data[0].y!)) {
if (plotlyInput.data[0]?.mode?.includes('markers') && !isNumberArray(plotlyInput.data[0].y!)) {
throw new Error(
`Unsupported chart - type :${plotlyInput.data[0]?.type}, mode: ${plotlyInput.data[0]?.mode}
, xAxisType: String or Date`,
Original file line number Diff line number Diff line change
@@ -69,10 +69,10 @@ const DEFAULT_LINE_STROKE_SIZE = 4;
const PATH_MULTIPLY_SIZE = 2.5;

// minimum of all x of line chart points
let xMin = 0;
let xMin = Number.NEGATIVE_INFINITY;

//minimum of all y of line chart points
let yMin = 0;
let yMin = Number.NEGATIVE_INFINITY;

/**
*
@@ -483,7 +483,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
this._xAxisScale = xScale;
this._yAxisScale = yScale;
this._renderedColorFillBars = this.props.colorFillBars ? this._createColorFillBars(containerHeight) : [];
this.lines = this._createLines(xElement!, containerHeight!);
this.lines = this._createLines(xElement!, containerHeight!, containerWidth!);
};

private _handleSingleLegendSelectionAction = (lineChartItem: LineChartDataWithIndex | IColorFillBarsProps) => {
@@ -646,19 +646,22 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
}
}
};
private _getExtraPixelsToRender(containerHeight: number): number {
const extraXPixels = this._xAxisScale(xMin) - this.margins.left!;
private _getRangeForScatterMarkerSize(containerHeight: number, containerWidth: number): number {
const extraXPixels = this._isRTL
? containerWidth - this.margins.right! - this._xAxisScale(xMin)
: this._xAxisScale(xMin) - this.margins.left!;
const extraYPixels = containerHeight - this.margins.bottom! - this._yAxisScale(yMin);
return Math.min(extraXPixels, extraYPixels);
}
private _createLines(xElement: SVGElement, containerHeight: number): JSX.Element[] {
private _createLines(xElement: SVGElement, containerHeight: number, containerWidth: number): JSX.Element[] {
const lines: JSX.Element[] = [];
if (this.state.isSelectedLegend) {
this._points = this.state.selectedLegendPoints;
} else {
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
}
const extraMaxPixels = this.props.lineMode === 'scatter' ? this._getExtraPixelsToRender(containerHeight) : 0;
const extraMaxPixels =
this.props.lineMode === 'scatter' ? this._getRangeForScatterMarkerSize(containerHeight, containerWidth) : 0;
const maxMarkerSize = d3Max(this._points, (point: ILineChartPoints) => {
return d3Max(point.data, (item: ILineChartDataPoint) => {
return item.markerSize as number;