Skip to content
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
2 changes: 1 addition & 1 deletion src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr) {
}
}

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

Expand Down
11 changes: 11 additions & 0 deletions src/plots/polar/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ function setConvertAngular(ax, polarLayout) {
for(i = 0; i < len; i++) {
arrayOut[i] = _d2c(arrayIn[i]);
}
} else {
var coord0 = coord + '0';
var dcoord = 'd' + coord;
var v0 = (coord0 in trace) ? _d2c(trace[coord0]) : 0;
var dv = (trace[dcoord]) ? _d2c(trace[dcoord]) : (ax.period || 2 * Math.PI) / len;

arrayOut = new Array(len);
for(i = 0; i < len; i++) {
arrayOut[i] = v0 + i * dv;
}
}

return arrayOut;
};

Expand Down
43 changes: 43 additions & 0 deletions src/traces/scatterpolar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,49 @@ module.exports = {
description: 'Sets the angular coordinates'
},

r0: {
valType: 'any',
dflt: 0,
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Alternate to `r`.',
'Builds a linear space of r coordinates.',
'Use with `dr`',
'where `r0` is the starting coordinate and `dr` the step.'
].join(' ')
},
dr: {
valType: 'number',
dflt: 1,
role: 'info',
editType: 'calc',
description: 'Sets the r coordinate step.'
},

theta0: {
valType: 'any',
dflt: 0,
role: 'info',
editType: 'calc+clearAxisTypes',
description: [
'Alternate to `theta`.',
'Builds a linear space of theta coordinates.',
'Use with `dtheta`',
'where `theta0` is the starting coordinate and `dtheta` the step.'
].join(' ')
},
dtheta: {
valType: 'number',
role: 'info',
editType: 'calc',
description: [
'Sets the theta coordinate step.',
'By default, the `dtheta` step equals the subplot\'s period divided',
'by the length of the `r` coordinates.'
].join(' ')
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One of the most underrated features, IMHO. Thanks for adding it!


thetaunit: {
valType: 'enumerated',
values: ['radians', 'degrees', 'gradians'],
Expand Down
38 changes: 31 additions & 7 deletions src/traces/scatterpolar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ var PTS_LINESONLY = require('../scatter/constants').PTS_LINESONLY;

var attributes = require('./attributes');

module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var r = coerce('r');
var theta = coerce('theta');
var len = (r && theta) ? Math.min(r.length, theta.length) : 0;

var len = handleRThetaDefaults(traceIn, traceOut, layout, coerce);
if(!len) {
traceOut.visible = false;
return;
}

traceOut._length = len;

coerce('thetaunit');
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
coerce('text');
Expand Down Expand Up @@ -76,4 +71,33 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('hoveron', dfltHoverOn.join('+') || 'points');

Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
}

function handleRThetaDefaults(traceIn, traceOut, layout, coerce) {
var r = coerce('r');
var theta = coerce('theta');
var len;

if(r) {
if(theta) {
len = Math.min(r.length, theta.length);
} else {
len = r.length;
coerce('theta0');
coerce('dtheta');
}
} else {
if(!theta) return 0;
len = traceOut.theta.length;
coerce('r0');
coerce('dr');
}

traceOut._length = len;
return len;
}

module.exports = {
handleRThetaDefaults: handleRThetaDefaults,
supplyDefaults: supplyDefaults
};
2 changes: 1 addition & 1 deletion src/traces/scatterpolar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
categories: ['polar', 'symbols', 'showLegend', 'scatter-like'],

attributes: require('./attributes'),
supplyDefaults: require('./defaults'),
supplyDefaults: require('./defaults').supplyDefaults,
colorbar: require('../scatter/marker_colorbar'),
calc: require('./calc'),
plot: require('./plot'),
Expand Down
4 changes: 4 additions & 0 deletions src/traces/scatterpolargl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = {
mode: scatterPolarAttrs.mode,
r: scatterPolarAttrs.r,
theta: scatterPolarAttrs.theta,
r0: scatterPolarAttrs.r0,
dr: scatterPolarAttrs.dr,
theta0: scatterPolarAttrs.theta0,
dtheta: scatterPolarAttrs.dtheta,
thetaunit: scatterPolarAttrs.thetaunit,

text: scatterPolarAttrs.text,
Expand Down
8 changes: 2 additions & 6 deletions src/traces/scatterpolargl/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var Lib = require('../../lib');

var subTypes = require('../scatter/subtypes');
var handleRThetaDefaults = require('../scatterpolar/defaults').handleRThetaDefaults;
var handleMarkerDefaults = require('../scatter/marker_defaults');
var handleLineDefaults = require('../scatter/line_defaults');
var handleFillColorDefaults = require('../scatter/fillcolor_defaults');
Expand All @@ -23,17 +24,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}

var r = coerce('r');
var theta = coerce('theta');
var len = (r && theta) ? Math.min(r.length, theta.length) : 0;

var len = handleRThetaDefaults(traceIn, traceOut, layout, coerce);
if(!len) {
traceOut.visible = false;
return;
}

traceOut._length = len;

coerce('thetaunit');
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
coerce('text');
Expand Down
Binary file added test/image/baselines/polar_r0dr-theta0dtheta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions test/image/mocks/polar_r0dr-theta0dtheta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"data": [{
"type": "scatterpolar",
"name": "missing θ",
"r": [1, 2, 3]
}, {
"type": "scatterpolar",
"name": "missing r",
"theta": [0, -90, -220]
}, {
"type": "scatterpolar",
"name": "set r0/dr",
"r0": 5,
"dr": -1,
"theta": [0, -90, -190]
}, {
"type": "scatterpolar",
"name": "set θ<sub>0</sub>/dθ",
"r": [1, 2, 3],
"theta0": 1,
"dtheta": 2,
"thetaunit": "radians"
},

{
"type": "scatterpolargl",
"name": "[gl] missing θ",
"subplot": "polar2",
"marker": {"color": "#1f77b4"},
"r": [1, 2, 3]
}, {
"type": "scatterpolargl",
"name": "[gl] missing r",
"subplot": "polar2",
"marker": {"color": "#ff7f0e"},
"theta": [0, -90, -220]
}, {
"type": "scatterpolargl",
"name": "[gl] set r0/dr",
"subplot": "polar2",
"marker": {"color": "#2ca02c"},
"r0": 5,
"dr": -1,
"theta": [0, -90, -190]
}, {
"type": "scatterpolargl",
"name": "[gl] set θ<sub>0</sub>/dθ",
"subplot": "polar2",
"marker": {"color": "#d62728"},
"r": [1, 2, 3],
"theta0": 1,
"dtheta": 2,
"thetaunit": "radians"
}],
"layout": {
"width": 500,
"height": 800,
"margin": {"l": 200, "t": 20, "b": 20},
"legend": {
"x": -0.2,
"xanchor": "right",
"y": 0.5
},
"polar": {
"domain": {
"x": [0, 1],
"y": [0.5, 1]
}
},
"polar2": {
"domain": {
"x": [0, 1],
"y": [0, 0.5]
}
}
}
}
37 changes: 37 additions & 0 deletions test/jasmine/tests/scatterpolar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('Test scatterpolar trace defaults:', function() {
expect(traceOut.r).toEqual([1, 2, 3, 4, 5]);
expect(traceOut.theta).toEqual([1, 2, 3]);
expect(traceOut._length).toBe(3);
expect(traceOut.r0).toBeUndefined();
expect(traceOut.dr).toBeUndefined();
expect(traceOut.theta0).toBeUndefined();
expect(traceOut.dtheta).toBeUndefined();
});

