Skip to content

Commit

Permalink
Merge pull request #352 from odow/od/remove_json_schema
Browse files Browse the repository at this point in the history
Remove JSONSchema as a dependency in favor of pure JSON.jl
  • Loading branch information
davidanthoff authored Jan 22, 2021
2 parents ee8b675 + 72c2390 commit a1454d8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FilePaths = "8fc22ac5-c921-52a6-82fd-178b2807b824"
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -30,7 +29,6 @@ FileIO = "1.0.1"
FilePaths = "0.7, 0.8"
IteratorInterfaceExtensions = "0.1.1, 1"
JSON = "0.19, 0.20, 0.21"
JSONSchema = "0.1, 0.2"
MacroTools = "0.4.4, 0.5"
NodeJS = "0.5.1, 0.6, 1"
Setfield = "0.4, 0.5, 0.6"
Expand Down
5 changes: 3 additions & 2 deletions src/VegaLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down
13 changes: 8 additions & 5 deletions src/dsl_vlplot_function/dsl_vlplot_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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
elseif spec["url"] isa URI
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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 18 additions & 15 deletions src/dsl_vlplot_function/shorthandparser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a1454d8

Please sign in to comment.