-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataViewer.jl
165 lines (120 loc) · 4.21 KB
/
DataViewer.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
module DataViewer
"""
pretty_repr(x) -> String
Return a pretty textual representation of `x`. By default it is based on `show`,
but can be customized as needed.
"""
function pretty_repr(x)
io = IOBuffer()
show(IOContext(io, :compact=>true, :limit=>true), "text/plain", x)
String(take!(io))
end
````
- `icon_name` identifies a Bootstrap icon
- `label` identifies the graphical representation in the UI
- `method` should generally be "graph" for graphical representations
- when several graphical representations apply, each is identified by its own
value of `param`
```
struct RepresentationOption
icon_name :: String
label :: String
method :: String
param :: String
end
"""
(options, repr) = graphic_repr(x)
If `x` supports one or more graphical representation(s), `options` is a
non-empty `Vector{RepresentationOption}`. In that case, calling
`repr(options[i].param)` should produce the graphical representation
corresponding to the i-th entry in the list.
"""
graphic_repr(::Any) = ([], nothing)
"""
recurse_into(x) -> Bool
Tells whether `x` is some form of "container" that can be recursed into, or a
"leaf" data.
"""
recurse_into(::Any) = false
"""
get_data(container, path)
Get the piece of data stored in `container` under `path`.
get_data(container, (a, b, b))
should be more or less equivalent to
container[a][b][c]
"""
function get_data end
"""
filetype(v::Val)
Get the file type associated to the name extension given by `v = Val(Symbol(extension))`.
## Example
```
julia> filetype(Val(Symbol(".jld2")))
JLD2File
```
"""
function filetype(::Val)
error("No known filetype matches the given extension. "
* "You may need to load the `JLD2` or `HDF5` packages to handle the relevant data types.")
end
"""
open_datafile(fun, fname, ftype)
Load the data contained in `fname`, which should be stored using the format
described by `ftype`. Apply `fun` on the loaded data. This function guarantees
that the file stays open as long as needed, but is closed before the function
returns.
## Example
```
julia> ftype = filetype(Val(Symbol(".jld2")))
JLD2File
julia> open_datafile("sample.jld2", ftype) do data
println(typeof(data))
end
Dict
```
"""
function open_datafile end
include("Internal.jl")
"""
view(data, name = "")
Open a viewer window for `data`, which may be a dictionary, HDF5 file, or
possibly another key=>value based data type.
Optionally, `name` is a `String` indicating where `data` originates from (for
example, a file name).
"""
view(data, name::String = "") = Internal.view(data, name)
"""
view(fname::String, ftype = "")
Open a viewer window for the data contained in file `fname`.
The extension of `fname` is normally used to determine how to read it. But the
optional argument `ftype` may be provided to override this behavior. In this
case, `ftype` should be a file extension associated to the file format (for
example: `".jld2"` for JLD2 files).
Because the file may need to be accessed during the whole browsing session, this
function does not return until the window has been closed, at which point the
data file itself is closed as well.
"""
view(fname::String, ftype::String = "") = Internal.view(fname, ftype)
"""
install(; command::String = "dataviewer",
destdir::String = joinpath(DEPOT_PATH[1], "bin"),
force::Bool = false,
sysimage::Bool = true)
Install a DataViewer launcher script to the `destdir` directory, with filename
`command`. The default directory is a `bin` subfolder inside the first
`DEPOT_PATH` entry, which usually translates to `~/.julia/bin`. Add this
directory to your `PATH` environment variable in order to more easily run the
DataViewer launcher.
Set `force` to `true` to overwrite an existing destination file with the same
path.
If `sysimage` is `true` (the default), a system image is compiled and the
launcher script is set up to use it.
"""
function install(; command::String = "dataviewer",
destdir::String = joinpath(DEPOT_PATH[1], "bin"),
force::Bool = false,
sysimage::Bool = true)
Internal.install(; command, destdir, force, sysimage)
end
include("precompile.jl")
end