Skip to content

Commit 7d71314

Browse files
authored
Merge pull request #7673 from chrimaho/feature-marker-line-dash-7667
Add support for dashed marker lines in scatter plots
2 parents e074459 + f698f6b commit 7d71314

File tree

18 files changed

+2191
-1395
lines changed

18 files changed

+2191
-1395
lines changed

draftlogs/7673_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add support for dashed marker lines in scatter plots [[#7673](https://github.com/plotly/plotly.js/pull/7673)], with thanks to @chrimaho for the contribution!

src/components/drawing/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ drawing.singlePointStyle = function (d, sel, trace, fns, gd, pt) {
965965
}
966966
}
967967

968+
const lineDash = d.mld || (markerLine || {}).dash;
969+
if (lineDash) drawing.dashLine(sel, lineDash, lineWidth);
968970
if (d.om) {
969971
// open markers can't have zero linewidth, default to 1px,
970972
// and use fill color as stroke color

src/components/legend/style.js

Lines changed: 229 additions & 209 deletions
Large diffs are not rendered by default.

src/traces/scatter/arrays_to_calcdata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = function arraysToCalcdata(cd, trace) {
3838
if(marker.line) {
3939
Lib.mergeArray(markerLine.color, cd, 'mlc');
4040
Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');
41+
Lib.mergeArray(markerLine.dash, cd, 'mld');
4142
}
4243

4344
var markerGradient = marker.gradient;

src/traces/scatter/attributes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ module.exports = {
555555
anim: true,
556556
description: 'Sets the width (in px) of the lines bounding the marker points.'
557557
},
558+
dash: extendFlat({}, dash, {
559+
arrayOk: true
560+
}),
558561
editType: 'calc'
559562
},
560563
colorScaleAttrs('marker.line', { anim: true })

src/traces/scatter/marker_defaults.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,70 +12,65 @@ var subTypes = require('./subtypes');
1212
* gradient: caller supports gradients
1313
* noSelect: caller does not support selected/unselected attribute containers
1414
*/
15-
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
15+
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts = {}) {
1616
var isBubble = subTypes.isBubble(traceIn);
1717
var lineColor = (traceIn.line || {}).color;
1818
var defaultMLC;
1919

20-
opts = opts || {};
21-
2220
// marker.color inherit from line.color (even if line.color is an array)
23-
if(lineColor) defaultColor = lineColor;
21+
if (lineColor) defaultColor = lineColor;
2422

2523
coerce('marker.symbol');
2624
coerce('marker.opacity', isBubble ? 0.7 : 1);
2725
coerce('marker.size');
28-
if(!opts.noAngle) {
26+
if (!opts.noAngle) {
2927
coerce('marker.angle');
30-
if(!opts.noAngleRef) {
31-
coerce('marker.angleref');
32-
}
33-
34-
if(!opts.noStandOff) {
35-
coerce('marker.standoff');
36-
}
28+
if (!opts.noAngleRef) coerce('marker.angleref');
29+
if (!opts.noStandOff) coerce('marker.standoff');
3730
}
3831

3932
coerce('marker.color', defaultColor);
40-
if(hasColorscale(traceIn, 'marker')) {
41-
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
33+
if (hasColorscale(traceIn, 'marker')) {
34+
colorscaleDefaults(traceIn, traceOut, layout, coerce, { prefix: 'marker.', cLetter: 'c' });
4235
}
4336

44-
if(!opts.noSelect) {
37+
if (!opts.noSelect) {
4538
coerce('selected.marker.color');
4639
coerce('unselected.marker.color');
4740
coerce('selected.marker.size');
4841
coerce('unselected.marker.size');
4942
}
5043

51-
if(!opts.noLine) {
44+
if (!opts.noLine) {
5245
// if there's a line with a different color than the marker, use
5346
// that line color as the default marker line color
5447
// (except when it's an array)
5548
// mostly this is for transparent markers to behave nicely
56-
if(lineColor && !Array.isArray(lineColor) && (traceOut.marker.color !== lineColor)) {
49+
if (lineColor && !Array.isArray(lineColor) && traceOut.marker.color !== lineColor) {
5750
defaultMLC = lineColor;
58-
} else if(isBubble) defaultMLC = Color.background;
59-
else defaultMLC = Color.defaultLine;
51+
} else if (isBubble) {
52+
defaultMLC = Color.background;
53+
} else {
54+
defaultMLC = Color.defaultLine;
55+
}
6056

6157
coerce('marker.line.color', defaultMLC);
62-
if(hasColorscale(traceIn, 'marker.line')) {
63-
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'});
58+
if (hasColorscale(traceIn, 'marker.line')) {
59+
colorscaleDefaults(traceIn, traceOut, layout, coerce, { prefix: 'marker.line.', cLetter: 'c' });
6460
}
6561

6662
coerce('marker.line.width', isBubble ? 1 : 0);
63+
if (!opts.noLineDash) coerce('marker.line.dash');
6764
}
6865

69-
if(isBubble) {
66+
if (isBubble) {
7067
coerce('marker.sizeref');
7168
coerce('marker.sizemin');
7269
coerce('marker.sizemode');
7370
}
7471

75-
if(opts.gradient) {
72+
if (opts.gradient) {
7673
var gradientType = coerce('marker.gradient.type');
77-
if(gradientType !== 'none') {
78-
coerce('marker.gradient.color');
79-
}
74+
if (gradientType !== 'none') coerce('marker.gradient.color');
8075
}
8176
};

src/traces/scatter3d/defaults.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3232
coerce('mode');
3333

3434
if (subTypes.hasMarkers(traceOut)) {
35-
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, { noSelect: true, noAngle: true });
35+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
36+
noAngle: true,
37+
noLineDash: true,
38+
noSelect: true
39+
});
3640
}
3741

3842
if (subTypes.hasLines(traceOut)) {

src/traces/scattercarpet/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ module.exports = {
9797
line: extendFlat(
9898
{
9999
width: scatterMarkerLineAttrs.width,
100+
dash: scatterMarkerLineAttrs.dash,
100101
editType: 'calc'
101102
},
102103
colorScaleAttrs('marker.line')

src/traces/scattergeo/attributes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ module.exports = overrideAll(
139139
colorbar: scatterMarkerAttrs.colorbar,
140140
line: extendFlat(
141141
{
142-
width: scatterMarkerLineAttrs.width
142+
width: scatterMarkerLineAttrs.width,
143+
dash: scatterMarkerLineAttrs.dash
143144
},
144145
colorAttributes('marker.line')
145146
),

src/traces/scattergl/defaults.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4141
coerce('mode', defaultMode);
4242

4343
if (subTypes.hasMarkers(traceOut)) {
44-
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, { noAngleRef: true, noStandOff: true });
44+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
45+
noAngleRef: true,
46+
noLineDash: true,
47+
noStandOff: true
48+
});
4549
coerce('marker.line.width', isOpen || isBubble ? 1 : 0);
4650
}
4751

0 commit comments

Comments
 (0)