Skip to content

Commit 55d98ff

Browse files
author
chmerdon
committed
fixed rescaling again
1 parent 41f0f2b commit 55d98ff

1 file changed

Lines changed: 20 additions & 33 deletions

File tree

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,14 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
8080

8181
# determine resolution (divided by 10, to reduce pixel count in the terminal)
8282
layout = ctx[:layout]
83-
resolution = ctx[:size] ./ 12 ./ (layout[2], 2 * layout[1])
83+
resolution = ctx[:size] ./ (48, 24) ./ (layout[2], layout[1])
8484
aspect = ctx[:aspect]
8585

86-
if (true) # auto scale feature, do we want this?
87-
wx = ex[2] - ex[1]
88-
wy = (ey[2] - ey[1]) * 2
89-
rescale = wx / wy * (resolution[1] / resolution[2])
90-
if rescale > 1
91-
resolution = (resolution[1] * aspect, Int(ceil(resolution[2] / rescale)))
92-
else
93-
resolution = (Int(ceil(resolution[1] * aspect / rescale)), resolution[2])
94-
end
95-
end
86+
# rescale resolution
87+
wx = ex[2] - ex[1]
88+
wy = ey[2] - ey[1]
89+
rescale = 2 * wx / wy * (resolution[2] / (resolution[1])) / aspect
90+
resolution = (resolution[1] * rescale, resolution[2])
9691

9792
# we need an integer resolution
9893
resolution = @. Int(round(resolution))
@@ -259,7 +254,7 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
259254
ncellregions = num_cellregions(grid)
260255
nbregions = num_bfaceregions(grid)
261256
layout = ctx[:layout]
262-
resolution = (Int(round(ctx[:size][1] / 6 / layout[2])), max(7, 5 + ncellregions + nbregions))
257+
resolution = (Int(round(ctx[:size][1] / 12 / layout[2])), max(7, 5 + ncellregions + nbregions))
263258

264259
# create UnicodePlots.Canvas
265260
CanvasType = UnicodePlots.BrailleCanvas # should this be a changeable parameter ?
@@ -460,16 +455,12 @@ function scalarplot!(
460455
ey = extrema(view(coords, 2, :))
461456

462457
aspect = ctx[:aspect]
463-
if (true) # auto scale feature, do we want this?
464-
wx = ex[2] - ex[1]
465-
wy = (ey[2] - ey[1])
466-
rescale = wx / wy * (resolution[1] / resolution[2])
467-
if rescale > 1
468-
resolution = (resolution[1] * aspect, Int(ceil(resolution[2] / rescale)))
469-
else
470-
resolution = (Int(ceil(resolution[1] * aspect / rescale)), resolution[2])
471-
end
472-
end
458+
459+
# rescale resolution
460+
wx = ex[2] - ex[1]
461+
wy = ey[2] - ey[1]
462+
rescale = wx / wy * (resolution[2] / (resolution[1])) / aspect
463+
resolution = (resolution[1] * rescale, resolution[2])
473464

474465
# we need an integer resolution
475466
resolution = @. Int(round(resolution))
@@ -576,7 +567,7 @@ end
576567
function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func)
577568

578569
layout = ctx[:layout]
579-
resolution = ctx[:size] ./ 12 ./ (layout[2], 2 * layout[1]) # reduce pixel count in the terminal
570+
resolution = ctx[:size] ./ (48, 24) ./ (layout[2], layout[1])
580571

581572
# find bounding box
582573
coords = grid[Coordinates]
@@ -592,18 +583,14 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
592583
else
593584
ey = extrema(view(coords, 2, :))
594585
end
586+
595587
aspect = ctx[:aspect]
596588

597-
if (true) # auto scale feature, do we want this?
598-
wx = ex[2] - ex[1]
599-
wy = (ey[2] - ey[1]) * 2
600-
rescale = wx / wy * (resolution[1] / resolution[2])
601-
if rescale > 1
602-
resolution = (resolution[1] * aspect, Int(ceil(resolution[2] / rescale)))
603-
else
604-
resolution = (Int(ceil(resolution[1] * aspect / rescale)), resolution[2])
605-
end
606-
end
589+
# rescale resolution
590+
wx = ex[2] - ex[1]
591+
wy = ey[2] - ey[1]
592+
rescale = 2 * wx / wy * (resolution[2] / (resolution[1])) / aspect
593+
resolution = (resolution[1] * rescale, resolution[2])
607594

608595
# we need an integer resolution
609596
resolution = @. Int(round(resolution))

0 commit comments

Comments
 (0)