Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Chart with arc mark (pie chart) using Selenium backend errors out #90

Closed
ostefano opened this issue Jan 11, 2021 · 6 comments
Closed

Chart with arc mark (pie chart) using Selenium backend errors out #90

ostefano opened this issue Jan 11, 2021 · 6 comments

Comments

@ostefano
Copy link

ostefano commented Jan 11, 2021

I am using 'master' and I fail to create PNG exports using Selenium using example data 'https://vega.github.io/vega-lite/examples/layer_arc_label.html'.

Note that the whole setup works perfectly for any other type of chart.

I am invoking altair_saver.save method with the following options {"method": "selenium", "scale_factor": 2.0}, and forcing output to PNG using a filename with a PNG extension, and I get the following error:

Traceback (most recent call last):
  File "./scripts/generate_chart.py", line 231, in <module>
    sys.exit(main())
  File "./scripts/generate_chart.py", line 145, in main
    package_name.save_chart(data_def, args.output_directory, "name")
  File "/Users/user/Workspace/package-name/package_name/__init__.py", line 49, in save_chart
    altair_saver.save(chart, **option_set)
  File "/Users/user/.virtualenvs/venv36/src/altair-saver/altair_saver/_core.py", line 172, in save
    return saver.save(fp=fp, fmt=fmt)
  File "/Users/user/.virtualenvs/venv36/src/altair-saver/altair_saver/savers/_saver.py", line 121, in save
    content = self._serialize(fmt, "save")
  File "/Users/user/.virtualenvs/venv36/src/altair-saver/altair_saver/savers/_selenium.py", line 284, in _serialize
    out = self._extract(fmt)
  File "/Users/user/.virtualenvs/venv36/src/altair-saver/altair_saver/savers/_selenium.py", line 280, in _extract
    raise JavascriptError(result["error"])
altair_saver.savers._selenium.JavascriptError: TypeError: Cannot read property 'orient' of undefined

The error pops up only with the selenium backend (node backend works alright, but resolution of the image if quite sub-optimal, hence the choice of the selenium backend)

I am using the following dependencies (requirements.txt file):

-e git+https://github.com/altair-viz/altair.git@81b40755c51b5821b078d36702b3cccadfc84071#egg=altair
-e git+https://github.com/altair-viz/altair_saver.git@3c8e1102776a7acd2c971354190a283c394d1cfd#egg=altair-saver
altair-data-server==0.4.1
altair-viewer==0.3.0
attrs==20.3.0
entrypoints==0.3
importlib-metadata==3.3.0
Jinja2==2.11.2
jsonschema==3.2.0
MarkupSafe==1.1.1
numpy==1.19.5
pandas==1.1.5
portpicker==1.3.1
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2020.5
selenium==3.141.0
six==1.15.0
toolz==0.11.1
tornado==6.1
typing-extensions==3.7.4.3
urllib3==1.26.2
vega-datasets==0.9.0
vegascope==1.0.14
zipp==3.4.0
@jakevdp
Copy link
Member

jakevdp commented Jan 11, 2021

Can you share the code you are using? The bundled vega libraries do not support pie charts (radial marks were added in a later release) so I wouldn't expect it to work unless you're using JS libraries loaded from CDN.

@ostefano
Copy link
Author

I am passing to altair_saver.save the Vega-Lite JSON definition below as python dictionary with the options I mentioned in the previous post. Nothing more than that. Let me know if you need more info.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "A simple pie chart with labels.",
  "data": {
    "values": [
      {"category": "a", "value": 4},
      {"category": "b", "value": 6},
      {"category": "c", "value": 10},
      {"category": "d", "value": 3},
      {"category": "e", "value": 7},
      {"category": "f", "value": 8}
    ]
  },
  "encoding": {
    "theta": {"field": "value", "type": "quantitative", "stack": true},
    "color": {"field": "category", "type": "nominal", "legend": null}
  },
  "layer": [{
    "mark": {"type": "arc", "outerRadius": 80}
  }, {
    "mark": {"type": "text", "radius": 90},
    "encoding": {
      "text": {"field": "category", "type": "nominal"}
    }
  }],
  "view": {"stroke": null}
}

@jakevdp
Copy link
Member

jakevdp commented Jan 11, 2021

As I mentioned, arc marks are not supported by the bundled javascript libraries. You'll have to save with offline=False and specify the versions of vega & vega-lite that you'd like to be used, because the Altair versions are too old. The relevant arguments can be seen here:

self,
spec: JSONDict,
mode: Optional[str] = None,
embed_options: Optional[JSONDict] = None,
vega_version: str = alt.VEGA_VERSION,
vegalite_version: str = alt.VEGALITE_VERSION,
vegaembed_version: str = alt.VEGAEMBED_VERSION,
driver_timeout: int = 20,
webdriver: Optional[Union[str, WebDriver]] = None,
offline: bool = True,
scale_factor: Optional[float] = 1,
**kwargs: Any,

@ostefano
Copy link
Author

Thanks @jakevdp for the snippet, that makes sense, feel free to close this.

By the way, is there any reason for the lower pace of altair/altair_saver releases?
I see there are many little issues that require using the package in master and not a proper release.

@jakevdp
Copy link
Member

jakevdp commented Jan 11, 2021

It's mainly that Vega-Lite 4.9 made some significant changes that will require some non-trivial adaption in Altair's wrappers, and its release happened to coincide with the time where a global pandemic caused me to lose childcare & out-of-home schooling for my kids.

@joelostblom
Copy link
Member

Since Altair 5.2, the functionality of Altair Saver is now available in Altair via the vl-convert package. Most of the functionality has been available since 5.0, and the main addition in 5.2 was PDF export. See the docs on how to save charts for more details

We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.

@joelostblom joelostblom closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants