Skip to content

Commit 004e1eb

Browse files
committed
Respect scaling and xlimits
1 parent 89b9a3d commit 004e1eb

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,57 @@ function scalarplot!(
342342
plt = ctx[:figure]
343343
end
344344

345+
xlim = ctx[:xlimits]
346+
if xlim[1] > xlim[2]
347+
# invalid, try to find the optimal range
348+
coord_min = min(ctx[:xlimits][1], minimum.([grid[Coordinates] for grid in grids])...)
349+
coord_max = max(ctx[:xlimits][2], maximum.([grid[Coordinates] for grid in grids])...)
350+
xlim = (coord_min, coord_max)
351+
end
352+
353+
# xscale::Symbol = :identity: x-axis scale (:identity, :ln, :log2, :log10), or scale function e.g. x -> log10(x).
354+
# xscale: x axis scale: one of [:log, :identity, :symlog]. Default: :identity
355+
356+
xscale = ctx[:xscale]
357+
xscale == :log && (xscale = :log10)
358+
xscale == :symlog && (xscale = x -> sign(x) * (log10(1 + abs(x))))
359+
360+
yscale = ctx[:yscale]
361+
yscale == :log && (yscale = :log10)
362+
yscale == :symlog && (yscale = x -> sign(x) * (log10(1 + abs(x))))
363+
364+
color = UnicodePlots.ansi_color(Symbol(ctx[:color]))
365+
345366
for ifunc in 1:nfuncs
346367
func = funcs[ifunc]
347368
grid = grids[ifunc]
348369
coord = grid[Coordinates] * ctx[:gridscale]
349370
name = name = isnothing(ctx[:label]) ? "" : ctx[:label]
371+
350372
if isnothing(plt)
351-
plt = UnicodePlots.lineplot(coord[1, :], func; ylim, xlabel = String(ctx[:xlabel]), name, height = resolution[2], width = resolution[1], title = ctx[:title])
373+
@show Symbol(ctx[:color])
374+
plt = UnicodePlots.lineplot(
375+
coord[1, :],
376+
func;
377+
xlim,
378+
ylim,
379+
xscale,
380+
yscale,
381+
xlabel = String(ctx[:xlabel]),
382+
name,
383+
height = resolution[2],
384+
width = resolution[1],
385+
title = ctx[:title],
386+
color
387+
)
352388
else
353-
UnicodePlots.lineplot!(plt, coord[1, :], func; name)
389+
UnicodePlots.lineplot!(
390+
plt,
391+
coord[1, :],
392+
func;
393+
name,
394+
color
395+
)
354396
end
355397
end
356398
ctx[:figure] = plt

0 commit comments

Comments
 (0)