Skip to content

Commit 9bcf7e6

Browse files
committed
Add shapes.layer value "belowtraces" for drawing shapes in between gridlines and traces
1 parent baa752d commit 9bcf7e6

File tree

5 files changed

+138
-5
lines changed

5 files changed

+138
-5
lines changed

src/components/shapes/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ module.exports = templatedArray('shape', {
110110

111111
layer: {
112112
valType: 'enumerated',
113-
values: ['below', 'above'],
113+
values: ['below', 'above', 'belowtraces'],
114114
dflt: 'above',
115115
editType: 'arraydraw',
116-
description: 'Specifies whether shapes are drawn below or above traces.'
116+
description: 'Specifies whether shapes are drawn below gridlines (*below*), between gridlines and traces (*belowtraces*) or above traces (*above*).'
117117
},
118118

119119
xref: extendFlat({}, annAttrs.xref, {

src/components/shapes/draw.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ function drawOne(gd, index) {
9191
// TODO: use d3 idioms instead of deleting and redrawing every time
9292
if(!options._input || options.visible !== true) return;
9393

94-
if(options.layer !== 'below') {
94+
if(options.layer === 'above') {
9595
drawShape(gd._fullLayout._shapeUpperLayer);
9696
} else if(options.xref === 'paper' || options.yref === 'paper') {
9797
drawShape(gd._fullLayout._shapeLowerLayer);
98+
} else if(options.layer === 'belowtraces') {
99+
drawShape(plotinfo.shapelayerBelowTraces);
98100
} else {
99101
if(plotinfo._hadPlotinfo) {
100102
var mainPlot = plotinfo.mainplotinfo || plotinfo;

src/plots/cartesian/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ function makeSubplotLayer(gd, plotinfo) {
465465
plotinfo.gridlayer = ensureSingle(plotgroup, 'g', 'gridlayer');
466466
plotinfo.zerolinelayer = ensureSingle(plotgroup, 'g', 'zerolinelayer');
467467

468+
var belowTracesLayer = ensureSingle(plotgroup, 'g', 'layer-below-traces');
469+
plotinfo.shapelayerBelowTraces = ensureSingle(belowTracesLayer, 'g', 'shapelayer');
470+
plotinfo.imagelayerBelowTraces = ensureSingle(belowTracesLayer, 'g', 'imagelayer');
471+
468472
ensureSingle(plotgroup, 'path', 'xlines-below');
469473
ensureSingle(plotgroup, 'path', 'ylines-below');
470474
plotinfo.overlinesBelow = ensureSingle(plotgroup, 'g', 'overlines-below');
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"data": [
3+
{
4+
"name": "scatter",
5+
"x": [
6+
"A",
7+
"B",
8+
"C",
9+
"D",
10+
2000.0
11+
],
12+
"y": [
13+
100,
14+
200,
15+
150,
16+
190,
17+
50
18+
],
19+
"type": "scatter"
20+
},
21+
{
22+
"name": "bar",
23+
"x": [
24+
"A",
25+
"B",
26+
"C",
27+
"D",
28+
2000.0
29+
],
30+
"y": [
31+
50,
32+
70,
33+
90,
34+
35,
35+
55
36+
],
37+
"type": "bar"
38+
}
39+
],
40+
"layout": {
41+
"shapes": [
42+
{
43+
"name": "dashdot line",
44+
"fillcolor": "rgba(179,179,179,0.6)",
45+
"layer": "above",
46+
"line": {
47+
"color": "rgba(66,127,109,0.6)",
48+
"dash": "dashdot"
49+
},
50+
"type": "line",
51+
"x0": 0.75,
52+
"x1": 0.75,
53+
"xref": "x",
54+
"y0": 0.0,
55+
"y1": 1.0,
56+
"yref": "paper"
57+
},
58+
{
59+
"name": "horizontal line",
60+
"fillcolor": "rgba(179,179,179,1)",
61+
"layer": "above",
62+
"line": {
63+
"color": "rgba(0,0,0,1)"
64+
},
65+
"type": "line",
66+
"x0": 0.0,
67+
"x1": 1.0,
68+
"xref": "paper",
69+
"y0": 120.0,
70+
"y1": 120.0,
71+
"yref": "y"
72+
},
73+
{
74+
"name": "blue rect",
75+
"fillcolor": "rgba(108,173,225,0.8)",
76+
"layer": "belowtraces",
77+
"line": {
78+
"color": "rgba(108,173,225,0.8)"
79+
},
80+
"type": "rect",
81+
"x0": "B",
82+
"x1": "D",
83+
"xref": "x",
84+
"y0": 40,
85+
"y1": 70.0
86+
},
87+
{
88+
"name": "big rect",
89+
"fillcolor": "rgba(179,179,179,1)",
90+
"layer": "below",
91+
"line": {
92+
"color": "rgba(179,179,179,1)"
93+
},
94+
"type": "rect",
95+
"x0": "C",
96+
"x1": 0.25,
97+
"xref": "x",
98+
"y0": 0.0,
99+
"y1": 1.0,
100+
"yref": "paper"
101+
},
102+
{
103+
"name": "dashed rect",
104+
"fillcolor": "rgba(130,143,198,1)",
105+
"layer": "belowtraces",
106+
"line": {
107+
"color": "rgba(0,0,0,1)",
108+
"dash": "dash",
109+
"width": 3.0
110+
},
111+
"type": "rect",
112+
"x0": "D",
113+
"x1": 5,
114+
"y0": 140,
115+
"y1": 200
116+
}
117+
],
118+
"yaxis": {
119+
"insiderange": [
120+
"0",
121+
"215"
122+
],
123+
"type": "linear"
124+
}
125+
}
126+
}

test/plot-schema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7708,13 +7708,14 @@
77087708
}
77097709
},
77107710
"layer": {
7711-
"description": "Specifies whether shapes are drawn below or above traces.",
7711+
"description": "Specifies whether shapes are drawn below gridlines (*below*), between gridlines and traces (*belowtraces*) or above traces (*above*).",
77127712
"dflt": "above",
77137713
"editType": "arraydraw",
77147714
"valType": "enumerated",
77157715
"values": [
77167716
"below",
7717-
"above"
7717+
"above",
7718+
"belowtraces"
77187719
]
77197720
},
77207721
"legend": {

0 commit comments

Comments
 (0)