Skip to content

Commit 3e4942a

Browse files
committed
fall back for unsupported font-weight values
1 parent 46e6b27 commit 3e4942a

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

src/plots/font_attributes.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ module.exports = function(opts) {
2020
var editType = opts.editType;
2121
var colorEditType = opts.colorEditType;
2222
if(colorEditType === undefined) colorEditType = editType;
23+
24+
var weight = {
25+
editType: editType,
26+
valType: 'integer',
27+
min: 1,
28+
max: 1000,
29+
extras: ['normal', 'bold'],
30+
dflt: 'normal',
31+
description: [
32+
'Sets the weight (or boldness) of the font.'
33+
].join(' ')
34+
};
35+
36+
if(opts.noNumericWeightValues) {
37+
weight.valType = 'enumerated';
38+
weight.values = weight.extras;
39+
weight.extras = undefined;
40+
weight.min = undefined;
41+
weight.max = undefined;
42+
}
43+
2344
var attrs = {
2445
family: {
2546
valType: 'string',
@@ -49,17 +70,7 @@ module.exports = function(opts) {
4970
editType: colorEditType
5071
},
5172

52-
weight: {
53-
editType: editType,
54-
valType: 'integer',
55-
min: 1,
56-
max: 1000,
57-
extras: ['normal', 'bold'],
58-
dflt: 'normal',
59-
description: [
60-
'Sets the weight (or boldness) of the font.'
61-
].join(' ')
62-
},
73+
weight: weight,
6374

6475
style: {
6576
editType: editType,

src/traces/scattergl/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var attrs = module.exports = overrideAll({
4141
editType: 'calc',
4242
colorEditType: 'style',
4343
arrayOk: true,
44+
noNumericWeightValues: true,
4445
variantValues: ['normal', 'small-caps'],
4546
description: 'Sets the text font.'
4647
}),

src/traces/scattergl/convert.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function convertTextStyle(gd, trace) {
190190
if(
191191
isArrayOrTypedArray(tfs) ||
192192
Array.isArray(tff) ||
193-
Array.isArray(tfw) ||
193+
Lib.isArrayOrTypedArray(tfw) ||
194194
Array.isArray(tfy) ||
195195
Array.isArray(tfv)
196196
) {
@@ -207,7 +207,7 @@ function convertTextStyle(gd, trace) {
207207
) * plotGlPixelRatio;
208208

209209
fonti.family = Array.isArray(tff) ? tff[i] : tff;
210-
fonti.weight = Array.isArray(tfw) ? tfw[i] : tfw;
210+
fonti.weight = weightFallBack(Lib.isArrayOrTypedArray(tfw) ? tfw[i] : tfw);
211211
fonti.style = Array.isArray(tfy) ? tfy[i] : tfy;
212212
fonti.variant = Array.isArray(tfv) ? tfv[i] : tfv;
213213
}
@@ -216,7 +216,7 @@ function convertTextStyle(gd, trace) {
216216
optsOut.font = {
217217
size: tfs * plotGlPixelRatio,
218218
family: tff,
219-
weight: tfw,
219+
weight: weightFallBack(tfw),
220220
style: tfy,
221221
variant: tfv
222222
};
@@ -225,6 +225,12 @@ function convertTextStyle(gd, trace) {
225225
return optsOut;
226226
}
227227

228+
function weightFallBack(w) {
229+
if(w <= 1000) {
230+
return w > 500 ? 'bold' : 'normal';
231+
}
232+
return w;
233+
}
228234

229235
function convertMarkerStyle(gd, trace) {
230236
var count = trace._length;

test/plot-schema.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65049,13 +65049,11 @@
6504965049
"description": "Sets the weight (or boldness) of the font.",
6505065050
"dflt": "normal",
6505165051
"editType": "calc",
65052-
"extras": [
65052+
"valType": "enumerated",
65053+
"values": [
6505365054
"normal",
6505465055
"bold"
65055-
],
65056-
"max": 1000,
65057-
"min": 1,
65058-
"valType": "integer"
65056+
]
6505965057
},
6506065058
"weightsrc": {
6506165059
"description": "Sets the source reference on Chart Studio Cloud for `weight`.",
@@ -70939,13 +70937,11 @@
7093970937
"description": "Sets the weight (or boldness) of the font.",
7094070938
"dflt": "normal",
7094170939
"editType": "calc",
70942-
"extras": [
70940+
"valType": "enumerated",
70941+
"values": [
7094370942
"normal",
7094470943
"bold"
70945-
],
70946-
"max": 1000,
70947-
"min": 1,
70948-
"valType": "integer"
70944+
]
7094970945
},
7095070946
"weightsrc": {
7095170947
"description": "Sets the source reference on Chart Studio Cloud for `weight`.",

0 commit comments

Comments
 (0)