Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SpacePhysicsMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions src/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
2 changes: 1 addition & 1 deletion src/recipes/linesplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/spectrogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions test/methods.jl
Original file line number Diff line number Diff line change
@@ -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
Loading