From 6c01d51c132c59b983f531a4826207eed5cce46c Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 21 Jan 2021 08:38:29 +1300 Subject: [PATCH] Remove JSONSchema as a dependency in favor of pure JSON.jl --- Project.toml | 58 +++++++++---------- src/VegaLite.jl | 5 +- .../dsl_vlplot_function.jl | 13 +++-- src/dsl_vlplot_function/shorthandparser.jl | 33 ++++++----- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/Project.toml b/Project.toml index 63ba0835..e96759df 100644 --- a/Project.toml +++ b/Project.toml @@ -3,48 +3,46 @@ uuid = "112f6efa-9a02-5b7d-90c0-432ed331239a" version = "2.3.1-DEV" [deps] -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" -REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" -JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -Vega = "239c3e63-733f-47ad-beb7-a12fde22c578" -DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692" -NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c" -MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda" +DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" FilePaths = "8fc22ac5-c921-52a6-82fd-178b2807b824" +IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" +TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda" URIParser = "30578b45-9adc-5946-b283-645ec420af67" - -[extras] -VegaDatasets = "0ae4a718-28b7-58ec-9efb-cded64d6d5b4" -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Vega = "239c3e63-733f-47ad-beb7-a12fde22c578" [compat] -TableTraits = "0.3.1, 0.4, 1" -IteratorInterfaceExtensions = "0.1.1, 1" -JSON = "0.19, 0.20, 0.21" -Vega = "0.1, 1, 2" DataStructures = "0.17" -JSONSchema = "0.1, 0.2" -NodeJS = "0.5.1, 0.6, 1" -MacroTools = "0.4.4, 0.5" -FileIO = "1.0.1" -TableTraitsUtils = "1" -julia = "1.3" DataValues = "0.4.4" +FileIO = "1.0.1" FilePaths = "0.7, 0.8" +IteratorInterfaceExtensions = "0.1.1, 1" +JSON = "0.19, 0.20, 0.21" +MacroTools = "0.4.4, 0.5" +NodeJS = "0.5.1, 0.6, 1" Setfield = "0.4, 0.5, 0.6" +TableTraits = "0.3.1, 0.4, 1" +TableTraitsUtils = "1" URIParser = "0.4" +Vega = "0.1, 1, 2" +julia = "1.3" + +[extras] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +VegaDatasets = "0ae4a718-28b7-58ec-9efb-cded64d6d5b4" [targets] test = ["VegaDatasets", "Dates", "Test", "DataFrames"] diff --git a/src/VegaLite.jl b/src/VegaLite.jl index c9e8e28f..b6b9461c 100644 --- a/src/VegaLite.jl +++ b/src/VegaLite.jl @@ -10,7 +10,6 @@ using URIParser using FilePaths using REPL, Dates using Random -import JSONSchema using Setfield: Setfield, PropertyLens, @lens, @set # import Cairo, Rsvg using Pkg.Artifacts @@ -28,7 +27,9 @@ export deletedata, deletedata! const vegaliate_app_path = artifact"vegalite_app" const vegaliate_app_includes_canvas = ispath(joinpath(vegaliate_app_path, "node_modules", "canvas")) -global vlschema = JSONSchema.Schema(JSON.parsefile(joinpath(vegaliate_app_path, "schemas", "vega-lite-schema.json"))) +const vlschema = JSON.parsefile( + joinpath(vegaliate_app_path, "schemas", "vega-lite-schema.json") +) include("vlspec.jl") diff --git a/src/dsl_vlplot_function/dsl_vlplot_function.jl b/src/dsl_vlplot_function/dsl_vlplot_function.jl index cf2cae9c..4370cae0 100644 --- a/src/dsl_vlplot_function/dsl_vlplot_function.jl +++ b/src/dsl_vlplot_function/dsl_vlplot_function.jl @@ -66,7 +66,7 @@ function fix_shortcut_level_data(spec_frag::VLFrag) else if haskey(spec_frag.named, "url") spec = copy(spec_frag.named) - + if spec["url"] isa AbstractPath as_uri = string(URI(spec["url"])) spec["url"] = Sys.iswindows() ? as_uri[1:5] * as_uri[7:end] : as_uri @@ -74,7 +74,7 @@ function fix_shortcut_level_data(spec_frag::VLFrag) as_uri = string(spec["url"]) spec["url"] = Sys.iswindows() && spec["url"].scheme=="file" ? as_uri[1:5] * as_uri[7:end] : as_uri end - + return VLFrag([], spec) else return spec_frag @@ -116,7 +116,10 @@ function fix_shortcut_level_spec(spec_frag::VLFrag) end # Move top level channels into encoding - encodings_to_be_moved = filter(i->i!="facet", collect(keys(vlschema.data["definitions"]["FacetedEncoding"]["properties"]))) + 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") @@ -177,7 +180,7 @@ function fix_shortcut_level_spec(spec_frag::VLFrag) transform.named["from"].named["data"] = fix_shortcut_level_data(transform.named["from"].named["data"]) end end - end + end if haskey(spec, "data") if !isempty(inline_unnamed_data) @@ -219,7 +222,7 @@ function convert_frag_tree_to_dict(spec::VLFrag) spec_as_dict2 = Vega.walk_dict(spec_as_dict, "root") do p, parent if p[1]=="typ" Base.depwarn("`typ` in VegaLite.jl specs is deprecated, use `type` instead.", :vlplot) - + return "type"=>p[2] else return p diff --git a/src/dsl_vlplot_function/shorthandparser.jl b/src/dsl_vlplot_function/shorthandparser.jl index f658be8e..cfc3e5b3 100644 --- a/src/dsl_vlplot_function/shorthandparser.jl +++ b/src/dsl_vlplot_function/shorthandparser.jl @@ -36,27 +36,30 @@ function decode_typ(s::AbstractString) elseif s=="t" s="temporal" end - - if s in union(vlschema.data["definitions"]["StandardType"]["enum"], vlschema.data["definitions"]["TypeForShape"]["enum"]) - return "type"=>s - else - throw(ArgumentError("Invalid type.")) + for key in ("StandardType", "TypeForShape") + if s in vlschema["definitions"][key]["enum"] + return "type" => s + end end + throw(ArgumentError("Invalid type.")) end function decode_func(s::AbstractString) s = lowercase(s) - if s in vlschema.data["definitions"]["AggregateOp"]["enum"] - return "aggregate"=>s - elseif s in union( - vlschema.data["definitions"]["LocalMultiTimeUnit"]["enum"], - vlschema.data["definitions"]["LocalSingleTimeUnit"]["enum"], - vlschema.data["definitions"]["UtcMultiTimeUnit"]["enum"], - vlschema.data["definitions"]["UtcSingleTimeUnit"]["enum"]) - return "timeUnit"=>s - else - throw(ArgumentError("Unknown aggregation function or time unit '$s'.")) + if s in vlschema["definitions"]["AggregateOp"]["enum"] + return "aggregate" => s + end + for key in ( + "LocalMultiTimeUnit", + "LocalSingleTimeUnit", + "UtcMultiTimeUnit", + "UtcSingleTimeUnit", + ) + if s in vlschema["definitions"][key]["enum"] + return "timeUnit" => s + end end + throw(ArgumentError("Unknown aggregation function or time unit '$s'.")) end function parse_shortcut(s::AbstractString)