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

Error if title fontWeight is a number #46

Closed
binste opened this issue Apr 4, 2023 · 5 comments · Fixed by #48
Closed

Error if title fontWeight is a number #46

binste opened this issue Apr 4, 2023 · 5 comments · Fixed by #48

Comments

@binste
Copy link

binste commented Apr 4, 2023

fontWeight of a view title can be either a string such as "bold" or a number such as 600, see the VL docs. However, when using a number, vl-convert gives an error about "expected a string". It works for e.g. "bold". I haven't tested other titles or texts, maybe they have the same issue.

Example spec which fails:

import vl_convert as vlc

vl_spec = """{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "Some title",
  "config": {"title": {"fontWeight": 600}},
  "data": {
    "values": [
      {"a": "A", "b": 28}, {"a": "B", "b": 55}, {"a": "C", "b": 43},
      {"a": "D", "b": 91}, {"a": "E", "b": 81}, {"a": "F", "b": 53},
      {"a": "G", "b": 19}, {"a": "H", "b": 87}, {"a": "I", "b": 52}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
    "y": {"field": "b", "type": "quantitative"}
  }
}"""
svg_str = vlc.vegalite_to_svg(vl_spec)

Error:

ERROR Error: Failed to deserialize text info: invalid type: integer `600`, expected a string at line 2 column 15
    at Object.sg.textMetrics.width (<anon>:14:30)
    at Be (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-scenegraph.js:1:29874)
    at $ (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-view-transforms.js:1:1587)
    at https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-view-transforms.js:1:1277
    at Array.forEach (<anonymous>)
    at gt.transform (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-view-transforms.js:1:1258)
    at gt.evaluate (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:15456)
    at gt.run (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:15313)
    at ne.Jt [as evaluate] (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-dataflow.js:1:12100)
    at ne.evaluate (https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports,min/optimized/vega-view.js:2:1621)
@jonmmease
Copy link
Collaborator

Thanks for the helpful report @binste.

Looks like weight here needs to accept a number:

weight: Option<String>,

@jonmmease
Copy link
Collaborator

Fix in progress in #48

@jonmmease
Copy link
Collaborator

@binste is this blocking you or are you able to work around it for the time being? It's now fixed on main, but I'm debating whether to publish a fix immediately or just wait until Vega-Lite 5.7 is released (I'll definitely do a release after Vega-Lite 5.7 and before Altair 5).

@binste
Copy link
Author

binste commented Apr 4, 2023

Thank you for asking and working on it so quickly! I switched to fontWeight "bold" which works for the use case I had so it's not blocking me. Releasing the fix together with support for VL 5.7 sounds good.

@jonmmease
Copy link
Collaborator

Fix released in 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants