Skip to content

Commit

Permalink
fix keyword args prop - docsstring - warns (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg authored Jun 25, 2022
1 parent 02340e7 commit c6734a4
Show file tree
Hide file tree
Showing 58 changed files with 667 additions and 634 deletions.
1 change: 0 additions & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ align_conditional = true
align_assignment = true
align_pair_arrow = true
import_to_using = false
always_for_in = true
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FileIO = "1"
FreeTypeAbstraction = "0.9"
LazyModules = "0.3"
MarchingCubes = "0.1"
NaNMath = "1"
NaNMath = "0.3, 1"
StaticArrays = "1"
StatsBase = "0.33"
Unitful = "1"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ The method `label!` is responsible for the setting all the textual decorations o
- `up::Symbol = :z`: up vector (`:x`, `:y` or `:z`), prefix with `m -> -` or `p -> +` to change the sign e.g. `:mz` for `-z` axis pointing upwards.
- `near::Float = 1.0`: distance to the near clipping plane (`:perspective` projection only).
- `far::Float = 100.0`: distance to the far clipping plane (`:perspective` projection only).
- `canvas_kw::NamedTuple = NamedTuple()`: extra canvas keywords.
- `blend::Bool = true`: blend colors on the underlying canvas.
- `fix_ar::Bool = false`: fix terminal aspect ratio (experimental).
- `visible::Bool = true`: visible canvas.
Expand Down
15 changes: 7 additions & 8 deletions docs/gen_docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ main() = begin

plain_md_par(x) = x |> Paragraph |> MD |> plain

tab = ' '^2
indent(x, n=1) = tab^n * join(x isa AbstractVector ? x : split(x, '\n'), '\n' * tab^n)
indent(x, n=1, tab=' '^2) = tab^n * join(x isa AbstractVector ? x : split(x, '\n'), '\n' * tab^n)

examples = NamedTuple{keys(exs)}(
(plain_md_par("```julia\n$(rstrip(e[2]))\n```\n<img src=\"$docs_url/$ver/$k.png\" width=\"450\"><br>") for (k, e) in pairs(exs))
(plain_md_par("```julia\n$(rstrip(e[2]))\n```\n<img src=\"$docs_url/$ver/$k.png\" width=\"450\"><br>") for (k, e) pairs(exs))
)

desc_ex(k, d, n=2) = (
Expand All @@ -171,7 +170,7 @@ main() = begin
indent(examples.border_dotted, n),
indent(examples.border_none, n),
), '\n')
elseif k in (:width, :height, :labels)
elseif k (:width, :height, :labels)
join((d, indent(getindex(examples, k), n)), '\n')
else
d
Expand Down Expand Up @@ -253,7 +252,7 @@ The following types of `Canvas` are implemented:
$(join(
(
"- `$(UnicodePlots.default_with_type(k))`: $(desc_ex(k, d * '.'))"
for (k, d) in pairs(UnicodePlots.DESCRIPTION) if k in keys(UnicodePlots.KEYWORDS)
for (k, d) pairs(UnicodePlots.DESCRIPTION) if k keys(UnicodePlots.KEYWORDS)
), '\n'
))
Expand Down Expand Up @@ -640,7 +639,7 @@ Inspired by [TextPlots.jl](https://github.com/sunetos/TextPlots.jl), which in tu
cursor_hide(stdout)
run(`clear`)
print(stdout, g)
win = if "WINDOWID" in keys(ENV)
win = if "WINDOWID" keys(ENV)
ENV["WINDOWID"]
else
readchomp(`xdotool getactivewindow`)
Expand Down Expand Up @@ -683,9 +682,9 @@ Inspired by [TextPlots.jl](https://github.com/sunetos/TextPlots.jl), which in tu
banner()
"""
)
for (i, (k, e)) in enumerate(pairs(exs))
for (i, (k, e)) enumerate(pairs(exs))
println(io, " # $k")
code = fix_rand.(filter(x -> length(x) != 0 && !startswith(lstrip(x), r"using|import"), [lstrip(c) for c in split(e[2], '\n')]))
code = fix_rand.(filter(x -> length(x) != 0 && !startswith(lstrip(x), r"using|import"), [lstrip(c) for c split(e[2], '\n')]))
println(io, """
println("ex n°$i - $k")
default_size!()
Expand Down
5 changes: 0 additions & 5 deletions src/UnicodePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ include("canvas/blockcanvas.jl")
include("canvas/asciicanvas.jl")
include("canvas/dotcanvas.jl")
include("canvas/heatmapcanvas.jl")
@assert typemax(UnicodeType) maximum(
(
typemax grid_type
).((HeatmapCanvas, BlockCanvas, AsciiCanvas, DotCanvas, BrailleCanvas)),
)

include("description.jl")
include("volume.jl")
Expand Down
46 changes: 23 additions & 23 deletions src/canvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ grid_type(c::Canvas) = grid_type(typeof(c))

function char_point!(
c::Canvas,
char_x::Int,
char_y::Int,
char_x::Integer,
char_y::Integer,
char::AbstractChar,
color::UserColorType,
)
Expand All @@ -53,12 +53,12 @@ end

@inline function set_color!(
c::Canvas,
x::Int,
y::Int,
x::Integer,
y::Integer,
color::ColorType,
blend::Bool = c.blend,
)
c.colors[y, x] = if (col = c.colors[y, x]) == INVALID_COLOR || !blend
c.colors[y, x] = if (col = c.colors[y, x]) INVALID_COLOR || !blend
color
else
blend_colors(col, color)
Expand Down Expand Up @@ -87,7 +87,7 @@ points!(c::Canvas, x::Number, y::Number, color::UserColorType) =
function points!(c::Canvas, X::AbstractVector, Y::AbstractVector, color::UserColorType)
length(X) == length(Y) ||
throw(DimensionMismatch("`X` and `Y` must be the same length"))
for I in eachindex(X, Y)
for I eachindex(X, Y)
points!(c, X[I], Y[I], color)
end
c
Expand All @@ -101,7 +101,7 @@ function points!(
) where {T<:UserColorType}
length(X) == length(Y) == length(color) ||
throw(DimensionMismatch("`X`, `Y` and `color` must be the same length"))
for i in eachindex(X)
for i eachindex(X)
points!(c, X[i], Y[i], color[i])
end
c
Expand Down Expand Up @@ -142,7 +142,7 @@ function lines!(
pixel!(c, floor(Int, cur_x), floor(Int, cur_y), col_cb(c_or_v1))
start_x, start_y = cur_x, cur_y
= 1 / (Δx^2 + Δy^2)
for _ in range(1, length = len)
for _ range(1, length = len)
cur_x += δx
cur_y += δy
(cur_y < py || cur_y > Py) && continue
Expand All @@ -157,7 +157,7 @@ function lines!(
end
else
pixel!(c, floor(Int, cur_x), floor(Int, cur_y), c_or_v1)
for _ in range(1, length = len)
for _ range(1, length = len)
cur_x += δx
cur_y += δy
(cur_y < py || cur_y > Py) && continue
Expand All @@ -180,7 +180,7 @@ lines!(
function lines!(c::Canvas, X::AbstractVector, Y::AbstractVector, color::UserColorType)
length(X) == length(Y) ||
throw(DimensionMismatch("`X` and `Y` must be the same length"))
for i in 2:length(X)
for i 2:length(X)
isfinite(X[i - 1]) || continue
isfinite(Y[i - 1]) || continue
isfinite(X[i]) || continue
Expand All @@ -195,14 +195,14 @@ lines!(c::Canvas, X::AbstractVector, Y::AbstractVector; color::UserColorType = :

function get_canvas_dimensions_for_matrix(
canvas::Type{T},
nrow::Int,
ncol::Int,
max_height::Int,
max_width::Int,
height::Union{Nothing,Int},
width::Union{Nothing,Int},
margin::Int,
padding::Int,
nrow::Integer,
ncol::Integer,
max_height::Integer,
max_width::Integer,
height::Union{Nothing,Integer},
width::Union{Nothing,Integer},
margin::Integer,
padding::Integer,
out_stream::Union{Nothing,IO},
fix_ar::Bool;
extra_rows = 0,
Expand Down Expand Up @@ -272,7 +272,7 @@ function align_char_point(
valign::Symbol,
)
nchar = length(text)
char_x = if halign in (:center, :hcenter)
char_x = if halign (:center, :hcenter)
char_x - nchar ÷ 2
elseif halign :left
char_x
Expand All @@ -281,7 +281,7 @@ function align_char_point(
else
throw(ArgumentError("`halign=$halign` not supported"))
end
char_y = if valign in (:center, :vcenter)
char_y = if valign (:center, :vcenter)
char_y
elseif valign :top
char_y + 1
Expand Down Expand Up @@ -320,15 +320,15 @@ function annotate!(
y::Number,
text::AbstractString,
color::UserColorType;
halign = :center,
valign = :center,
halign::Symbol = :center,
valign::Symbol = :center,
)
valid_x(c, x) || return c
valid_y(c, y) || return c

char_x, char_y = pixel_to_char_point(c, scale_x_to_pixel(c, x), scale_y_to_pixel(c, y))
char_x, char_y = align_char_point(text, char_x, char_y, halign, valign)
for char in text
for char text
char_point!(c, char_x, char_y, char, color)
char_x += 1
end
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/asciicanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ ASCII_LOOKUP[0b110_011_110] = '}'

const ASCII_DECODE = Vector{Char}(undef, typemax(N_ASCII))
ASCII_DECODE[1] = ' '
for i in 2:N_ASCII
for i 2:N_ASCII
min_dist = typemax(Int)
min_char = ' '
for (k, v) in sort_by_keys(ASCII_LOOKUP)
for (k, v) sort_by_keys(ASCII_LOOKUP)
if (cur_dist = count_ones(xor(typeof(N_ASCII)(i - 1), k))) < min_dist
min_dist = cur_dist
min_char = v
Expand Down
18 changes: 9 additions & 9 deletions src/canvas/braillecanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ end
@inline x_pixel_per_char(::Type{<:BrailleCanvas}) = 2

function BrailleCanvas(
char_height::Int,
char_width::Int;
blend::Bool = true,
visible::Bool = true,
char_height::Integer,
char_width::Integer;
blend::Bool = KEYWORDS.blend,
visible::Bool = KEYWORDS.visible,
origin_y::Number = 0.0,
origin_x::Number = 0.0,
height::Number = 1.0,
width::Number = 1.0,
yflip::Bool = false,
xflip::Bool = false,
yflip::Bool = KEYWORDS.xflip,
xflip::Bool = KEYWORDS.yflip,
yscale::Union{Symbol,Function} = :identity,
xscale::Union{Symbol,Function} = :identity,
)
Expand Down Expand Up @@ -73,7 +73,7 @@ function BrailleCanvas(
)
end

function pixel!(c::BrailleCanvas, pixel_x::Int, pixel_y::Int, color::UserColorType)
function pixel!(c::BrailleCanvas, pixel_x::Integer, pixel_y::Integer, color::UserColorType)
valid_x_pixel(c, pixel_x) || return c
valid_y_pixel(c, pixel_y) || return c
char_x, char_y, char_x_off, char_y_off = pixel_to_char_point_off(c, pixel_x, pixel_y)
Expand All @@ -86,9 +86,9 @@ function pixel!(c::BrailleCanvas, pixel_x::Int, pixel_y::Int, color::UserColorTy
c
end

function print_row(io::IO, _, print_color, c::BrailleCanvas, row::Int)
function print_row(io::IO, _, print_color, c::BrailleCanvas, row::Integer)
0 < row nrows(c) || throw(ArgumentError("`row` out of bounds: $row"))
for col in 1:ncols(c)
for col 1:ncols(c)
print_color(io, c.colors[row, col], Char(c.grid[row, col]))
end
nothing
Expand Down
22 changes: 11 additions & 11 deletions src/canvas/densitycanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ end
@inline x_pixel_per_char(::Type{<:DensityCanvas}) = 1

function DensityCanvas(
char_height::Int,
char_width::Int;
blend::Bool = true,
visible::Bool = true,
char_height::Integer,
char_width::Integer;
blend::Bool = KEYWORDS.blend,
visible::Bool = KEYWORDS.visible,
origin_y::Number = 0.0,
origin_x::Number = 0.0,
height::Number = 1.0,
width::Number = 1.0,
yflip::Bool = false,
xflip::Bool = false,
yscale::Union{Symbol,Function} = :identity,
xscale::Union{Symbol,Function} = :identity,
yflip::Bool = KEYWORDS.yflip,
xflip::Bool = KEYWORDS.xflip,
yscale::Union{Symbol,Function} = KEYWORDS.yscale,
xscale::Union{Symbol,Function} = KEYWORDS.xscale,
dscale::Union{Symbol,Function} = :identity,
)
height > 0 || throw(ArgumentError("`height` has to be positive"))
Expand Down Expand Up @@ -70,7 +70,7 @@ function DensityCanvas(
)
end

function pixel!(c::DensityCanvas, pixel_x::Int, pixel_y::Int, color::UserColorType)
function pixel!(c::DensityCanvas, pixel_x::Integer, pixel_y::Integer, color::UserColorType)
valid_x_pixel(c, pixel_x) || return c
valid_y_pixel(c, pixel_y) || return c
char_x, char_y = pixel_to_char_point(c, pixel_x, pixel_y)
Expand All @@ -86,11 +86,11 @@ function preprocess!(c::DensityCanvas)
c -> c.max_density[] = -Inf
end

function print_row(io::IO, _, print_color, c::DensityCanvas, row::Int)
function print_row(io::IO, _, print_color, c::DensityCanvas, row::Integer)
0 < row nrows(c) || throw(ArgumentError("`row` out of bounds: $row"))
signs = DEN_SIGNS[]
fact = (length(signs) - 1) / c.max_density[]
for col in 1:ncols(c)
for col 1:ncols(c)
val = fact * c.dscale(c.grid[row, col])
print_color(io, c.colors[row, col], signs[round(Int, val, RoundNearestTiesUp) + 1])
end
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/heatmapcanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function HeatmapCanvas(args...; kw...)
c
end

function print_row(io::IO, _, print_color, c::HeatmapCanvas, row::Int)
function print_row(io::IO, _, print_color, c::HeatmapCanvas, row::Integer)
0 < row nrows(c) || throw(ArgumentError("`row` out of bounds: $row"))
row *= y_pixel_per_char(HeatmapCanvas)

# extend the plot upwards by half a row
isodd(size(c.grid, 1)) && (row -= 1)

for col in 1:ncols(c)
for col 1:ncols(c)
# for odd numbers of rows, only print the foreground for the top row
bgcol = row > 1 ? c.colors[row - 1, col] : missing
print_color(io, c.colors[row, col], HALF_BLOCK; bgcol = bgcol)
Expand Down
31 changes: 13 additions & 18 deletions src/canvas/lookupcanvas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ abstract type LookupCanvas <: Canvas end
function CreateLookupCanvas(
::Type{T},
min_max,
char_height::Int,
char_width::Int;
blend::Bool = true,
visible::Bool = true,
char_height::Integer,
char_width::Integer;
blend::Bool = KEYWORDS.blend,
visible::Bool = KEYWORDS.visible,
origin_y::Number = 0.0,
origin_x::Number = 0.0,
height::Number = 1.0,
width::Number = 1.0,
yflip::Bool = false,
xflip::Bool = false,
yscale::Union{Symbol,Function} = :identity,
xscale::Union{Symbol,Function} = :identity,
min_char_height::Int = 5,
min_char_width::Int = 2,
yflip::Bool = KEYWORDS.yflip,
xflip::Bool = KEYWORDS.xflip,
yscale::Union{Symbol,Function} = KEYWORDS.yscale,
xscale::Union{Symbol,Function} = KEYWORDS.xscale,
min_char_height::Integer = 5,
min_char_width::Integer = 2,
) where {T<:LookupCanvas}
height > 0 || throw(ArgumentError("`height` has to be positive"))
width > 0 || throw(ArgumentError("`width` has to be positive"))
Expand Down Expand Up @@ -45,12 +45,7 @@ function CreateLookupCanvas(
)
end

function pixel!(
c::T,
pixel_x::Int,
pixel_y::Int,
color::UserColorType,
) where {T<:LookupCanvas}
function pixel!(c::LookupCanvas, pixel_x::Integer, pixel_y::Integer, color::UserColorType)
valid_x_pixel(c, pixel_x) || return c
valid_y_pixel(c, pixel_y) || return c
char_x, char_y, char_x_off, char_y_off = pixel_to_char_point_off(c, pixel_x, pixel_y)
Expand All @@ -65,9 +60,9 @@ function pixel!(
c
end

function print_row(io::IO, _, print_color, c::LookupCanvas, row::Int)
function print_row(io::IO, _, print_color, c::LookupCanvas, row::Integer)
0 < row nrows(c) || throw(ArgumentError("`row` out of bounds: $row"))
for col in 1:ncols(c)
for col 1:ncols(c)
print_color(io, c.colors[row, col], lookup_decode(c)[c.grid[row, col] + 1])
end
nothing
Expand Down
Loading

0 comments on commit c6734a4

Please sign in to comment.