Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Jul 26, 2022
1 parent 2ef9fe8 commit abdcb12
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 258 deletions.
46 changes: 22 additions & 24 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ function Base.show(io::IO, m::MIME"text/html", v::Vega.VGSpec)
end

makedocs(
modules=[Vega],
sitename="Vega.jl",
pages=[
"Home" => "index.md",
"Getting Started" => Any[
"Installation" => "gettingstarted/installation.md"
],
"User Guide" => Any[
"Using Vega" => "userguide/vega.md"
],
"Examples" => Any[

"Line & Area Charts" => "examples/examples_vega_line_area_charts.md",
"Circular Charts" => "examples/examples_vega_circular_charts.md",
"Scatter Plots" => "examples/examples_vega_scatter_plots.md",
"Tree Diagrams" => "examples/examples_vega_tree_diagrams.md",
"Network Diagrams" => "examples/examples_vega_network_diagrams.md",
"Single Data Source" => "examples/examples_vega_single_data_source.md",
"Multiple Data Source" => "examples/examples_vega_multi_data_source.md"
],
"Reference Manual" => [
"Global settings" => "referencemanual/global.md",
"Outputs" => "referencemanual/output.md"]
]
modules=[Vega],
sitename="Vega.jl",
pages=[
"Home" => "index.md",
"Getting Started" => Any[
"Installation"=>"gettingstarted/installation.md"
],
"User Guide" => Any[
"Using Vega"=>"userguide/vega.md"
],
"Examples" => Any["Line & Area Charts"=>"examples/examples_vega_line_area_charts.md",
"Circular Charts"=>"examples/examples_vega_circular_charts.md",
"Scatter Plots"=>"examples/examples_vega_scatter_plots.md",
"Tree Diagrams"=>"examples/examples_vega_tree_diagrams.md",
"Network Diagrams"=>"examples/examples_vega_network_diagrams.md",
"Single Data Source"=>"examples/examples_vega_single_data_source.md",
"Multiple Data Source"=>"examples/examples_vega_multi_data_source.md"
],
"Reference Manual" => [
"Global settings" => "referencemanual/global.md",
"Outputs" => "referencemanual/output.md"]
]
)

