Skip to content

Commit bddaafa

Browse files
committed
allow template input in Lib.coerce2 - fix issue 4852
- set axes tickcolor, tickwidth & tiklen via template
1 parent 2d6cf3d commit bddaafa

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed

src/lib/coerce.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dfl
412412
var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
413413
var valIn = propIn.get();
414414

415+
var attr = attributes[attribute];
416+
var theDefault = (dflt !== undefined) ? dflt : (attr || {}).dflt;
417+
if(
418+
theDefault !== undefined &&
419+
theDefault !== propOut
420+
) {
421+
return propOut;
422+
}
423+
415424
return (valIn !== undefined && valIn !== null) ? propOut : false;
416425
};
417426

test/image/mocks/axes_custom-ticks_log-date.json

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,48 @@
1515
"layout": {
1616
"width": 500,
1717
"height": 300,
18-
"title": {
19-
"text": "custom ticks on date & log axes"
20-
},
21-
"paper_bgcolor": "lightblue",
22-
"plot_bgcolor": "#ddd",
23-
"yaxis": {
24-
"type": "log",
25-
"tickmode": "array",
26-
"tickvals": [
27-
1,
28-
10,
29-
100
30-
],
31-
"ticktext": [
32-
"one",
33-
"ten",
34-
"one<br>hundred"
35-
],
36-
"gridwidth": 2,
37-
"tickwidth": 15,
38-
"tickcolor": "green",
39-
"gridcolor": "green"
40-
},
41-
"xaxis": {
42-
"type": "date",
43-
"tickmode": "array",
44-
"tickvals": [
45-
"2010-01-16",
46-
"2010-02-14"
47-
],
48-
"ticktext": [
49-
"Jan 16",
50-
"Feb 14"
51-
],
52-
"gridwidth": 10,
53-
"tickwidth": 50,
54-
"tickcolor": "rgba(255,0,0,0.75)",
55-
"gridcolor": "rgba(255,0,0,0.25)"
18+
"template": {
19+
"layout": {
20+
"title": {
21+
"text": "custom ticks on date & log axes"
22+
},
23+
"paper_bgcolor": "lightblue",
24+
"plot_bgcolor": "#ddd",
25+
"yaxis": {
26+
"type": "log",
27+
"tickmode": "array",
28+
"tickvals": [
29+
1,
30+
10,
31+
100
32+
],
33+
"ticktext": [
34+
"one",
35+
"ten",
36+
"one<br>hundred"
37+
],
38+
"gridwidth": 2,
39+
"tickwidth": 15,
40+
"tickcolor": "green",
41+
"gridcolor": "green"
42+
},
43+
"xaxis": {
44+
"type": "date",
45+
"tickmode": "array",
46+
"tickvals": [
47+
"2010-01-16",
48+
"2010-02-14"
49+
],
50+
"ticktext": [
51+
"Jan 16",
52+
"Feb 14"
53+
],
54+
"gridwidth": 10,
55+
"tickwidth": 50,
56+
"tickcolor": "rgba(255,0,0,0.75)",
57+
"gridcolor": "rgba(255,0,0,0.25)"
58+
}
59+
}
5660
}
5761
}
5862
}

0 commit comments

Comments
 (0)