Skip to content
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

Add shapes.layer "between" for drawing between gridlines and traces #6927

Merged
merged 13 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6927_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add `between` shape layer [[#6927](https://github.com/plotly/plotly.js/pull/6927)]
archmoj marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions src/components/shapes/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ module.exports = templatedArray('shape', {

layer: {
valType: 'enumerated',
values: ['below', 'above'],
values: ['below', 'above', 'between'],
archmoj marked this conversation as resolved.
Show resolved Hide resolved
dflt: 'above',
editType: 'arraydraw',
description: 'Specifies whether shapes are drawn below or above traces.'
description: [
'Specifies whether shapes are drawn below gridlines (*below*),',
'between gridlines and traces (*between*) or above traces (*above*).'
].join(' ')
},

xref: extendFlat({}, annAttrs.xref, {
Expand Down
4 changes: 3 additions & 1 deletion src/components/shapes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ function drawOne(gd, index) {
// TODO: use d3 idioms instead of deleting and redrawing every time
if(!options._input || options.visible !== true) return;

if(options.layer !== 'below') {
if(options.layer === 'above') {
drawShape(gd._fullLayout._shapeUpperLayer);
} else if(options.xref === 'paper' || options.yref === 'paper') {
drawShape(gd._fullLayout._shapeLowerLayer);
} else if(options.layer === 'between') {
archmoj marked this conversation as resolved.
Show resolved Hide resolved
drawShape(plotinfo.shapelayerBetween);
} else {
if(plotinfo._hadPlotinfo) {
var mainPlot = plotinfo.mainplotinfo || plotinfo;
Expand Down
7 changes: 5 additions & 2 deletions src/components/shapes/draw_newshape/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ module.exports = overrideAll({
},
layer: {
valType: 'enumerated',
values: ['below', 'above'],
values: ['below', 'above', 'between'],
dflt: 'above',
description: 'Specifies whether new shapes are drawn below or above traces.'
description: [
'Specifies whether new shapes are drawn below gridlines (*below*),',
'between gridlines and traces (*between*) or above traces (*above*).'
].join(' ')
},
drawdirection: {
valType: 'enumerated',
Expand Down
4 changes: 4 additions & 0 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ function makeSubplotLayer(gd, plotinfo) {
plotinfo.gridlayer = ensureSingle(plotgroup, 'g', 'gridlayer');
plotinfo.zerolinelayer = ensureSingle(plotgroup, 'g', 'zerolinelayer');

var betweenLayer = ensureSingle(plotgroup, 'g', 'layer-between');
plotinfo.shapelayerBetween = ensureSingle(betweenLayer, 'g', 'shapelayer');
plotinfo.imagelayerBetween = ensureSingle(betweenLayer, 'g', 'imagelayer');

ensureSingle(plotgroup, 'path', 'xlines-below');
ensureSingle(plotgroup, 'path', 'ylines-below');
plotinfo.overlinesBelow = ensureSingle(plotgroup, 'g', 'overlines-below');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions test/image/mocks/zz-shapes_layer_below_traces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"data": [
{
"name": "scatter",
"x": [
"A",
"B",
"C",
"D",
2000.0
],
"y": [
100,
200,
150,
190,
50
],
"type": "scatter"
},
{
"name": "bar",
"x": [
"A",
"B",
"C",
"D",
2000.0
],
"y": [
50,
70,
90,
35,
55
],
"type": "bar",
"yaxis":"y2"
}
],
"layout": {
"shapes": [
{
"name": "dashdot line",
"fillcolor": "rgba(179,179,179,1)",
"layer": "above",
"line": {
"color": "rgba(66,127,109,1)",
"dash": "dashdot"
},
"type": "line",
"x0": 0.4,
"x1": 0.4,
"xref": "x",
"y0": 0.0,
"y1": 1.0,
"yref": "paper"
},
{
"name": "horizontal line",
"fillcolor": "rgba(179,179,179,1)",
"layer": "above",
"line": {
"color": "rgba(0,0,0,1)"
},
"type": "line",
"x0": 0.0,
"x1": 1.0,
"xref": "paper",
"y0": 120.0,
"y1": 120.0,
"yref": "y"
},
{
"name": "blue rect",
"fillcolor": "rgba(108,173,225,1)",
"layer": "between",
my-tien marked this conversation as resolved.
Show resolved Hide resolved
"label": {
"text": "hello, I am between gridlines and traces!"
},
"line": {
"color": "rgba(108,173,225,1)"
},
"type": "rect",
"x0": "B",
"x1": "D",
"xref": "x",
"y0": 35,
"y1": 65.0
},
{
"name": "big rect",
"fillcolor": "rgba(179,179,179,1)",
"layer": "below",
"line": {
"color": "rgba(179,179,179,1)"
},
"type": "rect",
"x0": "C",
"x1": 0.25,
"xref": "x",
"y0": 0.0,
"y1": 1.0,
"yref": "paper"
},
{
"name": "dashed rect",
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"fillcolor": "rgba(130,143,198,1)",
"layer": "between",
my-tien marked this conversation as resolved.
Show resolved Hide resolved
"line": {
"color": "rgba(0,0,0,1)",
"dash": "dash",
"width": 3.0
},
"type": "rect",
"x0": "D",
"x1": 5,
"y0": 140,
"y1": 200
}
],
"yaxis": {
my-tien marked this conversation as resolved.
Show resolved Hide resolved
"insiderange": [
"0",
"215"
],
"type": "linear"
},
"yaxis2": {
my-tien marked this conversation as resolved.
Show resolved Hide resolved
"side": "right",
"overlaying": "y"
}

}
}
6 changes: 3 additions & 3 deletions test/jasmine/tests/splom_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ describe('Test splom interactions:', function() {
.then(function() {
_assert({
subplotCnt: 25,
innerSubplotNodeCnt: 18,
innerSubplotNodeCnt: 19,
hasSplomGrid: false,
bgCnt: 0
});
Expand All @@ -845,7 +845,7 @@ describe('Test splom interactions:', function() {
// grid layer would be above xaxis layer,
// if we didn't clear subplot children.
expect(gridIndex).toBe(2, '<g.gridlayer> index');
expect(xaxisIndex).toBe(15, '<g.xaxislayer-above> index');
expect(xaxisIndex).toBe(16, '<g.xaxislayer-above> index');

return Plotly.restyle(gd, 'dimensions', [dimsLarge]);
})
Expand All @@ -857,7 +857,7 @@ describe('Test splom interactions:', function() {
// new subplots though have reduced number of children.
innerSubplotNodeCnt: function(d) {
var p = d.match(SUBPLOT_PATTERN);
return (p[1] > 5 || p[2] > 5) ? 4 : 18;
return (p[1] > 5 || p[2] > 5) ? 4 : 19;
},
hasSplomGrid: true,
bgCnt: 0
Expand Down
10 changes: 6 additions & 4 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3720,13 +3720,14 @@
}
},
"layer": {
"description": "Specifies whether new shapes are drawn below or above traces.",
"description": "Specifies whether new shapes are drawn below gridlines (*below*), between gridlines and traces (*between*) or above traces (*above*).",
"dflt": "above",
"editType": "none",
"valType": "enumerated",
"values": [
"below",
"above"
"above",
"between"
]
},
"legend": {
Expand Down Expand Up @@ -7708,13 +7709,14 @@
}
},
"layer": {
"description": "Specifies whether shapes are drawn below or above traces.",
"description": "Specifies whether shapes are drawn below gridlines (*below*), between gridlines and traces (*between*) or above traces (*above*).",
"dflt": "above",
"editType": "arraydraw",
"valType": "enumerated",
"values": [
"below",
"above"
"above",
"between"
]
},
"legend": {
Expand Down