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

Draft changes for a declarative chart using plotly json schema #33348

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/charts/react-charting/etc/react-charting.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export const DataVizPalette: {
highSuccess: string;
Copy link
Collaborator

@fabricteam fabricteam Nov 26, 2024

Choose a reason for hiding this comment

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

🕵🏾‍♀️ visual regressions to review in the fluentuiv8 Visual Regression Report

Callout 6 screenshots
Image Name Diff(in Pixels) Image Type
Callout.Root.chromium.png 2309 Changed
Callout.Bottom Left Edge RTL.chromium.png 2178 Changed
Callout.Bottom Right Edge RTL.chromium.png 1593 Changed
Callout.Bottom left edge.chromium.png 2309 Changed
Callout.Right center.chromium.png 2396 Changed
Callout.Left top edge.chromium.png 1949 Changed
react-charting-VerticalBarChart 1 screenshots
Image Name Diff(in Pixels) Image Type
react-charting-VerticalBarChart.Basic - Secondary Y Axis.chromium.png 4 Changed

};

// @public (undocumented)
export const DeclarativeChart: React_2.FunctionComponent<DeclarativeChartProps>;

// @public (undocumented)
export interface DeclarativeChartProps extends React_2.RefAttributes<HTMLDivElement> {
chartSchema: any;
}

// @public
export const DonutChart: React_2.FunctionComponent<IDonutChartProps>;

Expand Down
1 change: 1 addition & 0 deletions packages/charts/react-charting/src/DeclarativeChart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/DeclarativeChart/DeclarativeChart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as React from 'react';
import { DonutChart } from '../DonutChart/index';
import { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';
import {
transformPlotlyJsonToDonutProps,
transformPlotlyJsonToColumnProps,
transformPlotlyJsonToScatterChartProps,
transformPlotlyJsonToHorizontalBarWithAxisProps,
transformPlotlyJsonToHeatmapProps,
transformPlotlyJsonToSankeyProps,
} from './PlotlySchemaAdapter';
import { LineChart } from '../LineChart/index';
import { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';
import { AreaChart } from '../AreaChart/index';
import { HeatMapChart } from '../HeatMapChart/index';

const isDate = (value: any): boolean => !isNaN(Date.parse(value));
const isNumber = (value: any): boolean => !isNaN(parseFloat(value)) && isFinite(value);
export const isDateArray = (array: any[]): boolean => Array.isArray(array) && array.every(isDate);
export const isNumberArray = (array: any[]): boolean => Array.isArray(array) && array.every(isNumber);
import { SankeyChart } from '../SankeyChart/SankeyChart';

export interface DeclarativeChartProps extends React.RefAttributes<HTMLDivElement> {
/**
* The schema representing the chart
*/
chartSchema: any;
}

export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> = React.forwardRef<
HTMLDivElement,
DeclarativeChartProps
>((props, forwardedRef) => {
const xValues = props.chartSchema.data[0].x;
const isXDate = isDateArray(xValues);
const isXNumber = isNumberArray(xValues);

switch (props.chartSchema.data[0].type) {
case 'pie':
return <DonutChart {...transformPlotlyJsonToDonutProps(props.chartSchema)} />;
case 'bar':
const orientation = props.chartSchema.data[0].orientation;
if (orientation === 'h') {
return <HorizontalBarChartWithAxis {...transformPlotlyJsonToHorizontalBarWithAxisProps(props.chartSchema)} />;
} else {
return <VerticalStackedBarChart {...transformPlotlyJsonToColumnProps(props.chartSchema)} />;
}
case 'scatter':
const isAreaChart = props.chartSchema.data.some((series: any) => series.fill === 'tonexty');
if (isXDate || isXNumber) {
if (isAreaChart) {
return <AreaChart {...transformPlotlyJsonToScatterChartProps(props.chartSchema, true)} />;
}
return <LineChart {...transformPlotlyJsonToScatterChartProps(props.chartSchema, false)} />;
}
return <VerticalStackedBarChart {...transformPlotlyJsonToColumnProps(props.chartSchema)} />;
case 'heatmap':
return <HeatMapChart {...transformPlotlyJsonToHeatmapProps(props.chartSchema)} />;
case 'sankey':
return <SankeyChart {...transformPlotlyJsonToSankeyProps(props.chartSchema)} />;
default:
return <div>Unsupported Schema</div>;
}
});
DeclarativeChart.displayName = 'DeclarativeChart';
Loading
Loading