Skip to content

Commit 37efadc

Browse files
committed
Avoid color scale persistence on trace / fullTrace if the user hasn't specified one (as interpreted by has_colorscale.js)
1 parent c753e47 commit 37efadc

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

src/traces/parcoords/calc.js

-7
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010

1111
var hasColorscale = require('../../components/colorscale/has_colorscale');
1212
var calcColorscale = require('../../components/colorscale/calc');
13-
var Lib = require('../../lib');
1413

1514

1615
module.exports = function calc(gd, trace) {
17-
var cs = !!trace.line.colorscale && Lib.isArray(trace.line.color);
18-
var color = cs ? trace.line.color : Array.apply(0, Array(trace.dimensions.reduce(function(p, n) {return Math.max(p, n.values.length);}, 0))).map(function() {return 0.5;});
19-
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
20-
21-
trace.line.color = color;
22-
trace.line.colorscale = cscale;
2316

2417
if(hasColorscale(trace, 'line')) {
2518
calcColorscale(trace, trace.line.color, 'line', 'c');

src/traces/parcoords/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var maxDimensionCount = require('./constants').maxDimensionCount;
1717
function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
1818

1919
coerce('line.color', defaultColor);
20-
coerce('line.colorscale');
2120

22-
if(hasColorscale(traceIn, 'line')) {
21+
if(hasColorscale(traceIn, 'line') && Lib.isArray(traceIn.line.color)) {
22+
coerce('line.colorscale');
2323
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
2424
}
2525
else {

src/traces/parcoords/parcoords.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ function model(layout, d, i) {
121121
dimensions = trace.dimensions,
122122
width = layout.width;
123123

124+
var cs = !!trace.line.colorscale && Lib.isArray(trace.line.color);
125+
var lineColor = cs ?
126+
trace.line.color :
127+
Array.apply(0, Array(trace.dimensions.reduce(function(p, n) {return Math.max(p, n.values.length);}, 0))).map(function() {return 0.5;});
128+
var lineColorScale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
129+
124130
var lines = Lib.extendDeep({}, line, {
125-
color: line.color.map(domainToUnitScale({values: line.color, range: [line.cmin, line.cmax]})),
131+
color: lineColor.map(domainToUnitScale({values: lineColor, range: [line.cmin, line.cmax]})),
126132
blockLineCount: c.blockLineCount,
127133
canvasOverdrag: c.overdrag * c.canvasPixelRatio
128134
});
@@ -139,7 +145,7 @@ function model(layout, d, i) {
139145
colCount: dimensions.filter(visible).length,
140146
dimensions: dimensions,
141147
tickDistance: c.tickDistance,
142-
unitToColor: unitToColorScale(line.colorscale),
148+
unitToColor: unitToColorScale(lineColorScale),
143149
lines: lines,
144150
translateX: domain.x[0] * width,
145151
translateY: layout.height - domain.y[1] * layout.height,

test/jasmine/tests/parcoords_test.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,11 @@ describe('parcoords initialization tests', function() {
197197
}));
198198

199199
expect(fullTrace.line).toEqual({
200-
color: [0.5, 0.5, 0.5, 0.5],
201-
colorscale: [[0, '#444'], [1, '#444']],
202-
cmin: 0,
203-
cmax: 1
200+
color: '#444'
204201
});
205202
});
206203

207-
it('use a singular \'color\' even if a \'colorscale\' is supplied', function() {
204+
it('use a singular \'color\' even if a \'colorscale\' is supplied as \'color\' is not an array', function() {
208205

209206
var fullTrace = _calc(Lib.extendDeep({}, base, {
210207
line: {
@@ -218,14 +215,7 @@ describe('parcoords initialization tests', function() {
218215
}));
219216

220217
expect(fullTrace.line).toEqual({
221-
color: [0.5, 0.5, 0.5, 0.5],
222-
colorscale: [[0, '#444'], [1, '#444']],
223-
autocolorscale: false,
224-
showscale: false,
225-
reversescale: false,
226-
cauto: true,
227-
cmin: 0,
228-
cmax: 1
218+
color: '#444'
229219
});
230220
});
231221
});

0 commit comments

Comments
 (0)