Skip to content
Snippets Groups Projects
Commit a46c1037 authored by Jacob Wikmark's avatar Jacob Wikmark
Browse files

tools

parent 514ebb55
Branches
No related tags found
No related merge requests found
......@@ -4,34 +4,6 @@ include("gridmaker.jl")
include("gui.jl")
include("construct.jl")
include("svg_helper.jl")
include("tools.jl")
#We redefine WebIO.newid to prevent nodes from getting infinitely high values,
# and Base.show is redefined to prevent memory leaks when constructing SVGs
#=
const max_nodes = 100000
let count=1
global newid
node_space=Dict()
function WebIO.newid(prefix)
if count == max_nodes
count = 0
end
string(prefix, "-", count+=1)
end
end
function Base.show(io::IO, m::MIME"text/html", x::Node)
if haskey(x.props, :id)
id = "$(x.props[:id])-parent"
else
id = WebIO.newid("node")
end
x in keys(WebIO.showcbs) && (x = WebIO.showcbs[x](id))
write(io, """<div id=$id></div>
<script>WebIO.mount('$id', '#$id',""")
WebIO.jsexpr(io, x)
write(io, ")</script>")
end
=#
end
......@@ -9,6 +9,11 @@ function make_row(columns::Integer)
(Node(:div, style=style, "Lorem Ipsum") for i in 1:columns)
end
"""
Constructs a Node containing empty nodes in a row by column grid. A member can then be accessed using [n,m] syntax, but [n][m] accesses the element container; [n][m][1] is equivalent to [n,m]. This is done to maintain the style (width etc) of the subelements.
"""
function make_grid(rows::Integer, columns::Integer, width = 800, height = 1000)
style_row = Dict(:height => "$(100/rows)%", :overflow => "auto")
style_grid = Dict(:width => width, :height => height)
......@@ -16,13 +21,6 @@ function make_grid(rows::Integer, columns::Integer, width = 800, height = 1000)
for i in 1:rows)...)
end
#specify this later, should be some sort of typedef of WebIO.Node{WebIO.DOM}
# We give the content of the container if given two arguments
# If given one argument, we give the child
# This means a[r,c] = a[r][c][1] and not a[r][c]
# We to do this to keep the style (width and formatting of the columns)
function Base.getindex(grid::WebIO.Node{WebIO.DOM}, ind::Integer)
grid.children[ind]
......@@ -32,8 +30,9 @@ function Base.getindex(grid::WebIO.Node{WebIO.DOM}, row::Integer, column::Intege
grid[row][column][1]
end
"""
WebIO.Node objects are immutable, so setindex_ simply returns a modified version of the original
"""
function setindex_(grid::WebIO.Node{WebIO.DOM},
new_value,
ind::Integer)
......
export link!
"""
Links the values of two observables by adding a listener. Optional arguments f and g specify transform of the value between the observables. If optional argument master=true all listeners of o2 are called if o1 is updated rather than just the value.
Example:
link(o1, o2, (x) -> 2*x, (x) -> x/2)
will ensure obs(o2)[] is always 2*obs(o1)[] and vice versa.
"""
function link!(o1::Observable, o2::Observable, f = (x)->(x), g = (x)->(x), master=false)
if master
push!(o1.listeners, (x) -> o2[]=f(o1[]))
else
push!(o1.listeners, (x) -> o2.val=f(o1[]))
end
push!(o2.listeners, (x) -> o1.val = g(o2[]))
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment