Skip to content

Commit 6d33eb9

Browse files
committed
revise log format
1 parent 84e74fc commit 6d33eb9

File tree

3 files changed

+86
-37
lines changed

3 files changed

+86
-37
lines changed

src/plots/cartesian/axes.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,18 +1899,30 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {
18991899

19001900
if(tickformat || (dtChar0 === 'L')) {
19011901
out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision);
1902-
} else if(isNumeric(dtick) || ((dtChar0 === 'D') && (Lib.mod(x + 0.01, 1) < 0.1 || ax.minorloglabels === 'complete'))) {
1903-
var p = Math.round(x);
1902+
} else if(isNumeric(dtick) || ((dtChar0 === 'D') &&
1903+
(ax.minorloglabels === 'complete' || Lib.mod(x + 0.01, 1) < 0.1))) {
1904+
1905+
var isMinor;
1906+
if(ax.minorloglabels === 'complete' && !(Lib.mod(x + 0.01, 1) < 0.1)) {
1907+
isMinor = true;
1908+
out.fontSize *= 0.75;
1909+
}
1910+
1911+
var exponentialString = Math.pow(10, x).toExponential(0);
1912+
var parts = exponentialString.split('e');
1913+
1914+
var p = +parts[1];
19041915
var absP = Math.abs(p);
19051916
var exponentFormat = ax.exponentformat;
19061917
if(exponentFormat === 'power' || (isSIFormat(exponentFormat) && beyondSI(p))) {
1907-
if(p === 0) out.text = 1;
1908-
else if(p === 1) out.text = '10';
1909-
else out.text = '10<sup>' + (p > 1 ? '' : MINUS_SIGN) + absP + '</sup>';
1918+
out.text = parts[0];
1919+
if(absP > 0) out.text += 'x10';
1920+
if(out.text === '1x10') out.text = '10';
1921+
if(p !== 0 && p !== 1) out.text += '<sup>' + (p > 0 ? '' : MINUS_SIGN) + absP + '</sup>';
19101922

19111923
out.fontSize *= 1.25;
19121924
} else if((exponentFormat === 'e' || exponentFormat === 'E') && absP > 2) {
1913-
out.text = '1' + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;
1925+
out.text = parts[0] + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;
19141926
} else {
19151927
out.text = numFormat(Math.pow(10, x), ax, '', 'fakehover');
19161928
if(dtick === 'D1' && ax._id.charAt(0) === 'y') {
Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,86 @@
11
{
22
"data": [{
3-
"name": "small digits",
43
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
54
"y": [0, 1, 2, 3, 4, 5, 6]
65
}, {
7-
"name": "complete",
86
"xaxis": "x2",
97
"yaxis": "y2",
108
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
119
"y": [0, 1, 2, 3, 4, 5, 6]
1210
}, {
13-
"name": "none",
1411
"xaxis": "x3",
1512
"yaxis": "y3",
1613
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
1714
"y": [0, 1, 2, 3, 4, 5, 6]
15+
}, {
16+
"xaxis": "x4",
17+
"yaxis": "y4",
18+
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
19+
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
20+
}, {
21+
"xaxis": "x5",
22+
"yaxis": "y5",
23+
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
24+
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
25+
}, {
26+
"xaxis": "x6",
27+
"yaxis": "y6",
28+
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
29+
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1830
}],
1931
"layout": {
2032
"grid": {
21-
"rows": 3,
33+
"rows": 7,
2234
"columns": 1,
23-
"xgap": 0.25,
24-
"ygap": 0.25,
35+
"ygap": 0.8,
2536
"pattern": "independent"
2637
},
2738
"xaxis": {
39+
"title": { "text": "none" },
2840
"type": "log",
29-
"minorloglabels": "small digits"
41+
"minorloglabels": "none",
42+
"minor": { "showgrid": true }
3043
},
3144
"xaxis2": {
45+
"title": { "text": "small digits" },
46+
"dtick": "D1",
3247
"type": "log",
33-
"minorloglabels": "complete"
48+
"minorloglabels": "small digits"
3449
},
3550
"xaxis3": {
51+
"title": { "text": "small digits" },
52+
"dtick": "D2",
53+
"type": "log",
54+
"minorloglabels": "small digits"
55+
},
56+
"xaxis4": {
57+
"title": { "text": "complete" },
58+
"dtick": "D2",
59+
"type": "log",
60+
"minorloglabels": "complete",
61+
"minor": { "showgrid": true }
62+
},
63+
"xaxis5": {
64+
"title": { "text": "complete <br> exponentformat: 'e'" },
65+
"exponentformat": "e",
66+
"dtick": "D2",
67+
"type": "log",
68+
"minorloglabels": "complete",
69+
"minor": { "showgrid": true }
70+
},
71+
"xaxis6": {
72+
"title": { "text": "complete <br> exponentformat: 'power'" },
73+
"exponentformat": "power",
74+
"dtick": "D2",
3675
"type": "log",
37-
"minorloglabels": "none"
76+
"minorloglabels": "complete",
77+
"minor": { "showgrid": true }
3878
},
3979
"title": {
4080
"text": "options of minorloglabels"
4181
},
42-
"width": 1200,
43-
"height": 600
82+
"width": 1400,
83+
"height": 1200,
84+
"showlegend": false
4485
}
4586
}

test/plot-schema.json

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5196,15 +5196,14 @@
51965196
"valType": "number"
51975197
},
51985198
"minorloglabels": {
5199-
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *exponential*, exponential notation is applied. If *scientific*, scientific notation is applied. If *metric*, SI-prefix with one significant digits are displayed.",
5200-
"dflt": "small digits",
5199+
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
5200+
"dflt": "metric",
52015201
"editType": "plot",
52025202
"valType": "enumerated",
52035203
"values": [
52045204
"small digits",
5205-
"exponential",
5206-
"scientific",
5207-
"metric"
5205+
"complete",
5206+
"none"
52085207
]
52095208
},
52105209
"nticks": {
@@ -5905,15 +5904,14 @@
59055904
"valType": "number"
59065905
},
59075906
"minorloglabels": {
5908-
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *exponential*, exponential notation is applied. If *scientific*, scientific notation is applied. If *metric*, SI-prefix with one significant digits are displayed.",
5909-
"dflt": "small digits",
5907+
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
5908+
"dflt": "metric",
59105909
"editType": "plot",
59115910
"valType": "enumerated",
59125911
"values": [
59135912
"small digits",
5914-
"exponential",
5915-
"scientific",
5916-
"metric"
5913+
"complete",
5914+
"none"
59175915
]
59185916
},
59195917
"nticks": {
@@ -13930,15 +13928,14 @@
1393013928
}
1393113929
},
1393213930
"minorloglabels": {
13933-
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *exponential*, exponential notation is applied. If *scientific*, scientific notation is applied. If *metric*, SI-prefix with one significant digits are displayed.",
13934-
"dflt": "small digits",
13931+
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
13932+
"dflt": "metric",
1393513933
"editType": "calc",
1393613934
"valType": "enumerated",
1393713935
"values": [
1393813936
"small digits",
13939-
"exponential",
13940-
"scientific",
13941-
"metric"
13937+
"complete",
13938+
"none"
1394213939
]
1394313940
},
1394413941
"mirror": {
@@ -15503,15 +15500,14 @@
1550315500
}
1550415501
},
1550515502
"minorloglabels": {
15506-
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *exponential*, exponential notation is applied. If *scientific*, scientific notation is applied. If *metric*, SI-prefix with one significant digits are displayed.",
15507-
"dflt": "small digits",
15503+
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
15504+
"dflt": "metric",
1550815505
"editType": "calc",
1550915506
"valType": "enumerated",
1551015507
"values": [
1551115508
"small digits",
15512-
"exponential",
15513-
"scientific",
15514-
"metric"
15509+
"complete",
15510+
"none"
1551515511
]
1551615512
},
1551715513
"mirror": {

0 commit comments

Comments
 (0)