Skip to content

Commit 41840cb

Browse files
committed
add scattermapbox-specific attributes and defaults
1 parent 10e19ea commit 41840cb

File tree

3 files changed

+159
-2
lines changed

3 files changed

+159
-2
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright 2012-2016, 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 scatterGeoAttrs = require('../scattergeo/attributes');
12+
var plotAttrs = require('../../plots/attributes');
13+
var extendFlat = require('../../lib/extend').extendFlat;
14+
15+
var lineAttrs = scatterGeoAttrs.line;
16+
var markerAttrs = scatterGeoAttrs.marker;
17+
18+
19+
module.exports = {
20+
lon: scatterGeoAttrs.lon,
21+
lat: scatterGeoAttrs.lat,
22+
23+
// locations
24+
// locationmode
25+
26+
mode: {
27+
valType: 'flaglist',
28+
flags: ['lines', 'markers'],
29+
dflt: 'markers',
30+
extras: ['none'],
31+
role: 'info',
32+
description: [
33+
'Determines the drawing mode for this scatter trace.'
34+
].join(' ')
35+
},
36+
37+
// text
38+
39+
line: {
40+
color: lineAttrs.color,
41+
width: lineAttrs.width,
42+
dash: lineAttrs.dash // TODO
43+
},
44+
45+
//connectgaps
46+
47+
marker: {
48+
symbol: {
49+
valType: 'enumerated',
50+
values: ['circle'], // TODO
51+
dflt: 'circle',
52+
role: 'style',
53+
description: [
54+
''
55+
].join(' ')
56+
},
57+
opacity: extendFlat({}, markerAttrs.opacity, {
58+
arrayOk: false
59+
}),
60+
size: markerAttrs.size,
61+
sizeref: markerAttrs.sizeref,
62+
sizemin: markerAttrs.sizemin,
63+
sizemode: markerAttrs.sizemode,
64+
color: markerAttrs.color,
65+
colorscale: markerAttrs.colorscale,
66+
cauto: markerAttrs.cauto,
67+
cmax: markerAttrs.cmax,
68+
cmin: markerAttrs.cmin,
69+
autocolorscale: markerAttrs.autocolorscale,
70+
reversescale: markerAttrs.reversescale,
71+
showscale: markerAttrs.showscale
72+
73+
// line
74+
},
75+
76+
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
77+
flags: ['lon', 'lat', 'text', 'name']
78+
}),
79+
80+
_nestedModules: {
81+
'marker.colorbar': 'Colorbar'
82+
}
83+
};

src/traces/scattermapbox/defaults.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright 2012-2016, 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+
10+
'use strict';
11+
12+
var Lib = require('../../lib');
13+
14+
var subTypes = require('../scatter/subtypes');
15+
var handleMarkerDefaults = require('../scatter/marker_defaults');
16+
var handleLineDefaults = require('../scatter/line_defaults');
17+
18+
var attributes = require('./attributes');
19+
var scatterAttrs = require('../scatter/attributes');
20+
21+
22+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
23+
function coerce(attr, dflt) {
24+
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
25+
}
26+
27+
function coerceMarker(attr, dflt) {
28+
var attrs = (attr.indexOf('.line') === -1) ? attributes : scatterAttrs;
29+
30+
// use 'scatter' attributes for 'marker.line.' attr,
31+
// so that we can reuse the scatter marker defaults
32+
33+
return Lib.coerce(traceIn, traceOut, attrs, attr, dflt);
34+
}
35+
36+
var len = handleLonLatDefaults(traceIn, traceOut, coerce);
37+
if(!len) {
38+
traceOut.visible = false;
39+
return;
40+
}
41+
42+
coerce('mode');
43+
44+
if(subTypes.hasLines(traceOut)) {
45+
handleLineDefaults(traceIn, traceOut, defaultColor, coerce);
46+
}
47+
48+
if(subTypes.hasMarkers(traceOut)) {
49+
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerceMarker);
50+
51+
// array marker.size and marker.color are only supported with circles
52+
53+
var marker = traceOut.marker;
54+
55+
if(marker.symbol !== 'circle') {
56+
if(Array.isArray(marker.size)) marker.size = marker.size[0];
57+
if(Array.isArray(marker.color)) marker.color = marker.color[0];
58+
}
59+
}
60+
61+
coerce('hoverinfo', (layout._dataLength === 1) ? 'lon+lat+text' : undefined);
62+
};
63+
64+
function handleLonLatDefaults(traceIn, traceOut, coerce) {
65+
var lon = coerce('lon') || [];
66+
var lat = coerce('lat') || [];
67+
var len = Math.min(lon.length, lat.length);
68+
69+
if(len < lon.length) traceOut.lon = lon.slice(0, len);
70+
if(len < lat.length) traceOut.lat = lat.slice(0, len);
71+
72+
return len;
73+
}

src/traces/scattermapbox/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ var ScatterMapbox = {};
2020
// - support for marker.line ???
2121
ScatterMapbox.attributes = require('../scattergeo/attributes');
2222
ScatterMapbox.supplyDefaults = require('../scattergeo/defaults');
23+
ScatterMapbox.attributes = require('./attributes');
24+
ScatterMapbox.supplyDefaults = require('./defaults');
2325
ScatterMapbox.colorbar = require('../scatter/colorbar');
2426
ScatterMapbox.calc = require('../scattergeo/calc');
2527
ScatterMapbox.plot = require('./plot');
2628

2729
ScatterMapbox.moduleType = 'trace';
2830
ScatterMapbox.name = 'scattermapbox';
2931
ScatterMapbox.basePlotModule = require('../../plots/mapbox');
30-
ScatterMapbox.categories = ['mapbox', 'gl', 'symbols', 'showLegend'];
31-
// ScatterMapbox.categories = ['mapbox', 'gl', 'symbols', 'markerColorscale', 'showLegend'];
32+
ScatterMapbox.categories = ['mapbox', 'gl', 'symbols', 'markerColorscale', 'showLegend'];
3233
ScatterMapbox.meta = {
3334
hrName: 'scatter_mapbox',
3435
description: [

0 commit comments

Comments
 (0)