Skip to content

Commit d1258b6

Browse files
committed
Merge pull request #4375 from plotly/fix_improve_supply_dflts_for_grid
Fix improve supply dflts for grid
2 parents f6b476f + 0188a4d commit d1258b6

File tree

8 files changed

+252
-18
lines changed

8 files changed

+252
-18
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"y": [
5+
-5,
6+
-1,
7+
1
8+
],
9+
"x": [
10+
-1,
11+
0,
12+
1
13+
],
14+
"uid": "e95128"
15+
}
16+
],
17+
"layout": {
18+
"xaxis": {
19+
"linecolor": "rgb(10, 10, 10)",
20+
"gridcolor": "rgb(200, 200, 200)",
21+
"zerolinecolor": "rgb(10, 10, 10)",
22+
"type": "linear",
23+
"range": [
24+
-1.122244488977956,
25+
1.122244488977956
26+
],
27+
"autorange": true
28+
},
29+
"yaxis": {
30+
"linecolor": "rgb(10, 10, 10)",
31+
"gridcolor": "rgb(200, 200, 200)",
32+
"zerolinecolor": "rgb(10, 10, 10)",
33+
"type": "linear",
34+
"range": [
35+
-5.439490445859873,
36+
1.4394904458598727
37+
],
38+
"autorange": true
39+
},
40+
"height": 450,
41+
"width": 1000,
42+
"autosize": true
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"y": [
5+
-5,
6+
-1,
7+
1
8+
],
9+
"x": [
10+
-1,
11+
0,
12+
1
13+
],
14+
"uid": "e9539e"
15+
}
16+
],
17+
"layout": {
18+
"xaxis": {
19+
"linewidth": 2,
20+
"gridwidth": 2,
21+
"zerolinewidth": 4,
22+
"type": "linear",
23+
"range": [
24+
-1.122244488977956,
25+
1.122244488977956
26+
],
27+
"autorange": true
28+
},
29+
"yaxis": {
30+
"linewidth": 2,
31+
"gridwidth": 2,
32+
"zerolinewidth": 4,
33+
"type": "linear",
34+
"range": [
35+
-5.439490445859873,
36+
1.4394904458598727
37+
],
38+
"autorange": true
39+
},
40+
"height": 450,
41+
"width": 1000,
42+
"autosize": true
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"y": [
5+
-1,
6+
0,
7+
-2
8+
],
9+
"x": [
10+
1,
11+
2,
12+
3
13+
],
14+
"uid": "02de62"
15+
}
16+
],
17+
"layout": {
18+
"xaxis": {
19+
"tickwidth": 2,
20+
"tickcolor": "blue",
21+
"ticklen": 4,
22+
"type": "linear",
23+
"range": [
24+
0.8777555110220441,
25+
3.122244488977956
26+
],
27+
"autorange": true
28+
},
29+
"yaxis": {
30+
"tickwidth": 2,
31+
"tickcolor": "blue",
32+
"ticklen": 4,
33+
"type": "linear",
34+
"range": [
35+
-2.1464968152866244,
36+
0.1464968152866242
37+
],
38+
"autorange": true
39+
},
40+
"height": 450,
41+
"width": 1000,
42+
"autosize": true
43+
}
44+
}
21.3 KB
Loading
22.3 KB
Loading
23.8 KB
Loading

shelly/plotlyjs/static/plotlyjs/src/axes.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -630,25 +630,35 @@ axes.handleAxisDefaults = function(containerIn, containerOut, coerce, options) {
630630

631631
axes.handleTickDefaults(containerIn, containerOut, coerce, axType, options);
632632

633-
var showLine = coerce('showline');
634-
if(showLine) {
635-
coerce('linecolor');
636-
coerce('linewidth');
633+
634+
635+
var lineColor = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'linecolor'),
636+
lineWidth = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'linewidth'),
637+
showLine = coerce('showline', !!lineColor || !!lineWidth);
638+
639+
if(!showLine) {
640+
delete containerOut.linecolor;
641+
delete containerOut.linewidth;
637642
}
638643

639644
if(showLine || containerOut.ticks) coerce('mirror');
640645

641-
642-
var showGridLines = coerce('showgrid', options.showGrid);
643-
if(showGridLines) {
644-
coerce('gridcolor');
645-
coerce('gridwidth');
646+
var gridColor = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'gridcolor'),
647+
gridWidth = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'gridwidth'),
648+
showGridLines = coerce('showgrid', options.showGrid || !!gridColor || !!gridWidth);
649+
650+
if(!showGridLines) {
651+
delete containerOut.gridcolor;
652+
delete containerOut.gridwidth;
646653
}
647654

648-
var showZeroLine = coerce('zeroline', options.showGrid);
649-
if(showZeroLine) {
650-
coerce('zerolinecolor');
651-
coerce('zerolinewidth');
655+
var zeroLineColor = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'zerolinecolor'),
656+
zeroLineWidth = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'zerolinewidth'),
657+
showZeroLine = coerce('zeroline', options.showGrid || !!zeroLineColor || !!zeroLineWidth);
658+
659+
if(!showZeroLine) {
660+
delete containerOut.zerolinecolor;
661+
delete containerOut.zerolinewidth;
652662
}
653663

