Skip to content
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

Add support for numeric font weight #6990

Merged
merged 33 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
37dee48
Revert "no integer weight"
archmoj May 3, 2024
3212866
also drop font-weight 400 when exporting to SVG
archmoj May 3, 2024
448eb80
test scatter font weight
archmoj May 3, 2024
3a3f458
test bar font weight
archmoj May 3, 2024
15b25a5
use numeric font-weight in mocks
archmoj May 3, 2024
be24a14
skip validating font-weight-bar mock
archmoj May 3, 2024
d8424a3
draft log
archmoj May 6, 2024
353efc4
numeric text weight in gl3d
archmoj May 6, 2024
abb3fc8
link to include extra valid font-weight options in css-font and gl-text
archmoj May 6, 2024
8266a6d
test numeric font-weight values in scattergl pipeline
archmoj May 6, 2024
46e6b27
Revert "link to include extra valid font-weight options in css-font a…
archmoj May 6, 2024
3e4942a
fall back for unsupported font-weight values
archmoj May 6, 2024
72044b5
scattergl numeric font-weight render using bold/normal fallback
archmoj May 6, 2024
4d52885
correct mock name
archmoj May 6, 2024
b92ef23
improve scattergl test
archmoj May 6, 2024
b125396
test numeric weight in gl2d axis text
archmoj May 6, 2024
54005b9
convert typed array spec in integer, number, color, etc
archmoj May 6, 2024
09f4dd3
handle typed arrays in scatter3d
archmoj May 6, 2024
f67b40c
handle typed arrays in gl-axes3d
archmoj May 6, 2024
99162e5
handle numeric font weight in mapbox supported fonts
archmoj May 6, 2024
990fa8d
fix toSVG using weight: 400
archmoj May 6, 2024
f3c0356
improve mapbox text weight and italic handling
archmoj May 6, 2024
a5cc7f8
fix support of Open Sans Extrabold fonts
archmoj May 7, 2024
63824c1
test metropolis fonts on mapbox
archmoj May 7, 2024
190aef1
test italic Metropolis fonts
archmoj May 7, 2024
091e7d3
add weight test for open sans fonts - duplicate simple open-sans base…
archmoj May 7, 2024
82de3ff
add weight test for metropolis fonts - duplicate simple metropolis ba…
archmoj May 7, 2024
59779f3
Revert "test italic Metropolis fonts"
archmoj May 7, 2024
f6fcbd7
test numeric weights on axes 3d
archmoj May 8, 2024
10f477f
bump gl-axes3d and gl-scatter3d
archmoj May 8, 2024
82863fd
refactor src/traces/scattergl/convert.js
archmoj May 8, 2024
bff00ac
improve font family checks
archmoj May 8, 2024
48d057f
add comment
archmoj May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6990_add.md
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)]
7 changes: 6 additions & 1 deletion src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ exports.valObjectMeta = {
'are coerced to the `dflt`.'
].join(' '),
requiredOpts: [],
otherOpts: ['dflt', 'min', 'max', 'arrayOk'],
otherOpts: ['dflt', 'min', 'max', 'arrayOk', 'extras'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archmoj Is this adding a new functionality to coerce, where numeric (or other) properties can also be configured to accept a list of 'extra' values?

That's pretty cool -- is there anywhere we should document that internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.
Yes that's true.
We have other types that support the extras option so I think it's clear internally.
But on plotly.py we need to see if this changes would be reflected properly by codegen.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 schema.json has changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a line in the docstring here explaining extras for integers (like the explanation here for flaglist)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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(v % 1 || !isNumeric(v) ||
(opts.min !== undefined && v < opts.min) ||
(opts.max !== undefined && v > opts.max)) {
Expand Down
6 changes: 4 additions & 2 deletions src/plots/font_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ module.exports = function(opts) {

weight: {
editType: editType,
valType: 'enumerated',
values: ['normal', 'bold'],
valType: 'integer',
min: 1,
max: 1000,
extras: ['normal', 'bold'],
dflt: 'normal',
description: [
'Sets the weight (or boldness) of the font.'
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot/tosvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function toSVG(gd, format, scale) {

// Drop normal font-weight, font-style and font-variant to reduce the size
var fw = this.style.fontWeight;
if(fw && fw === 'normal') {
if(fw && (fw === 'normal' || fw === 400)) { // font-weight 400 is similar to normal
txt.style('font-weight', undefined);
}
var fs = this.style.fontStyle;
Expand Down
1 change: 1 addition & 0 deletions tasks/test_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function notBlackListed(name) {
'fake_violins',
'fonts',
'font-variant-bar',
'zz-font-weight-bar',
'geo_africa-insets',
'gl2d_10',
'gl2d_12',
Expand Down
Binary file added test/image/baselines/zz-font-weight-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/zz-font-weight-scatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this mock, maybe use a font that has more available weights, to test that they work properly in WebGL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was interested to test it with the default font as that's what most users use at this moment.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/image/mocks/texttemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
],
"layout": {
"font": {
"weight": "bold",
"weight": 700,
"style": "italic",
"variant": "small-caps"
},
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/texttemplate_scatter.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
],
"layout": {
"font": {
"weight": "bold",
"weight": "700",
"style": "italic",
"variant": "small-caps"
},
Expand Down
68 changes: 68 additions & 0 deletions test/image/mocks/zz-font-weight-bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"data": [
{
"hovertemplate": "Difficult -0.123456789 | %{text}",
"texttemplate": "Difficult -0.123456789 | %{text}",
"text": [
"1 Minimum",
"100 Thin (Hairline)",
"200 Extra Light (Ultra Light)",
"300 Light",
"400 Normal (Regular)",
"500 Medium",
"600 Semi Bold (Demi Bold)",
"700 Bold",
"800 Extra Bold (Ultra Bold)",
"900 Black (Heavy)",
"950 Extra Black (Ultra Black)",
"1000 Maximum"
],
"textposition": "right",
"textfont": {
"size": 12,
"weight": [
1,
100,
200,
300,
400,
500,
600,
700,
800,
900,
950,
1000
]
},
"x": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
"type": "bar",
"orientation": "h"
}
],
"layout": {
"showlegend": false,
"margin": {
"l": 0,
"r": 0,
"t": 0,
"b": 0
},
"xaxis": {
"range": [1.1, -0.1],
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"yaxis": {
"range": [11.5, -0.5],
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"width": 400,
"height": 600,
"hovermode": "closest"
}
}
67 changes: 67 additions & 0 deletions test/image/mocks/zz-font-weight-scatter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"data": [
{
"hovertemplate": "Difficult -0.123456789 | %{text}",
"texttemplate": "Difficult -0.123456789 | %{text}",
"mode": "text",
"text": [
"1 Minimum",
"100 Thin (Hairline)",
"200 Extra Light (Ultra Light)",
"300 Light",
"400 Normal (Regular)",
"500 Medium",
"600 Semi Bold (Demi Bold)",
"700 Bold",
"800 Extra Bold (Ultra Bold)",
"900 Black (Heavy)",
"950 Extra Black (Ultra Black)",
"1000 Maximum"
],
"textfont": {
"family": "Inter",
"size": 16,
"weight": [
1,
100,
200,
300,
400,
500,
600,
700,
800,
900,
950,
1000
]
},
"x": [0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0],
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
}
],
"layout": {
"showlegend": false,
"margin": {
"l": 0,
"r": 0,
"t": 0,
"b": 0
},
"xaxis": {
"range": [-1, 1],
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"yaxis": {
"range": [11.5, -0.5],
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"width": 400,
"height": 600,
"hovermode": "closest"
}
}
99 changes: 99 additions & 0 deletions test/image/mocks/zz-gl3d_font-weight-scatter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"data": [
{
"type": "scatter3d",
"hovertemplate": "Difficult -0.123456789 | %{text}",
"texttemplate": "Difficult -0.123456789 | %{text}",
"mode": "text",
"text": [
"1 Minimum",
"100 Thin (Hairline)",
"200 Extra Light (Ultra Light)",
"300 Light",
"400 Normal (Regular)",
"500 Medium",
"600 Semi Bold (Demi Bold)",
"700 Bold",
"800 Extra Bold (Ultra Bold)",
"900 Black (Heavy)",
"950 Extra Black (Ultra Black)",
"1000 Maximum"
],
"textfont": {
"family": "Inter",
"size": 16,
"weight": [
1,
100,
200,
300,
400,
500,
600,
700,
800,
900,
950,
1000
]
},
"z": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"x": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"y": [-5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5]
}
],
"layout": {
"showlegend": false,
"margin": {
"l": 0,
"r": 0,
"t": 0,
"b": 0
},
"scene": {
"xaxis": {
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"yaxis": {
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"zaxis": {
"showticklabels": false,
"showgrid": false,
"zeroline": false
},
"aspectratio": {
"x": 1.5,
"y": 1.5,
"z": 1.5
},
"camera": {
"projection": {
"type": "orthographic"
},
"eye": {
"x": 0,
"y": 0,
"z": 10
},
"center": {
"x": 0,
"y": 0,
"z": 0
},
"up": {
"x": 0,
"y": 1,
"z": 0
}
}
},
"width": 400,
"height": 400,
"hovermode": "closest"
}
}
Loading