diff --git a/src/SpacePhysicsMakie.jl b/src/SpacePhysicsMakie.jl index 65445ba..619d54c 100644 --- a/src/SpacePhysicsMakie.jl +++ b/src/SpacePhysicsMakie.jl @@ -11,7 +11,7 @@ import Makie: convert_arguments, plot!, conversion_trait, get_plots export tplot!, tplot, tplot_panel, tplot_panel! export LinesPlot, linesplot, linesplot! -export tlims!, tlines!, add_labels! +export tlims!, tlines!, tvspan!, add_labels! export axis_attributes, plot_attributes include("types.jl") diff --git a/src/attributes.jl b/src/attributes.jl index e57b045..4aed752 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -18,7 +18,10 @@ title(A) = mget(A, "CATDESC") dims(x, d) = 1:size(x, d) -yvalues(x) = parent(mget(x, "DEPEND_1", dims(x, 2))) +function yvalues(x) + d1 = mget(x, "DEPEND_1", nothing) + return parent(d1 isa AbstractArray ? d1 : dims(x, 2)) +end function yvalues(::Type{Vector}, x) vals = yvalues(x) return if isa(vals, AbstractMatrix) diff --git a/src/methods.jl b/src/methods.jl index 2b31cb5..efeeee9 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -26,11 +26,16 @@ tlims!(tmin, tmax) = tlims!(current_axis(), tmin, tmax) tlims!(trange) = tlims!(trange...) """Add vertical lines to a plot""" -tlines!(ax, time; kwargs...) = vlines!(ax, Dates.value.(DateTime.(time)); kwargs...) -tlines!(time; kwargs...) = tlines!(current_axis(), time; kwargs...) -tlines!(faxes::FigureAxes, time; kwargs...) = - foreach(faxes.axes) do ax - tlines!(ax, time; kwargs...) +tlines!(ax::Axis, time; kwargs...) = vlines!(ax, Dates.value.(DateTime.(time)); kwargs...) + +# Temporary solution for https://github.com/MakieOrg/Makie.jl/issues/4412 +tvspan!(ax::Axis, tmins, tmaxs; kwargs...) = vspan!(ax, Dates.value.(DateTime.(tmins)), Dates.value.(DateTime.(tmaxs)); kwargs...) + +for f in (:tlines!, :tvspan!) + @eval $f(args...; kwargs...) = $f(current_axis(), args...; kwargs...) + @eval $f(faxes::FigureAxes, args...; kwargs...) = foreach(faxes.axes) do ax + $f(ax, args...; kwargs...) + end end """ diff --git a/src/recipes/linesplot.jl b/src/recipes/linesplot.jl index 3fb717a..a8e1867 100644 --- a/src/recipes/linesplot.jl +++ b/src/recipes/linesplot.jl @@ -63,7 +63,7 @@ Plot a multivariate time series on a panel function linesplot(gp::Drawable, A; axis=(;), add_title=DEFAULTS.add_title, legend=(;), plot=(;), kwargs...) ax = Axis(gp; axis_attributes(A; add_title)..., axis...) plots = linesplot!(ax, A; plot..., kwargs...) - !isnothing(legend) && add_legend!(gp, ax, depend_1_name(A); legend...) + !isnothing(legend) && add_legend!(gp, ax; legend...) return Makie.AxisPlot(ax, plots) end diff --git a/src/spectrogram.jl b/src/spectrogram.jl index 624a68b..71a30a2 100644 --- a/src/spectrogram.jl +++ b/src/spectrogram.jl @@ -26,6 +26,12 @@ function heatmap_attributes(A; kwargs...) :colorscale => _scale_func(mget(A, "SCALETYP")), :colorrange => colorrange(A) ) + heatmap_keys = Makie.MakieCore.attribute_names(Heatmap) + for (k, v) in meta(A) + if k in heatmap_keys + attrs[k] = v + end + end return attrs end diff --git a/test/methods.jl b/test/methods.jl new file mode 100644 index 0000000..ecc664f --- /dev/null +++ b/test/methods.jl @@ -0,0 +1,32 @@ +@testitem "Methods" begin + # https://github.com/MakieOrg/Makie.jl/issues/4412 + + using CairoMakie + using Dates + + # Test plotting into Float64 axis + f = Figure() + ax1 = Axis(f[1, 1]) + xs = [DateTime(2020, 1, 1), DateTime(2020, 1, 2), DateTime(2020, 1, 3)] + @test_throws "MethodError: Cannot `convert` an object of type DateTime to an object of type Float64" vlines!(ax1, xs) + ax2 = Axis(f[2, 1]) + @test_nowarn tlines!(ax2, xs) + + # vspan! + x1 = [DateTime(2020, 1, 1), DateTime(2020, 1, 5), DateTime(2020, 1, 11)] + x2 = [DateTime(2020, 1, 2), DateTime(2020, 1, 7), DateTime(2020, 1, 12)] + @test_throws "MethodError: Cannot `convert` an object of type DateTime to an object of type Float64" vspan!(ax1, x1, x2) + @test_nowarn tvspan!(ax2, x1, x2) + + # Test plotting into DateTime axis + xs = [DateTime(2020, 1, 1), DateTime(2020, 1, 2), DateTime(2020, 1, 3)] + f = scatter(xs, 1:3) + @test_throws "MethodError: Cannot `convert` an object of type DateTime to an object of type Float64" vlines!(xs) + @test_nowarn tlines!(xs) + + # vspan! + x1 = [DateTime(2020, 1, 1), DateTime(2020, 1, 5), DateTime(2020, 1, 11)] + x2 = [DateTime(2020, 1, 2), DateTime(2020, 1, 7), DateTime(2020, 1, 12)] + @test_throws "ArgumentError: Cannot change dim conversion for dimension 2, since it already is set to a conversion: Makie.NoDimConversion()." vspan!(x1, x2) + @test_throws "Plotting unit Int64 into axis with type DateTime not supported." tvspan!(x1, x2) +end