#85 Fix tests

Merged David Anthoff davidanthoff Pseudo commit used to compare (b221b11...e421241)
Missing base report.

Unable to compare commits because the base of the pull request did not upload a coverage report.

Changes found in between b221b11...e421241 (pseudo...base) which prevent comparing this pull request.

Showing 2 of 36 files from the diff.
Newly tracked file
src/vega.jl changed.
Other files ignored by Codecov
test/runtests.jl has changed.
appveyor.yml was deleted.
docs/Project.toml has changed.
Project.toml has changed.
README.md has changed.
docs/make.jl has changed.
.gitignore has changed.
.travis.yml was deleted.

@@ -2,10 +2,15 @@
Loading
2 2
3 3
export electrondisplay
4 4
5 -
using Electron, Base64, Markdown
5 +
using Electron, Base64, Markdown, JSON
6 6
7 7
import IteratorInterfaceExtensions, TableTraits, TableShowUtils
8 8
9 +
using FilePaths
10 +
11 +
asset(url...) = replace(normpath(joinpath(@__DIR__, "..", "assets", url...)), "\\" => "/")
12 +
react_html_url = joinpath(@__PATH__, "..", "assets", "plotgallery", "index.html")
13 +
9 14
Base.@kwdef mutable struct ElectronDisplayConfig
10 15
    showable = electron_showable
11 16
    single_window::Bool = false
@@ -20,16 +25,16 @@
Loading
20 25
"""
21 26
setconfig(
22 27
    config::ElectronDisplayConfig;
23 -
    showable = config.showable,
24 -
    single_window::Bool = config.single_window,
25 -
    focus::Bool = config.focus,
26 -
    max_json_bytes::Int = config.max_json_bytes,
28 +
    showable=config.showable,
29 +
    single_window::Bool=config.single_window,
30 +
    focus::Bool=config.focus,
31 +
    max_json_bytes::Int=config.max_json_bytes,
27 32
) =
28 33
    ElectronDisplayConfig(
29 -
        showable = showable,
30 -
        single_window = single_window,
31 -
        focus = focus,
32 -
        max_json_bytes = max_json_bytes,
34 +
        showable=showable,
35 +
        single_window=single_window,
36 +
        focus=focus,
37 +
        max_json_bytes=max_json_bytes,
33 38
    )
34 39
35 40
struct ElectronDisplayType <: Base.AbstractDisplay
@@ -79,6 +84,27 @@
Loading
79 84
    return _window[]
80 85
end
81 86
87 +
const _plot_window = Ref{Window}()
88 +
89 +
function _getglobalplotwindow()
90 +
    if !(isdefined(_plot_window, 1) && _plot_window[].exists)
91 +
        _plot_window[] = Electron.Window(
92 +
            URI(react_html_url),
93 +
            options=Dict("webPreferences" => Dict("webSecurity" => false)))
94 +
    end
95 +
    return _plot_window[]
96 +
end
97 +
98 +
function displayplot(d::ElectronDisplayType, type::String, data; options::Dict=Dict{String,Any}())
99 +
    w = _getglobalplotwindow()
100 +
    run(w, "addPlot({type: '$(type)', data: $(JSON.json(data))})")
101 +
102 +
    showfun = get(options, "show", d.config.focus) ? "show" : "showInactive"
103 +
    run(w.app, "BrowserWindow.fromId($(w.id)).$showfun()")
104 +
105 +
    return w
106 +
end
107 +
82 108
function displayhtml(d::ElectronDisplayType, payload; options::Dict=Dict{String,Any}())
83 109
    if d.config.single_window
84 110
        w = _getglobalwindow()
@@ -153,61 +179,26 @@
Loading
153 179
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("image/png")}, x)
154 180
    img = stringmime(MIME("image/png"), x)
155 181
156 -
    payload = string("<img src=\"data:image/png;base64,", img, "\"/>")
182 +
    imgdata = "data:image/png;base64, $(img)"
157 183
158 -
    displayhtml(d, payload)
184 +
    displayplot(d, "image", imgdata)
159 185
end
160 186
161 187
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("image/png")}) = true
162 188
163 189
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("image/svg+xml")}, x)
164 -
    payload = stringmime(MIME("image/svg+xml"), x)
190 +
    img = stringmime(MIME("image/svg+xml"), x)
191 +
    imgdata = "data:image/svg+xml;base64, $(base64encode(img))"
165 192
166 -
    displayhtml(d, payload)
193 +
    displayplot(d, "image", imgdata)
167 194
end
168 195
169 196
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("image/svg+xml")}) = true
170 197
171 -
asset(url...) = replace(normpath(joinpath(@__DIR__, "..", "assets", url...)), "\\" => "/")
172 -
173 198
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.plotly.v1+json")}, x)
174 199
    payload = stringmime(MIME("application/vnd.plotly.v1+json"), x)
175 200
176 -
    html_page = """
