D3Trees.D3OffsetSubtree
— TypeSubtree structure for use by the lazy fetching of data through the D3Trees server. Offset so that they can be easily entered into the children
structure of D3Tree.
D3Trees.D3Tree
— MethodD3Tree(children, <keyword arguments>)
Construct a tree to be displayed using D3 in a browser or ipython notebook, specifying structure with lists of children indices.
Arguments
Required
children::Vector{Vector{Int}}
: List of children for each node. E.g.
creates a tree with four nodes. Nodes 2 and 3 are children of node 1, and node 4 is the only child of node 3. Nodes 2 and 4 are childless.D3Tree([[2,3], [], [4], []])
Keyword:
text::Vector{String}
- text to appear under each node.tooltip::Vector{String}
- text to appear when hovering over each node.style::Vector{String}
- html style for each node.link_style::Vector{String}
- html style for each link.title::String
- html title.init_expand::Integer
- levels to expand initially.init_duration::Number
- duration of the initial animation in ms.svg_height::Number
- height of the svg containing the tree in px.
D3Trees.D3Tree
— MethodD3Tree(node; detect_repeat=true, lazy_expand_after_depth=typemax(Int), kwargs...)
Construct a tree to be displayed using D3 in a browser or ipython notebook with any object, node
, that implements the AbstractTrees interface.
The style may be controlled by implementing the following functions, which should return String
s for the nodes:
D3Trees.text(node)
D3Trees.tooltip(node)
D3Trees.style(node)
D3Trees.link_style(node)
Allows for lazy loading of large trees through the lazy_expand_after_depth
keyword argument. Nodes beyonnd this depth are not intially expanded for visualization. Instead, they are cached and only expanded when requested by the visualization. The serving is done by the D3Trees HTTP server.
The server does not have information about the lifetime of different visualizations so it might keep references to past visualizations, potentially holding up a lot of memory. To reset the server and remove references to old data, run either D3Trees.reset_server()
or D3Trees.shutdown_server()
.
Arguments
Required
node
: an object that has AbstractTrees.children(node) and AbstractTrees.printnode(io::IO, node)
Keyword
detect_repeat
: (default: true) if true, uses a dictionary to detect whether a node has appeared previouslylazy_expand_after_depth::Integer
: (default: typemax(Int)). Sets tree depth to at whichAbstractTrees.children(node)
will not be called anymore. Instead, nodes at this depth are cached andchildren(node)
is called only when node is clicked in the D3 interactive visualization. Root has depth 0, so settinglazy_expand_after_depth=1
expands only the root.lazy_subtree_depth::Integer
: (default: 2) sets depth of subtrees fetched from D3Trees serverport::Integer
: (default: 16370) specify server port for D3Trees server that will serve subtrees for visualization. Shutdown server byshutdown_server(port)
.dry_run_lazy_vizualization::Function
: (default: t -> D3Trees.dryrunserver(port, t)) function that is ran once before visualization is started to speed up first fetch in the visualization. Provide custom function if your tree's children method takes a long time on first run.- Also supports, the non-vector arguments of the vector-of-vectors
D3Tree
constructor, i.e.title
,init_expand
,init_duration
,svg_height
.
D3Trees.cors_middleware
— Methodcors_middleware: handles preflight request with the OPTIONS flag If a request was recieved with the correct headers, then a response will be sent back with a 200 code, if the correct headers were not specified in the request, then a CORS error will be recieved on the client side Since each request passes throught the CORS Handler, then if the request is not a preflight request, it will simply go to the rest of the layers to be passed to the correct service function.
D3Trees.dry_run_server
— MethodRuns api request against a simple tree. When ran before rendering first visualization, it leads to faster visualization responses on first click. This helps prevent errors caused by trying to fetching the same resource twice.
D3Trees.expand_node!
— MethodCalculate missing children, for use with the D3Trees server for lazyly fetching data.
D3Trees.inbrowser
— Methodinbrowser(t::D3Tree, command::Cmd)
Open an html document with the D3Tree in a program launched with the specified command.
D3Trees.inbrowser
— Methodinbrowser(t::D3Tree, browsername::String)
Open an html document with the D3Tree in a browser with a platform-specific command.
D3Trees.link_style
— MethodD3Trees.link_style(n)
Return the html style for the link leading to the D3Trees node corresponding to AbstractTrees node n
D3Trees.logging_middleware
— Methodlogging_middleware logs the request before passing it on to the tree router and request handler and then logs the returned response.
D3Trees.push_node!
— FunctionDFS add node to the D3Tree structure
D3Trees.serror
— Methodserror(error::Exception) -> String
Get error and stacktrace as String, e.g. for use in warning. Useful in Jypyter notebooks where error messages are not displayed correctly (https://github.com/JuliaLang/IJulia.jl/issues/1043)
Example
julia> try
a=b
catch e
@warn "Oh no, exception:
$(serror(e))"
end
┌ Warning: Oh no, exception:
│ UndefVarError: b not defined
│ 13-element Vector{Base.StackTraces.StackFrame}:
│ top-level scope at REPL[7]:2
│ eval at boot.jl:373 [inlined]
│ eval_user_input(ast::Any, backend::REPL.REPLBackend) at REPL.jl:150
│ repl_backend_loop(backend::REPL.REPLBackend) at REPL.jl:246
│ start_repl_backend(backend::REPL.REPLBackend, consumer::Any) at REPL.jl:231
│ run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool) at REPL.jl:364
│ run_repl(repl::REPL.AbstractREPL, consumer::Any) at REPL.jl:351
│ (::Base.var"#930#932"{Bool, Bool, Bool})(REPL::Module) at client.jl:394
│ #invokelatest#2 at essentials.jl:716 [inlined]
│ invokelatest at essentials.jl:714 [inlined]
│ run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool) at client.jl:379
│ exec_options(opts::Base.JLOptions) at client.jl:309
│ _start() at client.jl:495
└ @ Main REPL[7]:4
D3Trees.serve_tree!
— MethodStart serving tree from existing or new server on some port. Returns port for the server.
D3Trees.shutdown_server!
— MethodD3Trees.shutdown_server!(port)
D3Trees.shutdown_server!()
Shutdown D3Trees server (all servers if port is not specified) and remove associated tree data.
D3Trees.style
— MethodD3Trees.style(n)
Return the html style for the D3Trees node corresponding to AbstractTrees node n
D3Trees.text
— MethodD3Trees.text(n)
Return the text to be displayed at the D3Trees node corresponding to AbstractTrees node n
D3Trees.tooltip
— MethodD3Trees.tooltip(n)
Return the text to be displayed in the tooltip for the D3Trees node corresponding to AbstractTrees node n
JSON.Writer.json
— MethodConvert datastructure to json, shift indeces to zero-indexing for use in javascript
JSON.Writer.json
— MethodConvert datastructure to json, shift indeces to zero-indexing for use in javascript