Skip to content

Commit 9b457e8

Browse files
chmerdonpjaap
authored andcommitted
fixed spacing of vector samples
1 parent 18d8e7c commit 9b457e8

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
@@ -80,7 +80,7 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
8080
# determine resolution (divided by 10, to reduce pixel count in the terminal)
8181
layout = ctx[:layout]
8282
resolution = ctx[:size] ./ 12 ./ (layout[2], layout[1])
83-
aspect = ctx[:aspect] * resolution[1] / (resolution[1])
83+
aspect = ctx[:aspect]
8484

8585
if (true) # auto scale feature, do we want this?
8686
wx = ex[2] - ex[1]
@@ -96,6 +96,11 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
9696
# we need an integer resolution
9797
resolution = @. Int(round(resolution))
9898

99+
# ensure that legend fits
100+
ncellregions = num_cellregions(grid)
101+
nbregions = num_bfaceregions(grid)
102+
resolution = (resolution[1], max(resolution[2], 5 + ncellregions + nbregions))
103+
99104
# create UnicodePlots.Canvas
100105
CanvasType = UnicodePlots.BrailleCanvas # should this be a changeable parameter ?
101106
canvas = CanvasType(
@@ -141,7 +146,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
141146

142147
# color cell midpoints with cell regions color
143148
cellregions = grid[CellRegions]
144-
ncellregions = num_cellregions(grid)
145149
cmap = region_cmap(max(2, ncellregions))
146150
ctx[:cmap] = cmap
147151
cell_colors = [
@@ -192,7 +196,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
192196
end
193197

194198
# plot boundary faces with bregion_cmap colors
195-
nbregions = num_bfaceregions(grid)
196199
bcmap = bregion_cmap(nbregions)
197200
ctx[:bcmap] = bcmap
198201
bcolors = [
@@ -504,10 +507,19 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
504507

505508
# find bounding box
506509
coords = grid[Coordinates]
507-
ex = extrema(view(coords, 1, :))
508-
ey = extrema(view(coords, 2, :))
509-
510-
aspect = ctx[:aspect] * resolution[1] / resolution[1]
510+
xlimits = ctx[:xlimits]
511+
ylimits = ctx[:ylimits]
512+
if xlimits[1] < xlimits[2]
513+
ex = xlimits
514+
else
515+
ex = extrema(view(coords, 1, :))
516+
end
517+
if ylimits[1] < ylimits[2]
518+
ey = ylimits
519+
else
520+
ey = extrema(view(coords, 2, :))
521+
end
522+
aspect = ctx[:aspect]
511523

512524
if (true) # auto scale feature, do we want this?
513525
wx = ex[2] - ex[1]
@@ -522,9 +534,10 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
522534

523535
# we need an integer resolution
524536
resolution = @. Int(round(resolution))
537+
@info resolution
525538

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

530543
# construct canvas
@@ -536,7 +549,6 @@ function vectorplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid, func
536549
)
537550

538551
# plot arrows
539-
scale = minimum(resolution) / maximum(ctx[:rasterpoints]) / 300
540552
narrows = size(qv, 2)
541553
vscale = ctx[:vscale] # vscale steers arrow thickness
542554
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)