Skip to content

Commit 849f098

Browse files
Anush2303Anush
andauthored
fix(react-charts): Make legends of dotted line as dotted (#34947)
Co-authored-by: Anush <anushgupta@microsoft.com>
1 parent 827895d commit 849f098

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-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": "make legends of dotted lines dotted",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "anushgupta@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charts/library/etc/react-charts.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ export interface LineDataInVerticalStackedBarChart {
11271127
data?: number;
11281128
// (undocumented)
11291129
legend: string;
1130+
legendShape?: LegendShape;
11301131
lineOptions?: LineChartLineOptions;
11311132
useSecondaryYScale?: boolean;
11321133
// (undocumented)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,12 @@ export const transformPlotlyJsonToVSBCProps = (
286286
} else if (series.type === 'scatter' || !!fallbackVSBC) {
287287
const color = getColor(legend, colorMap, isDarkTheme);
288288
const lineOptions = getLineOptions(series.line);
289+
const dashType = series.line?.dash || 'solid';
290+
const legendShape =
291+
dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
289292
mapXToDataPoints[x].lineData!.push({
290293
legend,
294+
legendShape,
291295
y: yVal,
292296
color,
293297
...(lineOptions ? { lineOptions } : {}),
@@ -463,9 +467,12 @@ export const transformPlotlyJsonToScatterChartProps = (
463467
const lineColor = getColor(legend, colorMap, isDarkTheme);
464468
mode = series.fill === 'tozeroy' ? 'tozeroy' : 'tonexty';
465469
const lineOptions = getLineOptions(series.line);
470+
const dashType = series.line?.dash || 'solid';
471+
const legendShape = dashType === 'dot' || dashType === 'dash' || dashType === 'dashdot' ? 'dottedLine' : 'default';
466472

467473
return {
468474
legend,
475+
legendShape,
469476
data: xValues.map((x, i: number) => ({
470477
x: isString ? (isXDate ? new Date(x as string) : isXNumber ? parseFloat(x as string) : x) : x,
471478
y: series.y[i],

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,6 +3178,7 @@ Object {
31783178
},
31793179
],
31803180
"legend": "a",
3181+
"legendShape": "default",
31813182
"lineOptions": Object {
31823183
"curve": "linear",
31833184
},
@@ -3228,6 +3229,7 @@ Object {
32283229
},
32293230
],
32303231
"legend": "b",
3232+
"legendShape": "default",
32313233
"lineOptions": Object {
32323234
"curve": "linear",
32333235
},
@@ -3278,6 +3280,7 @@ Object {
32783280
},
32793281
],
32803282
"legend": "c",
3283+
"legendShape": "default",
32813284
"lineOptions": Object {
32823285
"curve": "linear",
32833286
},
@@ -3328,6 +3331,7 @@ Object {
33283331
},
33293332
],
33303333
"legend": "d",
3334+
"legendShape": "default",
33313335
"lineOptions": Object {
33323336
"curve": "linear",
33333337
},
@@ -3757,6 +3761,7 @@ Object {
37573761
},
37583762
],
37593763
"legend": "Trace 0",
3764+
"legendShape": "default",
37603765
"lineOptions": Object {
37613766
"curve": "linear",
37623767
},
@@ -4167,6 +4172,7 @@ Object {
41674172
},
41684173
],
41694174
"legend": "Trace 1",
4175+
"legendShape": "default",
41704176
"lineOptions": Object {
41714177
"curve": "linear",
41724178
},
@@ -4577,6 +4583,7 @@ Object {
45774583
},
45784584
],
45794585
"legend": "Trace 2",
4586+
"legendShape": "default",
45804587
"lineOptions": Object {
45814588
"curve": "linear",
45824589
},

packages/charts/react-charts/library/src/types/DataPoint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ export interface LineDataInVerticalStackedBarChart {
616616
y: number;
617617
color: string;
618618
legend: string;
619+
/**
620+
* The shape for the legend
621+
* default: show the rect legend
622+
*/
623+
legendShape?: LegendShape;
619624
/**
620625
* Data to show in callout
621626
*/

0 commit comments

Comments
 (0)