#Provides some routines for easier svg construction, along with some #(hopefully!) sane defaults export svg_rect, svg_circle, svg_line, svg_polyline, svg_polygon, svg_text, default_height, default_width, default_posy, default_posx, s_black, s_red, s_green, s_blue, stdstyle, stdattr, svgsvg_symb global const default_height = 900 global const default_width = 600 global const default_posy = 0 global const default_posx = 0 global const s_black = (0,0,0) global const s_red = (255,0,0) global const s_green = (0,255,0) global const s_blue = (0,0,255) global const stdattr = Dict("y" => "$default_posy", "x" => "$default_posx", "height" => "$default_height", "width" => "$default_width") global const stdstyle = Dict(:fill => "rgb$s_black") global const svgsvg_symb = instanceof(dom"svg:svg"()) #################### function svg_rect(width, height, x=0, y=0, style = stdstyle) attr = Dict("x" => "$x", "y" => "$y", "width" => "$width", "height" => "$height") Node(instanceof(dom"svg:rect"()), style = style, attributes = attr) end function svg_circle(x, y, r, style=stdstyle) attr = Dict("cy" => "$y", "cx" => "$x", "r" => "$r") Node(instanceof(dom"svg:circle"()), style = style, attributes = attr) end function svg_line(x1, y1, x2, y2, style=stdstyle) attr = Dict("x1" => "$x1", "y1" => "$y1", "x2" => "$x2", "y2" => "$y2") Node(instanceof(dom"svg:line"()), style = style, attributes = attr) end function svg_poly(ptsvector, style) #there must be a better way to do this pts = join((join((ptsvector[i][1], ptsvector[i][2]), ",") for i in 1:length(ptsvector)), " ") attr = Dict("points" => pts) Node(instanceof(dom"svg:polyline"()), style = style, attributes = attr) end function svg_polyline(ptsvector, thickness, color) style = Dict(:strokeWidth => "$thickness", :fill => "none", :stroke => "rgb$color") svg_poly(ptsvector, style) end function svg_polygon(ptsvector, color) style = Dict( :fill => "rgb$color") svg_poly(ptsvector, style) end function svg_text(x, y, text, style=stdstyle) attr = Dict("y" => "$y", "x" => "$x") Node(instanceof(dom"svg:text"(text)), style = style, attributes = attr) end