Skip to content
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

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

Merged
merged 18 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
14 changes: 7 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(ax._id === 'angularaxis' && Math.abs(rng[1] - rng[0]) === 360) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets a lot of reuse... perhaps function isAngular(axid) { return axid === 'angularaxis'; }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call -> 0c517d1

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(ax._id === 'angularaxis') {
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(ax._id === 'angularaxis') 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(axid === 'angularaxis') {
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(ax._id === 'angularaxis') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not new in this PR, but I think you have an axid here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went one step further in 0c517d1

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(axid === 'angularaxis') {
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(axid === 'angularaxis') {
tickLabels.each(function(d) {
d3.select(this).select('text')
.call(svgTextUtils.positionText, labelx(d), labely(d));
Expand Down
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