Skip to content

Commit c2cded4

Browse files
authored
Merge pull request #3384 from plotly/2862-scatter3d-colorscale
Display a colorscale when scatter3d.line.showscale is set
2 parents ebeddb5 + 60b87a2 commit c2cded4

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

src/components/colorbar/connect.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,26 @@ module.exports = function connectColorbar(gd, cd, moduleOpts) {
4141

4242
var trace = cd[0].trace;
4343
var cbId = 'cb' + trace.uid;
44-
var containerName = moduleOpts.container;
45-
var container = containerName ? trace[containerName] : trace;
44+
moduleOpts = Array.isArray(moduleOpts) ? moduleOpts : [moduleOpts];
4645

47-
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
48-
if(!container || !container.showscale) return;
46+
for(var i = 0; i < moduleOpts.length; i++) {
47+
var containerName = moduleOpts[i].container;
4948

50-
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
49+
var container = containerName ? trace[containerName] : trace;
5150

52-
var scl = container.reversescale ?
53-
flipScale(container.colorscale) :
54-
container.colorscale;
51+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
52+
if(!container || !container.showscale) continue;
5553

56-
cb.fillgradient(scl)
57-
.zrange([container[moduleOpts.min], container[moduleOpts.max]])
58-
.options(container.colorbar)();
54+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
55+
56+
var scl = container.reversescale ?
57+
flipScale(container.colorscale) :
58+
container.colorscale;
59+
60+
cb.fillgradient(scl)
61+
.zrange([container[moduleOpts[i].min], container[moduleOpts[i].max]])
62+
.options(container.colorbar)();
63+
64+
return;
65+
}
5966
};

src/traces/scatter/line_defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout,
1818
coerce('line.color', defaultColor);
1919

2020
if(hasColorscale(traceIn, 'line')) {
21-
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c', noScale: true});
21+
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
2222
} else {
2323
var lineColorDflt = (isArrayOrTypedArray(markerColor) ? false : markerColor) || defaultColor;
2424
coerce('line.color', lineColorDflt);

src/traces/scatter3d/attributes.js

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ var lineAttrs = extendFlat({
3131
description: 'Sets the dash style of the lines.'
3232
}
3333
}, colorAttributes('line'));
34-
// not yet implemented
35-
delete lineAttrs.showscale;
36-
delete lineAttrs.colorbar;
3734

3835
function makeProjectionAttr(axLetter) {
3936
return {

src/traces/scatter3d/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ Scatter3D.plot = require('./convert');
1414
Scatter3D.attributes = require('./attributes');
1515
Scatter3D.markerSymbols = require('../../constants/gl3d_markers');
1616
Scatter3D.supplyDefaults = require('./defaults');
17-
Scatter3D.colorbar = require('../scatter/marker_colorbar');
17+
Scatter3D.colorbar = [
18+
{
19+
container: 'marker',
20+
min: 'cmin',
21+
max: 'cmax'
22+
}, {
23+
container: 'line',
24+
min: 'cmin',
25+
max: 'cmax'
26+
}
27+
];
1828
Scatter3D.calc = require('./calc');
1929

2030
Scatter3D.moduleType = 'trace';
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"data": [
3+
{
4+
"x": [1, 2, 4, 8, 16],
5+
"y": [-1, -2, -4, -8, -16],
6+
"z": [0, 1, 0, 1, 0],
7+
"type": "scatter3d",
8+
"mode": "lines",
9+
"line": {
10+
"color": [0, 0.25, 0.5, 0.75, 1.0],
11+
"showscale": true,
12+
"width": 10
13+
}
14+
}
15+
],
16+
"layout": {
17+
"title": "Scatter3d show scale with line colors",
18+
"width": 600,
19+
"height": 600
20+
}
21+
}

0 commit comments

Comments
 (0)