Skip to content

Commit 1075d87

Browse files
committed
make scatterpolar use own attributes and defaults
1 parent c0c0189 commit 1075d87

File tree

4 files changed

+109
-14
lines changed

4 files changed

+109
-14
lines changed

src/traces/scatterpolar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ module.exports = {
2525
meta: {
2626
hrName: 'scatter_polar',
2727
description: [
28-
'The scatterpolar trace type encompasses line charts, scatter charts, text charts, and bubble charts.',
28+
'The scatterpolar trace type encompasses line charts, scatter charts, text charts, and bubble charts',
2929
'in polar coordinates.',
3030
'The data visualized as scatter point or lines is set in',
31-
'`r` (radial) and `theta` (angular). coordintes',
31+
'`r` (radial) and `theta` (angular) coordinates',
3232
'Text (appearing either on the chart or on hover only) is via `text`.',
3333
'Bubble charts are achieved by setting `marker.size` and/or `marker.color`',
3434
'to numerical arrays.'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var scatterPolarAttrs = require('../scatterpolar/attributes');
12+
var scatterGlAttrs = require('../scattergl/attributes');
13+
14+
module.exports = {
15+
mode: scatterPolarAttrs.mode,
16+
r: scatterPolarAttrs.r,
17+
theta: scatterPolarAttrs.theta,
18+
thetaunit: scatterPolarAttrs.thetaunit,
19+
20+
text: scatterPolarAttrs.text,
21+
// no hovertext
22+
23+
line: scatterGlAttrs.line,
24+
connectgaps: scatterGlAttrs.connectgaps,
25+
26+
marker: scatterGlAttrs.marker,
27+
// no cliponaxis
28+
29+
fill: scatterGlAttrs.fill,
30+
fillcolor: scatterGlAttrs.fillcolor,
31+
32+
hoverinfo: scatterPolarAttrs.hoverinfo,
33+
hoveron: scatterPolarAttrs.hoveron,
34+
35+
selected: scatterPolarAttrs.selected,
36+
unselected: scatterPolarAttrs.unselected
37+
};

src/traces/scatterpolargl/defaults.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var Lib = require('../../lib');
12+
13+
var subTypes = require('../scatter/subtypes');
14+
var handleMarkerDefaults = require('../scatter/marker_defaults');
15+
var handleLineDefaults = require('../scatter/line_defaults');
16+
var handleFillColorDefaults = require('../scatter/fillcolor_defaults');
17+
var PTS_LINESONLY = require('../scatter/constants').PTS_LINESONLY;
18+
19+
var attributes = require('./attributes');
20+
21+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
22+
function coerce(attr, dflt) {
23+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
24+
}
25+
26+
var r = coerce('r');
27+
var theta = coerce('theta');
28+
var len = (r && theta) ? Math.min(r.length, theta.length) : 0;
29+
30+
if(!len) {
31+
traceOut.visible = false;
32+
return;
33+
}
34+
35+
if(len < r.length) traceOut.r = r.slice(0, len);
36+
if(len < theta.length) traceOut.theta = theta.slice(0, len);
37+
38+
coerce('thetaunit');
39+
coerce('mode', len < PTS_LINESONLY ? 'lines+markers' : 'lines');
40+
coerce('text');
41+
42+
if(subTypes.hasLines(traceOut)) {
43+
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
44+
coerce('connectgaps');
45+
}
46+
47+
var dfltHoverOn = [];
48+
49+
if(subTypes.hasMarkers(traceOut)) {
50+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce);
51+
dfltHoverOn.push('points');
52+
}
53+
54+
coerce('fill');
55+
if(traceOut.fill !== 'none') {
56+
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
57+
}
58+
59+
if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
60+
dfltHoverOn.push('fills');
61+
}
62+
coerce('hoveron', dfltHoverOn.join('+') || 'points');
63+
64+
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
65+
};

src/traces/scatterpolargl/index.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var Axes = require('../../plots/cartesian/axes');
1515
var kdtree = require('kdgrass');
1616
var Lib = require('../../lib');
1717

18-
1918
function calc(container, trace) {
2019
var layout = container._fullLayout;
2120
var subplotId = trace.subplot;
@@ -202,17 +201,14 @@ function hoverPoints(pointData, xval, yval, hovermode) {
202201
return scatterPointData;
203202
}
204203

205-
206204
module.exports = {
207205
moduleType: 'trace',
208206
name: 'scatterpolargl',
209207
basePlotModule: require('../../plots/polar'),
210208
categories: ['gl', 'regl', 'polar', 'symbols', 'markerColorscale', 'showLegend', 'scatter-like'],
211209

212-
// TODO scatterpolargl won't support text
213-
// should have its own attributes and defaults
214-
attributes: require('../scatterpolar/attributes'),
215-
supplyDefaults: require('../scatterpolar/defaults'),
210+
attributes: require('./attributes'),
211+
supplyDefaults: require('./defaults'),
216212

217213
calc: calc,
218214
plot: plot,
@@ -223,13 +219,10 @@ module.exports = {
223219
meta: {
224220
hrName: 'scatter_polar_gl',
225221
description: [
226-
'!!! GL VERSION OF SCATTERPOLAR !!!',
227-
228-
'The scatterpolar trace type encompasses line charts, scatter charts, text charts, and bubble charts.',
229-
'in polar coordinates.',
222+
'The scatterpolargl trace type encompasses line charts, scatter charts, and bubble charts',
223+
'in polar coordinates using the WebGL plotting engine.',
230224
'The data visualized as scatter point or lines is set in',
231-
'`r` (radial) and `theta` (angular). coordintes',
232-
'Text (appearing either on the chart or on hover only) is via `text`.',
225+
'`r` (radial) and `theta` (angular) coordinates',
233226
'Bubble charts are achieved by setting `marker.size` and/or `marker.color`',
234227
'to numerical arrays.'
235228
].join(' ')

0 commit comments

Comments
 (0)