diff --git a/src/explorer/explore.jl b/src/explorer/explore.jl index 98b78a775..818481e38 100644 --- a/src/explorer/explore.jl +++ b/src/explorer/explore.jl @@ -112,6 +112,11 @@ function explore(sim_inst::SimulationInstance; title="Electron", model_index::In end +# Helper function returns true if VegaLite is verison 3 or above, and false otherwise +function _is_VegaLite_v3() + return isdefined(VegaLite, :vlplot) ? true : false +end + """ plot(m::Model, comp_name::Symbol, datum_name::Symbol; interactive::Bool = false) @@ -128,10 +133,8 @@ function plot(m::Model, comp_name::Symbol, datum_name::Symbol; interactive::Bool spec = Mimi._spec_for_item(m, comp_name, datum_name, interactive=interactive) spec === nothing ? error("Spec cannot be built.") : VLspec = spec["VLspec"] - return VegaLite.VLSpec{:plot}(VLspec) - + return _is_VegaLite_v3() ? VegaLite.VLSpec(VLspec) : VegaLite.VLSpec{:plot}(VLspec) end - """ plot(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbol; interactive::Bool = false, model_index::Int = 1, scen_name::Union{Nothing, String} = nothing, results_output_dir::Union{Nothing, String} = nothing) @@ -158,5 +161,6 @@ function plot(sim_inst::SimulationInstance, comp_name::Symbol, datum_name::Symbo spec = Mimi._spec_for_sim_item(sim_inst, comp_name, datum_name, results; interactive = interactive, model_index = model_index) spec === nothing ? error("Spec cannot be built.") : VLspec = spec["VLspec"] - return VegaLite.VLSpec{:plot}(VLspec) + return _is_VegaLite_v3() ? VegaLite.VLSpec(VLspec) : VegaLite.VLSpec{:plot}(VLspec) + end diff --git a/test/test_explorer_model.jl b/test/test_explorer_model.jl index fc06f1f20..a309632f4 100644 --- a/test/test_explorer_model.jl +++ b/test/test_explorer_model.jl @@ -7,6 +7,11 @@ using Electron import Mimi: dataframe_or_scalar, _spec_for_item, menu_item_list, getdataframe, dim_names +# Helper function returns true if VegaLite is verison 3 or above, and false otherwise +function _is_VegaLite_v3() + return isdefined(VegaLite, :vlplot) ? true : false +end + @defcomp MyComp begin a = Parameter(index=[time, regions]) b = Parameter(index=[time]) @@ -70,7 +75,8 @@ close(w) items = [:a, :b, :c, :d, :e, :f, :x] for item in items p = Mimi.plot(m, :MyComp, item) - @test typeof(p) == VegaLite.VLSpec{:plot} + p_type = _is_VegaLite_v3() ? VegaLite.VLSpec : VegaLite.VLSpec{:plot} + @test typeof(p) == p_type end #6. errors and warnings diff --git a/test/test_explorer_sim.jl b/test/test_explorer_sim.jl index f72055fce..ba74fd29d 100644 --- a/test/test_explorer_sim.jl +++ b/test/test_explorer_sim.jl @@ -73,48 +73,56 @@ close(w) ## 3. Plots +function plot_type_test(p) + if _is_VegaLite_v3() + @test typeof(p) == VegaLite.VLSpec + else + @test typeof(p) == VegaLite.VLSpec{:plot} + end +end + # trumpet plot p = Mimi.plot(si, :emissions, :E_Global) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si, :emissions, :E_Global; interactive = true) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :emissions, :E_Global, results_output_dir = results_output_dir) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :emissions, :E_Global; interactive = true, results_output_dir = results_output_dir) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) @test_throws ErrorException p = Mimi.plot(si_disk, :emissions, :E_Global) #should error, no in-memory results # mulitrumpet plot p = Mimi.plot(si, :emissions, :E) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si, :emissions, :E; interactive = true); -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :emissions, :E, results_output_dir = results_output_dir) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :emissions, :E; interactive = true, results_output_dir = results_output_dir); -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) # histogram plot p = Mimi.plot(si, :grosseconomy, :share_var) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si, :grosseconomy, :share_var; interactive = true); # currently just calls static version -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :grosseconomy, :share_var; results_output_dir = results_output_dir) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :grosseconomy, :share_var; interactive = true, results_output_dir = results_output_dir); # currently just calls static version -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) # multihistogram plot p = Mimi.plot(si, :grosseconomy, :depk_var) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si, :grosseconomy, :depk_var; interactive = true); -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :grosseconomy, :depk_var; results_output_dir = results_output_dir) -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p) p = Mimi.plot(si_disk, :grosseconomy, :depk_var; interactive = true, results_output_dir = results_output_dir); -@test typeof(p) == VegaLite.VLSpec{:plot} +plot_type_test(p)