Skip to content

Commit 90fd5b6

Browse files
Anush2303Anush
andauthored
feat(react-charts): Add support for scatter polar trace type (#34933)
Co-authored-by: Anush <anushgupta@microsoft.com>
1 parent 0aaf72c commit 90fd5b6

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "add support for scatter polar trace type",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "anushgupta@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charts/library/src/components/DeclarativeChart/DeclarativeChart.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
transformPlotlyJsonToGaugeProps,
2828
transformPlotlyJsonToGVBCProps,
2929
transformPlotlyJsonToVBCProps,
30+
projectPolarToCartesian,
3031
} from './PlotlySchemaAdapter';
3132
import { DonutChart } from '../DonutChart/index';
3233
import { VerticalStackedBarChart } from '../VerticalStackedBarChart/index';
@@ -306,6 +307,11 @@ export const DeclarativeChart: React.FunctionComponent<DeclarativeChartProps> =
306307
case 'area':
307308
case 'line':
308309
case 'fallback':
310+
case 'scatterpolar':
311+
if (chart.type === 'scatterpolar') {
312+
const cartesianProjection = projectPolarToCartesian(plotlyInputWithValidData);
313+
plotlyInputWithValidData.data = cartesianProjection.data;
314+
}
309315
// Need recheck for area chart as we don't have ability to check for valid months in previous step
310316
const isAreaChart = plotlyInputWithValidData.data.some(
311317
(series: PlotData) => series.fill === 'tonexty' || series.fill === 'tozeroy' || !!series.stackgroup,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,24 @@ export const transformPlotlyJsonToGaugeProps = (
808808
};
809809
};
810810

811+
export const projectPolarToCartesian = (input: PlotlySchema): PlotlySchema => {
812+
const projection: PlotlySchema = { ...input };
813+
for (let sindex = 0; sindex < input.data.length; sindex++) {
814+
const series: PlotData = input.data[sindex] as PlotData;
815+
series.x = [];
816+
series.y = [];
817+
for (let ptindex = 0; ptindex < series.r.length; ptindex++) {
818+
const thetaRad = ((series.theta[ptindex] as number) * Math.PI) / 180;
819+
const radius = series.r[ptindex] as number;
820+
series.x[ptindex] = radius * Math.cos(thetaRad);
821+
series.y[ptindex] = radius * Math.sin(thetaRad);
822+
}
823+
projection.data[sindex] = series;
824+
}
825+
826+
return projection;
827+
};
828+
811829
function isPlainObject(obj: any) {
812830
return (
813831
Object.prototype.toString.call(obj) === '[object Object]' &&

0 commit comments

Comments
 (0)