Skip to content

Commit dc365b1

Browse files
authored
fix(react-charting): declarative chart bug fixes (#33567)
1 parent 7026db8 commit dc365b1

6 files changed

+112
-103
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Declarative chart bug fixes",
4+
"packageName": "@fluentui/react-charting",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charting/src/components/AreaChart/AreaChart.base.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ export class AreaChartBase extends React.Component<IAreaChartProps, IAreaChartSt
450450
});
451451
stackedData.push(currentStack);
452452
});
453-
this._isMultiStackChart = stackedData && stackedData.length > 1 ? true : false;
453+
this._isMultiStackChart = !!(this.props.legendProps?.selectedLegends
454+
? stackedData?.length >= 1
455+
: stackedData?.length > 1);
454456
return {
455457
stackedData,
456458
maxOfYVal,

packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ import { IHorizontalBarChartWithAxisProps } from '../HorizontalBarChartWithAxis/
2424
import { ILineChartProps } from '../LineChart/index';
2525
import { IAreaChartProps } from '../AreaChart/index';
2626
import { IHeatMapChartProps } from '../HeatMapChart/index';
27-
import { DataVizPalette, getNextColor } from '../../utilities/colors';
27+
import { DataVizPalette, getColorFromToken, getNextColor } from '../../utilities/colors';
2828
import { GaugeChartVariant, IGaugeChartProps, IGaugeChartSegment } from '../GaugeChart/index';
2929
import { IGroupedVerticalBarChartProps } from '../GroupedVerticalBarChart/index';
3030
import { IVerticalBarChartProps } from '../VerticalBarChart/index';
31+
import { timeParse } from 'd3-time-format';
3132

3233
const isDate = (value: any): boolean => !isNaN(Date.parse(value));
3334
const isNumber = (value: any): boolean => !isNaN(parseFloat(value)) && isFinite(value);
3435
export const isDateArray = (array: any[]): boolean => isArrayOrTypedArray(array) && array.every(isDate);
3536
export const isNumberArray = (array: any[]): boolean => isArrayOrTypedArray(array) && array.every(isNumber);
3637
export const isMonthArray = (array: any[]): boolean => {
3738
if (array && array.length > 0) {
38-
const presentYear = new Date().getFullYear();
39+
const parseFullMonth = timeParse('%B');
40+
const parseShortMonth = timeParse('%b');
3941
return array.every(possiblyMonthValue => {
40-
return isDate(`${possiblyMonthValue} 01, ${presentYear}`);
42+
return parseFullMonth(possiblyMonthValue) !== null || parseShortMonth(possiblyMonthValue) !== null;
4143
});
4244
}
4345
return false;
@@ -147,7 +149,7 @@ export const transformPlotlyJsonToDonutProps = (
147149
height,
148150
innerRadius,
149151
hideLabels,
150-
showLabelsInPercent: firstData.textinfo ? firstData.textinfo === 'percent' : true,
152+
showLabelsInPercent: firstData.textinfo ? ['percent', 'label+percent'].includes(firstData.textinfo) : true,
151153
styles,
152154
};
153155
};
@@ -404,7 +406,9 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (
404406
};
405407
});
406408
})
407-
.flat();
409+
.flat()
410+
//reversing the order to invert the Y bars order as required by plotly.
411+
.reverse();
408412

409413
const chartHeight: number = typeof layout.height === 'number' ? layout.height : 450;
410414
const margin: number = typeof layout.margin?.l === 'number' ? layout.margin?.l : 0;
@@ -579,11 +583,11 @@ export const transformPlotlyJsonToGaugeProps = (
579583
const diff = firstData.value - firstData.delta.reference;
580584
if (diff >= 0) {
581585
sublabel = `\u25B2 ${diff}`;
582-
const color = getColor(firstData.delta.increasing?.color || '', colorMap, isDarkTheme);
586+
const color = getColorFromToken(DataVizPalette.success, isDarkTheme);
583587
sublabelColor = color;
584588
} else {
585589
sublabel = `\u25BC ${Math.abs(diff)}`;
586-
const color = getColor(firstData.delta.decreasing?.color || '', colorMap, isDarkTheme);
590+
const color = getColorFromToken(DataVizPalette.error, isDarkTheme);
587591
sublabelColor = color;
588592
}
589593
}

packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapterUT.test.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ describe('isMonthArray', () => {
102102
expect(isMonthArray([date, date.getDate() + 1, date.getDate() + 2])).toBe(false);
103103
});
104104

