Skip to content

Commit 0dd5467

Browse files
authored
Merge pull request #5326 from plotly/date-head-label-on-sides
Position the head of dates for ticklabels in respect to axis side and ticklabelposition on x-axis
2 parents 4e00196 + d67eda2 commit 0dd5467

File tree

7 files changed

+112
-3
lines changed

7 files changed

+112
-3
lines changed

src/plots/cartesian/axes.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1445,9 +1445,23 @@ function formatDate(ax, out, hover, extraPrecision) {
14451445
// except for year headPart: turn this into "Jan 1, 2000" etc.
14461446
if(tr === 'd') dateStr += ', ' + headStr;
14471447
else dateStr = headStr + (dateStr ? ', ' + dateStr : '');
1448-
} else if(!ax._inCalcTicks || (headStr !== ax._prevDateHead)) {
1449-
dateStr += '<br>' + headStr;
1450-
ax._prevDateHead = headStr;
1448+
} else {
1449+
if(
1450+
!ax._inCalcTicks ||
1451+
ax._prevDateHead !== headStr
1452+
) {
1453+
ax._prevDateHead = headStr;
1454+
dateStr += '<br>' + headStr;
1455+
} else {
1456+
var isInside = (ax.ticklabelposition || '').indexOf('inside') !== -1;
1457+
var side = ax._realSide || ax.side; // polar mocks the side of the radial axis
1458+
if(
1459+
(!isInside && side === 'top') ||
1460+
(isInside && side === 'bottom')
1461+
) {
1462+
dateStr += '<br> ';
1463+
}
1464+
}
14511465
}
14521466
}
14531467

src/plots/polar/polar.js

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ proto.updateLayout = function(fullLayout, polarLayout) {
255255
counterclockwise: 'top',
256256
clockwise: 'bottom'
257257
}[radialLayout.side],
258+
// keep track of real side
259+
_realSide: radialLayout.side,
258260
// spans length 1 radius
259261
domain: [innerRadius / gs.w, radius / gs.w]
260262
});
40.4 KB
Loading
-96 Bytes
Loading
239 Bytes
Loading
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
"1900-01-01",
6+
"2000-01-01",
7+
"2100-01-01"
8+
],
9+
"y": [1, 3, 2]
10+
},
11+
{
12+
"x": [
13+
"2013-05-01",
14+
"2013-09-01",
15+
"2014-01-01"
16+
],
17+
"y": [1, 3, 2],
18+
"xaxis": "x2",
19+
"yaxis": "y2"
20+
},
21+
{
22+
"x": [
23+
"2013-11-17",
24+
"2013-12-15",
25+
"2014-01-12"
26+
],
27+
"y": [1, 3, 2],
28+
"xaxis": "x3",
29+
"yaxis": "y3"
30+
},
31+
{
32+
"x": [
33+
"2013-01-01",
34+
"2013-01-02",
35+
"2013-01-03"
36+
],
37+
"y": [1, 3, 2],
38+
"xaxis": "x4",
39+
"yaxis": "y4"
40+
},
41+
{
42+
"x": [
43+
"2013-07-01 18:00",
44+
"2013-07-02 00:00",
45+
"2013-07-02 06:00"
46+
],
47+
"y": [1, 3, 2],
48+
"xaxis": "x5",
49+
"yaxis": "y5"
50+
},
51+
{
52+
"x": [
53+
"2013-01-01 23:59",
54+
"2013-01-02 00:00",
55+
"2013-01-02 00:01"
56+
],
57+
"y": [1, 3, 2],
58+
"xaxis": "x6",
59+
"yaxis": "y6"
60+
},
61+
{
62+
"x": [
63+
"2013-07-01 23:59:59",
64+
"2013-07-02 00:00:00",
65+
"2013-07-02 00:00:01"
66+
],
67+
"y": [1, 3, 2],
68+
"xaxis": "x7",
69+
"yaxis": "y7"
70+
}
71+
],
72+
"layout": {
73+
"showlegend": false,
74+
"width": 600,
75+
"height": 500,
76+
"yaxis": {"domain": [0, 0.04]},
77+
"yaxis2": {"domain": [0.16, 0.2]},
78+
"yaxis3": {"domain": [0.32, 0.36]},
79+
"yaxis4": {"domain": [0.48, 0.52]},
80+
"yaxis5": {"domain": [0.64, 0.68]},
81+
"yaxis6": {"domain": [0.80, 0.84]},
82+
"yaxis7": {"domain": [0.96, 1]},
83+
"xaxis": {"side": "top"},
84+
"xaxis2": {"side": "top", "anchor": "y2"},
85+
"xaxis3": {"side": "top", "anchor": "y3"},
86+
"xaxis4": {"side": "top", "anchor": "y4"},
87+
"xaxis5": {"side": "top", "anchor": "y5"},
88+
"xaxis6": {"side": "top", "anchor": "y6"},
89+
"xaxis7": {"side": "top", "anchor": "y7"}
90+
}
91+
}

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ var list = [
261261
'custom_colorscale',
262262
'custom_size_subplot',
263263
'date_axes',
264+
'date_axes_side_top',
264265
'date_axes_period',
265266
'date_axes_period2',
266267
'date_axes_period_breaks_automargin',
@@ -1348,6 +1349,7 @@ figs['contour-heatmap-coloring-set-contours'] = require('@mocks/contour-heatmap-
13481349
figs['custom_colorscale'] = require('@mocks/custom_colorscale');
13491350
figs['custom_size_subplot'] = require('@mocks/custom_size_subplot');
13501351
figs['date_axes'] = require('@mocks/date_axes');
1352+
figs['date_axes_side_top'] = require('@mocks/date_axes_side_top');
13511353
figs['date_axes_period'] = require('@mocks/date_axes_period');
13521354
figs['date_axes_period2'] = require('@mocks/date_axes_period2');
13531355
figs['date_axes_period_breaks_automargin'] = require('@mocks/date_axes_period_breaks_automargin');

0 commit comments

Comments
 (0)