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 all 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
1 change: 1 addition & 0 deletions apps/public-docsite-resources/config/api-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module.exports = {
'MultiStackedBarChart',
Copy link
Collaborator

@fabricteam fabricteam Nov 27, 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 fluentuiv9 Visual Regression Report

Avatar Converged 2 screenshots
Image Name Diff(in Pixels) Image Type
Avatar Converged.Badge Mask RTL.chromium.png 37 Changed
Avatar Converged.badgeMask.chromium.png 21 Changed

'TreeChart',
'VerticalStackedBarChart',
'DeclarativeChart',
],
},
};
6 changes: 6 additions & 0 deletions apps/public-docsite-resources/src/AppDefinition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,12 @@ export const AppDefinition: IAppDefinition = {
name: 'TreeChart',
url: '#/examples/TreeChart',
},
{
component: require<any>('./components/pages/Charting/DeclarativeChartPage').DeclarativeChartPage,
key: 'DeclarativeChart',
name: 'DeclarativeChart',
url: '#/examples/DeclarativeChart',
},
],
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { DemoPage } from '../../DemoPage';

import { DeclarativeChartPageProps } from '@fluentui/react-examples/lib/react-charting/DeclarativeChart/DeclarativeChart.doc';

export const DeclarativeChartPage = (props: { isHeaderVisible: boolean }) => (
<DemoPage
jsonDocs={require('../../../../dist/api/react-charting/DeclarativeChart.page.json')}
{...{ ...DeclarativeChartPageProps, ...props }}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const categories: { [name: string]: ICategory } = {
SankeyChart: {},
SparklineChart: {},
TreeChart: {},
DeclarativeChart: {},
},
Utilities: {
Announced: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TFabricPlatformPageProps } from '../../../interfaces/Platforms';
import { DeclarativeChartPageProps as ExternalProps } from '@fluentui/react-examples/lib/react-charting/DeclarativeChart/DeclarativeChart.doc';

export const DeclarativeChartPageProps: TFabricPlatformPageProps = {
web: {
...(ExternalProps as any),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from 'react';
import { ControlsAreaPage, IControlsPageProps } from '../ControlsAreaPage';
import { DeclarativeChartPageProps } from './DeclarativeChartPage.doc';

export const DeclarativeChartPage: React.FunctionComponent<IControlsPageProps> = props => {
const { platform } = props;
return <ControlsAreaPage {...props} {...DeclarativeChartPageProps[platform!]} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Create declarative chart component",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
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
export const DeclarativeChart: React_2.FunctionComponent<DeclarativeChartProps>;

// @public
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,79 @@
/* 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,
isDateArray,
isNumberArray,
transformPlotlyJsonToHeatmapProps,
transformPlotlyJsonToSankeyProps,
transformPlotlyJsonToGaugeProps,
} from './PlotlySchemaAdapter';
import { LineChart } from '../LineChart/index';
import { HorizontalBarChartWithAxis } from '../HorizontalBarChartWithAxis/index';
import { AreaChart } from '../AreaChart/index';
import { HeatMapChart } from '../HeatMapChart/index';
import { SankeyChart } from '../SankeyChart/SankeyChart';
import { GaugeChart } from '../GaugeChart/index';

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

/**
* DeclarativeChart component.
* {@docCategory DeclarativeChart}
*/
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)} />;
case 'indicator':
if (props.chartSchema?.data?.[0]?.mode?.includes('gauge')) {
return <GaugeChart {...transformPlotlyJsonToGaugeProps(props.chartSchema)} />;
}
return <div>Unsupported Schema</div>;
default:
return <div>Unsupported Schema</div>;
}
});
DeclarativeChart.displayName = 'DeclarativeChart';
Loading
Loading