-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conditionally require
FreeType
, FileIO
, Unitful
and `ImageInTer…
…minal` through weak deps or `Requires` (#332) * weak deps * make FileIO weak * consistency * update * add `UnitfulExt` * rework `import / using` when using weak exts * rework docs * change to minor bump * add compat `save_image` for Plots * change notes
- Loading branch information
Showing
19 changed files
with
328 additions
and
185 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
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,26 @@ | ||
module ImageInTerminalExt | ||
|
||
import UnicodePlots | ||
UnicodePlots.@ext_imp_use :import ImageInTerminal | ||
using ColorTypes | ||
|
||
UnicodePlots.sixel_encode(args...; kw...) = ImageInTerminal.sixel_encode(args...; kw...) # COV_EXCL_LINE | ||
UnicodePlots.imshow(args...; kw...) = ImageInTerminal.imshow(args...; kw...) | ||
|
||
function UnicodePlots.terminal_specs(img) | ||
char_h = char_w = nothing | ||
# COV_EXCL_START | ||
if ImageInTerminal.choose_sixel(img) | ||
ans = ImageInTerminal.Sixel.TerminalTools.query_terminal("\e[16t", stdout) | ||
if ans isa String && (m = match(r"\e\[6;(\d+);(\d+)t", ans)) ≢ nothing | ||
char_h, char_w = tryparse.(Int, m.captures) | ||
end | ||
end | ||
# COV_EXCL_STOP | ||
char_h ≢ nothing && char_w ≢ nothing, char_h, char_w | ||
end | ||
|
||
UnicodePlots.imageplot(img::AbstractArray{<:Colorant}; kw...) = | ||
UnicodePlots.Plot(UnicodePlots.ImageGraphics(img); border = :corners, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module UnitfulExt | ||
|
||
import UnicodePlots | ||
import UnicodePlots: KEYWORDS, Plot, Canvas | ||
UnicodePlots.@ext_imp_use :import Unitful Quantity RealOrRealQuantity ustrip unit | ||
|
||
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
Oops, something went wrong.