Skip to content

Commit bf2c8ed

Browse files
committed
UnicodePlots: add autoscale to scalarplot 2D
1 parent c6d7a08 commit bf2c8ed

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ function scalarplot!(
358358

359359
func = funcs[1]
360360
layout = ctx[:layout]
361-
resolution = @. Int(round(ctx[:size] ./ 10 ./ (layout[2], layout[1]))) # reduce pixel count in the terminal
361+
resolution = ctx[:size] ./ 10 ./ (layout[2], layout[1]) # reduce pixel count in the terminal
362362
ylim = ctx[:limits]
363363
colormap = ctx[:colormap]
364364

@@ -371,6 +371,20 @@ function scalarplot!(
371371
ex = extrema(view(coords, 1, :))
372372
ey = extrema(view(coords, 2, :))
373373

374+
if (true) # auto scale feature, do we want this?
375+
wx = ex[2] - ex[1]
376+
wy = ey[2] - ey[1]
377+
rescale = wx / wy * (resolution[1] / (resolution[2]))
378+
if rescale > 1
379+
resolution = (resolution[1], resolution[2] / rescale)
380+
else
381+
resolution = (resolution[1] / rescale, resolution[2])
382+
end
383+
end
384+
385+
# we need an integer resolution
386+
resolution = @. Int(round(resolution))
387+
374388
X = LinRange(ex[1], ex[2], resolution[1])
375389
Y = LinRange(ey[1], ey[2], resolution[2])
376390
xgrid_plot = simplexgrid(X, Y)

0 commit comments

Comments
 (0)