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 1 commit
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
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
6 changes: 2 additions & 4 deletions src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ proto.updateLayers = function(fullLayout, polarLayout) {
break;
case 'angular-grid':
sel.style('fill', 'none');
sel.append('g').classed('angular', 1);
sel.append('g').classed('angularaxis', 1);
break;
case 'radial-line':
sel.append('line').style('fill', 'none');
Expand Down Expand Up @@ -257,8 +257,6 @@ proto.updateLayout = function(fullLayout, polarLayout) {
_this.angularAxis = _this.mockAxis(fullLayout, polarLayout, angularLayout, {
_axislayer: layers['angular-axis'],
_gridlayer: layers['angular-grid'],
// angular axes need *special* logic
_id: 'angular',
Copy link
Collaborator

Choose a reason for hiding this comment

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

for reference, here's where _id gets set to angularaxis

axOut._id = axOut._name = axName;

side: 'right',
// to get auto nticks right
domain: [0, Math.PI],
Expand Down Expand Up @@ -547,7 +545,7 @@ proto.updateAngularAxis = function(fullLayout, polarLayout) {

var newTickLayout = strTickLayout(angularLayout);
if(_this.angularTickLayout !== newTickLayout) {
layers['angular-axis'].selectAll('.angulartick').remove();
layers['angular-axis'].selectAll('.' + ax._id + 'tick').remove();
_this.angularTickLayout = newTickLayout;
}

Expand Down
1 change: 0 additions & 1 deletion src/plots/polar/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ module.exports = function setConvert(ax, polarLayout, fullLayout) {
case 'radialaxis':
setConvertRadial(ax);
break;
case 'angular':
case 'angularaxis':
setConvertAngular(ax, polarLayout);
break;
Expand Down
14 changes: 7 additions & 7 deletions test/jasmine/tests/polar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ describe('Test relayout on polar subplots:', function() {
var pos1 = [];

Plotly.plot(gd, fig).then(function() {
d3.selectAll('.angulartick> text').each(function() {
d3.selectAll('.angularaxistick > text').each(function() {
var tx = d3.select(this);
pos0.push([tx.attr('x'), tx.attr('y')]);
});
return Plotly.relayout(gd, 'polar.angularaxis.rotation', 90);
})
.then(function() {
d3.selectAll('.angulartick> text').each(function() {
d3.selectAll('.angularaxistick > text').each(function() {
var tx = d3.select(this);
pos1.push([tx.attr('x'), tx.attr('y')]);
});
Expand All @@ -330,7 +330,7 @@ describe('Test relayout on polar subplots:', function() {
var fig = Lib.extendDeep({}, require('@mocks/polar_scatter.json'));

function check(cnt, expected) {
var ticks = d3.selectAll('path.angulartick');
var ticks = d3.selectAll('path.angularaxistick');

expect(ticks.size()).toBe(cnt, '# of ticks');
ticks.each(function() {
Expand Down Expand Up @@ -433,21 +433,21 @@ describe('Test relayout on polar subplots:', function() {
return toggle(
'polar.angularaxis.showgrid',
[true, false], [8, 0],
'.angular-grid > .angular > path', assertCnt
'.angular-grid > .angularaxis > path', assertCnt
);
})
.then(function() {
return toggle(
'polar.angularaxis.showticklabels',
[true, false], [8, 0],
'.angular-axis > .angulartick > text', assertCnt
'.angular-axis > .angularaxistick > text', assertCnt
);
})
.then(function() {
return toggle(
'polar.angularaxis.ticks',
['outside', ''], [8, 0],
'.angular-axis > path.angulartick', assertCnt
'.angular-axis > path.angularaxistick', assertCnt
);
})
.catch(failTest)
Expand Down Expand Up @@ -558,7 +558,7 @@ describe('Test relayout on polar subplots:', function() {
expect(gd._fullLayout.polar._subplot.angularAxis.range)
.toBeCloseToArray([0, exp.period], 2, 'range in mocked angular axis - ' + msg);

expect(d3.selectAll('path.angulartick').size())
expect(d3.selectAll('path.angularaxistick').size())
.toBe(exp.nTicks, '# of visible angular ticks - ' + msg);

expect([gd.calcdata[0][5].x, gd.calcdata[0][5].y])
Expand Down