Skip to content

Commit 3937f2f

Browse files
committed
fix cluster mapbox font inherit family, weight & style
1 parent 9bfe8d1 commit 3937f2f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/traces/scattermapbox/convert.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = function convert(gd, calcTrace) {
9393
paint: {},
9494
layout: {
9595
'text-field': '{point_count_abbreviated}',
96-
'text-font': ['Open Sans Regular', 'Arial Unicode MS Regular'],
96+
'text-font': getTextFont(trace),
9797
'text-size': 12
9898
}
9999
};
@@ -146,23 +146,16 @@ module.exports = function convert(gd, calcTrace) {
146146
}
147147

148148
if(hasText) {
149-
var font = trace.textfont;
150-
var str = '';
151-
if(font.weight === 'bold') str += ' Bold';
152-
if(font.style === 'italic') str += ' Italic';
153-
var textFont = font.family;
154-
if(str) textFont = textFont.replace(' Regular', str);
155-
textFont = textFont.split(', ');
156-
157149
var iconSize = (trace.marker || {}).size;
158150
var textOpts = convertTextOpts(trace.textposition, iconSize);
159151

160152
// all data-driven below !!
153+
161154
Lib.extendFlat(symbol.layout, {
162155
'text-size': trace.textfont.size,
163156
'text-anchor': textOpts.anchor,
164157
'text-offset': textOpts.offset,
165-
'text-font': textFont
158+
'text-font': getTextFont(trace)
166159
});
167160

168161
Lib.extendFlat(symbol.paint, {
@@ -373,3 +366,14 @@ function arrayifyAttribute(values, step) {
373366
}
374367
return newAttribute;
375368
}
369+
370+
function getTextFont(trace) {
371+
var font = trace.textfont;
372+
var str = '';
373+
if(font.weight === 'bold') str += ' Bold';
374+
if(font.style === 'italic') str += ' Italic';
375+
var textFont = font.family;
376+
if(str) textFont = textFont.replace(' Regular', str);
377+
textFont = textFont.split(', ');
378+
return textFont;
379+
}

src/traces/scattermapbox/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
101101
clusterSize !== false ||
102102
clusterOpacity !== false;
103103

104-
coerce('cluster.enabled', clusterEnabledDflt);
104+
var clusterEnabled = coerce('cluster.enabled', clusterEnabledDflt);
105105

106-
if(subTypes.hasText(traceOut)) {
106+
if(clusterEnabled || subTypes.hasText(traceOut)) {
107107
handleTextDefaults(traceIn, traceOut, layout, coerce,
108108
{
109109
noSelect: true,
2.12 KB
Loading

test/image/mocks/mapbox_scattercluster.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@
197197
}
198198
],
199199
"layout": {
200+
"font": {
201+
"weight": "bold",
202+
"style": "italic"
203+
},
200204
"title": {
201205
"text": "Clustering points over Canadian cities"
202206
},

0 commit comments

Comments
 (0)