Skip to content

Commit 8db1646

Browse files
authored
Merge pull request #6144 from njwhite/dev-griddash
`griddash`
2 parents 45a1d0f + 0bafc90 commit 8db1646

19 files changed

+547
-9
lines changed

draftlogs/6144_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add `griddash` axis property to cartesian, polar, smith, ternary and geo subplots and add `griddash` and `minorgriddash` to `carpet` trace [[6144](https://github.com/plotly/plotly.js/pull/6144)], with thanks to @njwhite for the contribution!

src/plots/cartesian/axes.js

+2
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,7 @@ axes.drawTicks = function(gd, ax, opts) {
28692869
* - {boolean} showgrid
28702870
* - {string} gridcolor
28712871
* - {string} gridwidth
2872+
* - {string} griddash
28722873
* - {boolean} zeroline
28732874
* - {string} type
28742875
* - {string} dtick
@@ -2918,6 +2919,7 @@ axes.drawGrid = function(gd, ax, opts) {
29182919
grid.attr('transform', opts.transFn)
29192920
.attr('d', opts.path)
29202921
.call(Color.stroke, ax.gridcolor || '#ddd')
2922+
.style('stroke-dasharray', Drawing.dashStyle(ax.griddash, ax.gridwidth))
29212923
.style('stroke-width', ax._gw + 'px')
29222924
.style('display', null); // visible
29232925

src/plots/cartesian/layout_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ module.exports = {
797797
editType: 'ticks',
798798
description: 'Sets the width (in px) of the grid lines.'
799799
},
800+
griddash: extendFlat({}, dash, {editType: 'ticks'}),
800801
zeroline: {
801802
valType: 'boolean',
802803
editType: 'ticks',

src/plots/cartesian/line_grid_defaults.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ module.exports = function handleLineGridDefaults(containerIn, containerOut, coer
3535
var gridColorDflt = colorMix(dfltColor, opts.bgColor, opts.blend || lightFraction).toRgbString();
3636
var gridColor = coerce2('gridcolor', gridColorDflt);
3737
var gridWidth = coerce2('gridwidth');
38-
var showGridLines = coerce('showgrid', opts.showGrid || !!gridColor || !!gridWidth);
38+
var gridDash = coerce2('griddash');
39+
var showGridLines = coerce('showgrid', opts.showGrid || !!gridColor || !!gridWidth || !!gridDash);
3940

4041
if(!showGridLines) {
4142
delete containerOut.gridcolor;
4243
delete containerOut.gridwidth;
44+
delete containerOut.griddash;
4345
}
4446

4547
if(!opts.noZeroLine) {

src/plots/geo/geo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ proto.updateBaseLayers = function(fullLayout, geoLayout) {
367367
} else if(isAxisLayer(d)) {
368368
path.datum(makeGraticule(d, geoLayout, fullLayout))
369369
.call(Color.stroke, geoLayout[d].gridcolor)
370-
.call(Drawing.dashLine, '', geoLayout[d].gridwidth);
370+
.call(Drawing.dashLine, geoLayout[d].griddash, geoLayout[d].gridwidth);
371371
}
372372

373373
if(isLineLayer(d)) {

src/plots/geo/layout_attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var colorAttrs = require('../../components/color/attributes');
44
var domainAttrs = require('../domain').attributes;
5+
var dash = require('../../components/drawing/attributes').dash;
56
var constants = require('./constants');
67
var overrideAll = require('../../plot_api/edit_types').overrideAll;
78
var sortObjectKeys = require('../../lib/sort_object_keys');
@@ -50,7 +51,8 @@ var geoAxesAttrs = {
5051
description: [
5152
'Sets the graticule\'s stroke width (in px).'
5253
].join(' ')
53-
}
54+
},
55+
griddash: dash
5456
};
5557

5658
var attrs = module.exports = overrideAll({

src/plots/geo/layout_defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
8787
if(show) {
8888
coerce(axisName + '.gridcolor');
8989
coerce(axisName + '.gridwidth');
90+
coerce(axisName + '.griddash');
9091
}
9192

9293
// mock axis for autorange computations

src/plots/polar/layout_attributes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var axisLineGridAttr = overrideAll({
1313
linewidth: axesAttrs.linewidth,
1414
showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),
1515
gridcolor: axesAttrs.gridcolor,
16-
gridwidth: axesAttrs.gridwidth
16+
gridwidth: axesAttrs.gridwidth,
17+
griddash: axesAttrs.griddash
1718

1819
// TODO add spike* attributes down the road
1920

src/plots/smith/layout_attributes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var axisLineGridAttr = overrideAll({
1313
linewidth: axesAttrs.linewidth,
1414
showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),
1515
gridcolor: axesAttrs.gridcolor,
16-
gridwidth: axesAttrs.gridwidth
16+
gridwidth: axesAttrs.gridwidth,
17+
griddash: axesAttrs.griddash
1718
}, 'plot', 'from-root');
1819

1920
var axisTickAttrs = overrideAll({

src/plots/ternary/layout_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var ternaryAxesAttrs = {
4747
showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),
4848
gridcolor: axesAttrs.gridcolor,
4949
gridwidth: axesAttrs.gridwidth,
50+
griddash: axesAttrs.griddash,
5051
layer: axesAttrs.layer,
5152
// range
5253
min: {

src/traces/carpet/axis_attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var colorAttrs = require('../../components/color/attributes');
55
var axesAttrs = require('../../plots/cartesian/layout_attributes');
66
var descriptionWithDates = require('../../plots/cartesian/axis_format_attributes').descriptionWithDates;
77
var overrideAll = require('../../plot_api/edit_types').overrideAll;
8+
var dash = require('../../components/drawing/attributes').dash;
9+
var extendFlat = require('../../lib/extend').extendFlat;
10+
811

912
module.exports = {
1013
color: {
@@ -359,6 +362,7 @@ module.exports = {
359362
editType: 'calc',
360363
description: 'Sets the width (in px) of the axis line.'
361364
},
365+
griddash: extendFlat({}, dash, {editType: 'calc'}),
362366
showgrid: {
363367
valType: 'boolean',
364368
dflt: true,
@@ -382,6 +386,7 @@ module.exports = {
382386
editType: 'calc',
383387
description: 'Sets the width (in px) of the grid lines.'
384388
},
389+
minorgriddash: extendFlat({}, dash, {editType: 'calc'}),
385390
minorgridcolor: {
386391
valType: 'color',
387392
dflt: colorAttrs.lightLine,

src/traces/carpet/axis_defaults.js

+5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
138138

139139
var gridColor = coerce2('gridcolor', addOpacity(dfltColor, 0.3));
140140
var gridWidth = coerce2('gridwidth');
141+
var gridDash = coerce2('griddash');
141142
var showGrid = coerce('showgrid');
142143

143144
if(!showGrid) {
144145
delete containerOut.gridcolor;
145146
delete containerOut.gridwidth;
147+
delete containerOut.griddash;
146148
}
147149

148150
var startLineColor = coerce2('startlinecolor', dfltColor);
@@ -166,13 +168,16 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, options)
166168
if(!showGrid) {
167169
delete containerOut.gridcolor;
168170
delete containerOut.gridwidth;
171+
delete containerOut.griddash;
169172
} else {
170173
coerce('minorgridcount');
171174
coerce('minorgridwidth', gridWidth);
175+
coerce('minorgriddash', gridDash);
172176
coerce('minorgridcolor', addOpacity(gridColor, 0.06));
173177

174178
if(!containerOut.minorgridcount) {
175179
delete containerOut.minorgridwidth;
180+
delete containerOut.minorgriddash;
176181
delete containerOut.minorgridcolor;
177182
}
178183
}

src/traces/carpet/calc_gridlines.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ module.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {
225225
if(j < 0 || j > data.length - 1) continue;
226226
gridlines.push(extendFlat(constructArrayGridline(j), {
227227
color: axis.gridcolor,
228-
width: axis.gridwidth
228+
width: axis.gridwidth,
229+
dash: axis.griddash
229230
}));
230231
}
231232

@@ -256,7 +257,8 @@ module.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {
256257
if(v < data[0] || v > data[data.length - 1]) continue;
257258
minorgridlines.push(extendFlat(constructValueGridline(v), {
258259
color: axis.minorgridcolor,
259-
width: axis.minorgridwidth
260+
width: axis.minorgridwidth,
261+
dash: axis.minorgriddash
260262
}));
261263
}
262264
}
@@ -299,7 +301,8 @@ module.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {
299301

300302
gridlines.push(extendFlat(constructValueGridline(value), {
301303
color: axis.gridcolor,
302-
width: axis.gridwidth
304+
width: axis.gridwidth,
305+
dash: axis.griddash
303306
}));
304307
}
305308

@@ -311,7 +314,8 @@ module.exports = function calcGridlines(trace, axisLetter, crossAxisLetter) {
311314
if(v < data[0] || v > data[data.length - 1]) continue;
312315
minorgridlines.push(extendFlat(constructValueGridline(v), {
313316
color: axis.minorgridcolor,
314-
width: axis.minorgridwidth
317+
width: axis.minorgridwidth,
318+
dash: axis.minorgriddash
315319
}));
316320
}
317321
}

src/traces/carpet/plot.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function drawGridLines(xaxis, yaxis, layer, axis, axisLetter, gridlines) {
102102
el.attr('d', path)
103103
.style('stroke-width', gridline.width)
104104
.style('stroke', gridline.color)
105+
.style('stroke-dasharray', Drawing.dashStyle(gridline.dash, gridline.width))
105106
.style('fill', 'none');
106107
});
107108

31.2 KB
Loading
Loading
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"data": [
3+
{
4+
"type": "carpet",
5+
"a": [
6+
0,
7+
5e-07,
8+
1e-06
9+
],
10+
"b": [
11+
0,
12+
500000,
13+
1000000
14+
],
15+
"y": [
16+
[
17+
1,
18+
1.32287,
19+
1.73205
20+
],
21+
[
22+
1.32287,
23+
1.58113,
24+
1.93649
25+
],
26+
[
27+
1.73205,
28+
1.93649,
29+
2.23606
30+
]
31+
],
32+
"aaxis": {
33+
"minorgridcount": 3,
34+
"gridcolor": "black",
35+
"minorgridcolor": "red",
36+
"griddash": "dot",
37+
"minorgriddash": "dash"
38+
},
39+
"baxis": {
40+
"minorgridcount": 3,
41+
"gridcolor": "black",
42+
"minorgridcolor": "red",
43+
"griddash": "dash",
44+
"minorgriddash": "dot"
45+
}
46+
}
47+
],
48+
"layout": {
49+
"width": 500,
50+
"height": 500,
51+
"margin": {
52+
"t": 40,
53+
"r": 20,
54+
"b": 40,
55+
"l": 40
56+
},
57+
"dragmode": "pan"
58+
}
59+
}

0 commit comments

Comments
 (0)