177 -
    <html>
178 -
179 -
    <head>
180 -
        <script src="file:///$(asset("plotly", "plotly-latest.min.js"))"></script>
181 -
    </head>
182 -
    <body>
183 -
    </body>
184 -
185 -
    <script type="text/javascript">
186 -
        gd = (function() {
187 -
            var WIDTH_IN_PERCENT_OF_PARENT = 100
188 -
            var HEIGHT_IN_PERCENT_OF_PARENT = 100;
189 -
            var gd = Plotly.d3.select('body')
190 -
                .append('div').attr("id", "plotdiv")
191 -
                .style({
192 -
                    width: WIDTH_IN_PERCENT_OF_PARENT + '%',
193 -
                    'margin-left': (100 - WIDTH_IN_PERCENT_OF_PARENT) / 2 + '%',
194 -
                    height: HEIGHT_IN_PERCENT_OF_PARENT + 'vh',
195 -
                    'margin-top': (100 - HEIGHT_IN_PERCENT_OF_PARENT) / 2 + 'vh'
196 -
                })
197 -
                .node();
198 -
            var spec = $payload
199 -
            Plotly.newPlot(gd, spec.data, spec.layout);
200 -
            window.onresize = function() {
201 -
                Plotly.Plots.resize(gd);
202 -
                };
203 -
            return gd;
204 -
        })();
205 -
    </script>
206 -
207 -
    </html>
208 -
    """
209 -
210 -
    displayhtml(d, html_page, options=Dict("webPreferences" => Dict("webSecurity" => false)))
201 +
    displayplot(d, "plotly", payload)
211 202
end
212 203
213 204
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.plotly.v1+json")}) = true
@@ -269,30 +260,32 @@
Loading
269 260
270 261
function Base.display(d::ElectronDisplayType, x)
271 262
    showable = d.config.showable
272 -
    if showable("application/vnd.vegalite.v3+json", x)
273 -
        display(d,MIME("application/vnd.vegalite.v3+json"), x)
263 +
    if showable("application/vnd.vegalite.v4+json", x)
264 +
        display(d, MIME("application/vnd.vegalite.v4+json"), x)
265 +
    elseif showable("application/vnd.vegalite.v3+json", x)
266 +
        display(d, MIME("application/vnd.vegalite.v3+json"), x)
274 267
    elseif showable("application/vnd.vegalite.v2+json", x)
275 -
        display(d,MIME("application/vnd.vegalite.v2+json"), x)
268 +
        display(d, MIME("application/vnd.vegalite.v2+json"), x)
276 269
    elseif showable("application/vnd.vega.v5+json", x)
277 -
        display(d,MIME("application/vnd.vega.v5+json"), x)
270 +
        display(d, MIME("application/vnd.vega.v5+json"), x)
278 271
    elseif showable("application/vnd.vega.v4+json", x)
279 -
        display(d,MIME("application/vnd.vega.v4+json"), x)
272 +
        display(d, MIME("application/vnd.vega.v4+json"), x)
280 273
    elseif showable("application/vnd.vega.v3+json", x)
281 -
        display(d,MIME("application/vnd.vega.v3+json"), x)
274 +
        display(d, MIME("application/vnd.vega.v3+json"), x)
282 275
    elseif showable("application/vnd.plotly.v1+json", x)
283 -
        display(d,MIME("application/vnd.plotly.v1+json"), x)
276 +
        display(d, MIME("application/vnd.plotly.v1+json"), x)
284 277
    elseif showable("application/vnd.dataresource+json", x)
285 278
        display(d, "application/vnd.dataresource+json", x)
286 279
    elseif showable("image/svg+xml", x)
287 -
        display(d,"image/svg+xml", x)
280 +
        display(d, "image/svg+xml", x)
288 281
    elseif showable("image/png", x)
289 -
        display(d,"image/png", x)
282 +
        display(d, "image/png", x)
290 283
    elseif showable("text/html", x)
291 284
        display(d, "text/html", x)
292 285
    elseif showable("text/markdown", x)
293 286
        display(d, "text/markdown", x)
294 287
    else
295 -
        throw(MethodError(Base.display,(d,x)))
288 +
        throw(MethodError(Base.display, (d, x)))
296 289
    end
297 290
end
298 291
@@ -330,10 +323,10 @@
Loading
330 323
331 324
function electrondisplay(x; config...)
332 325
    d = newdisplay(; showable=showable, config...)
333 -
    if TableTraits.isiterabletable(x)!==false
326 +
    if TableTraits.isiterabletable(x) !== false
334 327
        if showable("application/vnd.dataresource+json", x)
335 328
            display(d, x)
336 -
        elseif TableTraits.isiterabletable(x)===true
329 +
        elseif TableTraits.isiterabletable(x) === true
337 330
            display(d, DataresourceTableTraitsWrapper(x))
338 331
        else
339 332
            try

@@ -1,5 +1,6 @@
Loading
1 1
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vegalite.v2+json")}) = true
2 2
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vegalite.v3+json")}) = true
3 +
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vegalite.v4+json")}) = true
3 4
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vega.v3+json")}) = true
4 5
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vega.v4+json")}) = true
5 6
Base.displayable(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vega.v5+json")}) = true
@@ -20,89 +21,14 @@
Loading
20 21
    payload = stringmime(MIME("application/vnd.vegalite.v$major_version_vegalite+json"), x)
21 22
    ans = _maybe_fallback_to(MIME"image/png"(), d, x, payload)
22 23
    ans === nothing || return ans
23 -
24 -
    html_page = """
