Skip to content

Commit

Permalink
Merge pull request #1508 from plotly/parcoords-avoid-colorscale
Browse files Browse the repository at this point in the history
No unwarranted colorscale or related data on parcoords trace/fullTrace
  • Loading branch information
monfera committed Mar 22, 2017
2 parents c753e47 + 8b4124a commit 8ad7e93
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/traces/parcoords/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ module.exports = function calc(gd, trace) {
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;});
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];

trace.line.color = color;
trace.line.colorscale = cscale;

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

return [{}];
return [{
lineColor: color,
cscale: cscale
}];
};
4 changes: 2 additions & 2 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var maxDimensionCount = require('./constants').maxDimensionCount;
function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

coerce('line.color', defaultColor);
coerce('line.colorscale');

if(hasColorscale(traceIn, 'line')) {
if(hasColorscale(traceIn, 'line') && Lib.isArray(traceIn.line.color)) {
coerce('line.colorscale');
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
}
else {
Expand Down
9 changes: 6 additions & 3 deletions src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ function unwrap(d) {
}

function model(layout, d, i) {
var trace = unwrap(d).trace,
var cd0 = unwrap(d),
trace = cd0.trace,
lineColor = cd0.lineColor,
cscale = cd0.cscale,
line = trace.line,
domain = trace.domain,
dimensions = trace.dimensions,
width = layout.width;

var lines = Lib.extendDeep({}, line, {
color: line.color.map(domainToUnitScale({values: line.color, range: [line.cmin, line.cmax]})),
color: lineColor.map(domainToUnitScale({values: lineColor, range: [line.cmin, line.cmax]})),
blockLineCount: c.blockLineCount,
canvasOverdrag: c.overdrag * c.canvasPixelRatio
});
Expand All @@ -139,7 +142,7 @@ function model(layout, d, i) {
colCount: dimensions.filter(visible).length,
dimensions: dimensions,
tickDistance: c.tickDistance,
unitToColor: unitToColorScale(line.colorscale),
unitToColor: unitToColorScale(cscale),
lines: lines,
translateX: domain.x[0] * width,
translateY: layout.height - domain.y[1] * layout.height,
Expand Down
16 changes: 3 additions & 13 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,11 @@ describe('parcoords initialization tests', function() {
}));

expect(fullTrace.line).toEqual({
color: [0.5, 0.5, 0.5, 0.5],
colorscale: [[0, '#444'], [1, '#444']],
cmin: 0,
cmax: 1
color: '#444'
});
});

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

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

expect(fullTrace.line).toEqual({
color: [0.5, 0.5, 0.5, 0.5],
colorscale: [[0, '#444'], [1, '#444']],
autocolorscale: false,
showscale: false,
reversescale: false,
cauto: true,
cmin: 0,
cmax: 1
color: '#444'
});
});
});
Expand Down

0 comments on commit 8ad7e93

Please sign in to comment.