Skip to content

Commit

Permalink
Merge pull request #3901 from plotly/parcoords-coloraxis
Browse files Browse the repository at this point in the history
Parcoords coloraxis
  • Loading branch information
etpinard authored May 23, 2019
2 parents 6a6ecdb + b09df4e commit 554d3d1
Show file tree
Hide file tree
Showing 5 changed files with 1,002 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/traces/parcoords/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = {
line: extendFlat({editType: 'calc'},
colorScaleAttrs('line', {
// the default autocolorscale isn't quite usable for parcoords due to context ambiguity around 0 (grey, off-white)
// autocolorscale therefore defaults to false too, to avoid being overridden by the blue-white-red autocolor palette
// autocolorscale therefore defaults to false too, to avoid being overridden by the blue-white-red autocolor palette
colorscaleDflt: 'Viridis',
autoColorDflt: false,
editTypeOverride: 'calc'
Expand Down
27 changes: 14 additions & 13 deletions src/traces/parcoords/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

'use strict';

var hasColorscale = require('../../components/colorscale/helpers').hasColorscale;
var calcColorscale = require('../../components/colorscale/calc');
var Colorscale = require('../../components/colorscale');
var Lib = require('../../lib');
var wrap = require('../../lib/gup').wrap;

Expand All @@ -19,22 +18,24 @@ module.exports = function calc(gd, trace) {
}
trace.line.color = convertTypedArray(trace.line.color);

var cs = !!trace.line.colorscale && Array.isArray(trace.line.color);
var color = cs ? trace.line.color : constHalf(trace._length);
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
var lineColor;
var cscale;

if(hasColorscale(trace, 'line')) {
calcColorscale(gd, trace, {
vals: color,
if(Colorscale.hasColorscale(trace, 'line') && Array.isArray(trace.line.color)) {
lineColor = trace.line.color;
cscale = Colorscale.extractOpts(trace.line).colorscale;

Colorscale.calc(gd, trace, {
vals: lineColor,
containerStr: 'line',
cLetter: 'c'
});
} else {
lineColor = constHalf(trace._length);
cscale = [[0, trace.line.color], [1, trace.line.color]];
}

return wrap({
lineColor: color,
cscale: cscale
});
return wrap({lineColor: lineColor, cscale: cscale});
};

function constHalf(len) {
Expand All @@ -46,5 +47,5 @@ function constHalf(len) {
}

function convertTypedArray(a) {
return (Lib.isTypedArray(a)) ? Array.prototype.slice.call(a) : a;
return Lib.isTypedArray(a) ? Array.prototype.slice.call(a) : a;
}
5 changes: 3 additions & 2 deletions src/traces/parcoords/parcoords.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ function model(layout, d, i) {
var trace = cd0.trace;
var lineColor = cd0.lineColor;
var line = trace.line;
var cscale = line.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale;
var cOpts = Colorscale.extractOpts(line);
var cscale = cOpts.reversescale ? Colorscale.flipScale(cd0.cscale) : cd0.cscale;
var domain = trace.domain;
var dimensions = trace.dimensions;
var width = layout.width;
Expand All @@ -143,7 +144,7 @@ function model(layout, d, i) {
var lines = Lib.extendDeepNoArrays({}, line, {
color: lineColor.map(d3.scale.linear().domain(dimensionExtent({
values: lineColor,
range: [line.cmin, line.cmax],
range: [cOpts.min, cOpts.max],
_length: trace._length
}))),
blockLineCount: c.blockLineCount,
Expand Down
Binary file added test/image/baselines/gl2d_parcoords_coloraxis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 554d3d1

Please sign in to comment.