rework keywords

This commit is contained in:
t-bltg 2022-01-14 14:55:00 +01:00
parent 2c35964879
commit 6afc45473f
3 changed files with 39 additions and 24 deletions

View File

@ -55,7 +55,7 @@ Scratch = "1"
Showoff = "0.3.1, 1.0" Showoff = "0.3.1, 1.0"
StatsBase = "0.32 - 0.33" StatsBase = "0.32 - 0.33"
UnicodeFun = "0.4" UnicodeFun = "0.4"
UnicodePlots = "2.4" UnicodePlots = "2.6"
Unzip = "0.1" Unzip = "0.1"
julia = "1.6" julia = "1.6"

View File

@ -973,10 +973,10 @@ const _unicodeplots_marker = [
const _unicodeplots_scale = [:identity, :ln, :log2, :log10] const _unicodeplots_scale = [:identity, :ln, :log2, :log10]
# Additional constants # Additional constants
const _unicodeplots_canvas = Ref(:auto) const _up_colormap = Ref(:none)
const _unicodeplots_border = Ref(:auto) const _up_canvas = Ref(:auto)
const _unicodeplots_height = Ref(15) const _up_border = Ref(:auto)
const _unicodeplots_width = Ref(40) const _up_fix_ar = Ref(true)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# hdf5 # hdf5

View File

@ -24,36 +24,55 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
yaxis = sp[:yaxis] yaxis = sp[:yaxis]
xlim = collect(axis_limits(sp, :x)) xlim = collect(axis_limits(sp, :x))
ylim = collect(axis_limits(sp, :y)) ylim = collect(axis_limits(sp, :y))
F = float(eltype(xlim))
# We set x/y to have a single point, # We set x/y to have a single point,
# since we need to create the plot with some data. # since we need to create the plot with some data.
# Since this point is at the bottom left corner of the plot, # Since this point is at the bottom left corner of the plot,
# it should be hidden by consecutive plotting commands. # it should be hidden by consecutive plotting commands.
x = Float64[xlim[1]] x = F[xlim[1]]
y = Float64[ylim[1]] y = F[ylim[1]]
# create a plot window with xlim/ylim set, # create a plot window with xlim/ylim set,
# but the X/Y vectors are outside the bounds # but the X/Y vectors are outside the bounds
canvas = if (up_c = _unicodeplots_canvas[]) == :auto canvas = if (up_c = _up_canvas[]) == :auto
isijulia() ? :ascii : :braille isijulia() ? :ascii : :braille
else else
up_c up_c
end end
border = if (up_b = _unicodeplots_border[]) == :auto border = if (up_b = _up_border[]) == :auto
isijulia() ? :ascii : :solid isijulia() ? :ascii : :solid
else else
up_b up_b
end end
width, height = UnicodePlots.DEFAULT_WIDTH[], UnicodePlots.DEFAULT_HEIGHT[]
grid = xaxis[:grid] && yaxis[:grid]
quiver = contour = false
for series in series_list(sp)
st = series[:seriestype]
quiver |= series[:arrow] isa Arrow # post-pipeline detection (:quiver -> :path)
contour |= st === :contour
if st === :histogram2d
xlim = ylim = (0, 0)
elseif st === :spy || st === :heatmap
width = height = 0
grid = false
end
end
grid &= !contour && !quiver
kw = ( kw = (
compact = true, compact = true,
title = texmath2unicode(sp[:title]), title = texmath2unicode(sp[:title]),
xlabel = texmath2unicode(xaxis[:guide]), xlabel = texmath2unicode(xaxis[:guide]),
ylabel = texmath2unicode(yaxis[:guide]), ylabel = texmath2unicode(yaxis[:guide]),
grid = xaxis[:grid] && yaxis[:grid], grid = grid,
height = _unicodeplots_height[], blend = !(quiver || contour),
width = _unicodeplots_width[], height = height,
width = width,
xscale = xaxis[:scale], xscale = xaxis[:scale],
yscale = yaxis[:scale], yscale = yaxis[:scale],
border = border, border = border,
@ -114,26 +133,22 @@ function addUnicodeSeries!(
# special handling (src/interface) # special handling (src/interface)
if st === :histogram2d if st === :histogram2d
kw[:xlim][:] .= kw[:ylim][:] .= 0
return UnicodePlots.densityplot(x, y; kw...) return UnicodePlots.densityplot(x, y; kw...)
elseif st === :spy elseif st === :spy
kw = (; kw..., width = 0, height = 0) # w/h handled in UnicodePlots return UnicodePlots.spy(series[:z].surf; fix_ar = _up_fix_ar[], kw...)
return UnicodePlots.spy(series[:z].surf; kw...)
elseif st in (:contour, :heatmap) elseif st in (:contour, :heatmap)
kw_hm_ct = (; kw = (
kw...,
zlabel = sp[:colorbar_title], zlabel = sp[:colorbar_title],
colormap = up_cmap(series), colormap = (cm = _up_colormap[] === :none) ? up_cmap(series) : cm,
colorbar = hascolorbar(sp), colorbar = hascolorbar(sp),
) )
if st === :contour if st === :contour
isfilledcontour(series) && @warn "Plots(UnicodePlots): filled contour is not implemented" isfilledcontour(series) && @warn "Plots(UnicodePlots): filled contour is not implemented"
return UnicodePlots.contourplot( return UnicodePlots.contourplot(x, y, series[:z].surf; kw..., levels = series[:levels])
x, y, series[:z].surf; elseif st === :heatmap
levels = series[:levels], kw_hm_ct..., kw... return UnicodePlots.heatmap(series[:z].surf; fix_ar = _up_fix_ar[], kw...)
) # zlim = collect(axis_limits(sp, :z))
else
kw = (; kw..., width = 0, height = 0) # w/h handled in UnicodePlots
return UnicodePlots.heatmap(series[:z].surf; kw_hm_ct..., kw...)
end end
end end