Skip to content

Commit 8b4c2b5

Browse files
committed
do not implement 'date' angular axes (for now)
... but make 'period' work for category angular axes.
1 parent d4c7d2c commit 8b4c2b5

File tree

9 files changed

+122
-53
lines changed

9 files changed

+122
-53
lines changed

src/plots/polar/helpers.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ exports.setConvertAngular = function setConvertAngular(ax) {
1616
var _c2rad;
1717
var _rad2c;
1818

19+
function getTotalNumberOfCategories() {
20+
return ax.period ?
21+
Math.max(ax.period, ax._categories.length) :
22+
ax._categories.length;
23+
}
24+
1925
if(ax.type === 'linear') {
2026
_c2rad = function(v, unit) {
2127
if(unit === 'degrees') return Lib.deg2rad(v);
@@ -28,20 +34,12 @@ exports.setConvertAngular = function setConvertAngular(ax) {
2834
}
2935
else if(ax.type === 'category') {
3036
_c2rad = function(v) {
31-
return v * 2 * Math.PI / ax._categories.length;
32-
};
33-
_rad2c = function(v) {
34-
return v * ax._categories.length / Math.PI / 2;
35-
};
36-
}
37-
else if(ax.type === 'date') {
38-
var period = ax.period || 365 * 24 * 60 * 60 * 1000;
39-
40-
_c2rad = function(v) {
41-
return (v % period) * 2 * Math.PI / period;
37+
var tot = getTotalNumberOfCategories();
38+
return v * 2 * Math.PI / tot;
4239
};
4340
_rad2c = function(v) {
44-
return v * period / Math.PI / 2;
41+
var tot = getTotalNumberOfCategories();
42+
return v * tot / Math.PI / 2;
4543
};
4644
}
4745

src/plots/polar/layout_attributes.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ var angularAxisAttrs = {
147147
// to make clear that axis here is periodic and more tightly match
148148
// `thetaunit`?
149149
//
150+
// skip 'date' for first push
150151
// no 'log' for now
151-
values: ['-', 'linear', 'date', 'category'],
152+
values: ['-', 'linear', 'category'],
152153
dflt: '-',
153154
role: 'info',
154155
editType: 'calc',
155156
description: [
156157
'Sets the angular axis type.',
157158
'If *linear*, set `thetaunit` to determine the unit in which axis value are shown.',
158-
'If *date*, use `period` to set the unit of time that determines a complete rotation',
159159
'If *category, use `period` to set the number of integer coordinates around polar axis.'
160160
].join(' ')
161161
},
@@ -176,17 +176,16 @@ var angularAxisAttrs = {
176176
},
177177

178178
period: {
179-
valType: 'any',
179+
valType: 'number',
180180
editType: 'calc',
181+
min: 0,
181182
role: 'info',
182-
description: ''
183-
184-
// 360 / 2*pi for linear (might not need to set it)
185-
// and to full range for other types
186-
187-
// 'period' is the angular equivalent to 'range'
188-
189-
// similar to dtick, one way to achieve e.g.:
183+
description: [
184+
'Set the angular period.',
185+
'Has an effect only when `angularaxis.type` is *category*.',
186+
].join(' ')
187+
// Examples for date axes:
188+
//
190189
// - period that equals the timeseries length
191190
// http://flowingdata.com/2017/01/24/one-dataset-visualized-25-ways/18-polar-coordinates/
192191
// - and 1-year periods (focusing on seasonal change0

src/plots/polar/layout_defaults.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var Lib = require('../../lib');
1212
var Color = require('../../components/color');
13-
var Registry = require('../../registry');
1413
var handleSubplotDefaults = require('../subplot_defaults');
1514
var getSubplotData = require('../get_data').getSubplotData;
1615

@@ -62,11 +61,6 @@ function handleDefaults(contIn, contOut, coerce, opts) {
6261
orderedCategories(dataAttr, axOut.categoryorder, axOut.categoryarray, subplotData) :
6362
[];
6463

65-
if(axType === 'date') {
66-
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
67-
handleCalendarDefaults(axIn, axOut, 'calendar', layoutOut.calendar);
68-
}
69-
7064
var visible = coerceAxis('visible');
7165
setConvert(axOut, layoutOut);
7266

@@ -113,6 +107,26 @@ function handleDefaults(contIn, contOut, coerce, opts) {
113107
break;
114108

115109
case 'angularaxis':
110+
// We do not support 'true' date angular axes yet,
111+
// users can still plot dates on angular axes by setting
112+
// `angularaxis.type: 'category'`.
113+
//
114+
// Here, if a date angular axes is detected, we make
115+
// all its corresponding traces invisible, so that
116+
// when we do add support for data angular axes, the new
117+
// behavior won't conflict with existing behavior
118+
if(axType === 'date') {
119+
Lib.log('Polar plots do not support date angular axes yet.');
120+
121+
for(var j = 0; j < subplotData.length; j++) {
122+
subplotData[j].visible = false;
123+
}
124+
125+
// turn this into a 'dummy' linear axis so that
126+
// the subplot still renders ok
127+
axType = axIn.type = axOut.type = 'linear';
128+
}
129+
116130
if(axType === 'linear') {
117131
coerceAxis('thetaunit');
118132
} else {
@@ -179,7 +193,6 @@ function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr) {
179193
}
180194
}
181195

182-
// TODO add trace input calendar support
183196
if(trace) {
184197
axOut.type = autoType(trace[dataAttr], 'gregorian');
185198
}

src/plots/polar/polar.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,6 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {
446446
});
447447
};
448448
}
449-
else if(ax.type === 'date') {
450-
// ..
451-
}
452449

453450
setScale(ax, angularLayout, fullLayout);
454451
Axes.doAutoRange(ax);
@@ -977,8 +974,6 @@ proto.isPtWithinSector = function(d) {
977974
r1 = radialRange[0];
978975
}
979976

980-
// TODO add calendar support
981-
982977
return (
983978
(r >= r0 && r <= r1) &&
984979
(isFullCircle(sector) ||
-98 Bytes
Loading
14.1 KB
Loading

test/image/mocks/polar_categories.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"angle": 45
5151
},
5252
"angularaxis": {
53-
"direction": "clockwise"
53+
"direction": "clockwise",
54+
"period": 6
5455
}
5556
},
5657
"polar2": {

test/image/mocks/polar_dates.json

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,48 @@
22
"data": [
33
{
44
"type": "scatterpolar",
5-
"mode": "lines+markers",
6-
"name": "",
7-
"r": [5, 4, 2, 4, 3],
8-
"theta": ["2017-01-01", "2017-04-01", "2017-08-01", "2017-12-01", "2018-01-01"],
5+
"r": [
6+
5, 4, 2, 4, 3,
7+
5, 4, 2, 4,
8+
5, 4, 2, 4, 3
9+
],
10+
"theta": [
11+
"2017-01-01", "2017-04-01", "2017-08-01", "2017-12-01",
12+
"2018-01-01", "2018-03-01", "2018-10-20",
13+
"2019-01-01", "2019-07-09", "2019-08-20", "2019-12-10"
14+
],
915
"line": {
1016
"shape": "spline"
1117
}
12-
},
18+
},
1319
{
14-
"mode": "lines+markers",
15-
"name": "",
16-
"x": [5, 4, 2, 4, 3],
17-
"y": ["2017-01-01", "2017-04-01", "2017-08-01", "2017-12-01", "2018-01-01"],
20+
"type": "scatterpolar",
21+
"r": [
22+
5, 4, 2, 4, 3,
23+
5, 4, 2, 4,
24+
5, 4, 2, 4, 3
25+
],
26+
"theta": [
27+
"2017-01-01", "2017-04-01", "2017-08-01", "2017-12-01",
28+
"2018-01-01", "2018-03-01", "2018-10-20",
29+
"2019-01-01", "2019-07-09", "2019-08-20", "2019-12-10"
30+
],
31+
"line": {
32+
"shape": "spline"
33+
},
34+
"subplot": "polar2"
35+
},
36+
{
37+
"x": [
38+
5, 4, 2, 4, 3,
39+
5, 4, 2, 4,
40+
5, 4, 2, 4, 3
41+
],
42+
"y": [
43+
"2017-01-01", "2017-04-01", "2017-08-01", "2017-12-01",
44+
"2018-01-01", "2018-03-01", "2018-10-20",
45+
"2019-01-01", "2019-07-09", "2019-08-20", "2019-12-10"
46+
],
1847
"line": {
1948
"shape": "spline"
2049
}
@@ -25,20 +54,39 @@
2554
"domain": {
2655
"x": [0, 0.46],
2756
"y": [0.54, 1]
57+
},
58+
"angularaxis": {
59+
"rotation": 90,
60+
"direction": "clockwise"
61+
}
62+
},
63+
"polar2": {
64+
"domain": {
65+
"x": [0.54, 1],
66+
"y": [0.54, 1]
67+
},
68+
"angularaxis": {
69+
"period": 2629800000,
70+
"rotation": 90,
71+
"direction": "clockwise"
2872
}
2973
},
3074
"yaxis": {
3175
"domain": [0, 0.46]
3276
},
33-
"legend": {
34-
"x": 0.5,
35-
"y": -0.05,
36-
"xanchor": "center",
37-
"yanchor": "top"
38-
},
3977
"hovermode": "closest",
40-
"width": 550,
78+
"showlegend": false,
79+
"width": 650,
4180
"height": 550,
42-
"margin": {"l": 80, "r": 40, "b": 60, "t": 20, "pad": 0}
81+
"margin": {"l": 80, "r": 40, "b": 60, "t": 60, "pad": 0},
82+
"annotations": [{
83+
"showarrow": false,
84+
"text": "date angular axes are <b>not</b> supported yet.",
85+
"xref": "paper",
86+
"yref": "paper",
87+
"x": 0.5,
88+
"y": 1.05,
89+
"yanchor": "bottom"
90+
}]
4391
}
4492
}

test/jasmine/tests/polar_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ describe('Test polar plots defaults:', function() {
148148
expect(layoutOut.polar.angularaxis.direction).toBe('clockwise');
149149
expect(layoutOut.polar.angularaxis.rotation).toBe(90);
150150
});
151+
152+
it('(for now) should log message when detecting *date* angular axes and fallback to *linear*', function() {
153+
spyOn(Lib, 'log');
154+
155+
_supply({}, [{
156+
type: 'scatterpolar',
157+
r: [1, 2],
158+
theta: ['2017-01-01', '2018-01-01'],
159+
visible: true,
160+
subplot: 'polar'
161+
}]);
162+
163+
expect(Lib.log).toHaveBeenCalledWith('Polar plots do not support date angular axes yet.');
164+
expect(layoutOut.polar.angularaxis.type).toBe('linear');
165+
});
151166
});
152167

153168
describe('Test relayout on polar subplots:', function() {

0 commit comments

Comments
 (0)