@@ -7,14 +7,14 @@ using JSON
77
88asset (url... ) = normpath (vegalite_app_path (" minified" , url... ))
99
10- const package_json = Ref {Dict{String, Any}} ()
10+ const package_json = Ref {Dict{String,Any}} ()
1111
1212function version (package)
13- if ! isassigned (package_json)
14- package_json[] = JSON. parsefile (vegalite_app_path (" package.json" ))
15- end
13+ if ! isassigned (package_json)
14+ package_json[] = JSON. parsefile (vegalite_app_path (" package.json" ))
15+ end
1616
17- return package_json[][" dependencies" ][package]
17+ return package_json[][" dependencies" ][package]
1818end
1919
2020# Vega Scaffold: https://github.com/vega/vega/wiki/Runtime
@@ -23,47 +23,50 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
2323 divid = " vg" * randstring (3 )
2424
2525 println (io,
26- """
27- <html>
28- <head>
29- <title>$title </title>
30- <meta charset="UTF-8">
31- <script>$(read (asset (" vega.min.js" ), String)) </script>
32- <script>$(read (asset (" vega-embed.min.js" ), String)) </script>
33- </head>
34- <body>
35- <div id="$divid " style="width:100%;height:100%;"></div>
36- </body>
37-
38- <style media="screen">
39- .vega-actions a {
40- margin-right: 10px;
41- font-family: sans-serif;
42- font-size: x-small;
43- font-style: italic;
44- }
45- </style>
46-
47- <script type="text/javascript">
48-
49- var opt = {
50- mode: "vega",
51- renderer: "$RENDERER ",
52- actions: $ACTIONSLINKS
53- }
54-
55- var spec = """ )
26+ """
27+ <html>
28+ <head>
29+ <title>$title </title>
30+ <meta charset="UTF-8">
31+ <script>$(read (asset (" vega.min.js" ), String)) </script>
32+ <script>$(read (asset (" vega-embed.min.js" ), String)) </script>
33+ </head>
34+ <body>
35+ <div id="$divid " style="width:100%;height:100%;"></div>
36+ </body>
37+
38+ <style media="screen">
39+ .vega-actions a {
40+ margin-right: 10px;
41+ font-family: sans-serif;
42+ font-size: x-small;
43+ font-style: italic;
44+ }
45+ </style>
46+
47+ <script type="text/javascript">
48+
49+ var opt = {
50+ mode: "vega",
51+ renderer: "$RENDERER ",
52+ actions: $ACTIONSLINKS
53+ }
54+
55+ var spec = """ )
5656
5757 our_json_print (io, spec)
5858 println (io)
5959
60- println (io, """
61- vegaEmbed('#$divid ', spec, opt);
60+ println (
61+ io,
62+ """
63+ vegaEmbed('#$divid ', spec, opt);
6264
63- </script>
65+ </script>
6466
65- </html>
66- """ )
67+ </html>
68+ """
69+ )
6770end
6871
6972function writehtml_full (spec:: VGSpec ; title= " Vega plot" )
@@ -81,35 +84,41 @@ Creates a HTML script + div block for showing the plot (typically for Pluto).
8184VegaLite js files are loaded from the web using script tags.
8285"""
8386function writehtml_partial_script (io:: IO , spec:: VGSpec ; title= " VegaLite plot" )
84- divid = " vg" * randstring (3 )
85- print (io, """
86- <style media="screen">
87- .vega-actions a {
88- margin-right: 10px;
89- font-family: sans-serif;
90- font-size: x-small;
91- font-style: italic;
92- }
93- </style>
94-
95- <script src="https://cdn.jsdelivr.net/npm/vega@$(version (" vega" )) /build/vega.min.js"></script>
96- <script src="https://cdn.jsdelivr.net/npm/vega-embed@$(version (" vega-embed" )) /build/vega-embed.min.js"></script>
97-
98- <div id="$divid "></div>
99-
100- <script>
101- var spec = """ )
102- our_json_print (io, spec)
103- print (io,"""
104- ;
105- var opt = {
106- mode: "vega-lite",
107- renderer: "$(Vega. RENDERER) ",
108- actions: $(Vega. ACTIONSLINKS)
109- };
110- vegaEmbed("#$divid ", spec, opt);
111- </script>
112- """ )
87+ divid = " vg" * randstring (3 )
88+ print (
89+ io,
90+ """
91+ <style media="screen">
92+ .vega-actions a {
93+ margin-right: 10px;
94+ font-family: sans-serif;
95+ font-size: x-small;
96+ font-style: italic;
97+ }
98+ </style>
99+
100+ <script src="https://cdn.jsdelivr.net/npm/vega@$(version (" vega" )) /build/vega.min.js"></script>
101+ <script src="https://cdn.jsdelivr.net/npm/vega-embed@$(version (" vega-embed" )) /build/vega-embed.min.js"></script>
102+
103+ <div id="$divid "></div>
104+
105+ <script>
106+ var spec = """
107+ )
108+ our_json_print (io, spec)
109+ print (
110+ io,
111+ """
112+ ;
113+ var opt = {
114+ mode: "vega-lite",
115+ renderer: "$(Vega. RENDERER) ",
116+ actions: $(Vega. ACTIONSLINKS)
117+ };
118+ vegaEmbed("#$divid ", spec, opt);
119+ </script>
120+ """
121+ )
113122end
114123
115124
@@ -120,9 +129,9 @@ function launch_browser(tmppath::String)
120129 if Sys. isapple ()
121130 run (` open $tmppath ` )
122131 elseif Sys. iswindows ()
123- run (` cmd /c start $tmppath ` )
124- elseif Sys. islinux ()
125- run (` xdg-open $tmppath ` )
132+ run (` cmd /c start $tmppath ` )
133+ elseif Sys. islinux ()
134+ run (` xdg-open $tmppath ` )
126135 end
127136end
128137
0 commit comments