Skip to content

Commit ab3fd74

Browse files
Deprecate export functions in favour of :vega_lite_convert (#82)
1 parent 2d0c0e4 commit ab3fd74

File tree

4 files changed

+23
-100
lines changed

4 files changed

+23
-100
lines changed

lib/vega_lite.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ defmodule VegaLite do
9999
`axis: [label_angle: -45]`, this library will automatically
100100
rewrite it `labelAngle`, which is the name used by the VegaLite
101101
specification.
102+
103+
## Export
104+
105+
`VegaLite` graphics can be exported into various formats, such as
106+
SVG, PNG and PDF thorugh the [`:vega_lite_convert`](https://hexdocs.pm/vega_lite_convert)
107+
package.
102108
"""
103109

104110
@schema_url "https://vega.github.io/schema/vega-lite/v5.json"

lib/vega_lite/export.ex

Lines changed: 11 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
1+
# TODO: remove on v1.0
12
defmodule VegaLite.Export do
2-
@moduledoc """
3-
Various export methods for a `VegaLite` specification.
4-
5-
All of the export functions depend on the `:jason` package.
6-
Additionally the PNG, SVG and PDF exports rely on npm packages,
7-
so you will need Node.js, `npm`, and the following dependencies:
8-
9-
```console
10-
$ npm install -g vega vega-lite canvas
11-
```
12-
13-
Alternatively you can install the dependencies in a local directory:
14-
15-
```console
16-
$ npm install vega vega-lite canvas
17-
```
18-
"""
3+
@moduledoc false
194

205
alias VegaLite.Utils
216

22-
@doc """
23-
Saves a `VegaLite` specification to file in one of
24-
the supported formats.
25-
26-
## Options
27-
28-
* `:format` - the format to export the graphic as,
29-
must be either of: `:json`, `:html`, `:png`, `:svg`, `:pdf`.
30-
By default the format is inferred from the file extension.
31-
32-
* `:local_npm_prefix` - a relative path pointing to a local npm project directory
33-
where the necessary npm packages are installed. For instance, in Phoenix projects
34-
you may want to pass `local_npm_prefix: "assets"`. By default the npm packages
35-
are searched for in the current directory and globally.
36-
37-
"""
7+
@deprecated "Use VegaLite.Convert.save!/3 in from the :vega_lite_convert package instead"
388
@spec save!(VegaLite.t(), binary(), keyword()) :: :ok
399
def save!(vl, path, opts \\ []) do
4010
{format, opts} =
@@ -69,9 +39,7 @@ defmodule VegaLite.Export do
6939

7040
@compile {:no_warn_undefined, {Jason, :encode!, 1}}
7141

72-
@doc """
73-
Returns the underlying Vega-Lite specification as JSON.
74-
"""
42+
@deprecated "Use VegaLite.Convert.to_json/1 in from the :vega_lite_convert package instead"
7543
@spec to_json(VegaLite.t()) :: String.t()
7644
def to_json(vl) do
7745
Utils.assert_jason!("to_json/1")
@@ -81,12 +49,7 @@ defmodule VegaLite.Export do
8149
|> Jason.encode!()
8250
end
8351

84-
@doc """
85-
Builds an HTML page that renders the given graphic.
86-
87-
The HTML page loads necessary JavaScript dependencies from a CDN
88-
and then renders the graphic in a root element.
89-
"""
52+
@deprecated "Use VegaLite.Convert.to_html/1 in from the :vega_lite_convert package instead"
9053
@spec to_html(VegaLite.t()) :: binary()
9154
def to_html(vl) do
9255
json = to_json(vl)
@@ -113,62 +76,26 @@ defmodule VegaLite.Export do
11376
"""
11477
end
11578

79+
@doc false
80+
def to_html_no_deprecation(vl), do: to_html(vl)
81+
11682
defp escape_double_quotes(json) do
11783
String.replace(json, ~s{"}, ~s{\\"})
11884
end
11985

120-
@doc """
121-
Renders the given graphic as a PNG image and returns
122-
its binary content.
123-
124-
Relies on the `npm` packages mentioned above.
125-
126-
## Options
127-
128-
* `:local_npm_prefix` - a relative path pointing to a local npm project directory
129-
where the necessary npm packages are installed. For instance, in Phoenix projects
130-
you may want to pass `local_npm_prefix: "assets"`. By default the npm packages
131-
are searched for in the current directory and globally.
132-
133-
"""
86+
@deprecated "Use VegaLite.Convert.to_png/1 in from the :vega_lite_convert package instead"
13487
@spec to_png(VegaLite.t(), keyword()) :: binary()
13588
def to_png(vl, opts \\ []) do
13689
node_convert(vl, "png", "to_png/1", opts)
13790
end
13891

139-
@doc """
140-
Renders the given graphic as an SVG image and returns
141-
its binary content.
142-
143-
Relies on the `npm` packages mentioned above.
144-
145-
## Options
146-
147-
* `:local_npm_prefix` - a relative path pointing to a local npm project directory
148-
where the necessary npm packages are installed. For instance, in Phoenix projects
149-
you may want to pass `local_npm_prefix: "assets"`. By default the npm packages
150-
are searched for in the current directory and globally.
151-
152-
"""
92+
@deprecated "Use VegaLite.Convert.to_svg/1 in from the :vega_lite_convert package instead"
15393
@spec to_svg(VegaLite.t(), keyword()) :: binary()
15494
def to_svg(vl, opts \\ []) do
15595
node_convert(vl, "svg", "to_svg/1", opts)
15696
end
15797

158-
@doc """
159-
Renders the given graphic into a PDF and returns its
160-
binary content.
161-
162-
Relies on the `npm` packages mentioned above.
163-
164-
## Options
165-
166-
* `:local_npm_prefix` - a relative path pointing to a local npm project directory
167-
where the necessary npm packages are installed. For instance, in Phoenix projects
168-
you may want to pass `local_npm_prefix: "assets"`. By default the npm packages
169-
are searched for in the current directory and globally.
170-
171-
"""
98+
@deprecated "Use VegaLite.Convert.to_pdf/1 in from the :vega_lite_convert package instead"
17299
@spec to_pdf(VegaLite.t(), keyword()) :: binary()
173100
def to_pdf(vl, opts \\ []) do
174101
node_convert(vl, "pdf", "to_pdf/1", opts)

lib/vega_lite/viewer.ex

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1+
# TODO: remove on v1.0
12
defmodule VegaLite.Viewer do
2-
@moduledoc """
3-
Graphics rendering using Erlang's `:wx` bindings.
3+
@moduledoc false
44

5-
This method is useful for viewing graphics in scripts
6-
and IEx sessions. Note it requires Erlang/OTP 24+ with
7-
a recent WxWidgets installation with webview support.
8-
"""
9-
10-
@doc """
11-
Renders a `VegaLite` specification in GUI window widget.
12-
13-
Requires Erlang compilation to include the `:wx` module.
14-
"""
5+
@deprecated "Use VegaLite.Convert.open_viewer/1 in from the :vega_lite_convert package instead"
156
@spec show(VegaLite.t()) :: :ok | :error
167
def show(vl) do
178
with {:ok, _pid} <- start_wx_viewer(vl), do: :ok
189
end
1910

20-
@doc """
21-
Same as `show/1`, but blocks until the window widget is closed.
22-
"""
11+
@deprecated "Use VegaLite.Convert.open_viewer_and_wait/1 in from the :vega_lite_convert package instead"
2312
@spec show_and_wait(VegaLite.t()) :: :ok | :error
2413
def show_and_wait(vl) do
2514
with {:ok, pid} <- start_wx_viewer(vl) do
@@ -33,7 +22,7 @@ defmodule VegaLite.Viewer do
3322

3423
defp start_wx_viewer(vl) do
3524
vl
36-
|> VegaLite.Export.to_html()
25+
|> VegaLite.Export.to_html_no_deprecation()
3726
|> VegaLite.WxViewer.start()
3827
end
3928
end

lib/vega_lite/wx_viewer.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: remove on v1.0
12
defmodule VegaLite.WxViewer do
23
@moduledoc false
34

0 commit comments

Comments
 (0)