1
module DataVoyager
2

3
using Electron, DataValues
4

5
import IteratorInterfaceExtensions, TableTraits, IterableTables, JSON, VegaLite
6

7
export Voyager
8

9
app = nothing
10

11
mutable struct Voyager
12
    w::Window
13

14
    function Voyager()
15 12
        main_html_uri = string("file:///", replace(joinpath(@__DIR__, "htmlui", "main.html"), '\\' => '/'))
16

17 4
        global app
18

19 12
        if app == nothing
20 12
            app = Application()
21
        end
22

23 12
        w = Window(app, URI(main_html_uri), options = Dict("title" => "Data Voyager"))
24

25 12
        new(w)
26
    end
27
end
28

29
function (v::Voyager)(source)
30 12
    TableTraits.isiterabletable(source) === false && error("'source' is not a table.")
31

32 12
    it = IteratorInterfaceExtensions.getiterator(source)
33

34 12
    data_dict = Dict{String,Any}()
35

36 12
    data_dict["values"] = [Dict{Symbol,Any}(c[1] => isa(c[2], DataValue) ? (isna(c[2]) ? nothing : get(c[2])) : c[2] for c in zip(keys(r), values(r))) for r in it]
37

38 12
    data = JSON.json(data_dict)
39

40 12
    code = "voyagerInstance.updateData($data)"
41

42 12
    run(v.w, code)
43

44 12
    return v
45
end
46

47 0
function Base.getindex(v::Voyager)
48 0
    code = "voyagerInstance.getSpec(true)"
49

50 0
    content = run(v.w, code)
51

52 0
    return VegaLite.VLSpec(content)
53
end
54

55
# function Base.getindex(v::Voyager, index::Int)
56
#     code = "voyagerInstance.getBookmarkedSpecs()"
57

58
#     content = run(v.w, code)
59

60
#     info(content)
61

62
#     return VegaLite.VLSpec(JSON.parse(content[index]))
63
# end
64

65
function Voyager(source)
66 12
    v = Voyager()
67

68 12
    v(source)
69

70 12
    return v
71
end
72

73
end # module

Read our documentation on viewing source code .

Loading