Skip to content
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
3 changes: 2 additions & 1 deletion src/components/colorscale/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = function calc(trace, vals, containerStr, cLetter) {
if(containerStr) {
container = Lib.nestedProperty(trace, containerStr).get();
inputContainer = Lib.nestedProperty(trace._input, containerStr).get();
} else {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

😖 gah!

else {
container = trace;
inputContainer = trace._input;
}
Expand Down
6 changes: 0 additions & 6 deletions src/traces/scatter/colorscale_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ var calcColorscale = require('../../components/colorscale/calc');
var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d' and 'scattergeo'
module.exports = function calcMarkerColorscale(trace) {

// auto-z and autocolorscale if applicable

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

if(subTypes.hasMarkers(trace)) {

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

if(hasColorscale(trace, 'marker.line')) {
calcColorscale(trace, trace.marker.line.color, 'marker.line', 'c');
}
Expand Down
15 changes: 6 additions & 9 deletions src/traces/scatter/line_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ var hasColorscale = require('../../components/colorscale/has_colorscale');
var colorscaleDefaults = require('../../components/colorscale/defaults');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var markerColor = (traceIn.marker || {}).color;

coerce('line.color', defaultColor);

if(hasColorscale(traceIn, 'line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'}
);
} else {
coerce('line.color', (Array.isArray(markerColor) ? false : markerColor) ||
defaultColor);
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c'});
}
else {
var lineColorDflt = (Array.isArray(markerColor) ? false : markerColor) || defaultColor;
coerce('line.color', lineColorDflt);
}


coerce('line.width');
coerce('line.dash');
Expand Down
15 changes: 6 additions & 9 deletions src/traces/scatter/marker_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
var subTypes = require('./subtypes');


// common to 'scatter', 'scatter3d', 'scattergeo' and 'scattergl'
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var isBubble = subTypes.isBubble(traceIn),
lineColor = !Array.isArray(traceIn.line) ? (traceIn.line || {}).color : undefined,
lineColor = (traceIn.line || {}).color,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultMLC;

// marker.color inherit from line.color (even if line.color is an array)
if(lineColor) defaultColor = lineColor;

coerce('marker.symbol');
Expand All @@ -30,25 +30,22 @@ module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout

coerce('marker.color', defaultColor);
if(hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
);
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
}

// if there's a line with a different color than the marker, use
// that line color as the default marker line color
// (except when it's an array)
// mostly this is for transparent markers to behave nicely
if(lineColor && (traceOut.marker.color !== lineColor)) {
if(lineColor && !Array.isArray(lineColor) && (traceOut.marker.color !== lineColor)) {
defaultMLC = lineColor;
}
else if(isBubble) defaultMLC = Color.background;
else defaultMLC = Color.defaultLine;

coerce('marker.line.color', defaultMLC);
if(hasColorscale(traceIn, 'marker.line')) {
colorscaleDefaults(
traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
);
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'});
}

coerce('marker.line.width', isBubble ? 1 : 0);
Expand Down
68 changes: 68 additions & 0 deletions test/jasmine/tests/scatter3d_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var Scatter3D = require('@src/traces/scatter3d');
var Lib = require('@src/lib');
var Color = require('@src/components/color');


describe('Scatter3D defaults', function() {
'use strict';

var defaultColor = '#d3d3d3';

function _supply(traceIn) {
var traceOut = { visible: true },
layout = { _dataLength: 1 };

Scatter3D.supplyDefaults(traceIn, traceOut, defaultColor, layout);
return traceOut;
}

var base = {
x: [1, 2, 3],
y: [1, 2, 3],
z: [1, 2, 1]
};

it('should make marker.color inherit from line.color (scalar case)', function() {
var out = _supply(Lib.extendFlat({}, base, {
line: { color: 'red' }
}));

expect(out.line.color).toEqual('red');
expect(out.marker.color).toEqual('red');
expect(out.marker.line.color).toBe(Color.defaultLine, 'but not marker.line.color');
});

it('should make marker.color inherit from line.color (array case)', function() {
var color = [1, 2, 3];

var out = _supply(Lib.extendFlat({}, base, {
line: { color: color }
}));

expect(out.line.color).toBe(color);
expect(out.marker.color).toBe(color);
expect(out.marker.line.color).toBe(Color.defaultLine, 'but not marker.line.color');
});

it('should make line.color inherit from marker.color if scalar)', function() {
var out = _supply(Lib.extendFlat({}, base, {
marker: { color: 'red' }
}));

expect(out.line.color).toEqual('red');
expect(out.marker.color).toEqual('red');
expect(out.marker.line.color).toBe(Color.defaultLine);
});

it('should not make line.color inherit from marker.color if array', function() {
var color = [1, 2, 3];

var out = _supply(Lib.extendFlat({}, base, {
marker: { color: color }
}));

expect(out.line.color).toBe(defaultColor);
expect(out.marker.color).toBe(color);
expect(out.marker.line.color).toBe(Color.defaultLine);
});
});