Skip to content

Commit 51b5c25

Browse files
authored
Merge pull request #3408 from plotly/fix3392-errorbars-inherit-color2
Errorbars inherit color from line or marker color
2 parents c2cded4 + 9a69c79 commit 51b5c25

17 files changed

+397
-13
lines changed

src/traces/bar/defaults.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7070

7171
handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
7272

73+
var lineColor = (traceOut.marker.line || {}).color;
74+
7375
// override defaultColor for error bars with defaultLine
7476
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
75-
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
76-
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
77+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'y'});
78+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'x', inherit: 'y'});
7779

7880
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
7981
};

src/traces/histogram/defaults.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
6262

6363
handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
6464

65+
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
66+
67+
var lineColor = (traceOut.marker.line || {}).color;
68+
6569
// override defaultColor for error bars with defaultLine
6670
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
67-
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
68-
errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
69-
70-
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
71+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'y'});
72+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || Color.defaultLine, {axis: 'x', inherit: 'y'});
7173
};

src/traces/scatter/defaults.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
7171
if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);
7272
}
7373

74+
var lineColor = (traceOut.line || {}).color;
75+
var markerColor = (traceOut.marker || {}).color;
76+
7477
if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
7578
dfltHoverOn.push('fills');
7679
}
7780
coerce('hoveron', dfltHoverOn.join('+') || 'points');
7881
if(traceOut.hoveron !== 'fills') coerce('hovertemplate');
7982
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
80-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y'});
81-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'y'});
83+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y'});
84+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'y'});
8285

8386
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
8487
};

src/traces/scatter3d/defaults.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
6262
}
6363

6464
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
65-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'z'});
66-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y', inherit: 'z'});
67-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'z'});
65+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'z'});
66+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y', inherit: 'z'});
67+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'z'});
6868
};
6969

7070
function handleXYZDefaults(traceIn, traceOut, coerce, layout) {

src/traces/scattergl/defaults.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5555
handleTextDefaults(traceIn, traceOut, layout, coerce);
5656
}
5757

58+
var lineColor = (traceOut.line || {}).color;
59+
var markerColor = (traceOut.marker || {}).color;
60+
5861
coerce('fill');
5962
if(traceOut.fill !== 'none') {
6063
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
6164
}
6265

6366
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
64-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y'});
65-
errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'y'});
67+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'y'});
68+
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {axis: 'x', inherit: 'y'});
6669

6770
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
6871
};
Loading

test/image/baselines/benchmarks.png

