Skip to content

Commit

Permalink
Minor fixes (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg authored Feb 3, 2022
1 parent d0b1d85 commit fecf19a
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ The method `label!` is responsible for the setting all the textual decorations o
![Decorate](https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/doc/imgs/2.x/decorate.png)


* `annotate!(plot::Plot, x::Number, y::Number, text::AbstractString; kwargs...)`
* `annotate!(plot::Plot, x::Number, y::Number, text::AbstractString; kw...)`

* `text` arbitrary annotation at position (x, y)

Expand Down
2 changes: 1 addition & 1 deletion docs/generate_docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ The method `label!` is responsible for the setting all the textual decorations o
- `row` can be between 1 and the number of character rows of the canvas
$(MD(Paragraph(indent(examples.decorate, 2))))
- `annotate!(plot::Plot, x::Number, y::Number, text::AbstractString; kwargs...)`
- `annotate!(plot::Plot, x::Number, y::Number, text::AbstractString; kw...)`
- `text` arbitrary annotation at position (x, y)
## Know Issues
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/asciicanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ end
@inline lookup_encode(::AsciiCanvas) = ascii_signs
@inline lookup_decode(::AsciiCanvas) = ascii_decode

AsciiCanvas(args...; kwargs...) =
CreateLookupCanvas(AsciiCanvas, (0b000_000_000, 0b111_111_111), args...; kwargs...)
AsciiCanvas(args...; kw...) =
CreateLookupCanvas(AsciiCanvas, (0b000_000_000, 0b111_111_111), args...; kw...)

function char_point!(
c::AsciiCanvas,
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/blockcanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ end
@inline lookup_encode(::BlockCanvas) = block_signs
@inline lookup_decode(::BlockCanvas) = block_decode

BlockCanvas(args...; kwargs...) =
CreateLookupCanvas(BlockCanvas, (0b0000, 0b1111), args...; kwargs...)
BlockCanvas(args...; kw...) =
CreateLookupCanvas(BlockCanvas, (0b0000, 0b1111), args...; kw...)

function char_point!(
c::BlockCanvas,
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/dotcanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ end
@inline lookup_encode(::DotCanvas) = dot_signs
@inline lookup_decode(::DotCanvas) = dot_decode

DotCanvas(args...; kwargs...) =
CreateLookupCanvas(DotCanvas, (0b00, 0b11), args...; kwargs...)
DotCanvas(args...; kw...) = CreateLookupCanvas(DotCanvas, (0b00, 0b11), args...; kw...)

function char_point!(
c::DotCanvas,
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/heatmapcanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ const HALF_BLOCK = '▄'

@inline nrows(c::HeatmapCanvas) = div(size(grid(c), 2) + 1, 2)

HeatmapCanvas(args...; kwargs...) = CreateLookupCanvas(
HeatmapCanvas(args...; kw...) = CreateLookupCanvas(
HeatmapCanvas,
(0, 1),
args...;
min_char_width = 1,
min_char_height = 1,
kwargs...,
kw...,
)

_toCrayon(c) = c === nothing ? 0 : (c isa Unsigned ? Int(c) : c)
Expand Down
17 changes: 16 additions & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const ASPECT_RATIO = 4 / 3

# default display size for the default BrailleCanvas (which has aspect ratio = 2) ==> (40, 15)
const DEFAULT_HEIGHT = Ref(15)
const DEFAULT_WIDTH = Ref(2round(Int, ASPECT_RATIO * DEFAULT_HEIGHT[]))
const DEFAULT_WIDTH = Ref(round(Int, DEFAULT_HEIGHT[] * 2ASPECT_RATIO))

const MarkerType = Union{Symbol,Char,AbstractString}
const UserColorType = Union{Integer,Symbol,NTuple{3,Integer},Nothing} # allowed color type
Expand All @@ -167,6 +167,21 @@ const BASES = (identity = nothing, ln = "ℯ", log2 = "2", log10 = "10")

#! format: on

function default_size!(;
width::Union{Integer,Nothing} = nothing,
height::Union{Integer,Nothing} = nothing,
)
@assert (width === nothing) (height === nothing)
if width !== nothing
DEFAULT_WIDTH[] = width
DEFAULT_HEIGHT[] = round(Int, width / 2ASPECT_RATIO)
elseif height !== nothing
DEFAULT_HEIGHT[] = height
DEFAULT_WIDTH[] = round(Int, height * 2ASPECT_RATIO)
end
return
end

function char_marker(marker::MarkerType)::Char
if marker isa Symbol
get(MARKERS, marker, MARKERS[:circle])
Expand Down
12 changes: 6 additions & 6 deletions src/description.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const DESCRIPTION = (
const Z_DESCRIPTION =
(:zlabel, :zlim, :colorbar, :colormap, :colorbar_lim, :colorbar_border)

const DEFAULT_KWARGS = (
const DEFAULT_KW = (
# does not have to stay ordered
:name,
:title,
Expand Down Expand Up @@ -110,7 +110,7 @@ default_with_type(s::Symbol) = (
)

"""
keywords([extra]; default = DEFAULT_KWARGS, add = (), exclude = DEFAULT_EXCLUDED, remove = ())
keywords([extra]; default = DEFAULT_KW, add = (), exclude = DEFAULT_EXCLUDED, remove = ())
Adds default keywords to a function signature, in a docstring.
Expand All @@ -123,20 +123,20 @@ Adds default keywords to a function signature, in a docstring.
"""
function keywords(
extra::NamedTuple = NamedTuple();
default::Tuple = DEFAULT_KWARGS,
default::Tuple = DEFAULT_KW,
add::Tuple = (),
exclude::Tuple = DEFAULT_EXCLUDED,
remove::Tuple = (),
)
all_kw = (; KEYWORDS..., extra...)
candidates = keys(extra) filter(x -> x add default, DEFAULT_KWARGS)
candidates = keys(extra) filter(x -> x add default, DEFAULT_KW)
kw = filter(x -> x setdiff(exclude remove, add), candidates)
@assert allunique(kw) # extra check
join((k isa Symbol ? "$k = $(all_kw[k] |> repr)" : k for k in kw), ", ")
end

"""
arguments([desc]; default = DEFAULT_KWARGS, add = (), exclude = DEFAULT_EXCLUDED, remove = ())
arguments([desc]; default = DEFAULT_KW, add = (), exclude = DEFAULT_EXCLUDED, remove = ())
Defines arguments for docstring genreration.
Expand All @@ -149,7 +149,7 @@ Defines arguments for docstring genreration.
"""
function arguments(
desc::NamedTuple = NamedTuple();
default::Tuple = DEFAULT_KWARGS,
default::Tuple = DEFAULT_KW,
add::Tuple = (),
exclude::Tuple = DEFAULT_EXCLUDED,
remove::Tuple = (),
Expand Down
4 changes: 2 additions & 2 deletions src/interface/barplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
barplot(text, heights; kwargs...)
barplot(text, heights; kw...)
# Description
Expand All @@ -15,7 +15,7 @@ as the heights of the bars.
barplot(text, heights; $(keywords((border = :barplot, color = :green,), remove = (:xlim, :ylim, :xscale, :yscale, :height, :grid), add = (:symbols,))))
barplot(dict; kwargs...)
barplot(dict; kw...)
# Arguments
Expand Down
6 changes: 3 additions & 3 deletions src/interface/boxplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
boxplot(data; kwargs...)
boxplot(data; kw...)
# Description
Expand All @@ -20,7 +20,7 @@ used as the labels.
boxplot([text], data; $(keywords((border = :corners, color = :green,), remove = (:ylim, :height, :grid)))
boxplot(dict; kwargs...)
boxplot(dict; kw...)
# Arguments
Expand Down Expand Up @@ -102,7 +102,7 @@ function boxplot(
end

"""
boxplot!(plot, data; kwargs...)
boxplot!(plot, data; kw...)
Mutating variant of `boxplot`, in which the first parameter (`plot`) specifies the existing plot to draw on.
Expand Down
8 changes: 4 additions & 4 deletions src/interface/contourplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
contourplot(x, y, A; kwargs...)
contourplot(x, y, A; kw...)
Draws a contour plot on a new canvas.
Expand Down Expand Up @@ -102,7 +102,7 @@ function contourplot!(
end

"""
contourplot(A; kwargs...)
contourplot(A; kw...)
Draws a contour plot of matrix `A` along axis `x` and `y` on a new canvas.
Expand All @@ -120,5 +120,5 @@ axes(A, 1) │ │ y │
│ x
```
"""
contourplot(A::AbstractMatrix; kwargs...) =
contourplot(axes(A, 2) |> collect, axes(A, 1) |> reverse |> collect, A; kwargs...)
contourplot(A::AbstractMatrix; kw...) =
contourplot(axes(A, 2) |> collect, axes(A, 1) |> reverse |> collect, A; kw...)
2 changes: 1 addition & 1 deletion src/interface/densityplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
densityplot(x, y; kwargs...)
densityplot(x, y; kw...)
# Description
Expand Down
2 changes: 1 addition & 1 deletion src/interface/heatmap.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
heatmap(A; kwargs...)
heatmap(A; kw...)
# Description
Expand Down
4 changes: 2 additions & 2 deletions src/interface/histogram.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
histogram(data; kwargs...)
histogram(data; kw...)
# Description
Expand All @@ -12,7 +12,7 @@ Note internally that `histogram` is a simply wrapper for
# Usage
histogram(x; nbins, closed = :left, kwargs...)
histogram(x; nbins, closed = :left, kw...)
histogram(hist; $(keywords((border = :barplot, color = :green,), remove = (:ylim, :yscale, :height, :grid), add = (:symbols,)))
Expand Down
4 changes: 2 additions & 2 deletions src/interface/lineplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
lineplot(x, y; kwargs...)
lineplot(x, y; kw...)
# Description
Expand All @@ -13,7 +13,7 @@ This means that the two vectors must be of the same length and ordering.
lineplot([x], y; $(keywords(; add = (:canvas,)))
lineplot(fun, [start], [stop]; kwargs...)
lineplot(fun, [start], [stop]; kw...)
# Arguments
Expand Down
2 changes: 1 addition & 1 deletion src/interface/scatterplot.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
scatterplot(x, y; kwargs...)
scatterplot(x, y; kw...)
# Description
Expand Down
8 changes: 4 additions & 4 deletions src/interface/spy.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
spy(A; kwargs...)
spy(A; kw...)
# Description
Expand Down Expand Up @@ -69,17 +69,17 @@ julia> spy(sprandn(50, 120, .05))
[`BrailleCanvas`](@ref), [`BlockCanvas`](@ref),
[`AsciiCanvas`](@ref), [`DotCanvas`](@ref)
"""
function spy(A::AbstractMatrix; kwargs...)
function spy(A::AbstractMatrix; kw...)
rows, cols, vals = _strict_non_zeros(_findnz(A)...)
if get(kwargs, :show_zeros, false)
if get(kw, :show_zeros, false)
I = CartesianIndex.(zip(rows, cols)) # non zeros
mask = trues(size(A))
mask[I] .= false
Z = CartesianIndices(axes(A))[mask] # zeros
rows, cols = getindex.(Z, 1), getindex.(Z, 2)
vals = zeros(eltype(vals), length(rows))
end
spy(size(A)..., rows, cols, vals; kwargs...)
spy(size(A)..., rows, cols, vals; kw...)
end

function _strict_non_zeros(rows, cols, vals)
Expand Down
2 changes: 1 addition & 1 deletion src/interface/stairs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
stairs(x, y; kwargs...)
stairs(x, y; kw...)
# Description
Expand Down
Loading

0 comments on commit fecf19a

Please sign in to comment.