Skip to content

Commit

Permalink
Merge pull request #20 from queryverse/create-pull-request/patch
Browse files Browse the repository at this point in the history
[AUTO] Format files using DocumentFormat
  • Loading branch information
davidanthoff authored Mar 10, 2021
2 parents dbf11b3 + 9b5f3bb commit 1d336a2
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Documenter, Vega, UUIDs

function Base.show(io::IO, m::MIME"text/html", v::Vega.VGSpec)
divid = string("vg", replace(string(uuid4()), "-"=>""))
divid = string("vg", replace(string(uuid4()), "-" => ""))
print(io, "<div id='$divid' style=\"width:100%;height:100%;\"></div>")
print(io, "<script type='text/javascript'>requirejs.config({paths:{'vg-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6?noext','vega-lib': 'https://cdn.jsdelivr.net/npm/vega-lib?noext','vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@4?noext','vega': 'https://cdn.jsdelivr.net/npm/vega@5?noext'}}); require(['vg-embed'],function(vegaEmbed){vegaEmbed('#$divid',")
Vega.our_json_print(io, v)
Expand All @@ -10,8 +10,8 @@ end

makedocs(
modules=[Vega],
sitename = "Vega.jl",
pages = [
sitename="Vega.jl",
pages=[
"Home" => "index.md",
"Getting Started" => Any[
"Installation" => "gettingstarted/installation.md"
Expand All @@ -36,5 +36,5 @@ makedocs(
)

deploydocs(
repo = "github.com/queryverse/Vega.jl.git",
repo="github.com/queryverse/Vega.jl.git",
)
6 changes: 3 additions & 3 deletions src/Vega.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ set rendering mode (svg or canvas)
"""
renderer() = RENDERER
function renderer(m::Symbol)
global RENDERER
m in [:svg, :canvas] || error("rendering mode should be either :svg or :canvas")
RENDERER = m
global RENDERER
m in [:svg, :canvas] || error("rendering mode should be either :svg or :canvas")
RENDERER = m
end


Expand Down
16 changes: 8 additions & 8 deletions src/dsl_vlplot_function/dsl_vlplot_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ struct VGFrag <: AbstractVegaFragment
end

function vgfrag(args...; kwargs...)
return VGFrag(Any[args...], OrderedDict{String,Any}(string(k)=>convert_nt_to_dict(v, VGFrag) for (k,v) in kwargs))
return VGFrag(Any[args...], OrderedDict{String,Any}(string(k) => convert_nt_to_dict(v, VGFrag) for (k, v) in kwargs))
end

convert_nt_to_dict(item, fragtype) = item

function convert_nt_to_dict(item::NamedTuple, fragtype)
return fragtype(Any[], OrderedDict{String,Any}(string(k)=>convert_nt_to_dict(v, fragtype) for (k,v) in pairs(item)))
return fragtype(Any[], OrderedDict{String,Any}(string(k) => convert_nt_to_dict(v, fragtype) for (k, v) in pairs(item)))
end

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)) )
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
new_p = f(p[1]=>walk_dict(f, p[2], p[1]), parent)
new_p = f(p[1] => walk_dict(f, p[2], p[1]), parent)

if new_p isa Vector
for i in new_p
Expand Down Expand Up @@ -62,7 +62,7 @@ function replace_remaining_frag(frag::AbstractVegaFragment)
if !isempty(frag.positional)
error("There is an unknown positional argument in this spec.")
else
return OrderedDict{String,Any}(k=>replace_remaining_frag(v) for (k,v) in frag.named)
return OrderedDict{String,Any}(k => replace_remaining_frag(v) for (k, v) in frag.named)
end
end

Expand All @@ -73,7 +73,7 @@ function fix_shortcut_vg_data(v)
return VGFrag([], OrderedDict{String,Any}("url" => Sys.iswindows() ? as_uri[1:5] * as_uri[7:end] : as_uri))
elseif v[2] isa URI
as_uri = string(v[2])
return VGFrag([], OrderedDict{String,Any}("url" => Sys.iswindows() && v[2].scheme=="file" ? as_uri[1:5] * as_uri[7:end] : as_uri))
return VGFrag([], OrderedDict{String,Any}("url" => Sys.iswindows() && v[2].scheme == "file" ? as_uri[1:5] * as_uri[7:end] : as_uri))
elseif TableTraits.isiterabletable(v[2])
it = IteratorInterfaceExtensions.getiterator(v[2])
return VGFrag([], OrderedDict{String,Any}("name" => string(v[1]), "values" => DataValuesNode(it)))
Expand Down Expand Up @@ -105,7 +105,7 @@ function convert_frag_tree_to_dict(spec::VGFrag)
# and we can convert everything into a plain Dict structure
isempty(spec.positional) || error("There shouldn't be any positional argument left.")

return OrderedDict{String,Any}(k=>replace_remaining_frag(v) for (k,v) in spec.named)
return OrderedDict{String,Any}(k => replace_remaining_frag(v) for (k, v) in spec.named)
end

function vgplot(args...;kwargs...)
Expand Down
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 @@ -2,7 +2,7 @@ function convert_curly_style_array(exprs, fragtype)
res = Expr(:vect)

for ex in exprs
if ex isa Expr && ex.head==:braces
if ex isa Expr && ex.head == :braces
push!(res.args, :( $(convert_curly_style(ex.args, fragtype)) ))
else
push!(res.args, esc(ex))
Expand All @@ -19,15 +19,15 @@ function convert_curly_style(exprs, fragtype)
named_args = new_expr.args[3].args

for ex in exprs
if ex isa Expr && ex.head==:(=)
if ex.args[2] isa Expr && ex.args[2].head==:braces
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)) ))
elseif ex.args[2] isa Expr && ex.args[2].head==:vect
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)) ))
else
push!(named_args, :( $(string(ex.args[1])) => $(esc(ex.args[2])) ))
end
elseif ex isa Expr && ex.head==:braces
elseif ex isa Expr && ex.head == :braces
push!(pos_args, convert_curly_style(ex.args, fragtype))
else
push!(pos_args, esc(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
34 changes: 17 additions & 17 deletions src/rendering/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

asset(url...) = normpath(joinpath(vegaliate_app_path, "minified", url...))

#Vega Scaffold: https://github.com/vega/vega/wiki/Runtime
# Vega Scaffold: https://github.com/vega/vega/wiki/Runtime

function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
divid = "vg" * randstring(3)
divid = "vg" * randstring(3)

println(io,
println(io,
"""
<html>
<head>
Expand Down Expand Up @@ -43,10 +43,10 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
var spec = """)

our_json_print(io, spec)
println(io)
our_json_print(io, spec)
println(io)

println(io, """
println(io, """
vegaEmbed('#$divid', spec, opt);
</script>
Expand All @@ -56,29 +56,29 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
end

function writehtml_full(spec::VGSpec; title="Vega plot")
tmppath = string(tempname(), ".vega.html")
tmppath = string(tempname(), ".vega.html")

open(tmppath, "w") do io
writehtml_full(io, spec, title=title)
end
open(tmppath, "w") do io
writehtml_full(io, spec, title=title)
end

tmppath
tmppath
end

"""
opens a browser tab with the given html file
"""
function launch_browser(tmppath::String)
if Sys.isapple()
run(`open $tmppath`)
elseif Sys.iswindows()
if Sys.isapple()
run(`open $tmppath`)
elseif Sys.iswindows()
run(`cmd /c start $tmppath`)
elseif Sys.islinux()
run(`xdg-open $tmppath`)
end
end
end

function Base.display(d::REPL.REPLDisplay, plt::VGSpec)
tmppath = writehtml_full(plt)
launch_browser(tmppath) # Open the browser
tmppath = writehtml_full(plt)
launch_browser(tmppath) # Open the browser
end
4 changes: 2 additions & 2 deletions src/rendering/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function convert_vg_to_x(v::VGSpec, script)
reader = @async read(p, String)
wait(p)
res = fetch(reader)
if p.exitcode!=0
if p.exitcode != 0
throw(ArgumentError("Invalid spec"))
end
return res
Expand All @@ -38,7 +38,7 @@ function convert_vg_to_svg(v::VGSpec)
reader = @async read(p, String)
wait(p)
res = fetch(reader)
if p.exitcode!=0
if p.exitcode != 0
throw(ArgumentError("Invalid spec"))
end
return res
Expand Down
10 changes: 5 additions & 5 deletions src/spec_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract type AbstractVegaSpec end

Base.copy(spec::T) where {T <: AbstractVegaSpec} = T(copy(getparams(spec)))

const ObjectLike = Union{AbstractVegaSpec, ObjectProxy}
const ObjectLike = Union{AbstractVegaSpec,ObjectProxy}

getparams(spec) = getfield(spec, :params)

Expand Down Expand Up @@ -52,21 +52,21 @@ struct DataValuesNode

col_values, col_names = TableTraitsUtils.create_columns_from_iterabletable(it)

return new(OrderedDict{Symbol,AbstractVector}(i[1]=>i[2] for i in zip(col_names,col_values)))
return new(OrderedDict{Symbol,AbstractVector}(i[1] => i[2] for i in zip(col_names, col_values)))
end
end

Base.:(==)(a::DataValuesNode, b::DataValuesNode) = a.columns==b.columns
Base.:(==)(a::DataValuesNode, b::DataValuesNode) = a.columns == b.columns

function our_show_json(io, it, col_names)
print(io, "[")

for (row_index, row) in enumerate(it)
row_index==1 || print(io, ",")
row_index == 1 || print(io, ",")
print(io, "{")

for (col_index, col_value) in enumerate(row)
col_index==1 || print(io, ",")
col_index == 1 || print(io, ",")
JSON.print(io, col_names[col_index])
print(io, ":")
JSON.print(io, col_value isa DataValue ? get(col_value, nothing) : col_value)
Expand Down
2 changes: 1 addition & 1 deletion src/vgspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
# data is an array in vega
function vg_set_spec_data!(specdict, datait, name)
updated = false
recs = [OrderedDict{String,Any}(string(c[1])=>isa(c[2], DataValues.DataValue) ? (isna(c[2]) ? nothing : get(c[2])) : c[2] for c in zip(keys(r), values(r))) for r in datait]
recs = [OrderedDict{String,Any}(string(c[1]) => isa(c[2], DataValues.DataValue) ? (isna(c[2]) ? nothing : get(c[2])) : c[2] for c in zip(keys(r), values(r))) for r in datait]
for def in specdict["data"]
if def["name"] == name
def["values"] = recs
Expand Down
18 changes: 9 additions & 9 deletions test/test_io.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using Vega
using Vega: getparams
using Vega:getparams
using DataFrames
using Dates
using FileIO
Expand Down Expand Up @@ -32,23 +32,23 @@ vgp = getvgplot()
# end

Base.Filesystem.mktempdir() do folder
save(joinpath(folder,"test4.svg"), vgp)
@test isfile(joinpath(folder,"test4.svg"))
save(joinpath(folder, "test4.svg"), vgp)
@test isfile(joinpath(folder, "test4.svg"))

save(joinpath(folder,"test4.pdf"), vgp)
@test isfile(joinpath(folder,"test4.pdf"))
save(joinpath(folder, "test4.pdf"), vgp)
@test isfile(joinpath(folder, "test4.pdf"))

save(joinpath(folder,"test4.png"), vgp)
@test isfile(joinpath(folder,"test4.png"))
save(joinpath(folder, "test4.png"), vgp)
@test isfile(joinpath(folder, "test4.png"))

# save(joinpath(folder,"test4.eps"), vgp)
# @test isfile(joinpath(folder,"test4.eps"))

vgpl1 = getvgplot()

Vega.savespec(joinpath(folder,"test1.vega"), vgpl1, include_data=true)
Vega.savespec(joinpath(folder, "test1.vega"), vgpl1, include_data=true)

vgpl2 = Vega.loadvgspec(joinpath(folder,"test1.vega"))
vgpl2 = Vega.loadvgspec(joinpath(folder, "test1.vega"))

@test vgpl1 == vgpl1

Expand Down
2 changes: 1 addition & 1 deletion test/test_macro.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Vega
using Vega: getparams
using Vega:getparams
using JSON
using Test

Expand Down

0 comments on commit 1d336a2

Please sign in to comment.