deploydocs(
Expand Down
2 changes: 1 addition & 1 deletion src/Vega.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ show if plots will have (true) or not (false) the action links displayed
indicate if actions links should be dislpayed under the plot
"""
actionlinks() = ACTIONSLINKS
actionlinks(b::Bool) = (global ACTIONSLINKS ; ACTIONSLINKS = b)
actionlinks(b::Bool) = (global ACTIONSLINKS; ACTIONSLINKS = b)


######################## includes #####################################
Expand Down
6 changes: 3 additions & 3 deletions src/dsl_vlplot_function/dsl_vlplot_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function convert_nt_to_dict(item::AbstractVegaFragment, fragtype)
return fragtype(item.positional, OrderedDict{String,Any}(string(k) => convert_nt_to_dict(v, fragtype) for (k, v) in pairs(item.named)))
end

function walk_dict(f, d::T, parent) where {T <: AbstractDict}
function walk_dict(f, d::T, parent) where {T<:AbstractDict}
res = T()
for p in d
if p[2] isa Dict
Expand Down Expand Up @@ -108,6 +108,6 @@ function convert_frag_tree_to_dict(spec::VGFrag)
return OrderedDict{String,Any}(k => replace_remaining_frag(v) for (k, v) in spec.named)
end

function vgplot(args...;kwargs...)
return VGSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec(vgfrag(args...;kwargs...))))
function vgplot(args...; kwargs...)
return VGSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec(vgfrag(args...; kwargs...))))
end
10 changes: 5 additions & 5 deletions src/dsl_vlplot_macro/dsl_vlplot_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function convert_curly_style_array(exprs, fragtype)

for ex in exprs
if ex isa Expr && ex.head == :braces
push!(res.args, :( $(convert_curly_style(ex.args, fragtype)) ))
push!(res.args, :($(convert_curly_style(ex.args, fragtype))))
else
push!(res.args, esc(ex))
end
Expand All @@ -21,11 +21,11 @@ function convert_curly_style(exprs, fragtype)
for ex in exprs
if ex isa Expr && ex.head == :(=)
if ex.args[2] isa Expr && ex.args[2].head == :braces
push!(named_args, :( $(string(ex.args[1])) => $(convert_curly_style(ex.args[2].args, fragtype)) ))
push!(named_args, :($(string(ex.args[1])) => $(convert_curly_style(ex.args[2].args, fragtype))))
elseif ex.args[2] isa Expr && ex.args[2].head == :vect
push!(named_args, :( $(string(ex.args[1])) => $(convert_curly_style_array(ex.args[2].args, fragtype)) ))
push!(named_args, :($(string(ex.args[1])) => $(convert_curly_style_array(ex.args[2].args, fragtype))))
else
push!(named_args, :( $(string(ex.args[1])) => $(esc(ex.args[2])) ))
push!(named_args, :($(string(ex.args[1])) => $(esc(ex.args[2]))))
end
elseif ex isa Expr && ex.head == :braces
push!(pos_args, convert_curly_style(ex.args, fragtype))
Expand All @@ -40,7 +40,7 @@ end
macro vgplot(ex...)
new_ex = convert_curly_style(ex, VGFrag)

return :( Vega.VGSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec($new_ex))) )
return :(Vega.VGSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec($new_ex))))
end

macro vgfrag(ex...)
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ end

savespec(filename::AbstractString, v::AbstractVegaSpec; kwargs...) =
open(filename, "w") do io
savespec(io, v; kwargs...)
end
savespec(io, v; kwargs...)
end
143 changes: 76 additions & 67 deletions src/rendering/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,50 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
divid = "vg" * randstring(3)

println(io,
"""
<html>
<head>
<title>$title</title>
<meta charset="UTF-8">
<script>$(read(asset("vega.min.js"), String))</script>
<script>$(read(asset("vega-embed.min.js"), String))</script>
</head>
<body>
<div id="$divid" style="width:100%;height:100%;"></div>
</body>
<style media="screen">
.vega-actions a {
margin-right: 10px;
font-family: sans-serif;
font-size: x-small;
font-style: italic;
}
</style>
<script type="text/javascript">
var opt = {
mode: "vega",
renderer: "$RENDERER",
actions: $ACTIONSLINKS
}
var spec = """)
"""
<html>
<head>
<title>$title</title>
<meta charset="UTF-8">
<script>$(read(asset("vega.min.js"), String))</script>
<script>$(read(asset("vega-embed.min.js"), String))</script>
</head>
<body>
<div id="$divid" style="width:100%;height:100%;"></div>
</body>
<style media="screen">
.vega-actions a {
margin-right: 10px;
font-family: sans-serif;
font-size: x-small;
font-style: italic;
}
</style>
<script type="text/javascript">
var opt = {
mode: "vega",
renderer: "$RENDERER",
actions: $ACTIONSLINKS
}
var spec = """)

our_json_print(io, spec)
println(io)

println(io, """
vegaEmbed('#$divid', spec, opt);
println(
io,
"""
vegaEmbed('#$divid', spec, opt);
</script>
</script>
</html>
""")
</html>
"""
)
end

function writehtml_full(spec::VGSpec; title="Vega plot")
Expand All @@ -74,35 +77,41 @@ Creates a HTML script + div block for showing the plot (typically for Pluto).
VegaLite js files are loaded from the web using script tags.
"""
function writehtml_partial_script(io::IO, spec::VGSpec; title="VegaLite plot")
divid = "vg" * randstring(3)
print(io, """
<style media="screen">
.vega-actions a {
margin-right: 10px;
font-family: sans-serif;
font-size: x-small;
font-style: italic;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vega@$(version("vega"))/build/vega.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@$(version("vega-embed"))/build/vega-embed.min.js"></script>
<div id="$divid"></div>
<script>
var spec = """)
our_json_print(io, spec)
print(io,"""
;
var opt = {
mode: "vega-lite",
renderer: "$(Vega.RENDERER)",
actions: $(Vega.ACTIONSLINKS)
};
vegaEmbed("#$divid", spec, opt);
</script>
""")
divid = "vg" * randstring(3)
print(
io,
"""
<style media="screen">
.vega-actions a {
margin-right: 10px;
font-family: sans-serif;
font-size: x-small;
font-style: italic;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vega@$(version("vega"))/build/vega.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@$(version("vega-embed"))/build/vega-embed.min.js"></script>
<div id="$divid"></div>
<script>
var spec = """
)
our_json_print(io, spec)
print(
io,
"""
;
var opt = {
mode: "vega-lite",
renderer: "$(Vega.RENDERER)",
actions: $(Vega.ACTIONSLINKS)
};
vegaEmbed("#$divid", spec, opt);
</script>
"""
)
end


Expand All @@ -113,9 +122,9 @@ function launch_browser(tmppath::String)
if Sys.isapple()
run(`open $tmppath`)
elseif Sys.iswindows()
run(`cmd /c start $tmppath`)
elseif Sys.islinux()
run(`xdg-open $tmppath`)
run(`cmd /c start $tmppath`)
elseif Sys.islinux()
run(`xdg-open $tmppath`)
end
end

Expand Down
Loading

0 comments on commit abdcb12

Please sign in to comment.