Skip to content

Commit e291264

Browse files
committed
Repeat categorical colors
1 parent 3d8582e commit e291264

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/components/fields/MarkerColor.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,29 @@ class UnconnectedMarkerColor extends Component {
104104
const numberOfTraces = this.context.traceIndexes.length;
105105
const colors = colorscale.map(c => c[1]);
106106

107-
let adjustedColors = getColorscale(
108-
colors,
109-
numberOfTraces,
110-
null,
111-
null,
112-
colorscaleType
113-
);
107+
let adjustedColors = colors;
108+
109+
if (colorscaleType !== 'categorical') {
110+
adjustedColors = getColorscale(
111+
colors,
112+
numberOfTraces,
113+
null,
114+
null,
115+
colorscaleType
116+
);
117+
}
114118

115-
if (adjustedColors.every(c => c === adjustedColors[0])) {
116-
adjustedColors = colors;
119+
if (
120+
adjustedColors.every(c => c === adjustedColors[0]) ||
121+
colorscaleType === 'categorical'
122+
) {
123+
const repetitions = Math.ceil(numberOfTraces / colors.length);
124+
const newArray = new Array(repetitions).fill(colors);
125+
adjustedColors = newArray
126+
.reduce((a, b) => {
127+
return a.concat(b);
128+
}, [])
129+
.slice(0, numberOfTraces);
117130
}
118131

119132
const updates = adjustedColors.map(color => ({

0 commit comments

Comments
 (0)