Created
October 8, 2018 13:49
-
-
Save SimonDanisch/ab1eee07b224100286d505382c47c3ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using WebIO, TreeViews, CSSUtil, JSExpr, Interact | |
x = Lal(1f0, rand(10)) | |
using TreeViews: treenode, numberofnodes | |
function represent_node(s, x, i) | |
unfold = true | |
n = treenode(x, i) | |
str = sprint() do io | |
treelabel(io, x, i) | |
print(io, " → ") | |
if n isa Union{Tuple, AbstractArray, AbstractDict, AbstractSet} || numberofnodes(n) > 1 | |
print(io, typeof(n)) | |
else | |
print(io, n) | |
unfold = false | |
end | |
end | |
label = node(:div, str) | |
if unfold | |
placeholder = node(:div, id = "child$i", style = Dict(:display => :none)) | |
label = vbox(label, placeholder) | |
b = button(">") | |
on(b) do val | |
childview = WebIO.htmlstring(WebIO.render(treeview(s, n))) | |
id = "#child$i" | |
evaljs(s, @js begin | |
@var child = this.dom.querySelector($id) | |
WebIO.propUtils.setInnerHtml(child, $childview); | |
child.style.display = "block" | |
end) | |
end | |
return hbox(b, label) | |
else | |
return label | |
end | |
end | |
using Interact | |
function treeview(s, x::Vector) | |
node(:div, sprint(io-> show(IOContext(io, :compact => true), x))) | |
end | |
function treeview(s, x) | |
s(vbox( | |
ntuple(i-> represent_node(s, x, i), numberofnodes(x))... | |
)) | |
end | |
struct Lal | |
a | |
b | |
c | |
end | |
s = Scope() | |
treeview(s, Lal(rand(10), rand(4), 1f0)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment