Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d99bfd5

Browse files
committed
make convert handle bubble with text case:
- also tweak factor for cleaner look - add bubble with text image test
1 parent 2d6db7b commit d99bfd5

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

src/traces/scattermapbox/convert.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module.exports = function convert(calcTrace) {
2424
hasLines = subTypes.hasLines(trace),
2525
hasMarkers = subTypes.hasMarkers(trace),
2626
hasText = subTypes.hasText(trace),
27-
hasCircles = (hasMarkers && trace.marker.symbol === 'circle');
27+
hasCircles = (hasMarkers && trace.marker.symbol === 'circle'),
28+
hasSymbols = (hasMarkers && trace.marker.symbol !== 'circle');
2829

2930
var fill = initContainer(),
3031
line = initContainer(),
@@ -84,7 +85,7 @@ module.exports = function convert(calcTrace) {
8485
});
8586
}
8687

87-
if(!hasCircles || hasText) {
88+
if(hasSymbols || hasText) {
8889
symbol.geojson = makeSymbolGeoJSON(calcTrace);
8990

9091
Lib.extendFlat(symbol.layout, {
@@ -93,7 +94,7 @@ module.exports = function convert(calcTrace) {
9394
'text-field': '{text}'
9495
});
9596

96-
if(hasMarkers) {
97+
if(hasSymbols) {
9798
Lib.extendFlat(symbol.layout, {
9899
'icon-size': trace.marker.size / 10
99100
});
@@ -314,8 +315,9 @@ function calcTextOpts(trace) {
314315

315316
// ballpack values
316317
var ms = (trace.marker || {}).size,
317-
xInc = 0.5 + (ms / 15),
318-
yInc = 1.5 + (ms / 15);
318+
factor = Array.isArray(ms) ? Lib.mean(ms) : ms,
319+
xInc = 0.5 + (factor / 100),
320+
yInc = 1.5 + (factor / 100);
319321

320322
var anchorVals = ['', ''],
321323
offset = [0, 0];
78.1 KB
Loading
41 Bytes
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"data": [
3+
{
4+
"type": "scattermapbox",
5+
"mode": "markers+lines+text",
6+
"lon": [
7+
10,
8+
20,
9+
30
10+
],
11+
"lat": [
12+
10,
13+
20,
14+
30
15+
],
16+
"marker": {
17+
"size": [
18+
10,
19+
30,
20+
20
21+
],
22+
"color": [
23+
"red",
24+
"green",
25+
"blue"
26+
]
27+
},
28+
"text": [
29+
"A",
30+
"B",
31+
"C"
32+
],
33+
"textposition": "top left",
34+
"textfont": {
35+
"size": 20,
36+
"color": "red"
37+
}
38+
}
39+
],
40+
"layout": {
41+
"mapbox": {
42+
"style": "light",
43+
"zoom": 2.5,
44+
"center": {
45+
"lon": 19.5,
46+
"lat": 22
47+
}
48+
},
49+
"width": 700,
50+
"height": 450
51+
}
52+
}

test/jasmine/tests/scattermapbox_test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ describe('scattermapbox convert', function() {
363363

364364
it('should correctly convert \'textposition\' to \'text-anchor\' and \'text-offset\'', function() {
365365
var specs = {
366-
'top left': ['top-right', [-1.5, -2.5]],
367-
'top center': ['top', [0, -2.5]],
368-
'top right': ['top-left', [1.5, -2.5]],
369-
'middle left': ['right', [-1.5, 0]],
366+
'top left': ['top-right', [-0.65, -1.65]],
367+
'top center': ['top', [0, -1.65]],
368+
'top right': ['top-left', [0.65, -1.65]],
369+
'middle left': ['right', [-0.65, 0]],
370370
'middle center': ['center', [0, 0]],
371-
'middle right': ['left', [1.5, 0]],
372-
'bottom left': ['bottom-right', [-1.5, 2.5]],
373-
'bottom center': ['bottom', [0, 2.5]],
374-
'bottom right': ['bottom-left', [1.5, 2.5]]
371+
'middle right': ['left', [0.65, 0]],
372+
'bottom left': ['bottom-right', [-0.65, 1.65]],
373+
'bottom center': ['bottom', [0, 1.65]],
374+
'bottom right': ['bottom-left', [0.65, 1.65]]
375375
};
376376

377377
Object.keys(specs).forEach(function(k) {

0 commit comments

Comments
 (0)