25 -
    <html>
26 -
27 -
    <head>
28 -
        <script src="file:///$(asset("vega-$major_version_vega", "vega.min.js"))"></script>
29 -
        <script src="file:///$(asset("vega-lite-$major_version_vegalite", "vega-lite.min.js"))"></script>
30 -
        <script src="file:///$(asset("vega-embed", "vega-embed.min.js"))"></script>
31 -
    </head>
32 -
    <body>
33 -
      <div id="plotdiv"></div>
34 -
    </body>
35 -
36 -
    <style media="screen">
37 -
      .vega-actions a {
38 -
        margin-right: 10px;
39 -
        font-family: sans-serif;
40 -
        font-size: x-small;
41 -
        font-style: italic;
42 -
      }
43 -
    </style>
44 -
45 -
    <script type="text/javascript">
46 -
47 -
      var opt = {
48 -
        mode: "vega-lite",
49 -
        actions: false
50 -
      }
51 -
52 -
      var spec = $payload
53 -
54 -
      vegaEmbed('#plotdiv', spec, opt);
55 -
56 -
    </script>
57 -
58 -
    </html>
59 -
    """
60 -
61 -
    displayhtml(d, html_page, options=Dict("webPreferences" => Dict("webSecurity" => false)))
24 +
    displayplot(d, "vega-lite", JSON.JSONText(payload), options=Dict("webPreferences" => Dict("webSecurity" => false)))
62 25
end
63 26
64 27
function _display_vega(d, major_version, x)
65 28
    payload = stringmime(MIME("application/vnd.vega.v$major_version+json"), x)
66 29
    ans = _maybe_fallback_to(MIME"image/png"(), d, x, payload)
67 30
    ans === nothing || return ans
68 -
69 -
    html_page = """
70 -
    <html>
71 -
72 -
    <head>
73 -
        <script src="file:///$(asset("vega-$major_version", "vega.min.js"))"></script>
74 -
        <script src="file:///$(asset("vega-embed", "vega-embed.min.js"))"></script>
75 -
    </head>
76 -
    <body>
77 -
      <div id="plotdiv"></div>
78 -
    </body>
79 -
80 -
    <style media="screen">
81 -
      .vega-actions a {
82 -
        margin-right: 10px;
83 -
        font-family: sans-serif;
84 -
        font-size: x-small;
85 -
        font-style: italic;
86 -
      }
87 -
    </style>
88 -
89 -
    <script type="text/javascript">
90 -
91 -
      var opt = {
92 -
        mode: "vega",
93 -
        actions: false
94 -
      }
95 -
96 -
      var spec = $payload
97 -
98 -
      vegaEmbed('#plotdiv', spec, opt);
99 -
100 -
    </script>
101 -
102 -
    </html>
103 -
    """
104 -
105 -
    displayhtml(d, html_page, options=Dict("webPreferences" => Dict("webSecurity" => false)))  
31 +
    displayplot(d, "vega", JSON.JSONText(payload), options=Dict("webPreferences" => Dict("webSecurity" => false)))  
106 32
end
107 33
108 34
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vegalite.v2+json")}, x)
@@ -113,6 +39,10 @@
Loading
113 39
    return _display_vegalite(d, "3", "5", x)
114 40
end
115 41
42 +
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vegalite.v4+json")}, x)
43 +
    return _display_vegalite(d, "4", "5", x)
44 +
end
45 +
116 46
function Base.display(d::ElectronDisplayType, ::MIME{Symbol("application/vnd.vega.v3+json")}, x)
117 47
    return _display_vega(d, "3", x)
118 48
end

Unable to process changes.

No base report to compare against.

71 Commits

Hiding 56 contexual commits
+12
+9
+3
Hiding 13 contexual commits
Pull Request Base Commit
Files Coverage
src/ElectronDisplay.jl 78.00%
src/vega.jl 95.83%
Project Totals (2 files) 81.45%
Loading