-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix scatter3d marker.line.color inheritance #754
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
|
@@ -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); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😖 gah!