Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUTO] Format files using DocumentFormat #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -68,7 +68,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
153 changes: 81 additions & 72 deletions src/rendering/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ using JSON

asset(url...) = normpath(vegalite_app_path("minified", url...))

const package_json = Ref{Dict{String, Any}}()
const package_json = Ref{Dict{String,Any}}()

function version(package)
if !isassigned(package_json)
package_json[] = JSON.parsefile(vegalite_app_path("package.json"))
end
if !isassigned(package_json)
package_json[] = JSON.parsefile(vegalite_app_path("package.json"))
end

return package_json[]["dependencies"][package]
return package_json[]["dependencies"][package]
end

# Vega Scaffold: https://github.com/vega/vega/wiki/Runtime
Expand All @@ -23,47 +23,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 @@ -81,35 +84,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 @@ -120,9 +129,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
4 changes: 2 additions & 2 deletions src/rendering/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function convert_vg_to_x(v::VGSpec, fileformat; cmd_args="")
reader = @async read(p, String)

wait(writer)
wait(p)
wait(p)
res = fetch(reader)

if p.exitcode != 0
throw(ArgumentError("Invalid spec"))
end
Expand Down
Loading