Skip to content

Commit 09bcc61

Browse files
committed
Fix defaults for legend when pie has no slices.
1 parent f9c65da commit 09bcc61

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/components/legend/defaults.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
5151
if (trace.visible) {
5252
legendTraceCount++;
5353
}
54-
if (Array.isArray(trace.legend)) {
55-
for (var index = 0; index < trace._length; index++) {
54+
if(Array.isArray(trace.legend)) {
55+
for(var index = 0; index < trace._length; index++) {
5656
var legend = trace.legend[index] || 'legend';
5757
if(legend === legendId) {
5858
// showlegend can be undefined, boolean or a boolean array.
5959
// will fall back to default if undefined or if array index is out-of-range
60-
if (
60+
if(
6161
!Array.isArray(trace.showlegend)
6262
? trace.showlegend || trace._dfltShowLegend
6363
: trace.showlegend[index] == null
@@ -69,15 +69,18 @@ function groupDefaults(legendId, layoutIn, layoutOut, fullData) {
6969
}
7070
}
7171
}
72-
if (legendId === 'legend' && trace._length > trace.legend.length) {
73-
for (var idx = trace.legend.length; idx < trace._length; idx++) {
74-
legendReallyHasATrace = true;
75-
legendTraceCount++;
76-
}
72+
if(
73+
legendId === 'legend' &&
74+
(trace._length == null || trace._length > trace.legend.length)
75+
) {
76+
for(var idx = trace.legend.length; idx < trace._length; idx++) {
77+
legendReallyHasATrace = true;
78+
legendTraceCount++;
79+
}
7780
}
78-
} else if (legendId === (trace.legend || 'legend')) {
81+
} else if(legendId === (trace.legend || 'legend')) {
7982
legendReallyHasATrace = true;
80-
legendTraceCount += trace._length;
83+
legendTraceCount += trace._length || 1;
8184
}
8285
});
8386

0 commit comments

Comments
 (0)