it('should not truncate *theta* when longer than *r*', function() {
Expand All @@ -40,6 +44,39 @@ describe('Test scatterpolar trace defaults:', function() {
expect(traceOut.r).toEqual([1, 2, 3]);
expect(traceOut.theta).toEqual([1, 2, 3, 4, 5]);
expect(traceOut._length).toBe(3);
expect(traceOut.r0).toBeUndefined();
expect(traceOut.dr).toBeUndefined();
expect(traceOut.theta0).toBeUndefined();
expect(traceOut.dtheta).toBeUndefined();
});

it('should coerce *theta0* and *dtheta* when *theta* is not set', function() {
_supply({
r: [1, 2, 3]
});

expect(traceOut.r).toEqual([1, 2, 3]);
expect(traceOut.theta).toBeUndefined();
expect(traceOut._length).toBe(3);
expect(traceOut.r0).toBeUndefined();
expect(traceOut.dr).toBeUndefined();
expect(traceOut.theta0).toBe(0);
// its default value is computed later
expect(traceOut.dtheta).toBeUndefined();
});

it('should coerce *r0* and *dr* when *r* is not set', function() {
_supply({
theta: [1, 2, 3, 4, 5]
});

expect(traceOut.r).toBeUndefined();
expect(traceOut.theta).toEqual([1, 2, 3, 4, 5]);
expect(traceOut._length).toBe(5);
expect(traceOut.r0).toBe(0);
expect(traceOut.dr).toBe(1);
expect(traceOut.theta0).toBeUndefined();
expect(traceOut.dtheta).toBeUndefined();
});
});

Expand Down