From 943d47c746f42b0d6b90920789c7992bd4fa0cae Mon Sep 17 00:00:00 2001 From: davidanthoff Date: Fri, 14 Oct 2022 13:13:19 +0000 Subject: [PATCH] Format files using DocumentFormat --- docs/make.jl | 74 ++--- src/VegaLite.jl | 2 +- .../dsl_vlplot_function.jl | 14 +- src/dsl_vlplot_function/shorthandparser.jl | 10 +- src/dsl_vlplot_macro/dsl_vlplot_macro.jl | 2 +- src/rendering/fileio.jl | 2 +- src/rendering/io.jl | 4 +- src/rendering/render.jl | 265 +++++++++--------- src/vlspec.jl | 36 +-- test/runtests.jl | 24 +- test/scratchpad.jl | 10 +- test/test_base.jl | 32 +-- test/test_inlinedata.jl | 8 +- test/test_io.jl | 145 +++++----- test/test_macro.jl | 60 ++-- test/test_positional.jl | 20 +- test/test_properties.jl | 22 +- test/test_shorthand.jl | 68 ++--- test/test_show.jl | 26 +- test/test_spec.jl | 124 ++++---- test/test_vg.jl | 60 ++-- test/test_vlplot_macro.jl | 180 ++++++------ 22 files changed, 599 insertions(+), 589 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 9d1d3c78..fef84fe0 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -3,52 +3,52 @@ using Documenter, VegaLite, UUIDs function Base.show(io::IO, m::MIME"text/html", v::VegaLite.VLSpec) divid = string("vl", replace(string(uuid4()), "-" => "")) print(io, "
") - print(io, "") end makedocs( - modules=[VegaLite], - sitename="VegaLite.jl", - pages=[ - "Home" => "index.md", - "Getting Started" => Any[ - "Installation" => "gettingstarted/installation.md", - "Tutorial" => "gettingstarted/tutorial.md" - ], - "User Guide" => Any[ - "Vega-lite specifications" => "userguide/vlspec.md", - "The @vlplot command" => "userguide/vlplotmacro.md", - "Data sources" => "userguide/data.md" - ], - "Examples" => Any[ - "Single-View Plots" => Any[ - "Bar Charts" => "examples/examples_barcharts.md", - "Histograms, Density Plots, and Dot Plots" => "examples/examples_histograms.md", - "Scatter & Strip Plots" => "examples/examples_scatter_strip_plots.md", - "Line Charts" => "examples/examples_line_charts.md", - "Area Charts & Streamgraphs" => "examples/examples_area_Charts_streamgraphs.md", - "Table-based Plots" => "examples/examples_table_based_plots.md", - "Circular Plots" => "examples/examples_circular_plots.md", - "Advanced Calculations" => "examples/examples_advancedcalculations.md" + modules=[VegaLite], + sitename="VegaLite.jl", + pages=[ + "Home" => "index.md", + "Getting Started" => Any[ + "Installation"=>"gettingstarted/installation.md", + "Tutorial"=>"gettingstarted/tutorial.md" ], - "Composite Mark" => Any[ - "Error Bars & Error Bands" => "examples/examples_error_bars_bands.md", - "Box Plots" => "examples/examples_box_plots.md" + "User Guide" => Any[ + "Vega-lite specifications"=>"userguide/vlspec.md", + "The @vlplot command"=>"userguide/vlplotmacro.md", + "Data sources"=>"userguide/data.md" ], - "Multi-View Displays" => Any[ - "Faceting (Trellis Plot / Small Multiples)" => "examples/examples_faceting.md", - "Repeat & Concatenation" => "examples/examples_repeat_concatenation.md" + "Examples" => Any[ + "Single-View Plots"=>Any[ + "Bar Charts"=>"examples/examples_barcharts.md", + "Histograms, Density Plots, and Dot Plots"=>"examples/examples_histograms.md", + "Scatter & Strip Plots"=>"examples/examples_scatter_strip_plots.md", + "Line Charts"=>"examples/examples_line_charts.md", + "Area Charts & Streamgraphs"=>"examples/examples_area_Charts_streamgraphs.md", + "Table-based Plots"=>"examples/examples_table_based_plots.md", + "Circular Plots"=>"examples/examples_circular_plots.md", + "Advanced Calculations"=>"examples/examples_advancedcalculations.md" + ], + "Composite Mark"=>Any[ + "Error Bars & Error Bands"=>"examples/examples_error_bars_bands.md", + "Box Plots"=>"examples/examples_box_plots.md" + ], + "Multi-View Displays"=>Any[ + "Faceting (Trellis Plot / Small Multiples)"=>"examples/examples_faceting.md", + "Repeat & Concatenation"=>"examples/examples_repeat_concatenation.md" + ], + "Maps (Geographic Displays)"=>"examples/examples_maps.md" ], - "Maps (Geographic Displays)" => "examples/examples_maps.md" - ], - "Reference Manual" => [ - "Global settings" => "referencemanual/global.md", - "Outputs" => "referencemanual/output.md", - "Performance tips" => "referencemanual/performance.md", + "Reference Manual" => [ + "Global settings" => "referencemanual/global.md", + "Outputs" => "referencemanual/output.md", + "Performance tips" => "referencemanual/performance.md", ] - ] + ] ) deploydocs( diff --git a/src/VegaLite.jl b/src/VegaLite.jl index 50840246..c202a1c2 100644 --- a/src/VegaLite.jl +++ b/src/VegaLite.jl @@ -30,7 +30,7 @@ export deletedata, deletedata! vegalite_app_path(args...) = joinpath(artifact"vegalite_app", args...) const vegaliate_app_includes_canvas = Ref{Bool}() -const vlschema = Ref{Dict{String, Any}}() +const vlschema = Ref{Dict{String,Any}}() function __init__() vegaliate_app_includes_canvas[] = ispath(vegalite_app_path("node_modules", "canvas")) diff --git a/src/dsl_vlplot_function/dsl_vlplot_function.jl b/src/dsl_vlplot_function/dsl_vlplot_function.jl index 71758d89..29d592cf 100644 --- a/src/dsl_vlplot_function/dsl_vlplot_function.jl +++ b/src/dsl_vlplot_function/dsl_vlplot_function.jl @@ -96,7 +96,7 @@ function fix_shortcut_level_data(spec_frag) if TableTraits.isiterabletable(spec_frag) it = IteratorInterfaceExtensions.getiterator(spec_frag) return VLFrag([], OrderedDict{String,Any}("values" => Vega.DataValuesNode(it))) -else + else return spec_frag end end @@ -105,7 +105,7 @@ function fix_shortcut_level_spec(spec_frag::VLFrag) spec = copy(spec_frag.named) if length(spec_frag.positional) > 0 - spec["mark"] = spec_frag.positional[1] + spec["mark"] = spec_frag.positional[1] elseif length(spec_frag.positional) > 3 error("More than three positional element specified at the spec level.") end @@ -119,7 +119,7 @@ function fix_shortcut_level_spec(spec_frag::VLFrag) encodings_to_be_moved = filter( i -> i != "facet", collect(keys(vlschema[]["definitions"]["FacetedEncoding"]["properties"])), - ) + ) for k in collect(keys(spec)) if string(k) in encodings_to_be_moved if !haskey(spec, "encoding") @@ -163,7 +163,7 @@ function fix_shortcut_level_spec(spec_frag::VLFrag) inline_unnamed_data = Pair{Symbol,AbstractVector}[] if haskey(spec, "encoding") - if spec["encoding"] isa VLFrag + if spec["encoding"] isa VLFrag if !isempty(spec["encoding"].positional) error("Can't have positional arguments inside the encoding element.") else @@ -226,12 +226,12 @@ function convert_frag_tree_to_dict(spec::VLFrag) return "type" => p[2] else return p -end + end end return spec_as_dict2 end -function vlplot(args...;kwargs...) - return VLSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec(vlfrag(args...;kwargs...)))) +function vlplot(args...; kwargs...) + return VLSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec(vlfrag(args...; kwargs...)))) end diff --git a/src/dsl_vlplot_function/shorthandparser.jl b/src/dsl_vlplot_function/shorthandparser.jl index e3ad4ed4..96e6060a 100644 --- a/src/dsl_vlplot_function/shorthandparser.jl +++ b/src/dsl_vlplot_function/shorthandparser.jl @@ -69,18 +69,18 @@ function parse_shortcut(s::AbstractString) if length(tokens) > 2 && tokens[3] == ")" if length(tokens) == 3 decoded_func = decode_func(tokens[1]) - return [decoded_func,"type" => decoded_func[1] == "timeUnit" ? "temporal" : "quantitative"] + return [decoded_func, "type" => decoded_func[1] == "timeUnit" ? "temporal" : "quantitative"] elseif length(tokens) == 5 && tokens[4] == ":" - return [decode_func(tokens[1]),decode_typ(tokens[5])] + return [decode_func(tokens[1]), decode_typ(tokens[5])] else throw(ArgumentError("invalid shortcut string")) end elseif length(tokens) > 3 && tokens[4] == ")" if length(tokens) == 4 decoded_func = decode_func(tokens[1]) - return [decoded_func,"field" => tokens[3],"type" => decoded_func[1] == "timeUnit" ? "temporal" : "quantitative"] + return [decoded_func, "field" => tokens[3], "type" => decoded_func[1] == "timeUnit" ? "temporal" : "quantitative"] elseif length(tokens) == 6 && tokens[5] == ":" - return [decode_func(tokens[1]),"field" => tokens[3],decode_typ(tokens[6])] + return [decode_func(tokens[1]), "field" => tokens[3], decode_typ(tokens[6])] else throw(ArgumentError("invalid shortcut string")) end @@ -88,7 +88,7 @@ function parse_shortcut(s::AbstractString) throw(ArgumentError("Invalid shortcut string")) end elseif length(tokens) == 3 && tokens[2] == ":" - return ["field" => tokens[1],decode_typ(tokens[3])] + return ["field" => tokens[1], decode_typ(tokens[3])] else throw(ArgumentError("Invalid shortcut string")) end diff --git a/src/dsl_vlplot_macro/dsl_vlplot_macro.jl b/src/dsl_vlplot_macro/dsl_vlplot_macro.jl index c49880e7..e28791de 100644 --- a/src/dsl_vlplot_macro/dsl_vlplot_macro.jl +++ b/src/dsl_vlplot_macro/dsl_vlplot_macro.jl @@ -1,7 +1,7 @@ macro vlplot(ex...) new_ex = Vega.convert_curly_style(ex, VLFrag) - return :( VegaLite.VLSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec($new_ex))) ) + return :(VegaLite.VLSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec($new_ex)))) end macro vlfrag(ex...) diff --git a/src/rendering/fileio.jl b/src/rendering/fileio.jl index 62251391..806d9fcf 100644 --- a/src/rendering/fileio.jl +++ b/src/rendering/fileio.jl @@ -26,4 +26,4 @@ function fileio_save(stream::FileIO.Stream{FileIO.format"vega"}, data::VLSpec; i parsed = JSON.parse(s) vgspec = Vega.VGSpec(parsed) Vega.savespec(stream.io, vgspec; include_data=include_data, kwargs...) -end \ No newline at end of file +end diff --git a/src/rendering/io.jl b/src/rendering/io.jl index fe30edec..b961bcde 100644 --- a/src/rendering/io.jl +++ b/src/rendering/io.jl @@ -20,8 +20,8 @@ function savefig(filename::AbstractString, v::VLSpec) mime = "image/png" elseif file_ext == ".eps" mime = "application/eps" - # elseif file_ext == ".ps" - # mime = "application/postscript" + # elseif file_ext == ".ps" + # mime = "application/postscript" else throw(ArgumentError("Unknown file type.")) end diff --git a/src/rendering/render.jl b/src/rendering/render.jl index d7fec5de..ebdafa31 100644 --- a/src/rendering/render.jl +++ b/src/rendering/render.jl @@ -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 - - return package_json[]["dependencies"][package] + if !isassigned(package_json) + package_json[] = JSON.parsefile(vegalite_app_path("package.json")) + end + + return package_json[]["dependencies"][package] end # Vega Scaffold: https://github.com/vega/vega/wiki/Runtime @@ -27,48 +27,51 @@ function writehtml_full(io::IO, spec::VLSpec; title="VegaLite plot") divid = "vg" * randstring(3) print(io, - """ - - - $title - - - - - - -
- - - - - + + + + +
+ + + + + + - - """) + +""" + ) end function writehtml_full(spec::VLSpec; title="VegaLite plot") @@ -88,63 +91,63 @@ VegaLite js files are loaded from the web (to accommodate the security model of IJulia) using requirejs. """ function writehtml_partial_require(io::IO, spec::String; title="VegaLite plot") - divid = "vg" * randstring(3) + divid = "vg" * randstring(3) println(io, - """ - - -
- - - - - - - - """) + """ + + +
+ + + + + + + + """) end """ @@ -152,40 +155,46 @@ 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::VLSpec; title="VegaLite plot") - divid = "vg" * randstring(3) - print(io, """ - - - - - - -
- - - """) + divid = "vg" * randstring(3) + print( + io, + """ + + + + + + +
+ + +""" + ) end function Base.display(d::REPL.REPLDisplay, plt::VLSpec) - # checkplot(plt) + # checkplot(plt) tmppath = writehtml_full(plt) Vega.launch_browser(tmppath) # Open the browser end diff --git a/src/vlspec.jl b/src/vlspec.jl index 5ac76b26..185e87c4 100644 --- a/src/vlspec.jl +++ b/src/vlspec.jl @@ -17,13 +17,13 @@ end function augment_encoding_type(x::AbstractDict, data::Vega.DataValuesNode) if !haskey(x, "type") && !haskey(x, "aggregate") && haskey(x, "field") && haskey(data.columns, Symbol(x["field"])) new_x = copy(x) - + jl_type = eltype(data.columns[Symbol(x["field"])]) - + if jl_type <: DataValues.DataValue jl_type = eltype(jl_type) end - + if jl_type <: Number new_x["type"] = "quantitative" elseif jl_type <: AbstractString @@ -31,21 +31,21 @@ function augment_encoding_type(x::AbstractDict, data::Vega.DataValuesNode) elseif jl_type <: Dates.AbstractTime new_x["type"] = "temporal" end - + return new_x else return x -end + end end function add_encoding_types(specdict, parentdata=nothing) - if (haskey(specdict, "data") && haskey(specdict["data"], "values") && specdict["data"]["values"] isa Vega.DataValuesNode) || parentdata !== nothing + if (haskey(specdict, "data") && haskey(specdict["data"], "values") && specdict["data"]["values"] isa Vega.DataValuesNode) || parentdata !== nothing data = (haskey(specdict, "data") && haskey(specdict["data"], "values") && specdict["data"]["values"] isa Vega.DataValuesNode) ? specdict["data"]["values"] : parentdata newspec = OrderedDict{String,Any}( - (k == "encoding" && v isa AbstractDict) ? k => OrderedDict{String,Any}(kk => augment_encoding_type(vv, data) for (kk, vv) in v) : - k == "spec" ? k => add_encoding_types(v, data) : - k in ("layer", "concat", "vconcat", "hconcat") ? k => [add_encoding_types(i, data) for i in v] : k => v for (k, v) in specdict + (k == "encoding" && v isa AbstractDict) ? k => OrderedDict{String,Any}(kk => augment_encoding_type(vv, data) for (kk, vv) in v) : + k == "spec" ? k => add_encoding_types(v, data) : + k in ("layer", "concat", "vconcat", "hconcat") ? k => [add_encoding_types(i, data) for i in v] : k => v for (k, v) in specdict ) return newspec @@ -59,8 +59,8 @@ function our_json_print(io, spec::VLSpec) end function (p::VLSpec)(data) - TableTraits.isiterabletable(data) || throw(ArgumentError("'data' is not a table.")) - + TableTraits.isiterabletable(data) || throw(ArgumentError("'data' is not a table.")) + it = IteratorInterfaceExtensions.getiterator(data) datavaluesnode = Vega.DataValuesNode(it) @@ -70,7 +70,7 @@ function (p::VLSpec)(data) new_dict["data"] = OrderedDict{String,Any}("values" => datavaluesnode) return VLSpec(new_dict) - end +end function (p::VLSpec)(uri::URI) new_dict = copy(Vega.getparams(p)) @@ -138,10 +138,10 @@ function Base.hcat(A::VLSpec...) end function Base.vcat(A::VLSpec...) - spec = VLSpec(OrderedDict{String,Any}()) - Vega.getparams(spec)["vconcat"] = [] - for i in A - push!(Vega.getparams(spec)["vconcat"], deepcopy(Vega.getparams(i))) - end - return spec + spec = VLSpec(OrderedDict{String,Any}()) + Vega.getparams(spec)["vconcat"] = [] + for i in A + push!(Vega.getparams(spec)["vconcat"], deepcopy(Vega.getparams(i))) + end + return spec end diff --git a/test/runtests.jl b/test/runtests.jl index eef51e69..869465da 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,17 +5,17 @@ using Dates @testset "VegaLite" begin -include("testhelper_create_vg_plot.jl") -include("test_io.jl") -include("test_show.jl") -include("test_base.jl") -include("test_macro.jl") -include("test_shorthand.jl") -include("test_spec.jl") -include("test_vg.jl") -include("test_vlplot_macro.jl") -include("test_properties.jl") -include("test_inlinedata.jl") -include("test_positional.jl") + include("testhelper_create_vg_plot.jl") + include("test_io.jl") + include("test_show.jl") + include("test_base.jl") + include("test_macro.jl") + include("test_shorthand.jl") + include("test_spec.jl") + include("test_vg.jl") + include("test_vlplot_macro.jl") + include("test_properties.jl") + include("test_inlinedata.jl") + include("test_positional.jl") end diff --git a/test/scratchpad.jl b/test/scratchpad.jl index d704b316..19acfd68 100644 --- a/test/scratchpad.jl +++ b/test/scratchpad.jl @@ -1,6 +1,6 @@ @time using VegaLite -module VegaLite ; end +module VegaLite end using VegaLite # 55s w/ precompilation, 23s w/o precompilation using NamedTuples @@ -17,7 +17,7 @@ rooturl = "https://raw.githubusercontent.com/vega/new-editor/master/data/" dataurl = rooturl * "data/cars.json" plot( - rep(row=["Horsepower","Acceleration"], + rep(row=["Horsepower", "Acceleration"], column=["Horsepower", "Miles_per_Gallon"]), spec( data(url=durl), @@ -30,9 +30,9 @@ plot( translate = "[mousedown[event.shiftKey], mouseup] > mousemove"), grid=@NT( typ = "interval", resolve = "global", bind = "scales", - translate = "[mousedown[!event.shiftKey], mouseup] > mousemove") ), + translate = "[mousedown[!event.shiftKey], mouseup] > mousemove")), enc.x.quantitative(@NT(repeat = :row)), enc.y.quantitative(@NT(repeat = :column)), enc.color.nominal(:Origin, condition=@NT(selection = "!brush", value = :grey)) - ) - ) |> display + ) +) |> display diff --git a/test/test_base.jl b/test/test_base.jl index 414e6188..35b01fe2 100644 --- a/test/test_base.jl +++ b/test/test_base.jl @@ -1,26 +1,26 @@ using Test using VegaLite -using VegaLite:Vega.getparams +using VegaLite: Vega.getparams @testset "base" begin -equiv(a::VegaLite.VLSpec, b::VegaLite.VLSpec) = - ==(Vega.getparams(a), Vega.getparams(b)) + equiv(a::VegaLite.VLSpec, b::VegaLite.VLSpec) = + ==(Vega.getparams(a), Vega.getparams(b)) -### -@test isa(renderer(), Symbol) -@test_throws MethodError renderer(456) -@test_throws ErrorException renderer(:abcd) -renderer(:canvas) -@test renderer() == :canvas + ### + @test isa(renderer(), Symbol) + @test_throws MethodError renderer(456) + @test_throws ErrorException renderer(:abcd) + renderer(:canvas) + @test renderer() == :canvas -@test isa(actionlinks(), Bool) -@test_throws MethodError actionlinks(46) -actionlinks(false) -@test actionlinks() == false + @test isa(actionlinks(), Bool) + @test_throws MethodError actionlinks(46) + actionlinks(false) + @test actionlinks() == false -ts = collect(range(0, stop=2, length=100)) -rs = Float64[ rand() * 0.1 + cos(x) for x in ts] -datvals = [ Dict(:time => t, :res => r) for (t, r) in zip(ts, rs) ] + ts = collect(range(0, stop=2, length=100)) + rs = Float64[rand() * 0.1 + cos(x) for x in ts] + datvals = [Dict(:time => t, :res => r) for (t, r) in zip(ts, rs)] end diff --git a/test/test_inlinedata.jl b/test/test_inlinedata.jl index 6693ac8a..967424fa 100644 --- a/test/test_inlinedata.jl +++ b/test/test_inlinedata.jl @@ -1,9 +1,9 @@ @testset "Inline Data" begin -@test @vlplot(:point, x = {[1,2,3]}, y = [4,5,6]) == - @vlplot(:point, data = DataFrame(x=[1,2,3], y=[4,5,6]), x = {:x, title = nothing}, y = {:y, title = nothing}) + @test @vlplot(:point, x = {[1, 2, 3]}, y = [4, 5, 6]) == + @vlplot(:point, data = DataFrame(x=[1, 2, 3], y=[4, 5, 6]), x = {:x, title = nothing}, y = {:y, title = nothing}) -@test @vlplot(:point, x = {[1,2,3], title = :test}, y = [4,5,6]) == - @vlplot(:point, data = DataFrame(x=[1,2,3], y=[4,5,6]), x = {:x, title = :test}, y = {:y, title = nothing}) + @test @vlplot(:point, x = {[1, 2, 3], title = :test}, y = [4, 5, 6]) == + @vlplot(:point, data = DataFrame(x=[1, 2, 3], y=[4, 5, 6]), x = {:x, title = :test}, y = {:y, title = nothing}) end diff --git a/test/test_io.jl b/test/test_io.jl index 9961d3bc..fb22fad8 100644 --- a/test/test_io.jl +++ b/test/test_io.jl @@ -1,113 +1,114 @@ using Test using VegaLite -using VegaLite:Vega.getparams +using VegaLite: Vega.getparams using DataFrames using Dates using FileIO @testset "io" begin -p = DataFrame(x=[1,2,3], y=[1,2,3]) |> @vlplot(:point, x = "x:q", y = "y:q") -vgp = getvgplot() -vlp = getvlplot() + p = DataFrame(x=[1, 2, 3], y=[1, 2, 3]) |> @vlplot(:point, x = "x:q", y = "y:q") + vgp = getvgplot() + vlp = getvlplot() -@testset "$fmt (indent=$(repr(indent)))" for (fmt, plt) in [ - (format"vegalite", vlp) -], - indent in [nothing, 4] + @testset "$fmt (indent=$(repr(indent)))" for (fmt, plt) in [ + (format"vegalite", vlp) + ], + indent in [nothing, 4] - let json = sprint(io -> save(Stream{fmt}(io), plt, indent=indent)), - code = "vg\"\"\"$json\"\"\"" - @test Vega.getparams(include_string(@__MODULE__, code)) == Vega.getparams(plt) - end + let json = sprint(io -> save(Stream{fmt}(io), plt, indent=indent)), + code = "vg\"\"\"$json\"\"\"" - let io = IOBuffer() - save(Stream{fmt}(io), plt, indent=indent) - seek(io, 0) - @test Vega.getparams(load(Stream{fmt}(io))) == Vega.getparams(plt) - end + @test Vega.getparams(include_string(@__MODULE__, code)) == Vega.getparams(plt) + end - let code = repr("text/plain", plt, context=:compact => false) - @test Vega.getparams(include_string(@__MODULE__, code)) == Vega.getparams(plt) + let io = IOBuffer() + save(Stream{fmt}(io), plt, indent=indent) + seek(io, 0) + @test Vega.getparams(load(Stream{fmt}(io))) == Vega.getparams(plt) + end + + let code = repr("text/plain", plt, context=:compact => false) + @test Vega.getparams(include_string(@__MODULE__, code)) == Vega.getparams(plt) + end end -end - -Base.Filesystem.mktempdir() do folder - VegaLite.svg(joinpath(folder, "test1.svg"), p) - @test isfile(joinpath(folder, "test1.svg")) - VegaLite.pdf(joinpath(folder, "test1.pdf"), p) - @test isfile(joinpath(folder, "test1.pdf")) + Base.Filesystem.mktempdir() do folder + VegaLite.svg(joinpath(folder, "test1.svg"), p) + @test isfile(joinpath(folder, "test1.svg")) - VegaLite.png(joinpath(folder, "test1.png"), p) - @test isfile(joinpath(folder, "test1.png")) + VegaLite.pdf(joinpath(folder, "test1.pdf"), p) + @test isfile(joinpath(folder, "test1.pdf")) - VegaLite.savefig(joinpath(folder, "test2.svg"), p) - @test isfile(joinpath(folder, "test2.svg")) + VegaLite.png(joinpath(folder, "test1.png"), p) + @test isfile(joinpath(folder, "test1.png")) - VegaLite.savefig(joinpath(folder, "test2.pdf"), p) - @test isfile(joinpath(folder, "test2.pdf")) + VegaLite.savefig(joinpath(folder, "test2.svg"), p) + @test isfile(joinpath(folder, "test2.svg")) - VegaLite.savefig(joinpath(folder, "test2.png"), p) - @test isfile(joinpath(folder, "test2.png")) + VegaLite.savefig(joinpath(folder, "test2.pdf"), p) + @test isfile(joinpath(folder, "test2.pdf")) - save(joinpath(folder, "test3.svg"), p) - @test isfile(joinpath(folder, "test3.svg")) + VegaLite.savefig(joinpath(folder, "test2.png"), p) + @test isfile(joinpath(folder, "test2.png")) - save(joinpath(folder, "test3.pdf"), p) - @test isfile(joinpath(folder, "test3.pdf")) + save(joinpath(folder, "test3.svg"), p) + @test isfile(joinpath(folder, "test3.svg")) - save(joinpath(folder, "test3.png"), p) - @test isfile(joinpath(folder, "test3.png")) + save(joinpath(folder, "test3.pdf"), p) + @test isfile(joinpath(folder, "test3.pdf")) - save(joinpath(folder, "test4.svg"), vgp) - @test isfile(joinpath(folder, "test4.svg")) + save(joinpath(folder, "test3.png"), p) + @test isfile(joinpath(folder, "test3.png")) - save(joinpath(folder, "test4.pdf"), vgp) - @test isfile(joinpath(folder, "test4.pdf")) + save(joinpath(folder, "test4.svg"), vgp) + @test isfile(joinpath(folder, "test4.svg")) - save(joinpath(folder, "test4.png"), vgp) - @test isfile(joinpath(folder, "test4.png")) + save(joinpath(folder, "test4.pdf"), vgp) + @test isfile(joinpath(folder, "test4.pdf")) - p |> save(joinpath(folder, "test5.svg")) - @test isfile(joinpath(folder, "test5.svg")) + save(joinpath(folder, "test4.png"), vgp) + @test isfile(joinpath(folder, "test4.png")) - p |> save(joinpath(folder, "test5.pdf")) - @test isfile(joinpath(folder, "test5.pdf")) + p |> save(joinpath(folder, "test5.svg")) + @test isfile(joinpath(folder, "test5.svg")) - p |> save(joinpath(folder, "test5.png")) - @test isfile(joinpath(folder, "test5.png")) + p |> save(joinpath(folder, "test5.pdf")) + @test isfile(joinpath(folder, "test5.pdf")) - vgp |> save(joinpath(folder, "test6.svg")) - @test isfile(joinpath(folder, "test6.svg")) + p |> save(joinpath(folder, "test5.png")) + @test isfile(joinpath(folder, "test5.png")) - vgp |> save(joinpath(folder, "test6.pdf")) - @test isfile(joinpath(folder, "test6.pdf")) + vgp |> save(joinpath(folder, "test6.svg")) + @test isfile(joinpath(folder, "test6.svg")) - vgp |> save(joinpath(folder, "test6.png")) - @test isfile(joinpath(folder, "test6.png")) + vgp |> save(joinpath(folder, "test6.pdf")) + @test isfile(joinpath(folder, "test6.pdf")) - Vega.savespec(joinpath(folder, "test1.vegalite"), p) - @test isfile(joinpath(folder, "test1.vegalite")) + vgp |> save(joinpath(folder, "test6.png")) + @test isfile(joinpath(folder, "test6.png")) - @test_throws ArgumentError VegaLite.savefig(joinpath(folder, "test1.foo"), p) + Vega.savespec(joinpath(folder, "test1.vegalite"), p) + @test isfile(joinpath(folder, "test1.vegalite")) - save(joinpath(folder, "test2.vegalite"), p) - @test isfile(joinpath(folder, "test2.vegalite")) + @test_throws ArgumentError VegaLite.savefig(joinpath(folder, "test1.foo"), p) - p2 = VegaLite.loadspec(joinpath(folder, "test1.vegalite")) - @test isa(p2, VegaLite.VLSpec) + save(joinpath(folder, "test2.vegalite"), p) + @test isfile(joinpath(folder, "test2.vegalite")) - p2 = load(joinpath(folder, "test1.vegalite")) - @test isa(p2, VegaLite.VLSpec) + p2 = VegaLite.loadspec(joinpath(folder, "test1.vegalite")) + @test isa(p2, VegaLite.VLSpec) - vgpl1 = getvgplot() + p2 = load(joinpath(folder, "test1.vegalite")) + @test isa(p2, VegaLite.VLSpec) - Vega.savespec(joinpath(folder, "test1.vega"), vgpl1, include_data=true) + vgpl1 = getvgplot() - vgpl2 = VegaLite.Vega.loadvgspec(joinpath(folder, "test1.vega")) + Vega.savespec(joinpath(folder, "test1.vega"), vgpl1, include_data=true) - @test vgpl1 == vgpl1 -end + vgpl2 = VegaLite.Vega.loadvgspec(joinpath(folder, "test1.vega")) + + @test vgpl1 == vgpl1 + end end diff --git a/test/test_macro.jl b/test/test_macro.jl index 334ae26e..8e7a9da1 100644 --- a/test/test_macro.jl +++ b/test/test_macro.jl @@ -1,39 +1,39 @@ using VegaLite -using VegaLite:Vega.getparams +using VegaLite: Vega.getparams using JSON using Test @testset "macro" begin -spec = vl""" -{ - "data": { - "values": [ - {"a": "A","b": 28}, {"a": "B","b": 55} - ] - }, - "mark": "bar", - "encoding": { - "x": {"field": "a", "type": "ordinal"}, - "y": {"field": "b", "type": "quantitative"} - } -} -""" + spec = vl""" + { + "data": { + "values": [ + {"a": "A","b": 28}, {"a": "B","b": 55} + ] + }, + "mark": "bar", + "encoding": { + "x": {"field": "a", "type": "ordinal"}, + "y": {"field": "b", "type": "quantitative"} + } + } + """ -@test isa(spec, VegaLite.VLSpec) -@test Vega.getparams(spec) == JSON.parse(""" -{ - "data": { - "values": [ - {"a": "A","b": 28}, {"a": "B","b": 55} - ] - }, - "mark": "bar", - "encoding": { - "x": {"field": "a", "type": "ordinal"}, - "y": {"field": "b", "type": "quantitative"} - } -} -""") + @test isa(spec, VegaLite.VLSpec) + @test Vega.getparams(spec) == JSON.parse(""" + { + "data": { + "values": [ + {"a": "A","b": 28}, {"a": "B","b": 55} + ] + }, + "mark": "bar", + "encoding": { + "x": {"field": "a", "type": "ordinal"}, + "y": {"field": "b", "type": "quantitative"} + } + } + """) end diff --git a/test/test_positional.jl b/test/test_positional.jl index 7a9f6d33..64ca901f 100644 --- a/test/test_positional.jl +++ b/test/test_positional.jl @@ -1,15 +1,15 @@ @testset "Positional shortcuts" begin -df = DataFrame(a=[1,2,3], b=[4,5,6]) + df = DataFrame(a=[1, 2, 3], b=[4, 5, 6]) -@test @vlplot(:point, [1,2,3]) == @vlplot(:point, x = [1,2,3]) -@test @vlplot(:point, {[1,2,3]}) == @vlplot(:point, x = [1,2,3]) -@test @vlplot(:point, [1,2,3], [4,5,6]) == @vlplot(:point, x = [1,2,3], y = [4,5,6]) -@test @vlplot(:point, {[1,2,3]}, {[4,5,6]}) == @vlplot(:point, x = [1,2,3], y = [4,5,6]) -@test @vlplot(:point, :a, data = df) == @vlplot(:point, x = :a, data = df) -@test @vlplot(:point, :a, :b, data = df) == @vlplot(:point, x = :a, y = :b, data = df) -@test @vlplot(:point, {:a}, data = df) == @vlplot(:point, x = :a, data = df) -@test @vlplot(:point, {:a}, {:b}, data = df) == @vlplot(:point, x = :a, y = :b, data = df) -@test @vlplot(:point, {"a:q"}, {"b:q"}, data = df) == @vlplot(:point, x = "a:q", y = "b:q", data = df) + @test @vlplot(:point, [1, 2, 3]) == @vlplot(:point, x = [1, 2, 3]) + @test @vlplot(:point, {[1, 2, 3]}) == @vlplot(:point, x = [1, 2, 3]) + @test @vlplot(:point, [1, 2, 3], [4, 5, 6]) == @vlplot(:point, x = [1, 2, 3], y = [4, 5, 6]) + @test @vlplot(:point, {[1, 2, 3]}, {[4, 5, 6]}) == @vlplot(:point, x = [1, 2, 3], y = [4, 5, 6]) + @test @vlplot(:point, :a, data = df) == @vlplot(:point, x = :a, data = df) + @test @vlplot(:point, :a, :b, data = df) == @vlplot(:point, x = :a, y = :b, data = df) + @test @vlplot(:point, {:a}, data = df) == @vlplot(:point, x = :a, data = df) + @test @vlplot(:point, {:a}, {:b}, data = df) == @vlplot(:point, x = :a, y = :b, data = df) + @test @vlplot(:point, {"a:q"}, {"b:q"}, data = df) == @vlplot(:point, x = "a:q", y = "b:q", data = df) end diff --git a/test/test_properties.jl b/test/test_properties.jl index 2e22cd17..d130f159 100644 --- a/test/test_properties.jl +++ b/test/test_properties.jl @@ -4,18 +4,18 @@ using Setfield @testset "properties" begin -vgp = getvgplot() -@test vgp.width isa Number -@static if VERSION >= v"1.3" - @test vgp.var"$schema" isa String -end + vgp = getvgplot() + @test vgp.width isa Number + @static if VERSION >= v"1.3" + @test vgp.var"$schema" isa String + end -vlp = getvlplot() -@test vlp.mark isa String -@test vlp.encoding.x.field isa String -@test_deprecated vlp.params["mark"] isa String + vlp = getvlplot() + @test vlp.mark isa String + @test vlp.encoding.x.field isa String + @test_deprecated vlp.params["mark"] isa String -@test (@set vlp.mark = :point).mark == :point -@test vlp.mark == "bar" # not mutated + @test (@set vlp.mark = :point).mark == :point + @test vlp.mark == "bar" # not mutated end diff --git a/test/test_shorthand.jl b/test/test_shorthand.jl index ee6fb495..2aed145b 100644 --- a/test/test_shorthand.jl +++ b/test/test_shorthand.jl @@ -3,53 +3,53 @@ using VegaLite @testset "Shorthand" begin -@test VegaLite.parse_shortcut("foo") == ["field" => "foo"] + @test VegaLite.parse_shortcut("foo") == ["field" => "foo"] -@test VegaLite.parse_shortcut("foo:q") == ["field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("foo:Q") == ["field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("foo:quantitative") == ["field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("foo:quAntitAtive") == ["field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("foo:q") == ["field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("foo:Q") == ["field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("foo:quantitative") == ["field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("foo:quAntitAtive") == ["field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("foo:n") == ["field" => "foo", "type" => "nominal"] -@test VegaLite.parse_shortcut("foo:N") == ["field" => "foo", "type" => "nominal"] -@test VegaLite.parse_shortcut("foo:nominal") == ["field" => "foo", "type" => "nominal"] -@test VegaLite.parse_shortcut("foo:nOminAl") == ["field" => "foo", "type" => "nominal"] + @test VegaLite.parse_shortcut("foo:n") == ["field" => "foo", "type" => "nominal"] + @test VegaLite.parse_shortcut("foo:N") == ["field" => "foo", "type" => "nominal"] + @test VegaLite.parse_shortcut("foo:nominal") == ["field" => "foo", "type" => "nominal"] + @test VegaLite.parse_shortcut("foo:nOminAl") == ["field" => "foo", "type" => "nominal"] -@test VegaLite.parse_shortcut("foo:o") == ["field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("foo:O") == ["field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("foo:ordinal") == ["field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("foo:OrDinAl") == ["field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("foo:o") == ["field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("foo:O") == ["field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("foo:ordinal") == ["field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("foo:OrDinAl") == ["field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("foo:t") == ["field" => "foo", "type" => "temporal"] -@test VegaLite.parse_shortcut("foo:T") == ["field" => "foo", "type" => "temporal"] -@test VegaLite.parse_shortcut("foo:temporal") == ["field" => "foo", "type" => "temporal"] -@test VegaLite.parse_shortcut("foo:tEmporAl") == ["field" => "foo", "type" => "temporal"] + @test VegaLite.parse_shortcut("foo:t") == ["field" => "foo", "type" => "temporal"] + @test VegaLite.parse_shortcut("foo:T") == ["field" => "foo", "type" => "temporal"] + @test VegaLite.parse_shortcut("foo:temporal") == ["field" => "foo", "type" => "temporal"] + @test VegaLite.parse_shortcut("foo:tEmporAl") == ["field" => "foo", "type" => "temporal"] -@test_throws ArgumentError VegaLite.parse_shortcut("foo:x") -@test_throws ArgumentError VegaLite.parse_shortcut("foo:bar") + @test_throws ArgumentError VegaLite.parse_shortcut("foo:x") + @test_throws ArgumentError VegaLite.parse_shortcut("foo:bar") -@test VegaLite.parse_shortcut("sum(foo)") == ["aggregate" => "sum", "field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("sum(foo):o") == ["aggregate" => "sum", "field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("sum(foo):quantitative") == ["aggregate" => "sum", "field" => "foo", "type" => "quantitative"] -@test_throws ArgumentError VegaLite.parse_shortcut("sum(foo):bar") + @test VegaLite.parse_shortcut("sum(foo)") == ["aggregate" => "sum", "field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("sum(foo):o") == ["aggregate" => "sum", "field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("sum(foo):quantitative") == ["aggregate" => "sum", "field" => "foo", "type" => "quantitative"] + @test_throws ArgumentError VegaLite.parse_shortcut("sum(foo):bar") -@test VegaLite.parse_shortcut("year(foo)") == ["timeUnit" => "year", "field" => "foo", "type" => "temporal"] -@test VegaLite.parse_shortcut("month(foo):o") == ["timeUnit" => "month", "field" => "foo", "type" => "ordinal"] -@test VegaLite.parse_shortcut("yearmonth(foo):quantitative") == ["timeUnit" => "yearmonth", "field" => "foo", "type" => "quantitative"] + @test VegaLite.parse_shortcut("year(foo)") == ["timeUnit" => "year", "field" => "foo", "type" => "temporal"] + @test VegaLite.parse_shortcut("month(foo):o") == ["timeUnit" => "month", "field" => "foo", "type" => "ordinal"] + @test VegaLite.parse_shortcut("yearmonth(foo):quantitative") == ["timeUnit" => "yearmonth", "field" => "foo", "type" => "quantitative"] -@test VegaLite.parse_shortcut("count()") == ["aggregate" => "count", "type" => "quantitative"] -@test VegaLite.parse_shortcut("count():o") == ["aggregate" => "count", "type" => "ordinal"] + @test VegaLite.parse_shortcut("count()") == ["aggregate" => "count", "type" => "quantitative"] + @test VegaLite.parse_shortcut("count():o") == ["aggregate" => "count", "type" => "ordinal"] -@test_throws ArgumentError VegaLite.parse_shortcut("%lijasef9") + @test_throws ArgumentError VegaLite.parse_shortcut("%lijasef9") -@test_throws ArgumentError VegaLite.parse_shortcut("bar(foo)") + @test_throws ArgumentError VegaLite.parse_shortcut("bar(foo)") -@test_throws ArgumentError VegaLite.parse_shortcut("bar():lij:lij") + @test_throws ArgumentError VegaLite.parse_shortcut("bar():lij:lij") -@test_throws ArgumentError VegaLite.parse_shortcut("count):o:foo") + @test_throws ArgumentError VegaLite.parse_shortcut("count):o:foo") -@test_throws ArgumentError VegaLite.parse_shortcut("count(bar(:o:foo") + @test_throws ArgumentError VegaLite.parse_shortcut("count(bar(:o:foo") -@test_throws ArgumentError VegaLite.parse_shortcut("count(bar):o:foo") + @test_throws ArgumentError VegaLite.parse_shortcut("count(bar):o:foo") end diff --git a/test/test_show.jl b/test/test_show.jl index 2556598a..d0007f85 100644 --- a/test/test_show.jl +++ b/test/test_show.jl @@ -3,29 +3,29 @@ using VegaLite @testset "show" begin -vl = @vlplot(:point) -vg = Vega.VGSpec(Dict{String,Any}()) + vl = @vlplot(:point) + vg = Vega.VGSpec(Dict{String,Any}()) -@test sprint(show, vl) == "VegaLite.VLSpec" + @test sprint(show, vl) == "VegaLite.VLSpec" -@test sprint(show, "text/plain", vl) == "@vlplot(\n mark=\"point\"\n)" + @test sprint(show, "text/plain", vl) == "@vlplot(\n mark=\"point\"\n)" -@test sprint(show, vg) == "Vega.VGSpec" + @test sprint(show, vg) == "Vega.VGSpec" -@test sprint(show, "text/plain", vg) == "@vgplot(\n\n)" + @test sprint(show, "text/plain", vg) == "@vgplot(\n\n)" -@test_throws ArgumentError sprint(show, "image/svg+xml", @vlplot()) + @test_throws ArgumentError sprint(show, "image/svg+xml", @vlplot()) -@test istextmime("application/vnd.vegalite.v4+json") + @test istextmime("application/vnd.vegalite.v4+json") -@test istextmime("application/vnd.vega.v5+json") + @test istextmime("application/vnd.vega.v5+json") -@test sprint(show, "application/vnd.vegalite.v4+json", @vlplot(:point)) == "{\"mark\":\"point\"}" + @test sprint(show, "application/vnd.vegalite.v4+json", @vlplot(:point)) == "{\"mark\":\"point\"}" -@test sprint(show, "application/vnd.vega.v5+json", vg"{}") == "{}" + @test sprint(show, "application/vnd.vega.v5+json", vg"{}") == "{}" -@test !showable(MIME("text/html"), vl) + @test !showable(MIME("text/html"), vl) -@test occursin("var spec = {\"mark\":\"point\"}", sprint(show, "text/html",vl)) + @test occursin("var spec = {\"mark\":\"point\"}", sprint(show, "text/html", vl)) end diff --git a/test/test_spec.jl b/test/test_spec.jl index e8fd7448..c8805a86 100644 --- a/test/test_spec.jl +++ b/test/test_spec.jl @@ -7,82 +7,82 @@ using VegaDatasets @testset "Spec" begin -@test @vlplot()(URI("http://www.foo.com/bar.json")) == vl""" - { - "data": { - "url": "http://www.foo.com/bar.json" + @test @vlplot()(URI("http://www.foo.com/bar.json")) == vl""" + { + "data": { + "url": "http://www.foo.com/bar.json" + } } - } - """ + """ -@test_throws ArgumentError @vlplot()(5) + @test_throws ArgumentError @vlplot()(5) -df = DataFrame(a=[1.,2.], b=["A", "B"], c=[Date(2000), Date(2001)]) + df = DataFrame(a=[1.0, 2.0], b=["A", "B"], c=[Date(2000), Date(2001)]) -p1 = (df |> @vlplot("line", x = :c, y = :a, color = :b)) -p2 = vl""" -{ - "encoding": { - "x": { - "field": "c" - }, - "color": { - "field": "b" - }, - "y": { - "field": "a" + p1 = (df |> @vlplot("line", x = :c, y = :a, color = :b)) + p2 = vl""" + { + "encoding": { + "x": { + "field": "c" + }, + "color": { + "field": "b" + }, + "y": { + "field": "a" + } + }, + "mark": "line" } - }, - "mark": "line" -} -""" + """ -p3 = Vega.deletedata(p1) -@test p3 != p1 -@test p3 == p2 + p3 = Vega.deletedata(p1) + @test p3 != p1 + @test p3 == p2 -Vega.deletedata!(p1) + Vega.deletedata!(p1) -@test p1 == p2 + @test p1 == p2 -p3 = DataFrame(a=[1,2,missing], b=[3.,2.,1.]) |> @vlplot(:point, x = :a, y = :b) + p3 = DataFrame(a=[1, 2, missing], b=[3.0, 2.0, 1.0]) |> @vlplot(:point, x = :a, y = :b) -p4 = vl""" -{ - "encoding": { - "x": { - "field": "a", - "type": "quantitative" - }, - "y": { - "field": "b", - "type": "quantitative" - } - }, - "data": { - "values": [ - { - "b": 3.0, - "a": 1 + p4 = vl""" + { + "encoding": { + "x": { + "field": "a", + "type": "quantitative" + }, + "y": { + "field": "b", + "type": "quantitative" + } }, - { - "b": 2.0, - "a": 2 + "data": { + "values": [ + { + "b": 3.0, + "a": 1 + }, + { + "b": 2.0, + "a": 2 + }, + { + "b": 1.0, + "a": null + } + ] }, - { - "b": 1.0, - "a": null - } - ] - }, - "mark": "point" -} -""" + "mark": "point" + } + """ -# @test p3 == p4 + # @test p3 == p4 -p5 = dataset("cars").path |> @vlplot(:point, x = :Miles_per_Gallon, y = :Acceleration) + p5 = dataset("cars").path |> @vlplot(:point, x = :Miles_per_Gallon, y = :Acceleration) -@test haskey(Vega.getparams(p5)["data"], "url") + @test haskey(Vega.getparams(p5)["data"], "url") end diff --git a/test/test_vg.jl b/test/test_vg.jl index 0a48c2b5..ebb1a74e 100644 --- a/test/test_vg.jl +++ b/test/test_vg.jl @@ -9,48 +9,48 @@ include("testhelper_create_vg_plot.jl") @testset "VGSpec" begin -@test vg"""{ "data": [ { "name": "test" } ] }"""(URI("http://www.foo.com/bar.json"), "test") == vg""" - { - "data": [{ - "name": "test", - "url": "http://www.foo.com/bar.json" - }] - } - """ - -if Sys.iswindows() - @test vg"""{ "data": [ { "name": "test" } ] }"""(Path("/julia/dev"), "test") == vg""" + @test vg"""{ "data": [ { "name": "test" } ] }"""(URI("http://www.foo.com/bar.json"), "test") == vg""" { "data": [{ "name": "test", - "url": "file://julia/dev" + "url": "http://www.foo.com/bar.json" }] } """ -else - @test vg"""{ "data": [ { "name": "test" } ] }"""(Path("/julia/dev"), "test") == vg""" - { - "data": [{ - "name": "test", - "url": "file:///julia/dev" - }] - } - """ -end -df = DataFrame(a=[1.,2.], b=["A", "B"], c=[Date(2000), Date(2001)]) + if Sys.iswindows() + @test vg"""{ "data": [ { "name": "test" } ] }"""(Path("/julia/dev"), "test") == vg""" + { + "data": [{ + "name": "test", + "url": "file://julia/dev" + }] + } + """ + else + @test vg"""{ "data": [ { "name": "test" } ] }"""(Path("/julia/dev"), "test") == vg""" + { + "data": [{ + "name": "test", + "url": "file:///julia/dev" + }] + } + """ + end + + df = DataFrame(a=[1.0, 2.0], b=["A", "B"], c=[Date(2000), Date(2001)]) -p1 = getvgplot() + p1 = getvgplot() -p2 = Vega.deletedata(p1) -@test !haskey(Vega.getparams(p2)["data"][1], "values") + p2 = Vega.deletedata(p1) + @test !haskey(Vega.getparams(p2)["data"][1], "values") -p3 = p2(df, "table") + p3 = p2(df, "table") -@test Vega.getparams(p3)["data"][1]["values"][1]["b"] == "A" + @test Vega.getparams(p3)["data"][1]["values"][1]["b"] == "A" -Vega.deletedata!(p1) + Vega.deletedata!(p1) -@test p1 == p2 + @test p1 == p2 end diff --git a/test/test_vlplot_macro.jl b/test/test_vlplot_macro.jl index fa94acf5..34595279 100644 --- a/test/test_vlplot_macro.jl +++ b/test/test_vlplot_macro.jl @@ -6,117 +6,117 @@ using Test @testset "@vlplot macro" begin -@test @vlplot(mark = {"point"}) == (vl""" - {"mark": {"type": "point"}} + @test @vlplot(mark = {"point"}) == (vl""" + {"mark": {"type": "point"}} + """) + + @test @vlplot("point", data = {values = [{a = 1}]}) == (vl""" + {"mark": "point", "data": {"values":[{"a": 1}]}} """) -@test @vlplot("point", data = {values = [{a = 1}]}) == (vl""" - {"mark": "point", "data": {"values":[{"a": 1}]}} -""") + @test @vlplot(:point, x = :foo) == @vlplot(:point, enc = {x = :foo}) -@test @vlplot(:point, x = :foo) == @vlplot(:point, enc = {x = :foo}) + @test @vlplot(mark = {type = :point}) == @vlplot(mark = {:point}) -@test @vlplot(mark = {type = :point}) == @vlplot(mark = {:point}) + @test (p"/foo/bar" |> @vlplot(:point)) == @vlplot(:point, data = p"/foo/bar") -@test (p"/foo/bar" |> @vlplot(:point)) == @vlplot(:point, data = p"/foo/bar") + @test (p"/foo/bar" |> @vlplot(:point)) == @vlplot(:point, data = {url = p"/foo/bar"}) -@test (p"/foo/bar" |> @vlplot(:point)) == @vlplot(:point, data = {url = p"/foo/bar"}) + @test (URI("http://foo.com/bar.json") |> @vlplot(:point)) == @vlplot(:point, data = URI("http://foo.com/bar.json")) -@test (URI("http://foo.com/bar.json") |> @vlplot(:point)) == @vlplot(:point, data = URI("http://foo.com/bar.json")) + @test (URI("http://foo.com/bar.json") |> @vlplot(:point)) == @vlplot(:point, data = {url = URI("http://foo.com/bar.json")}) -@test (URI("http://foo.com/bar.json") |> @vlplot(:point)) == @vlplot(:point, data = {url = URI("http://foo.com/bar.json")}) + @test (DataFrame(a=[1]) |> @vlplot(:point)) == @vlplot(:point, data = DataFrame(a=[1])) -@test (DataFrame(a=[1]) |> @vlplot(:point)) == @vlplot(:point, data = DataFrame(a=[1])) + @test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = p"/foo/bar", key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == (Sys.iswindows() ? "file://foo/bar" : "file:///foo/bar") + @test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = {url = p"/foo/bar"}, key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == (Sys.iswindows() ? "file://foo/bar" : "file:///foo/bar") + @test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = URI("http://foo.com/bar.json"), key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == "http://foo.com/bar.json" + @test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = {url = URI("http://foo.com/bar.json")}, key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == "http://foo.com/bar.json" -@test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = p"/foo/bar", key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == (Sys.iswindows() ? "file://foo/bar" : "file:///foo/bar") -@test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = {url = p"/foo/bar"}, key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == (Sys.iswindows() ? "file://foo/bar" : "file:///foo/bar") -@test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = URI("http://foo.com/bar.json"), key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == "http://foo.com/bar.json" -@test Vega.getparams(@vlplot("point", transform = [{lookup = "foo", from = {data = {url = URI("http://foo.com/bar.json")}, key = "bar"}}]))["transform"][1]["from"]["data"]["url"] == "http://foo.com/bar.json" + @test JSON.parse(sprint(VegaLite.our_json_print, @vlplot("point", transform = [{lookup = "foo", from = {data = DataFrame(a = [1]), key = "bar"}}])))["transform"][1]["from"]["data"]["values"][1]["a"] == 1 -@test JSON.parse(sprint(VegaLite.our_json_print, @vlplot("point", transform = [{lookup = "foo", from = {data = DataFrame(a = [1]), key = "bar"}}])))["transform"][1]["from"]["data"]["values"][1]["a"] == 1 + @test [@vlplot("point") @vlplot("circle")] == (vl""" + { + "hconcat": [ + { + "mark": "point" + }, + { + "mark": "circle" + } + ] + } + """) -@test [@vlplot("point") @vlplot("circle")] == (vl""" -{ - "hconcat": [ - { - "mark": "point" - }, - { - "mark": "circle" - } - ] -} -""") - -@test [@vlplot("point"); @vlplot("circle")] == (vl""" -{ - "vconcat": [ - { - "mark": "point" - }, - { - "mark": "circle" - } - ] -} -""") - -@test @vlplot("point", x = {"foo:q"}) == (vl""" -{ - "mark": "point", - "encoding": { - "x": { - "field": "foo", - "type": "quantitative" + @test [@vlplot("point"); @vlplot("circle")] == (vl""" + { + "vconcat": [ + { + "mark": "point" + }, + { + "mark": "circle" + } + ] + } + """) + + @test @vlplot("point", x = {"foo:q"}) == (vl""" + { + "mark": "point", + "encoding": { + "x": { + "field": "foo", + "type": "quantitative" + } } } -} -""") + """) -@test (@vlplot(description = "foo") + @vlplot(:point) + @vlplot(:circle)) == @vlplot(description = "foo", layer = [{mark = :point},{mark = :circle}]) + @test (@vlplot(description = "foo") + @vlplot(:point) + @vlplot(:circle)) == @vlplot(description = "foo", layer = [{mark = :point}, {mark = :circle}]) -@test (@vlplot(facet = {row = {field = :foo, type = :bar}}) + @vlplot(:point)) == @vlplot(facet = {row = {field = :foo, type = :bar}}, spec = {mark = :point}) + @test (@vlplot(facet = {row = {field = :foo, type = :bar}}) + @vlplot(:point)) == @vlplot(facet = {row = {field = :foo, type = :bar}}, spec = {mark = :point}) -@test (@vlplot(repeat = {column = [:foo, :bar]}) + @vlplot(:point)) == @vlplot(repeat = {column = [:foo, :bar]}, spec = {mark = :point}) + @test (@vlplot(repeat = {column = [:foo, :bar]}) + @vlplot(:point)) == @vlplot(repeat = {column = [:foo, :bar]}, spec = {mark = :point}) -@test (@vlplot(description = "foo") + [@vlplot(:point) @vlplot(:circle)]) == @vlplot(description = "foo", hconcat = [{mark = :point},{mark = :circle}]) + @test (@vlplot(description = "foo") + [@vlplot(:point) @vlplot(:circle)]) == @vlplot(description = "foo", hconcat = [{mark = :point}, {mark = :circle}]) -@test (@vlplot(description = "foo") + [@vlplot(:point); @vlplot(:circle)]) == @vlplot(description = "foo", vconcat = [{mark = :point},{mark = :circle}]) + @test (@vlplot(description = "foo") + [@vlplot(:point); @vlplot(:circle)]) == @vlplot(description = "foo", vconcat = [{mark = :point}, {mark = :circle}]) -@test (@vlplot(:point, x = :a)(DataFrame(a=[1])) == @vlplot(:point, data = DataFrame(a=[1]), x = :a)) + @test (@vlplot(:point, x = :a)(DataFrame(a=[1])) == @vlplot(:point, data = DataFrame(a=[1]), x = :a)) -@test @vlplot("point", wrap = :x) == vl""" -{ - "mark": "point", - "encoding": { - "facet": {"field": "x"} - } -} -""" - -@test @vlplot("point", enc = {x = :foo}, wrap = :x) == vl""" -{ - "mark": "point", - "encoding": { - "x": {"field": "foo"}, - "facet": {"field": "x"} + @test @vlplot("point", wrap = :x) == vl""" + { + "mark": "point", + "encoding": { + "facet": {"field": "x"} + } + } + """ + + @test @vlplot("point", enc = {x = :foo}, wrap = :x) == vl""" + { + "mark": "point", + "encoding": { + "x": {"field": "foo"}, + "facet": {"field": "x"} + } } -} -""" - -@testset "Test using outside variables in vlplot spec" begin - color_bar1 = "green" - @test @vlplot( - x = :x, - y = :y, - mark = {type = :circle}, - color = {field = :z, type = "nominal", scale = {range = [color_bar1, "blue"]}} - ) == @vlplot( - x = :x, - y = :y, - mark = {type = :circle}, - color = {field = :z, type = "nominal", scale = {range = ["green", "blue"]}} - ) -end + """ + + @testset "Test using outside variables in vlplot spec" begin + color_bar1 = "green" + @test @vlplot( + x = :x, + y = :y, + mark = {type = :circle}, + color = {field = :z, type = "nominal", scale = {range = [color_bar1, "blue"]}} + ) == @vlplot( + x = :x, + y = :y, + mark = {type = :circle}, + color = {field = :z, type = "nominal", scale = {range = ["green", "blue"]}} + ) + end end