105-
test('Should return true when input array contains months data', () => {
106-
expect(isMonthArray([10, 11, 1])).toBe(true);
107-
});
108-
109-
test('Should return false when input array contains numeric data(apart from months 1 to 12)', () => {
105+
test('Should return false when input array contains numeric data', () => {
110106
expect(isMonthArray([20, 30, 40])).toBe(false);
111107
});
112108

packages/charts/react-charting/src/components/DeclarativeChart/__snapshots__/DeclarativeChartRTL.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -4187,7 +4187,7 @@ exports[`DeclarativeChart Should render gaugechart in DeclarativeChart 1`] = `
41874187
class=
41884188

41894189
{
4190-
fill: #9373c0;
4190+
fill: #107c10;
41914191
font-size: 12px;
41924192
font-weight: 600;
41934193
}

packages/charts/react-charting/src/components/DeclarativeChart/__snapshots__/PlotlySchemaAdapterUT.test.tsx.snap

+89-89
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ Object {
384384
],
385385
"styles": Object {
386386
"sublabel": Object {
387-
"fill": "#f7adda",
387+
"fill": "#54b054",
388388
},
389389
},
390390
"sublabel": "▲ 20",
@@ -2844,70 +2844,70 @@ Object {
28442844
"chartTitle": "PHP Framework Popularity at Work - SitePoint, 2015",
28452845
"data": Array [
28462846
Object {
2847-
"color": "#cf87da",
2848-
"legend": "Laravel",
2849-
"x": 1659,
2850-
"y": "Laravel",
2847+
"color": "#4f6bed",
2848+
"legend": "Aura",
2849+
"x": 10,
2850+
"y": "Aura",
28512851
},
28522852
Object {
2853-
"color": "#dac157",
2854-
"legend": "Symfony2",
2855-
"x": 1067,
2856-
"y": "Symfony2",
2853+
"color": "#d0b232",
2854+
"legend": "Drupal",
2855+
"x": 11,
2856+
"y": "Drupal",
28572857
},
28582858
Object {
2859-
"color": "#637cef",
2860-
"legend": "Nette",
2861-
"x": 671,
2862-
"y": "Nette",
2859+
"color": "#c36bd1",
2860+
"legend": "TYPO3 Flow",
2861+
"x": 17,
2862+
"y": "TYPO3 Flow",
28632863
},
28642864
Object {
2865-
"color": "#e3008c",
2866-
"legend": "CodeIgniter",
2867-
"x": 597,
2868-
"y": "CodeIgniter",
2865+
"color": "#73aa24",
2866+
"legend": "FuelPHP",
2867+
"x": 25,
2868+
"y": "FuelPHP",
28692869
},
28702870
Object {
2871-
"color": "#2aa0a4",
2872-
"legend": "Yii 2",
2873-
"x": 504,
2874-
"y": "Yii 2",
2871+
"color": "#d77440",
2872+
"legend": "Kohana",
2873+
"x": 35,
2874+
"y": "Kohana",
28752875
},
28762876
Object {
2877-
"color": "#9373c0",
2878-
"legend": "PHPixie",
2879-
"x": 418,
2880-
"y": "PHPixie",
2877+
"color": "#4fa1e1",
2878+
"legend": "Typo 3",
2879+
"x": 35,
2880+
"y": "Typo 3",
28812881
},
28822882
Object {
2883-
"color": "#13a10e",
2884-
"legend": "Yii 1",
2885-
"x": 407,
2886-
"y": "Yii 1",
2883+
"color": "#27ac22",
2884+
"legend": "Simple MVC Framework",
2885+
"x": 42,
2886+
"y": "Simple MVC Framework",
28872887
},
28882888
Object {
2889-
"color": "#3a96dd",
2890-
"legend": "Zend Framework 2",
2891-
"x": 390,
2892-
"y": "Zend Framework 2",
2889+
"color": "#a083c9",
2890+
"legend": "Silex",
2891+
"x": 65,
2892+
"y": "Silex",
28932893
},
28942894
Object {
2895-
"color": "#ca5010",
2896-
"legend": "Company Internal Framework",
2897-
"x": 378,
2898-
"y": "Company Internal Framework",
2895+
"color": "#4cb4b7",
2896+
"legend": "Slim",
2897+
"x": 79,
2898+
"y": "Slim",
28992899
},
29002900
Object {
2901-
"color": "#57811b",
2902-
"legend": "Zend Framework 1",
2903-
"x": 274,
2904-
"y": "Zend Framework 1",
2901+
"color": "#ee5fb7",
2902+
"legend": "Phalcon",
2903+
"x": 169,
2904+
"y": "Phalcon",
29052905
},
29062906
Object {
2907-
"color": "#b146c2",
2908-
"legend": "CakePHP",
2909-
"x": 255,
2910-
"y": "CakePHP",
2907+
"color": "#93a4f4",
2908+
"legend": "We use a CMS for everything",
2909+
"x": 203,
2910+
"y": "We use a CMS for everything",
29112911
},
29122912
Object {
29132913
"color": "#ae8c00",
@@ -2916,70 +2916,70 @@ Object {
29162916
"y": "No Framework",
29172917
},
29182918
Object {
2919-
"color": "#93a4f4",
2920-
"legend": "We use a CMS for everything",
2921-
"x": 203,
2922-
"y": "We use a CMS for everything",
2919+
"color": "#b146c2",
2920+
"legend": "CakePHP",
2921+
"x": 255,
2922+
"y": "CakePHP",
29232923
},
29242924
Object {
2925-
"color": "#ee5fb7",
2926-
"legend": "Phalcon",
2927-
"x": 169,
2928-
"y": "Phalcon",
2925+
"color": "#57811b",
2926+
"legend": "Zend Framework 1",
2927+
"x": 274,
2928+
"y": "Zend Framework 1",
29292929
},
29302930
Object {
2931-
"color": "#4cb4b7",
2932-
"legend": "Slim",
2933-
"x": 79,
2934-
"y": "Slim",
2931+
"color": "#ca5010",
2932+
"legend": "Company Internal Framework",
2933+
"x": 378,
2934+
"y": "Company Internal Framework",
29352935
},
29362936
Object {
2937-
"color": "#a083c9",
2938-
"legend": "Silex",
2939-
"x": 65,
2940-
"y": "Silex",
2937+
"color": "#3a96dd",
2938+
"legend": "Zend Framework 2",
2939+
"x": 390,
2940+
"y": "Zend Framework 2",
29412941
},
29422942
Object {
2943-
"color": "#27ac22",
2944-
"legend": "Simple MVC Framework",
2945-
"x": 42,
2946-
"y": "Simple MVC Framework",
2943+
"color": "#13a10e",
2944+
"legend": "Yii 1",
2945+
"x": 407,
2946+
"y": "Yii 1",
29472947
},
29482948
Object {
2949-
"color": "#4fa1e1",
2950-
"legend": "Typo 3",
2951-
"x": 35,
2952-
"y": "Typo 3",
2949+
"color": "#9373c0",
2950+
"legend": "PHPixie",
2951+
"x": 418,
2952+
"y": "PHPixie",
29532953
},
29542954
Object {
2955-
"color": "#d77440",
2956-
"legend": "Kohana",
2957-
"x": 35,
2958-
"y": "Kohana",
2955+
"color": "#2aa0a4",
2956+
"legend": "Yii 2",
2957+
"x": 504,
2958+
"y": "Yii 2",
29592959
},
29602960
Object {
2961-
"color": "#73aa24",
2962-
"legend": "FuelPHP",
2963-
"x": 25,
2964-
"y": "FuelPHP",
2961+
"color": "#e3008c",
2962+
"legend": "CodeIgniter",
2963+
"x": 597,
2964+
"y": "CodeIgniter",
29652965
},
29662966
Object {
2967-
"color": "#c36bd1",
2968-
"legend": "TYPO3 Flow",
2969-
"x": 17,
2970-
"y": "TYPO3 Flow",
2967+
"color": "#637cef",
2968+
"legend": "Nette",
2969+
"x": 671,
2970+
"y": "Nette",
29712971
},
29722972
Object {
2973-
"color": "#d0b232",
2974-
"legend": "Drupal",
2975-
"x": 11,
2976-
"y": "Drupal",
2973+
"color": "#dac157",
2974+
"legend": "Symfony2",
2975+
"x": 1067,
2976+
"y": "Symfony2",
29772977
},
29782978
Object {
2979-
"color": "#4f6bed",
2980-
"legend": "Aura",
2981-
"x": 10,
2982-
"y": "Aura",
2979+
"color": "#cf87da",
2980+
"legend": "Laravel",
2981+
"x": 1659,
2982+
"y": "Laravel",
29832983
},
29842984
],
29852985
"secondaryYAxistitle": "",

0 commit comments

Comments
 (0)