Skip to content

Commit b8877ff

Browse files
committed
add bold and italic to scattermapbox
1 parent 8452e53 commit b8877ff

File tree

9 files changed

+61
-12
lines changed

9 files changed

+61
-12
lines changed

src/lib/coerce.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ exports.coerceFont = function(coerce, attr, dfltObj, opts) {
471471
out.size = coerce(attr + '.size', dfltObj.size);
472472
out.color = coerce(attr + '.color', dfltObj.color);
473473

474-
if(!opts.noWeight) out.weight = coerce(attr + '.weight', dfltObj.weight);
475-
if(!opts.noStyle) out.style = coerce(attr + '.style', dfltObj.style);
474+
out.weight = coerce(attr + '.weight', dfltObj.weight);
475+
out.style = coerce(attr + '.style', dfltObj.style);
476476
if(!opts.noVariant) out.variant = coerce(attr + '.variant', dfltObj.variant);
477477

478478
return out;

src/plots/font_attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = function(opts) {
7171
].join(' ')
7272
},
7373

74-
variant: {
74+
variant: opts.noVariant ? undefined : {
7575
editType: editType,
7676
valType: 'enumerated',
7777
values: variantValues || [

src/plots/mapbox/layout_attributes.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ var templatedArray = require('../../plot_api/plot_template').templatedArray;
1111
var constants = require('./constants');
1212

1313
var fontAttr = fontAttrs({
14+
noVariant: true,
1415
description: [
1516
'Sets the icon text font (color=mapbox.layer.paint.text-color, size=mapbox.layer.layout.text-size).',
1617
'Has an effect only when `type` is set to *symbol*.'
1718
].join(' ')
1819
});
1920
fontAttr.family.dflt = 'Open Sans Regular, Arial Unicode MS Regular';
20-
delete fontAttr.weight;
21-
delete fontAttr.style;
22-
delete fontAttr.variant;
2321

2422
var attrs = module.exports = overrideAll({
2523
_arrayAttrRegexps: [Lib.counterRegex('mapbox', '.layers', true)],

src/traces/scatter/text_defaults.js

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ module.exports = function(traceIn, traceOut, layout, coerce, opts) {
1111

1212
coerce('textposition');
1313
Lib.coerceFont(coerce, 'textfont', opts.font || layout.font, {
14-
noWeight: opts.noFontWeight,
15-
noStyle: opts.noFontStyle,
1614
noVariant: opts.noFontVariant
1715
});
1816

src/traces/scattermapbox/convert.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,23 @@ 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+
149157
var iconSize = (trace.marker || {}).size;
150158
var textOpts = convertTextOpts(trace.textposition, iconSize);
151159

152160
// all data-driven below !!
153-
154161
Lib.extendFlat(symbol.layout, {
155162
'text-size': trace.textfont.size,
156163
'text-anchor': textOpts.anchor,
157164
'text-offset': textOpts.offset,
158-
'text-font': trace.textfont.family.split(', '),
165+
'text-font': textFont
159166
});
160167

161168
Lib.extendFlat(symbol.paint, {

src/traces/scattermapbox/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
107107
handleTextDefaults(traceIn, traceOut, layout, coerce,
108108
{
109109
noSelect: true,
110-
noFontWeight: true,
111-
noFontStyle: true,
112110
noFontVariant: true,
113111
font: {
114112
family: supportedFonts.indexOf(layout.font.family) !== -1 ? layout.font.family : 'Open Sans Regular',
113+
weight: layout.font.weight,
114+
style: layout.font.style,
115115
size: layout.font.size,
116116
color: layout.font.color
117117
}
237 Bytes
Loading

test/image/mocks/mapbox_bubbles-text.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
],
3333
"textposition": "top left",
3434
"textfont": {
35+
"weight": "bold",
36+
"style": "italic",
3537
"size": 20,
3638
"color": "red"
3739
}

test/plot-schema.json

+44
Original file line numberDiff line numberDiff line change
@@ -3780,6 +3780,28 @@
37803780
"editType": "plot",
37813781
"min": 1,
37823782
"valType": "number"
3783+
},
3784+
"style": {
3785+
"description": "Sets whether a font should be styled with a normal or italic face from its family.",
3786+
"dflt": "normal",
3787+
"editType": "plot",
3788+
"valType": "enumerated",
3789+
"values": [
3790+
"normal",
3791+
"italic"
3792+
]
3793+
},
3794+
"weight": {
3795+
"description": "Sets the weight (or boldness) of the font.",
3796+
"dflt": "normal",
3797+
"editType": "plot",
3798+
"extras": [
3799+
"normal",
3800+
"bold"
3801+
],
3802+
"max": 1000,
3803+
"min": 1,
3804+
"valType": "integer"
37833805
}
37843806
},
37853807
"textposition": {
@@ -66656,6 +66678,28 @@
6665666678
"editType": "calc",
6665766679
"min": 1,
6665866680
"valType": "number"
66681+
},
66682+
"style": {
66683+
"description": "Sets whether a font should be styled with a normal or italic face from its family.",
66684+
"dflt": "normal",
66685+
"editType": "calc",
66686+
"valType": "enumerated",
66687+
"values": [
66688+
"normal",
66689+
"italic"
66690+
]
66691+
},
66692+
"weight": {
66693+
"description": "Sets the weight (or boldness) of the font.",
66694+
"dflt": "normal",
66695+
"editType": "calc",
66696+
"extras": [
66697+
"normal",
66698+
"bold"
66699+
],
66700+
"max": 1000,
66701+
"min": 1,
66702+
"valType": "integer"
6665966703
}
6666066704
},
6666166705
"textposition": {

0 commit comments

Comments
 (0)