Skip to content

Commit 665a9c4

Browse files
authored
Merge pull request #2895 from plotly/polar-better-set-convert
Better polar setConvert + a few misc polar touch ups
2 parents 22ce90d + 75786e4 commit 665a9c4

27 files changed

+747
-315
lines changed

Diff for: src/lib/angles.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ exports.wrap180 = function(deg) {
2727
if(Math.abs(deg) > 180) deg -= Math.round(deg / 360) * 360;
2828
return deg;
2929
};
30+
31+
exports.isFullCircle = function(sector) {
32+
var arc = Math.abs(sector[1] - sector[0]);
33+
return arc === 360;
34+
};

Diff for: src/lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ lib.deg2rad = anglesModule.deg2rad;
8787
lib.rad2deg = anglesModule.rad2deg;
8888
lib.wrap360 = anglesModule.wrap360;
8989
lib.wrap180 = anglesModule.wrap180;
90+
lib.isFullCircle = anglesModule.isFullCircle;
9091

9192
var geom2dModule = require('./geometry2d');
9293
lib.segmentsIntersect = geom2dModule.segmentsIntersect;

Diff for: src/plots/cartesian/axes.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ axes.calcTicks = function calcTicks(ax) {
554554

555555
// If same angle over a full circle, the last tick vals is a duplicate.
556556
// TODO must do something similar for angular date axes.
557-
if(ax._id === 'angular' && Math.abs(rng[1] - rng[0]) === 360) {
557+
if(isAngular(ax) && Math.abs(rng[1] - rng[0]) === 360) {
558558
vals.pop();
559559
}
560560

@@ -722,7 +722,7 @@ axes.autoTicks = function(ax, roughDTick) {
722722
ax.tick0 = 0;
723723
ax.dtick = Math.ceil(Math.max(roughDTick, 1));
724724
}
725-
else if(ax._id === 'angular') {
725+
else if(isAngular(ax)) {
726726
ax.tick0 = 0;
727727
base = 1;
728728
ax.dtick = roundDTick(roughDTick, base, roundAngles);
@@ -958,7 +958,7 @@ axes.tickText = function(ax, x, hover) {
958958
if(ax.type === 'date') formatDate(ax, out, hover, extraPrecision);
959959
else if(ax.type === 'log') formatLog(ax, out, hover, extraPrecision, hideexp);
960960
else if(ax.type === 'category') formatCategory(ax, out);
961-
else if(ax._id === 'angular') formatAngle(ax, out, hover, extraPrecision, hideexp);
961+
else if(isAngular(ax)) formatAngle(ax, out, hover, extraPrecision, hideexp);
962962
else formatLinear(ax, out, hover, extraPrecision, hideexp);
963963

964964
// add prefix and suffix
@@ -1646,7 +1646,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
16461646
else return 'M' + shift + ',0h' + len;
16471647
};
16481648
}
1649-
else if(axid === 'angular') {
1649+
else if(isAngular(ax)) {
16501650
sides = ['left', 'right'];
16511651
transfn = ax._transfn;
16521652
tickpathfn = function(shift, len) {
@@ -1682,7 +1682,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
16821682
var valsClipped = vals.filter(clipEnds);
16831683

16841684
// don't clip angular values
1685-
if(ax._id === 'angular') {
1685+
if(isAngular(ax)) {
16861686
valsClipped = vals;
16871687
}
16881688

@@ -1751,7 +1751,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
17511751
return axside === 'right' ? 'start' : 'end';
17521752
};
17531753
}
1754-
else if(axid === 'angular') {
1754+
else if(isAngular(ax)) {
17551755
ax._labelShift = labelShift;
17561756
ax._labelStandoff = labelStandoff;
17571757
ax._pad = pad;
@@ -1798,7 +1798,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
17981798
maxFontSize = Math.max(maxFontSize, d.fontSize);
17991799
});
18001800

1801-
if(axid === 'angular') {
1801+
if(isAngular(ax)) {
18021802
tickLabels.each(function(d) {
18031803
d3.select(this).select('text')
18041804
.call(svgTextUtils.positionText, labelx(d), labely(d));
@@ -2425,3 +2425,7 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
24252425
np(layout, yFullAxes[i]._name + '.' + key).set(xVal);
24262426
}
24272427
}
2428+
2429+
function isAngular(ax) {
2430+
return ax._id === 'angularaxis';
2431+
}

Diff for: src/plots/polar/helpers.js

-61
This file was deleted.

Diff for: src/plots/polar/layout_defaults.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ var handleTickLabelDefaults = require('../cartesian/tick_label_defaults');
1919
var handleCategoryOrderDefaults = require('../cartesian/category_order_defaults');
2020
var handleLineGridDefaults = require('../cartesian/line_grid_defaults');
2121
var autoType = require('../cartesian/axis_autotype');
22-
var setConvert = require('../cartesian/set_convert');
2322

24-
var setConvertAngular = require('./helpers').setConvertAngular;
2523
var layoutAttributes = require('./layout_attributes');
24+
var setConvert = require('./set_convert');
2625
var constants = require('./constants');
2726
var axisNames = constants.axisNames;
2827

@@ -66,7 +65,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
6665
});
6766

6867
var visible = coerceAxis('visible');
69-
setConvert(axOut, layoutOut);
68+
setConvert(axOut, contOut, layoutOut);
7069

7170
var dfltColor;
7271
var dfltFontColor;
@@ -140,8 +139,6 @@ function handleDefaults(contIn, contOut, coerce, opts) {
140139

141140
var direction = coerceAxis('direction');
142141
coerceAxis('rotation', {counterclockwise: 0, clockwise: 90}[direction]);
143-
144-
setConvertAngular(axOut);
145142
break;
146143
}
147144

@@ -201,7 +198,7 @@ function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr) {
201198
}
202199
}
203200

204-
if(trace) {
201+
if(trace && trace[dataAttr]) {
205202
axOut.type = autoType(trace[dataAttr], 'gregorian');
206203
}
207204

0 commit comments

Comments
 (0)