654664
return containerOut;
@@ -658,11 +668,14 @@ axes.handleAxisDefaults = function(containerIn, containerOut, coerce, options) {
658668
* options: inherits font, outerTicks, noHover from axes.handleAxisDefaults
659669
*/
660670
axes.handleTickDefaults = function(containerIn, containerOut, coerce, axType, options) {
661-
var showTicks = coerce('ticks', options.outerTicks ? 'outside' : '');
662-
if(showTicks) {
663-
coerce('ticklen');
664-
coerce('tickwidth');
665-
coerce('tickcolor');
671+
var tickLen = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'ticklen'),
672+
tickWidth = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'tickwidth'),
673+
tickColor = Plotly.Lib.coerce2(containerIn, containerOut, axes.layoutAttributes, 'tickcolor'),
674+
showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : '');
675+
if(!showTicks) {
676+
delete containerOut.ticklen;
677+
delete containerOut.tickwidth;
678+
delete containerOut.tickcolor;
666679
}
667680

668681
var showTickLabels = coerce('showticklabels');

shelly/plotlyjs/static/plotlyjs/tests/axes_test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,95 @@ describe('Test axes', function () {
155155
});
156156
});
157157

158+
describe('supplyLayoutDefaults', function() {
159+
var layoutIn = {},
160+
layoutOut = {},
161+
fullData=[];
162+
163+
var supplyLayoutDefaults = Plotly.Axes.supplyLayoutDefaults;
164+
165+
it('should set undefined linewidth/linecolor if linewidth, linecolor or showline is not supplied', function() {
166+
layoutIn = {
167+
xaxis: {},
168+
yaxis: {}
169+
};
170+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
171+
expect(layoutOut.xaxis.linewidth).toBe(undefined);
172+
expect(layoutOut.xaxis.linecolor).toBe(undefined);
173+
expect(layoutOut.yaxis.linewidth).toBe(undefined);
174+
expect(layoutOut.yaxis.linecolor).toBe(undefined);
175+
});
176+
177+
it('should set default linewidth and linecolor if showline is true', function() {
178+
layoutIn = {
179+
xaxis: {showline: true}
180+
};
181+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
182+
expect(layoutOut.xaxis.linewidth).toBe(1);
183+
expect(layoutOut.xaxis.linecolor).toBe(Plotly.Color.defaultLine);
184+
});
185+
186+
it('should set linewidth to default if linecolor is supplied and valid', function() {
187+
layoutIn = {
188+
xaxis: {linecolor:'black'}
189+
};
190+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
191+
expect(layoutOut.xaxis.linecolor).toBe('black');
192+
expect(layoutOut.xaxis.linewidth).toBe(1);
193+
});
194+
195+
it('should set linecolor to default if linewidth is supplied and valid', function() {
196+
layoutIn = {
197+
yaxis: {linewidth:2}
198+
};
199+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
200+
expect(layoutOut.yaxis.linewidth).toBe(2);
201+
expect(layoutOut.yaxis.linecolor).toBe(Plotly.Color.defaultLine);
202+
});
203+
204+
it('should set default gridwidth and gridcolor', function() {
205+
layoutIn = {
206+
xaxis: {},
207+
yaxis: {}
208+
};
209+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
210+
expect(layoutOut.xaxis.gridwidth).toBe(1);
211+
expect(layoutOut.xaxis.gridcolor).toBe(Plotly.Color.lightLine);
212+
expect(layoutOut.yaxis.gridwidth).toBe(1);
213+
expect(layoutOut.yaxis.gridcolor).toBe(Plotly.Color.lightLine);
214+
});
215+
216+
it('should set gridcolor/gridwidth to undefined if showgrid is false', function() {
217+
layoutIn = {
218+
yaxis: {showgrid: false}
219+
};
220+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
221+
expect(layoutOut.yaxis.gridwidth).toBe(undefined);
222+
expect(layoutOut.yaxis.gridcolor).toBe(undefined);
223+
});
224+
225+
it('should set default zerolinecolor/zerolinewidth', function() {
226+
layoutIn = {
227+
xaxis: {},
228+
yaxis: {}
229+
};
230+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
231+
expect(layoutOut.xaxis.zerolinewidth).toBe(1);
232+
expect(layoutOut.xaxis.zerolinecolor).toBe(Plotly.Color.defaultLine);
233+
expect(layoutOut.yaxis.zerolinewidth).toBe(1);
234+
expect(layoutOut.yaxis.zerolinecolor).toBe(Plotly.Color.defaultLine);
235+
});
236+
237+
it('should set zerolinecolor/zerolinewidth to undefined if zeroline is false', function() {
238+
layoutIn = {
239+
xaxis: {zeroline: false}
240+
};
241+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
242+
expect(layoutOut.xaxis.zerolinewidth).toBe(undefined);
243+
expect(layoutOut.xaxis.zerolinecolor).toBe(undefined);
244+
});
245+
});
246+
158247
describe('handleTickValueDefaults', function() {
159248
function handleTickValueDefaults(axIn, axOut, axType) {
160249
function coerce(attr, dflt) {

0 commit comments

Comments
 (0)