Skip to content

Commit f79bca8

Browse files
committed
Nest line options under marker.line
1 parent 2e59cda commit f79bca8

16 files changed

+107
-186
lines changed

src/traces/quiver/attributes.js

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ var baseAttrs = require('../../plots/attributes');
44
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
55
var fontAttrs = require('../../plots/font_attributes');
66
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat;
7-
var dash = require('../../components/drawing/attributes').dash;
8-
97
var extendFlat = require('../../lib/extend').extendFlat;
108
var colorScaleAttrs = require('../../components/colorscale/attributes');
9+
var dash = require('../../components/drawing/attributes').dash;
1110

1211
var attrs = {
1312
x: {
@@ -100,54 +99,6 @@ var attrs = {
10099
description: 'Deprecated alias for `arrowsize`-based sizing. Prefer using `arrowsize`.'
101100
},
102101

103-
// Line styling for arrows
104-
line: {
105-
color: {
106-
valType: 'color',
107-
dflt: '#000',
108-
editType: 'style',
109-
description: 'Sets the color of the arrow lines.'
110-
},
111-
width: {
112-
valType: 'number',
113-
min: 0,
114-
dflt: 1,
115-
editType: 'style',
116-
description: 'Sets the width (in px) of the arrow lines.'
117-
},
118-
dash: dash,
119-
shape: {
120-
valType: 'enumerated',
121-
values: ['linear', 'spline', 'hv', 'vh', 'hvh', 'vhv'],
122-
dflt: 'linear',
123-
editType: 'plot',
124-
description: 'Determines the line shape.'
125-
},
126-
smoothing: {
127-
valType: 'number',
128-
min: 0,
129-
max: 1.3,
130-
dflt: 1,
131-
editType: 'plot',
132-
description: 'Has an effect only if `shape` is set to *spline*. Sets the amount of smoothing.'
133-
},
134-
simplify: {
135-
valType: 'boolean',
136-
dflt: true,
137-
editType: 'plot',
138-
description: 'Simplifies lines by removing nearly-overlapping points.'
139-
},
140-
editType: 'style'
141-
},
142-
143-
// Alias consistent with annotations; maps to line.width
144-
arrowwidth: {
145-
valType: 'number',
146-
min: 0.1,
147-
editType: 'style',
148-
description: 'Sets the width (in px) of the arrow line (alias of `line.width`).'
149-
},
150-
151102
// Text and labels
152103
text: {
153104
valType: 'data_array',
@@ -174,9 +125,20 @@ var attrs = {
174125
description: 'Sets the text font.'
175126
}),
176127

177-
// Marker (for colorscale-based coloring of arrows)
128+
// Marker: color, colorscale, and line styling for arrows
178129
marker: extendFlat(
179130
{
131+
line: {
132+
width: {
133+
valType: 'number',
134+
min: 0,
135+
dflt: 1,
136+
editType: 'style',
137+
description: 'Sets the width (in px) of the arrow lines.'
138+
},
139+
dash: dash,
140+
editType: 'style'
141+
},
180142
editType: 'calc'
181143
},
182144
colorScaleAttrs('marker', {

src/traces/quiver/defaults.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3838
// Arrow styling
3939
coerce('arrowsize');
4040
coerce('arrow_scale'); // back-compat alias
41-
coerce('arrowwidth');
4241
coerce('hoverdistance');
4342

44-
// Line styling - use coerce for proper validation
45-
coerce('line.color', defaultColor);
46-
// If arrowwidth is set, use it as line.width default
47-
var arrowwidth = traceOut.arrowwidth;
48-
if(arrowwidth !== undefined) {
49-
coerce('line.width', arrowwidth);
50-
} else {
51-
coerce('line.width');
52-
}
53-
coerce('line.dash');
54-
coerce('line.shape');
55-
coerce('line.smoothing');
56-
coerce('line.simplify');
43+
// Line styling under marker.line
44+
coerce('marker.line.width');
45+
coerce('marker.line.dash');
5746

5847
// Text
5948
coerce('text');
@@ -71,13 +60,22 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7160
// Ensure traceOut.marker exists before colorscaleDefaults, which captures
7261
// a reference to it via npMaybe at the start of its execution.
7362
if(!traceOut.marker) traceOut.marker = {};
74-
coerce('marker.color');
63+
coerce('marker.color', defaultColor);
7564
var withColorscale = hasColorscale(traceIn, 'marker') || (traceIn.marker || {}).coloraxis;
7665
traceOut._hasColorscale = !!withColorscale;
7766
if(withColorscale) {
7867
colorscaleDefaults(traceIn, traceOut, layout, coerce, { prefix: 'marker.', cLetter: 'c' });
7968
}
8069

70+
// Provide trace.line for compat with shared code (legend, getTraceColor)
71+
var markerLine = traceOut.marker.line || {};
72+
var mc = traceOut.marker.color;
73+
traceOut.line = {
74+
width: markerLine.width,
75+
color: Lib.isArrayOrTypedArray(mc) ? defaultColor : mc,
76+
dash: markerLine.dash
77+
};
78+
8179
// Selection styling
8280
coerce('selected.line.color');
8381
coerce('selected.line.width');

src/traces/quiver/plot.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
173173
});
174174

175175
// Apply styling using Plotly's standard styling system
176-
Drawing.lineGroupStyle(lineSegments, trace.line && trace.line.width, trace.line && trace.line.color, trace.line && trace.line.dash);
176+
var marker = trace.marker || {};
177+
var markerLine = marker.line || {};
178+
var lineColor = Lib.isArrayOrTypedArray(marker.color) ? undefined : marker.color;
179+
Drawing.lineGroupStyle(lineSegments, markerLine.width, lineColor, markerLine.dash);
177180

178181
// If colorscale present, color arrows by marker.color or magnitude |(u,v)|
179182
if(trace._hasColorscale) {
180-
var marker = trace.marker || {};
181183
var colorFunc = Colorscale.makeColorScaleFuncFromTrace(marker);
182184
lineSegments.style('stroke', function(cdi) {
183185
var markerColor = marker.color;

src/traces/quiver/style.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var d3 = require('@plotly/d3');
4+
var Lib = require('../../lib');
45

56
var Drawing = require('../../components/drawing');
67
var Color = require('../../components/color');
@@ -11,16 +12,20 @@ function style(gd) {
1112

1213
s.each(function(d) {
1314
var trace = d[0].trace;
14-
var line = trace.line || {};
15+
var marker = trace.marker || {};
16+
var markerLine = marker.line || {};
17+
var lineColor = Lib.isArrayOrTypedArray(marker.color) ? undefined : marker.color;
1518

1619
d3.select(this).selectAll('path.js-line')
17-
.call(Drawing.lineGroupStyle, line.width, line.color, line.dash);
20+
.call(Drawing.lineGroupStyle, markerLine.width, lineColor, markerLine.dash);
1821
});
1922
}
2023

2124
function styleOnSelect(gd, cd, sel) {
2225
var trace = cd[0].trace;
23-
var line = trace.line || {};
26+
var marker = trace.marker || {};
27+
var markerLine = marker.line || {};
28+
var lineColor = Lib.isArrayOrTypedArray(marker.color) ? undefined : marker.color;
2429

2530
if(!sel) return;
2631

@@ -34,24 +39,24 @@ function styleOnSelect(gd, cd, sel) {
3439
var path = d3.select(this);
3540

3641
if(d.selected) {
37-
var sc = selectedLine.color || line.color;
38-
var sw = selectedLine.width !== undefined ? selectedLine.width : line.width;
39-
Drawing.lineGroupStyle(path, sw, sc, line.dash);
42+
var sc = selectedLine.color || lineColor;
43+
var sw = selectedLine.width !== undefined ? selectedLine.width : markerLine.width;
44+
Drawing.lineGroupStyle(path, sw, sc, markerLine.dash);
4045
} else {
4146
var uc = unselectedLine.color;
4247
var uw = unselectedLine.width;
4348
if(!uc) {
44-
uc = line.color ? Color.addOpacity(line.color, DESELECTDIM) : undefined;
49+
uc = lineColor ? Color.addOpacity(lineColor, DESELECTDIM) : undefined;
4550
}
46-
if(uw === undefined) uw = line.width;
47-
Drawing.lineGroupStyle(path, uw, uc, line.dash);
51+
if(uw === undefined) uw = markerLine.width;
52+
Drawing.lineGroupStyle(path, uw, uc, markerLine.dash);
4853
}
4954
});
5055

5156
Drawing.selectedTextStyle(sel.selectAll('text'), trace);
5257
} else {
5358
sel.selectAll('path.js-line')
54-
.call(Drawing.lineGroupStyle, line.width, line.color, line.dash);
59+
.call(Drawing.lineGroupStyle, markerLine.width, lineColor, markerLine.dash);
5560
Drawing.textPointStyle(sel.selectAll('text'), trace, gd);
5661
}
5762
}

test/image/mocks/quiver_anchor.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"sizemode": "scaled",
1111
"sizeref": 0.5,
1212
"anchor": "tail",
13-
"line": {
13+
"marker": {
1414
"color": "red",
15-
"width": 2
15+
"line": {"width": 2}
1616
},
1717
"xaxis": "x",
1818
"yaxis": "y"
@@ -27,9 +27,9 @@
2727
"sizemode": "scaled",
2828
"sizeref": 0.5,
2929
"anchor": "tip",
30-
"line": {
30+
"marker": {
3131
"color": "blue",
32-
"width": 2
32+
"line": {"width": 2}
3333
},
3434
"xaxis": "x2",
3535
"yaxis": "y2"
@@ -44,9 +44,9 @@
4444
"sizemode": "scaled",
4545
"sizeref": 0.5,
4646
"anchor": "center",
47-
"line": {
47+
"marker": {
4848
"color": "green",
49-
"width": 2
49+
"line": {"width": 2}
5050
},
5151
"xaxis": "x3",
5252
"yaxis": "y3"

test/image/mocks/quiver_arrow-styling.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"sizeref": 0.5,
1212
"arrowsize": 0.5,
1313
"anchor": "tail",
14-
"line": {
14+
"marker": {
1515
"color": "red",
16-
"width": 1
16+
"line": {"width": 1}
1717
}
1818
},
1919
{
@@ -27,9 +27,9 @@
2727
"sizeref": 0.5,
2828
"arrowsize": 1.0,
2929
"anchor": "tail",
30-
"line": {
30+
"marker": {
3131
"color": "blue",
32-
"width": 2
32+
"line": {"width": 2}
3333
}
3434
},
3535
{
@@ -43,9 +43,9 @@
4343
"sizeref": 0.5,
4444
"arrowsize": 2.0,
4545
"anchor": "tail",
46-
"line": {
46+
"marker": {
4747
"color": "green",
48-
"width": 3
48+
"line": {"width": 3}
4949
}
5050
}
5151
],

test/image/mocks/quiver_categorical.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"sizemode": "scaled",
1010
"sizeref": 0.5,
1111
"anchor": "tail",
12-
"line": {
13-
"width": 2
12+
"marker": {
13+
"line": {"width": 2}
1414
}
1515
}
1616
],

test/image/mocks/quiver_colorscale.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
"showscale": true,
1515
"colorbar": {
1616
"title": {"text": "Magnitude"}
17-
}
18-
},
19-
"line": {
20-
"width": 2
17+
},
18+
"line": {"width": 2}
2119
}
2220
}
2321
],

test/image/mocks/quiver_custom-colorscale.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
"colorbar": {
1818
"title": {"text": "Custom Field"},
1919
"x": 1.02
20-
}
20+
},
21+
"line": {"width": 2}
2122
},
2223
"sizemode": "scaled",
2324
"sizeref": 0.25,
24-
"anchor": "tail",
25-
"line": {
26-
"width": 2
27-
}
25+
"anchor": "tail"
2826
}
2927
],
3028
"layout": {

test/image/mocks/quiver_multi-trace.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"sizemode": "scaled",
1111
"sizeref": 0.4,
1212
"anchor": "tail",
13-
"line": {
13+
"marker": {
1414
"color": "red",
15-
"width": 2
15+
"line": {"width": 2}
1616
}
1717
},
1818
{
@@ -25,9 +25,9 @@
2525
"sizemode": "scaled",
2626
"sizeref": 0.4,
2727
"anchor": "tail",
28-
"line": {
28+
"marker": {
2929
"color": "blue",
30-
"width": 2
30+
"line": {"width": 2}
3131
}
3232
}
3333
],

0 commit comments

Comments
 (0)