Skip to content

feat(react-charting): Adding Scatter Chart component #34374

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

srmukher
Copy link
Contributor

@srmukher srmukher commented May 6, 2025

Adding Scatter Chart component in V8.
Also enabling year as categorical value for scatter chart.
Work items:

  1. https://uifabric.visualstudio.com/iss/_workitems/edit/12692/
  2. https://uifabric.visualstudio.com/iss/_workitems/edit/12826/

Basic:
image

Date Axis:
image

String Axis:
image

@srmukher srmukher requested a review from a team as a code owner May 6, 2025 04:33
Copy link

github-actions bot commented May 6, 2025

📊 Bundle size report

✅ No changes found

Copy link

github-actions bot commented May 6, 2025

Pull request demo site: URL

@@ -157,11 +157,7 @@ const validateBarData = (data: Partial<PlotData>) => {
};

const validateScatterData = (data: Partial<PlotData>) => {
if (['markers', 'text+markers', 'markers+text'].includes(data.mode ?? '') && !isNumberArray(data.x)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'markers', 'text+markers', 'markers+text'].includes(data.mode ?? '')

this check has to be present

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed 'markers' and kept the rest

/**
* {@docCategory IChartData}
*/
export interface IBaseDataPoint {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IBaseDataPoint

move this code above LineChartDataPoint

Copy link
Contributor Author

@srmukher srmukher May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order of declaring interfaces in TypeScript does not matter as far as I know

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order does not matter for functionality but helps to maintain readability as this file has become huge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -167,10 +169,11 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =

const renderLineArea = (plotlyData: Data[], isAreaChart: boolean): JSX.Element => {
const isScatterMarkers = ['markers', 'text+markers', 'markers+text'].includes((plotlyData[0] as PlotData)?.mode);
const chartProps: ILineChartProps | IAreaChartProps = {
const chartType = isAreaChart ? 'Area' : isScatterMarkers ? 'Scatter' : 'Line';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line

keep the name smallcase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for making it small case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general fluent follows snakeCase for string literals. I meant first letter smallcase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -579,9 +587,8 @@ export const transformPlotlyJsonToScatterChartProps = (
height: input.layout?.height ?? 350,
hideTickOverlap: true,
enableReflow: false,
hideLegend,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hideLegend

revert this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

React.useImperativeHandle(
props.componentRef,
() => ({
chartContainer: cartesianChartRef.current?.chartContainer ?? null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is export as image working correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

setIsSelectedLegend(false);
}

function _createLegends(data: ScatterChartDataWithIndex[]): JSX.Element {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is editing of legends from textbox and updating to textbox working as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes all are working as expected

@@ -180,6 +183,9 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
if (isAreaChart) {
return <ResponsiveAreaChart {...chartProps} />;
}
if (isScatterMarkers) {
return <ResponsiveScatterChart {...(chartProps as IScatterChartProps)} />;
}
return <ResponsiveLineChart {...chartProps} lineMode={isScatterMarkers ? 'scatter' : 'default'} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lineMode={isScatterMarkers ? 'scatter' : 'default'}

change this to 'default' only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AtishayMsft
Copy link
Contributor

if ((isXDate || isXNumber) && !isXYear) {

For XYear for scatter, don't fallback to VSBC as year is rendered as categorical/string.
Scatter has support for string now and VSBC does not support scatter.


Refers to: packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx:205 in a0d82be. [](commit_id = a0d82be, deletion_comment = False)

@AtishayMsft
Copy link
Contributor

  return renderLineArea(plotlyInputWithValidData.data, isAreaChart);

Have you verified string x axis scatter chart in declarative chart


Refers to: packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx:206 in a0d82be. [](commit_id = a0d82be, deletion_comment = False)

@srmukher
Copy link
Contributor Author

  return renderLineArea(plotlyInputWithValidData.data, isAreaChart);

Have you verified string x axis scatter chart in declarative chart

Refers to: packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx:206 in a0d82be. [](commit_id = a0d82be, deletion_comment = False)

I have already added an example for String x-axis in react-eamples, also there is a screenshot for it in description

@AtishayMsft
Copy link
Contributor

  return renderLineArea(plotlyInputWithValidData.data, isAreaChart);

Have you verified string x axis scatter chart in declarative chart
Refers to: packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx:206 in a0d82be. [](commit_id = a0d82be, deletion_comment = False)

I have already added an example for String x-axis in react-eamples, also there is a screenshot for it in description

Ok. Then is test schema 433 working now.

@srmukher
Copy link
Contributor Author

  return renderLineArea(plotlyInputWithValidData.data, isAreaChart);

Have you verified string x axis scatter chart in declarative chart
Refers to: packages/charts/react-charting/src/components/DeclarativeChart/DeclarativeChart.tsx:206 in a0d82be. [](commit_id = a0d82be, deletion_comment = False)

I have already added an example for String x-axis in react-eamples, also there is a screenshot for it in description

Ok. Then is test schema 433 working now.

yes displaying as Scatter chart

@srmukher
Copy link
Contributor Author

@srmukher
Copy link
Contributor Author

srmukher commented Jun 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants