@@ -7,14 +7,14 @@ using JSON
7
7
8
8
asset (url... ) = normpath (vegalite_app_path (" minified" , url... ))
9
9
10
- const package_json = Ref {Dict{String, Any}} ()
10
+ const package_json = Ref {Dict{String,Any}} ()
11
11
12
12
function 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
16
16
17
- return package_json[][" dependencies" ][package]
17
+ return package_json[][" dependencies" ][package]
18
18
end
19
19
20
20
# Vega Scaffold: https://github.com/vega/vega/wiki/Runtime
@@ -23,47 +23,50 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
23
23
divid = " vg" * randstring (3 )
24
24
25
25
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 = """ )
56
56
57
57
our_json_print (io, spec)
58
58
println (io)
59
59
60
- println (io, """
61
- vegaEmbed('#$divid ', spec, opt);
60
+ println (
61
+ io,
62
+ """
63
+ vegaEmbed('#$divid ', spec, opt);
62
64
63
- </script>
65
+ </script>
64
66
65
- </html>
66
- """ )
67
+ </html>
68
+ """
69
+ )
67
70
end
68
71
69
72
function writehtml_full (spec:: VGSpec ; title= " Vega plot" )
@@ -81,35 +84,41 @@ Creates a HTML script + div block for showing the plot (typically for Pluto).
81
84
VegaLite js files are loaded from the web using script tags.
82
85
"""
83
86
function 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
+ )
113
122
end
114
123
115
124
@@ -120,9 +129,9 @@ function launch_browser(tmppath::String)
120
129
if Sys. isapple ()
121
130
run (` open $tmppath ` )
122
131
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 ` )
126
135
end
127
136
end
128
137
0 commit comments