Skip to content

Commit ff079db

Browse files
authored
Merge pull request #622 from plotly/hot-fix-colors
Colorscale bug fix
2 parents 958babe + e8b803f commit ff079db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/components/fields/MarkerColor.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ class UnconnectedMarkerColor extends Component {
106106
let adjustedColors = colors;
107107

108108
if (colorscaleType !== 'categorical') {
109-
adjustedColors = adjustColorscale(colors, numberOfTraces);
109+
adjustedColors = adjustColorscale(colors, numberOfTraces, colorscaleType);
110110
}
111111

112112
if (
113113
adjustedColors.every(c => c === adjustedColors[0]) ||
114114
colorscaleType === 'categorical'
115115
) {
116-
adjustedColors = adjustColorscale(colors, numberOfTraces, {repeat: true});
116+
adjustedColors = adjustColorscale(
117+
colors,
118+
numberOfTraces,
119+
colorscaleType,
120+
{repeat: true}
121+
);
117122
}
118123

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

src/lib/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ function adjustColorscale(
182182
colorscaleType,
183183
config
184184
) {
185-
if (config.repeat) {
185+
if (config && config.repeat) {
186+
if (numberOfNeededColors < colorscale.length) {
187+
return colorscale.slice(0, numberOfNeededColors);
188+
}
189+
186190
const repetitions = Math.ceil(numberOfNeededColors / colorscale.length);
187191
const newArray = new Array(repetitions).fill(colorscale);
188192
return newArray

0 commit comments

Comments
 (0)