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(charts): Update V9 Charts to use DataVizGradientPalette #33323

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
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
e5e79fc
add gradient declarations
shawn-grant Nov 20, 2024
b362372
replace color with gradient in ChartDataPoint and add gradient utilit…
shawn-grant Nov 20, 2024
758f388
refactor: update test-data.ts dataPoints to use gradient property
shawn-grant Nov 20, 2024
09b1252
feat: implement gradient support in DonutChart components
shawn-grant Nov 21, 2024
eef1cf2
test: update DonutChart tests to use gradient instead of color
shawn-grant Nov 21, 2024
0c562b5
feat: add gradient support to HorizontalBarChart and update rendering…
shawn-grant Nov 21, 2024
2eb7d67
refactor: replace color with gradient in HorizontalBarChart test cases
shawn-grant Nov 21, 2024
942d9a3
build: update charts api readme
shawn-grant Nov 21, 2024
d3cc0db
add update-snapshots script to package.json
shawn-grant Nov 21, 2024
5d90039
update tests and test snapshot
shawn-grant Nov 21, 2024
f64134a
Merge branch 'master' into chart-gradients
shawn-grant Nov 21, 2024
d9aa34d
refactor: update all DonutChart stories to use gradient pallete
shawn-grant Nov 21, 2024
40f628c
refactor: update HorizontalBarChart stories to use gradient palette
shawn-grant Nov 21, 2024
355faa6
Merge branch 'master' into chart-gradients
shawn-grant Nov 21, 2024
18988c5
fix HBC test snapshots
shawn-grant Nov 21, 2024
61e5ad7
update change files
shawn-grant Nov 21, 2024
fc6d1c4
update change files
shawn-grant Nov 22, 2024
e10f630
Merge branch 'chart-gradients' of https://github.com/shawn-grant/flue…
shawn-grant Nov 22, 2024
8a3d7bf
update change type to patch
shawn-grant Nov 22, 2024
751e2e0
Merge branch 'master' into chart-gradients
shawn-grant Nov 22, 2024
c58d7af
build: fix formatting issues
shawn-grant Nov 22, 2024
0cc5413
build: fix ci fail (vr-tests-react-components)
shawn-grant Nov 22, 2024
f75812e
add change file
shawn-grant Nov 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default {

Copy link
Collaborator

@fabricteam fabricteam Nov 22, 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 19 Changed
Avatar Converged.badgeMask.chromium.png 13 Changed
Charts-DonutChart 6 screenshots
Image Name Diff(in Pixels) Image Type
Charts-DonutChart.Basic RTL.chromium.png 189 Changed
Charts-DonutChart.Dynamic RTL.chromium.png 266 Changed
Charts-DonutChart.Basic.chromium.png 189 Changed
Charts-DonutChart.Dynamic Dark Mode.chromium.png 225 Changed
Charts-DonutChart.Basic Dark Mode.chromium.png 175 Changed
Charts-DonutChart.Dynamic.chromium.png 267 Changed
Charts-HorizontalBarChart 9 screenshots
Image Name Diff(in Pixels) Image Type
Charts-HorizontalBarChart.Variant.chromium.png 54 Changed
Charts-HorizontalBarChart.Basic Dark Mode.chromium.png 10637 Changed
Charts-HorizontalBarChart.Basic RTL.chromium.png 3975 Changed
Charts-HorizontalBarChart.Variant Dark Mode.chromium.png 24 Changed
Charts-HorizontalBarChart.Basic.chromium.png 3975 Changed
Charts-HorizontalBarChart.With Benchmark Dark Mode.chromium.png 7215 Changed
Charts-HorizontalBarChart.Variant RTL.chromium.png 54 Changed
Charts-HorizontalBarChart.With Benchmark RTL.chromium.png 2678 Changed
Charts-HorizontalBarChart.With_Benchmark.chromium.png 2678 Changed

export const Basic = () => {
const points: ChartDataPoint[] = [
{ legend: 'first', data: 20000, color: '#DADADA', xAxisCalloutData: '2020/04/30' },
{ legend: 'second', data: 39000, color: '#0078D4', xAxisCalloutData: '2020/04/20' },
{ legend: 'first', data: 20000, gradient: ['#DADADA', '#DADADA'], xAxisCalloutData: '2020/04/30' },
{ legend: 'second', data: 39000, gradient: ['#0078D4', '#0078D4'], xAxisCalloutData: '2020/04/20' },
];

const data: ChartProps = {
Expand Down Expand Up @@ -54,22 +54,22 @@ export const Dynamic = () => {
{
legend: 'first',
data: Math.floor(120),
color: '#00bcf2',
gradient: ['#00bcf2', '#00bcf2'],
},
{
legend: 'second',
data: Math.floor(130),
color: '#b4a0ff',
gradient: ['#b4a0ff', '#b4a0ff'],
},
{
legend: 'third',
data: Math.floor(10),
color: '#fff100',
gradient: ['#fff100', '#fff100'],
},
{
legend: 'fourth',
data: Math.floor(270),
color: '#605e5c',
gradient: ['#605e5c', '#605e5c'],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Basic = () => {
{
legend: 'one',
horizontalBarChartdata: { x: 1543, y: 15000 },
color: '#4cb4b7',
gradient: ['#4cb4b7', '#4cb4b7'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '10%',
},
Expand All @@ -47,7 +47,7 @@ export const Basic = () => {
{
legend: 'two',
horizontalBarChartdata: { x: 800, y: 15000 },
color: '#800080',
gradient: ['#800080', '#800080'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '5%',
},
Expand All @@ -59,7 +59,7 @@ export const Basic = () => {
{
legend: 'three',
horizontalBarChartdata: { x: 8888, y: 15000 },
color: '#ff0000',
gradient: ['#ff0000', '#ff0000'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '59%',
},
Expand All @@ -71,7 +71,7 @@ export const Basic = () => {
{
legend: 'four',
horizontalBarChartdata: { x: 15888, y: 15000 },
color: '#fbc0c3',
gradient: ['#fbc0c3', '#fbc0c3'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '105%',
},
Expand All @@ -83,7 +83,7 @@ export const Basic = () => {
{
legend: 'five',
horizontalBarChartdata: { x: 11444, y: 15000 },
color: '#f7630c',
gradient: ['#f7630c', '#f7630c'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '76%',
},
Expand All @@ -95,7 +95,7 @@ export const Basic = () => {
{
legend: 'six',
horizontalBarChartdata: { x: 14000, y: 15000 },
color: '#107c10',
gradient: ['#107c10', '#107c10'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '93%',
},
Expand All @@ -107,7 +107,7 @@ export const Basic = () => {
{
legend: 'seven',
horizontalBarChartdata: { x: 9855, y: 15000 },
color: '#6e0811',
gradient: ['#6e0811', '#6e0811'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '65%',
},
Expand All @@ -119,7 +119,7 @@ export const Basic = () => {
{
legend: 'eight',
horizontalBarChartdata: { x: 4250, y: 15000 },
color: '#3a96dd',
gradient: ['#3a96dd', '#3a96dd'],
xAxisCalloutData: '2020/04/30',
yAxisCalloutData: '28%',
},
Expand Down Expand Up @@ -149,7 +149,7 @@ export const WithBenchmark = () => {
legend: 'one',
data: 50,
horizontalBarChartdata: { x: 10, y: 100 },
color: '#4cb4b7',
gradient: ['#4cb4b7', '#4cb4b7'],
},
],
},
Expand All @@ -160,7 +160,7 @@ export const WithBenchmark = () => {
legend: 'two',
data: 30,
horizontalBarChartdata: { x: 30, y: 200 },
color: '#800080',
gradient: ['#800080', '#800080'],
},
],
},
Expand All @@ -171,7 +171,7 @@ export const WithBenchmark = () => {
legend: 'three',
data: 5,
horizontalBarChartdata: { x: 15, y: 50 },
color: '#ff0000',
gradient: ['#ff0000', '#ff0000'],
},
],
},
Expand All @@ -198,7 +198,7 @@ export const Variant = () => {
{
legend: 'one',
horizontalBarChartdata: { x: 1543, y: 15000 },
color: '#4cb4b7',
gradient: ['#4cb4b7', '#4cb4b7'],
},
],
},
Expand All @@ -208,7 +208,7 @@ export const Variant = () => {
{
legend: 'two',
horizontalBarChartdata: { x: 800, y: 15000 },
color: '#800080',
gradient: ['#800080', '#800080'],
},
],
},
Expand All @@ -218,7 +218,7 @@ export const Variant = () => {
{
legend: 'three',
horizontalBarChartdata: { x: 8888, y: 15000 },
color: '#ff0000',
gradient: ['#ff0000', '#ff0000'],
},
],
},
Expand All @@ -228,7 +228,7 @@ export const Variant = () => {
{
legend: 'four',
horizontalBarChartdata: { x: 15888, y: 15000 },
color: '#fbc0c3',
gradient: ['#fbc0c3', '#fbc0c3'],
},
],
},
Expand All @@ -238,7 +238,7 @@ export const Variant = () => {
{
legend: 'five',
horizontalBarChartdata: { x: 11444, y: 15000 },
color: '#f7630c',
gradient: ['#f7630c', '#f7630c'],
},
],
},
Expand All @@ -248,7 +248,7 @@ export const Variant = () => {
{
legend: 'six',
horizontalBarChartdata: { x: 14000, y: 15000 },
color: '#107c10',
gradient: ['#107c10', '#107c10'],
},
],
},
Expand All @@ -258,7 +258,7 @@ export const Variant = () => {
{
legend: 'seven',
horizontalBarChartdata: { x: 9855, y: 15000 },
color: '#6e0811',
gradient: ['#6e0811', '#6e0811'],
},
],
},
Expand All @@ -268,7 +268,7 @@ export const Variant = () => {
{
legend: 'eight',
horizontalBarChartdata: { x: 4250, y: 15000 },
color: '#3a96dd',
gradient: ['#3a96dd', '#3a96dd'],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Introduce gradients and rounded corners to v9 charts",
"packageName": "@fluentui/react-charts-preview",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "updated to use gradient property for charts-preview",
"packageName": "@fluentui/react-virtualizer",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export type ChartDataMode = 'default' | 'fraction' | 'percentage';
// @public (undocumented)
export interface ChartDataPoint {
callOutAccessibilityData?: AccessibilityProps;
color?: string;
data?: number;
gradient?: [string, string];
horizontalBarChartdata?: HorizontalDataPoint;
legend?: string;
onClick?: VoidFunction;
Expand Down Expand Up @@ -304,6 +304,36 @@ export interface DataPoint {
y: number;
}

// @public (undocumented)
export const DataVizGradientPalette: {
gradient1: string;
gradient2: string;
gradient3: string;
gradient4: string;
gradient5: string;
gradient6: string;
gradient7: string;
gradient8: string;
gradient9: string;
gradient10: string;
gradient1Ext: string;
gradient2Ext: string;
gradient3Ext: string;
gradient4Ext: string;
gradient5Ext: string;
gradient6Ext: string;
gradient7Ext: string;
gradient8Ext: string;
gradient9Ext: string;
gradient10Ext: string;
success: string;
highSuccess: string;
warning: string;
error: string;
highError: string;
disabled: string;
};

// @public (undocumented)
export const DataVizPalette: {
color1: string;
Expand Down Expand Up @@ -403,9 +433,15 @@ export interface EventsAnnotationProps {
// @public (undocumented)
export const getColorFromToken: (token: string, isDarkTheme?: boolean) => string;

// @public (undocumented)
export const getGradientFromToken: (token: string, isDarkTheme?: boolean) => [string, string];

// @public (undocumented)
export const getNextColor: (index: number, offset?: number, isDarkTheme?: boolean) => string;

// @public (undocumented)
export const getNextGradient: (index: number, offset?: number, isDarkTheme?: boolean) => [string, string];

// @public (undocumented)
export interface GroupedVerticalBarChartData {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"start": "yarn storybook",
"storybook": "yarn --cwd ../stories storybook",
"test": "jest --passWithNoTests",
"update-snapshots": "jest -u",
"type-check": "just-scripts type-check"
},
"syncpack": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ChartDataPoint } from '../index';
import { ArcProps } from './index';
import { format as d3Format } from 'd3-format';
import { formatValueWithSIPrefix, useRtl } from '../../../utilities/index';
import { useId } from '@fluentui/react-utilities';

// Create a Arc within Donut Chart variant which uses these default styles and this styled subcomponent.
/**
Expand All @@ -13,7 +14,7 @@ import { formatValueWithSIPrefix, useRtl } from '../../../utilities/index';
*/
export const Arc: React.FunctionComponent<ArcProps> = React.forwardRef<HTMLDivElement, ArcProps>(
(props, forwardedRef) => {
const arc = d3Arc();
const arc = d3Arc().cornerRadius(5);
const currentRef = React.createRef<SVGPathElement>();
const _isRTL: boolean = useRtl();
const classes = useArcStyles_unstable(props);
Expand Down Expand Up @@ -90,33 +91,54 @@ export const Arc: React.FunctionComponent<ArcProps> = React.forwardRef<HTMLDivEl
//TO DO 'replace' is throwing error
const id = props.uniqText! + props.data!.data.legend!.replace(/\s+/, '') + props.data!.data.data;
const opacity: number = props.activeArc === props.data!.data.legend || props.activeArc === '' ? 1 : 0.1;

const clipId = useId('Arc_clip') + `${props.gradient[0]}_${props.gradient[1]}`;
const gradientFill = `conic-gradient(
from ${props.data?.startAngle}rad,
${props.gradient[0]},
${props.gradient[1]} ${props.data?.endAngle}rad
)`;

const pathData = arc({ ...props.data!, innerRadius: props.innerRadius, outerRadius: props.outerRadius })!;
const focusPathData = arc({ ...props.focusData!, innerRadius: props.innerRadius, outerRadius: props.outerRadius })!;

return (
<g ref={currentRef}>
{!!focusedArcId && focusedArcId === id && (
// TODO innerradius and outerradius were absent
<path
id={id + 'focusRing'}
d={arc({ ...props.focusData!, innerRadius: props.innerRadius, outerRadius: props.outerRadius })!}
className={classes.focusRing}
/>
<path id={id + 'focusRing'} d={focusPathData} className={classes.focusRing} />
)}
<path
// TODO innerradius and outerradius were absent
id={id}
d={arc({ ...props.data!, innerRadius: props.innerRadius, outerRadius: props.outerRadius })!}
className={classes.root}
style={{ fill: props.color, cursor: href ? 'pointer' : 'default' }}
d={pathData}
style={{ fill: 'transparent', cursor: href ? 'pointer' : 'default' }}
Copy link
Contributor

Choose a reason for hiding this comment

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

why removed the classname?

Copy link
Contributor Author

@shawn-grant shawn-grant Nov 22, 2024

Choose a reason for hiding this comment

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

Moved the classname to the <div> that renders the gradients. The <path> element won't be visible, so the class and its styles aren't needed.
Test also break if both elements have the class.

onFocus={_onFocus.bind(this, props.data!.data, id)}
data-is-focusable={props.activeArc === props.data!.data.legend || props.activeArc === ''}
onMouseOver={_hoverOn.bind(this, props.data!.data)}
onMouseMove={_hoverOn.bind(this, props.data!.data)}
onMouseLeave={_hoverOff}
onBlur={_onBlur}
Copy link
Contributor

Choose a reason for hiding this comment

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

why removed the opacity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to previous comment, the element is to always be transparent, so opacity is unnecessary

opacity={opacity}
onClick={props.data?.data.onClick}
aria-label={_getAriaLabel()}
role="img"
/>
{/* clipping mask */}
<clipPath id={clipId}>
<path d={pathData} />
</clipPath>
{/* div to attach conic-gradient fill to */}
<foreignObject x="-50%" y="-50%" width="100%" height="100%" clipPath={`url(#${clipId})`}>
<div
className={classes.root}
style={{
width: '100%',
height: '100%',
background: gradientFill,
opacity,
}}
/>
</foreignObject>
{_renderArcLabel(classes.arcLabel)}
</g>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export interface ArcProps {
outerRadius: number;

/**
* Color for the Arc.
* Gradient for the legend in the chart. If not provided, it will fallback on the default color palette.
*/
color: string;
gradient: [string, string];

/**
* Defines the function that is executed upon hovering over the legend
Expand Down
Loading
Loading