Skip to content

No unwarranted colorscale or related data on parcoords trace/fullTrace #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no point in attempting to use a color scale if line.color is not an array but e.g. a plain color, because the line.color numerical array values are mapped to the colors on the color scale.
Also, now line.colorscale is only performed if it's warranted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe patching defaults.js is all you need to fix this bug.

}
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