Skip to content

Better polar setConvert + a few misc polar touch ups #2895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib/angles.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ exports.wrap180 = function(deg) {
if(Math.abs(deg) > 180) deg -= Math.round(deg / 360) * 360;
return deg;
};

exports.isFullCircle = function(sector) {
var arc = Math.abs(sector[1] - sector[0]);
return arc === 360;
};
1 change: 1 addition & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ lib.deg2rad = anglesModule.deg2rad;
lib.rad2deg = anglesModule.rad2deg;
lib.wrap360 = anglesModule.wrap360;
lib.wrap180 = anglesModule.wrap180;
lib.isFullCircle = anglesModule.isFullCircle;

var geom2dModule = require('./geometry2d');
lib.segmentsIntersect = geom2dModule.segmentsIntersect;
Expand Down
18 changes: 11 additions & 7 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ axes.calcTicks = function calcTicks(ax) {

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

Expand Down Expand Up @@ -722,7 +722,7 @@ axes.autoTicks = function(ax, roughDTick) {
ax.tick0 = 0;
ax.dtick = Math.ceil(Math.max(roughDTick, 1));
}
else if(ax._id === 'angular') {
else if(isAngular(ax)) {
ax.tick0 = 0;
base = 1;
ax.dtick = roundDTick(roughDTick, base, roundAngles);
Expand Down Expand Up @@ -958,7 +958,7 @@ axes.tickText = function(ax, x, hover) {
if(ax.type === 'date') formatDate(ax, out, hover, extraPrecision);
else if(ax.type === 'log') formatLog(ax, out, hover, extraPrecision, hideexp);
else if(ax.type === 'category') formatCategory(ax, out);
else if(ax._id === 'angular') formatAngle(ax, out, hover, extraPrecision, hideexp);
else if(isAngular(ax)) formatAngle(ax, out, hover, extraPrecision, hideexp);
else formatLinear(ax, out, hover, extraPrecision, hideexp);

// add prefix and suffix
Expand Down Expand Up @@ -1646,7 +1646,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
else return 'M' + shift + ',0h' + len;
};
}
else if(axid === 'angular') {
else if(isAngular(ax)) {
sides = ['left', 'right'];
transfn = ax._transfn;
tickpathfn = function(shift, len) {
Expand Down Expand Up @@ -1682,7 +1682,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
var valsClipped = vals.filter(clipEnds);

// don't clip angular values
if(ax._id === 'angular') {
if(isAngular(ax)) {
valsClipped = vals;
}

Expand Down Expand Up @@ -1751,7 +1751,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
return axside === 'right' ? 'start' : 'end';
};
}
else if(axid === 'angular') {
else if(isAngular(ax)) {
ax._labelShift = labelShift;
ax._labelStandoff = labelStandoff;
ax._pad = pad;
Expand Down Expand Up @@ -1798,7 +1798,7 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
maxFontSize = Math.max(maxFontSize, d.fontSize);
});

if(axid === 'angular') {
if(isAngular(ax)) {
tickLabels.each(function(d) {
d3.select(this).select('text')
.call(svgTextUtils.positionText, labelx(d), labely(d));
Expand Down Expand Up @@ -2425,3 +2425,7 @@ function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
np(layout, yFullAxes[i]._name + '.' + key).set(xVal);
}
}

function isAngular(ax) {
return ax._id === 'angularaxis';
}
61 changes: 0 additions & 61 deletions src/plots/polar/helpers.js

This file was deleted.

9 changes: 3 additions & 6 deletions src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ var handleTickLabelDefaults = require('../cartesian/tick_label_defaults');
var handleCategoryOrderDefaults = require('../cartesian/category_order_defaults');
var handleLineGridDefaults = require('../cartesian/line_grid_defaults');
var autoType = require('../cartesian/axis_autotype');
var setConvert = require('../cartesian/set_convert');

var setConvertAngular = require('./helpers').setConvertAngular;
var layoutAttributes = require('./layout_attributes');
var setConvert = require('./set_convert');
var constants = require('./constants');
var axisNames = constants.axisNames;

Expand Down Expand Up @@ -66,7 +65,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
});

var visible = coerceAxis('visible');
setConvert(axOut, layoutOut);
setConvert(axOut, contOut, layoutOut);

var dfltColor;
var dfltFontColor;
Expand Down Expand Up @@ -140,8 +139,6 @@ function handleDefaults(contIn, contOut, coerce, opts) {

var direction = coerceAxis('direction');
coerceAxis('rotation', {counterclockwise: 0, clockwise: 90}[direction]);

setConvertAngular(axOut);
break;
}

Expand Down Expand Up @@ -201,7 +198,7 @@ function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr) {
}
}

if(trace) {
if(trace && trace[dataAttr]) {
axOut.type = autoType(trace[dataAttr], 'gregorian');
}

Expand Down
Loading