Skip to content

Commit 1733458

Browse files
author
chmerdon
committed
fixed spacing of vector samples
1 parent af04d0f commit 1733458

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

ext/GridVisualizeUnicodePlotsExt.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
8888
# determine resolution (divided by 10, to reduce pixel count in the terminal)
8989
layout = ctx[:layout]
9090
resolution = ctx[:size] ./ 12 ./ (layout[2], layout[1])
91-
aspect = ctx[:aspect] * resolution[1] / (resolution[1])
91+
aspect = ctx[:aspect]
9292

9393
if (true) # auto scale feature, do we want this?
9494
wx = ex[2] - ex[1]
@@ -104,6 +104,11 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
104104
# we need an integer resolution
105105
resolution = @. Int(round(resolution))
106106

107+
# ensure that legend fits
108+
ncellregions = num_cellregions(grid)
109+
nbregions = num_bfaceregions(grid)
110+
resolution = (resolution[1], max(resolution[2], 5 + ncellregions + nbregions))
111+
107112
# create UnicodePlots.Canvas
108113
CanvasType = UnicodePlots.BrailleCanvas # should this be a changeable parameter ?
109114
canvas = CanvasType(
@@ -146,7 +151,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
146151

147152
# color cell midpoints with cell regions color
148153
cellregions = grid[CellRegions]
149-
ncellregions = num_cellregions(grid)
150154
cmap = region_cmap(max(2, ncellregions))
151155
ctx[:cmap] = cmap
152156
colors = [
@@ -176,7 +180,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
176180
end
177181

178182
# plot boundary faces with bregion_cmap colors
179-
nbregions = num_bfaceregions(grid)
180183
bcmap = bregion_cmap(nbregions)
181184
ctx[:bcmap] = bcmap
182185
bcolors = [
@@ -486,10 +489,19 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
486489

487490
# find bounding box
488491
coords = grid[Coordinates]
489-
ex = extrema(view(coords, 1, :))
490-
ey = extrema(view(coords, 2, :))
491-
492-
aspect = ctx[:aspect] * resolution[1] / resolution[1]
492+
xlimits = ctx[:xlimits]
493+
ylimits = ctx[:ylimits]
494+
if xlimits[1] < xlimits[2]
495+
ex = xlimits
496+
else
497+
ex = extrema(view(coords, 1, :))
498+
end
499+
if ylimits[1] < ylimits[2]
500+
ey = ylimits
501+
else
502+
ey = extrema(view(coords, 2, :))
503+
end
504+
aspect = ctx[:aspect]
493505

494506
if (true) # auto scale feature, do we want this?
495507
wx = ex[2] - ex[1]
@@ -504,9 +516,10 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
504516

505517
# we need an integer resolution
506518
resolution = @. Int(round(resolution))
519+
@info resolution
507520

508521
# query vector field raster points
509-
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], rasterpoints = ((resolution[1] - 1) / 2, 2 * (resolution[2] - 1)), offset = ctx[:offset])
522+
rc, rv = vectorsample(grid, func; gridscale = ctx[:gridscale], rasterpoints = ((resolution[1] - 1) / 2, resolution[2] - 1), offset = ctx[:offset], xlimits = ex, ylimits = ey)
510523
qc, qv = quiverdata(rc, rv; vscale = ctx[:vscale], vnormalize = ctx[:vnormalize], vconstant = ctx[:vconstant])
511524

512525
# construct canvas
@@ -518,7 +531,6 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
518531
)
519532

520533
# plot arrows
521-
scale = minimum(resolution) / maximum(ctx[:rasterpoints]) / 300
522534
narrows = size(qv, 2)
523535
vscale = ctx[:vscale] # vscale steers arrow thickness
524536
if vscale <= 0.25

src/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ function vectorsample(
257257
tol = reltol * extent
258258

259259
# point spacing
260-
spacing = [extent / rasterpoints[i] for i in 1:dim]
260+
spacing = [(cminmax[i][2] - cminmax[i][1]) / rasterpoints[i] for i in 1:dim]
261261

262262
# index range
263263
ijkmax = ones(Int, 3)

0 commit comments

Comments
 (0)