-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
140 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module UnitfulExt | ||
|
||
import UnicodePlots | ||
import UnicodePlots: KEYWORDS, Plot, Canvas | ||
@static if isdefined(Base, :get_extension) | ||
import Unitful: Quantity, RealOrRealQuantity, ustrip, unit | ||
else | ||
import ..Unitful: Quantity, RealOrRealQuantity, ustrip, unit | ||
end | ||
|
||
function unit_str(x, fancy) | ||
io = IOContext(PipeBuffer(), :fancy_exponent => fancy) | ||
show(io, unit(x)) | ||
read(io, String) | ||
end | ||
|
||
unit_label(label::AbstractString, unit::AbstractString) = | ||
(lab_strip = rstrip(label)) |> isempty ? unit : "$lab_strip ($unit)" | ||
unit_label(label::AbstractString, unit::Nothing) = rstrip(label) | ||
|
||
number_unit(x::Union{AbstractVector,Number}, args...) = x, nothing | ||
number_unit(x::AbstractVector{<:Quantity}, fancy = true) = | ||
ustrip.(x), unit_str(first(x), fancy) | ||
number_unit(x::Quantity, fancy = true) = ustrip(x), unit_str(x, fancy) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# lineplot | ||
function UnicodePlots.lineplot( | ||
x::AbstractVector{<:RealOrRealQuantity}, | ||
y::AbstractVector{<:Quantity}; | ||
unicode_exponent::Bool = KEYWORDS.unicode_exponent, | ||
xlabel = KEYWORDS.xlabel, | ||
ylabel = KEYWORDS.ylabel, | ||
kw..., | ||
) | ||
x, ux = number_unit(x, unicode_exponent) | ||
y, uy = number_unit(y, unicode_exponent) | ||
UnicodePlots.lineplot( | ||
ustrip.(x), | ||
ustrip.(y); | ||
xlabel = unit_label(xlabel, ux), | ||
ylabel = unit_label(ylabel, uy), | ||
unicode_exponent, | ||
kw..., | ||
) | ||
end | ||
|
||
UnicodePlots.lineplot!( | ||
plot::Plot{<:Canvas}, | ||
x::AbstractVector{<:RealOrRealQuantity}, | ||
y::AbstractVector{<:Quantity}; | ||
kw..., | ||
) = UnicodePlots.lineplot!(plot, ustrip.(x), ustrip.(y); kw...) | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# scatterplot | ||
function UnicodePlots.scatterplot( | ||
x::AbstractVector{<:RealOrRealQuantity}, | ||
y::AbstractVector{<:Quantity}; | ||
unicode_exponent::Bool = KEYWORDS.unicode_exponent, | ||
xlabel = KEYWORDS.xlabel, | ||
ylabel = KEYWORDS.ylabel, | ||
kw..., | ||
) | ||
x, ux = number_unit(x, unicode_exponent) | ||
y, uy = number_unit(y, unicode_exponent) | ||
UnicodePlots.scatterplot( | ||
ustrip.(x), | ||
ustrip.(y); | ||
xlabel = unit_label(xlabel, ux), | ||
ylabel = unit_label(ylabel, uy), | ||
unicode_exponent, | ||
kw..., | ||
) | ||
end | ||
|
||
UnicodePlots.scatterplot!( | ||
plot::Plot{<:Canvas}, | ||
x::AbstractVector{<:RealOrRealQuantity}, | ||
y::AbstractVector{<:Quantity}; | ||
kw..., | ||
) = UnicodePlots.scatterplot!(plot, ustrip.(x), ustrip.(y); kw...) | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
@testset "Aqua" begin | ||
# JuliaTesting/Aqua.jl/issues/77 | ||
Aqua.test_all(UnicodePlots; ambiguities = false, project_toml_formatting = false) | ||
Aqua.test_all( | ||
UnicodePlots; | ||
ambiguities = false, | ||
project_toml_formatting = false, # issues since weak deps | ||
stale_deps = !isdefined(Base, :get_extension), # issue with `Requires` not used when weak deps are enabled | ||
) | ||
Aqua.test_ambiguities(UnicodePlots) | ||
end |