57 Bytes
Loading
1 Byte
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"data": [
3+
{
4+
"x": [0, 1, 2, 3, 4],
5+
"y": [0, 100, 500, 600, 0],
6+
"type": "bar",
7+
"barmode": "group",
8+
"error_y": {
9+
"type": "sqrt"
10+
}
11+
},
12+
{
13+
"x": [0, 1, 2, 3, 4],
14+
"y": [100, 200, 600, 700, 100],
15+
"type": "bar",
16+
"barmode": "group",
17+
"marker": {
18+
"line": {
19+
"width": 2,
20+
"color": "gray"
21+
}
22+
},
23+
"error_y": {
24+
"type": "sqrt"
25+
}
26+
},
27+
{
28+
"x": [0, 1, 2, 3, 4],
29+
"y": [200, 300, 700, 800, 200],
30+
"type": "bar",
31+
"barmode": "group",
32+
"marker": {
33+
"color": "yellow"
34+
},
35+
"error_y": {
36+
"type": "sqrt"
37+
}
38+
},
39+
{
40+
"x": [0, 1, 2, 3, 4],
41+
"y": [300, 400, 800, 900, 300],
42+
"type": "bar",
43+
"barmode": "group",
44+
"marker": {
45+
"line": {
46+
"color": "green"
47+
}
48+
},
49+
"error_y": {
50+
"type": "sqrt"
51+
}
52+
},
53+
{
54+
"x": [0, 1, 2, 3, 4],
55+
"y": [400, 500, 900, 1000, 400],
56+
"type": "bar",
57+
"barmode": "group",
58+
"marker": {
59+
"line": {
60+
"color": "blue"
61+
},
62+
"color": "black"
63+
},
64+
"error_y": {
65+
"type": "sqrt"
66+
}
67+
}
68+
],
69+
"layout": {
70+
"width": 600,
71+
"heigh": 600,
72+
"title": {
73+
"text": "Bar chart error bars inherit color from marker.line not marker"
74+
}
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"data": [
3+
{
4+
"x": [0, 1, 2, 3, 4],
5+
"y": [0, 100, 500, 600, 0],
6+
"type": "scattergl",
7+
"mode": "markers+lines",
8+
"error_y": {
9+
"type": "sqrt"
10+
}
11+
},
12+
{
13+
"x": [0, 1, 2, 3, 4],
14+
"y": [100, 200, 600, 700, 100],
15+
"type": "scattergl",
16+
"mode": "markers+lines",
17+
"marker": {
18+
"line": {
19+
"width": 2,
20+
"color": "gray"
21+
}
22+
},
23+
"error_y": {
24+
"type": "sqrt"
25+
}
26+
},
27+
{
28+
"x": [0, 1, 2, 3, 4],
29+
"y": [200, 300, 700, 800, 200],
30+
"type": "scattergl",
31+
"mode": "markers+lines",
32+
"marker": {
33+
"color": "red"
34+
},
35+
"error_y": {
36+
"type": "sqrt"
37+
}
38+
},
39+
{
40+
"x": [0, 1, 2, 3, 4],
41+
"y": [300, 400, 800, 900, 300],
42+
"type": "scattergl",
43+
"mode": "markers+lines",
44+
"line": {
45+
"color": "green"
46+
},
47+
"error_y": {
48+
"type": "sqrt"
49+
}
50+
},
51+
{
52+
"x": [0, 1, 2, 3, 4],
53+
"y": [400, 500, 900, 1000, 400],
54+
"type": "scattergl",
55+
"mode": "markers+lines",
56+
"line": {
57+
"color": "blue"
58+
},
59+
"marker": {
60+
"color": "black"
61+
},
62+
"error_y": {
63+
"type": "sqrt"
64+
}
65+
}
66+
],
67+
"layout": {
68+
"width": 600,
69+
"heigh": 600,
70+
"title": {
71+
"text": "Scatter-gl error bars inherit color from line or marker"
72+
}
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"data": [
3+
{
4+
"x": [0, 1, 2, 3, 4],
5+
"y": [-5, -10, -30, -35, -5],
6+
"z": [0, 0, 0, 0, 0],
7+
"type": "scatter3d",
8+
"mode": "markers+lines",
9+
"error_y": {
10+
"type": "sqrt"
11+
}
12+
},
13+
{
14+
"x": [0, 1, 2, 3, 4],
15+
"y": [-5, -10, -30, -35, -5],
16+
"z": [1, 1, 1, 1, 1],
17+
"type": "scatter3d",
18+
"mode": "markers+lines",
19+
"marker": {
20+
"line": {
21+
"width": 2,
22+
"color": "gray"
23+
}
24+
},
25+
"error_y": {
26+
"type": "sqrt"
27+
}
28+
},
29+
{
30+
"x": [0, 1, 2, 3, 4],
31+
"y": [-5, -10, -30, -35, -5],
32+
"z": [2, 2, 2, 2, 2],
33+
"type": "scatter3d",
34+
"mode": "markers+lines",
35+
"marker": {
36+
"color": "red"
37+
},
38+
"error_y": {
39+
"type": "sqrt"
40+
}
41+
},
42+
{
43+
"x": [0, 1, 2, 3, 4],
44+
"y": [-5, -10, -30, -35, -5],
45+
"z": [3, 3, 3, 3, 3],
46+
"type": "scatter3d",
47+
"mode": "markers+lines",
48+
"line": {
49+
"color": "green"
50+
},
51+
"error_y": {
52+
"type": "sqrt"
53+
}
54+
},
55+
{
56+
"x": [0, 1, 2, 3, 4],
57+
"y": [-5, -10, -30, -35, -5],
58+
"z": [4, 4, 4, 4, 4],
59+
"type": "scatter3d",
60+
"mode": "markers+lines",
61+
"line": {
62+
"color": "blue"
63+
},
64+
"marker": {
65+
"color": "black"
66+
},
67+
"error_y": {
68+
"type": "sqrt"
69+
}
70+
}
71+
],
72+
"layout": {
73+
"width": 600,
74+
"heigh": 600,
75+
"title": {
76+
"text": "Scatter3d error bars inherit color from line or marker"
77+
}
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"data": [
3+
{
4+
"x": [0, 1, 5, 6, 0],
5+
"type": "histogram",
6+
"barmode": "stack",
7+
"error_y": {
8+
"type": "sqrt"
9+
}
10+
},
11+
{
12+
"x": [1, 2, 6, 7, 1],
13+
"type": "histogram",
14+
"barmode": "stack",
15+
"marker": {
16+
"line": {
17+
"width": 2,
18+
"color": "gray"
19+
}
20+
},
21+
"error_y": {
22+
"type": "sqrt"
23+
}
24+
},
25+
{
26+
"x": [2, 3, 7, 8, 2],
27+
"type": "histogram",
28+
"barmode": "stack",
29+
"marker": {
30+
"color": "yellow"
31+
},
32+
"error_y": {
33+
"type": "sqrt"
34+
}
35+
},
36+
{
37+
"x": [3, 4, 8, 9, 3],
38+
"type": "histogram",
39+
"barmode": "stack",
40+
"marker": {
41+
"line": {
42+
"color": "green"
43+
}
44+
},
45+
"error_y": {
46+
"type": "sqrt"
47+
}
48+
},
49+
{
50+
"x": [4, 5, 9, 10, 4],
51+
"type": "histogram",
52+
"barmode": "stack",
53+
"marker": {
54+
"line": {
55+
"color": "blue"
56+
},
57+
"color": "black"
58+
},
59+
"error_y": {
60+
"type": "sqrt"
61+
}
62+
}
63+
],
64+
"layout": {
65+
"width": 600,
66+
"heigh": 600,
67+
"title": {
68+
"text": "Histogram error bars inherit color from marker.line not marker"
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)