-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for numeric font weight
#6990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
37dee48
3212866
448eb80
3a3f458
15b25a5
be24a14
d8424a3
353efc4
abb3fc8
8266a6d
46e6b27
3e4942a
72044b5
4d52885
b92ef23
b125396
54005b9
09f4dd3
f67b40c
99162e5
990fa8d
f3c0356
a5cc7f8
63824c1
190aef1
091e7d3
82de3ff
59779f3
f6fcbd7
10f477f
82863fd
bff00ac
48d057f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add support for numeric text font `weight` [[#6990](https://github.com/plotly/plotly.js/pull/6990)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,8 @@ exports.valObjectMeta = { | |
requiredOpts: [], | ||
otherOpts: ['dflt', 'min', 'max', 'arrayOk'], | ||
coerceFunction: function(v, propOut, dflt, opts) { | ||
if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v); | ||
|
||
if(!isNumeric(v) || | ||
(opts.min !== undefined && v < opts.min) || | ||
(opts.max !== undefined && v > opts.max)) { | ||
|
@@ -114,8 +116,15 @@ exports.valObjectMeta = { | |
'are coerced to the `dflt`.' | ||
].join(' '), | ||
requiredOpts: [], | ||
otherOpts: ['dflt', 'min', 'max', 'arrayOk'], | ||
otherOpts: ['dflt', 'min', 'max', 'arrayOk', 'extras'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @archmoj Is this adding a new functionality to That's pretty cool -- is there anywhere we should document that internally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Makes me think, it would be awesome if we could build checking the Plotly.py codegen into the CI process. It would have to produce some kind of output that's easy to verify. It could run only if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a line in the docstring here explaining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For flag lists combination mean something. That's why it is commented. |
||
coerceFunction: function(v, propOut, dflt, opts) { | ||
if((opts.extras || []).indexOf(v) !== -1) { | ||
propOut.set(v); | ||
return; | ||
} | ||
|
||
if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v); | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(v % 1 || !isNumeric(v) || | ||
(opts.min !== undefined && v < opts.min) || | ||
(opts.max !== undefined && v > opts.max)) { | ||
|
@@ -156,6 +165,8 @@ exports.valObjectMeta = { | |
requiredOpts: [], | ||
otherOpts: ['dflt', 'arrayOk'], | ||
coerceFunction: function(v, propOut, dflt) { | ||
if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v); | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(tinycolor(v).isValid()) propOut.set(v); | ||
else propOut.set(dflt); | ||
} | ||
|
@@ -198,6 +209,8 @@ exports.valObjectMeta = { | |
requiredOpts: [], | ||
otherOpts: ['dflt', 'arrayOk'], | ||
coerceFunction: function(v, propOut, dflt) { | ||
if(isTypedArraySpec(v)) v = decodeTypedArraySpec(v); | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(v === 'auto') propOut.set('auto'); | ||
else if(!isNumeric(v)) propOut.set(dflt); | ||
else propOut.set(modHalf(+v, 360)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,7 @@ function convertTextStyle(gd, trace) { | |
if( | ||
isArrayOrTypedArray(tfs) || | ||
Array.isArray(tff) || | ||
Array.isArray(tfw) || | ||
Lib.isArrayOrTypedArray(tfw) || | ||
archmoj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Array.isArray(tfy) || | ||
Array.isArray(tfv) | ||
) { | ||
|
@@ -207,7 +207,7 @@ function convertTextStyle(gd, trace) { | |
) * plotGlPixelRatio; | ||
|
||
fonti.family = Array.isArray(tff) ? tff[i] : tff; | ||
fonti.weight = Array.isArray(tfw) ? tfw[i] : tfw; | ||
fonti.weight = weightFallBack(Lib.isArrayOrTypedArray(tfw) ? tfw[i] : tfw); | ||
fonti.style = Array.isArray(tfy) ? tfy[i] : tfy; | ||
fonti.variant = Array.isArray(tfv) ? tfv[i] : tfv; | ||
} | ||
|
@@ -216,7 +216,7 @@ function convertTextStyle(gd, trace) { | |
optsOut.font = { | ||
size: tfs * plotGlPixelRatio, | ||
family: tff, | ||
weight: tfw, | ||
weight: weightFallBack(tfw), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed if we are already disallowing numeric weight values at the schema level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha, thank you. Could you perhaps add that as a comment above the function definition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 48d057f. |
||
style: tfy, | ||
variant: tfv | ||
}; | ||
|
@@ -225,6 +225,12 @@ function convertTextStyle(gd, trace) { | |
return optsOut; | ||
} | ||
|
||
function weightFallBack(w) { | ||
if(w <= 1000) { | ||
return w > 500 ? 'bold' : 'normal'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the threshold be 400? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 500 is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, ok, I guess if the only options are |
||
} | ||
return w; | ||
} | ||
|
||
function convertMarkerStyle(gd, trace) { | ||
var count = trace._length; | ||
|
Uh oh!
There was an error while loading. Please reload this page.