@@ -61,8 +61,18 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
6161
6262 # find bounding box
6363 coords = grid[Coordinates]
64- ex = extrema (view (coords, 1 , :))
65- ey = extrema (view (coords, 2 , :))
64+ xlimits = ctx[:xlimits ]
65+ ylimits = ctx[:ylimits ]
66+ if xlimits[1 ] < xlimits[2 ]
67+ ex = xlimits
68+ else
69+ ex = extrema (view (coords, 1 , :))
70+ end
71+ if ylimits[1 ] < ylimits[2 ]
72+ ey = ylimits
73+ else
74+ ey = extrema (view (coords, 2 , :))
75+ end
6676
6777 # line color for interior edges
6878 if typeof (ctx[:color ]) <: RGB
@@ -78,8 +88,7 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
7888 # determine resolution (divided by 10, to reduce pixel count in the terminal)
7989 layout = ctx[:layout ]
8090 resolution = ctx[:size ] ./ 12 ./ (layout[2 ], layout[1 ])
81- legend_space = 0
82- aspect = ctx[:aspect ] * resolution[1 ] / (resolution[1 ] + legend_space)
91+ aspect = ctx[:aspect ] * resolution[1 ] / (resolution[1 ])
8392
8493 if (true ) # auto scale feature, do we want this?
8594 wx = ex[2 ] - ex[1 ]
@@ -96,14 +105,11 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
96105 resolution = @. Int (round (resolution))
97106
98107 # create UnicodePlots.Canvas
99- padding = 0 # 0.1 * max(ex[2] - ex[1], ey[2] - ey[1])
100- ex = (ex[1 ] - 2 * padding, ex[2 ] + 0.5 * padding)
101- ey = (ey[1 ] - padding, ey[2 ] + padding)
102108 CanvasType = UnicodePlots. BrailleCanvas # should this be a changeable parameter ?
103109 canvas = CanvasType (
104- resolution[2 ], resolution[1 ] + legend_space , # number of rows and columns (characters)
110+ resolution[2 ], resolution[1 ], # number of rows and columns (characters)
105111 origin_y = ey[1 ], origin_x = ex[1 ], # position in virtual space
106- height = (ey[2 ] - ey[1 ]) / (resolution[ 1 ] / (resolution[ 1 ] + legend_space)) , width = ex[2 ] - ex[1 ]; blend = false
112+ height = (ey[2 ] - ey[1 ]), width = ex[2 ] - ex[1 ]; blend = false
107113 )
108114
109115 # # plot all edges in the grid
@@ -201,8 +207,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
201207 region_legend! (plt, " regions" , y0 + 3 , bcolors)
202208
203209 # corner coordinates
204- ex = extrema (view (coords, 1 , :))
205- ey = extrema (view (coords, 2 , :))
206210 UnicodePlots. label! (plt, :bl , string (Float16 (ex[1 ])), UnicodePlots. ansi_color (UnicodePlots. BORDER_COLOR[]))
207211 UnicodePlots. label! (plt, :b , " x" )
208212 UnicodePlots. label! (plt, :br , string (Float16 (ex[2 ])), UnicodePlots. ansi_color (UnicodePlots. BORDER_COLOR[]))
@@ -218,11 +222,15 @@ end
218222
219223function gridplot! (ctx, TP:: Type{UnicodePlotsType} , :: Type{Val{1}} , grid)
220224 UnicodePlots = ctx[:Plotter ]
221- text_color = UnicodePlots. ansi_color (:normal )
222225
223226 # find bounding box
227+ xlimits = ctx[:xlimits ]
224228 coords = grid[Coordinates]
225- ex = extrema (view (coords, 1 , :))
229+ if xlimits[1 ] < xlimits[2 ]
230+ ex = xlimits
231+ else
232+ ex = extrema (view (coords, 1 , :))
233+ end
226234
227235 # line color for interior edges
228236 if typeof (ctx[:color ]) <: RGB
@@ -242,12 +250,9 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
242250 resolution = (Int (round (ctx[:size ][1 ] / 6 / layout[2 ])), max (7 , 5 + ncellregions + nbregions))
243251
244252 # create UnicodePlots.Canvas
245- legend_space = 0 # 5
246- padding = 0 # 0.05 * (ex[2] - ex[1])
247- ex = (ex[1 ] - padding, ex[2 ] + padding)
248253 CanvasType = UnicodePlots. BrailleCanvas # should this be a changeable parameter ?
249254 canvas = CanvasType (
250- resolution[2 ], resolution[1 ] + legend_space , # number of rows and columns (characters)
255+ resolution[2 ], resolution[1 ], # number of rows and columns (characters)
251256 origin_y = 0 , origin_x = ex[1 ], # position in virtual space
252257 height = 1 , width = ex[2 ] - ex[1 ]; blend = false
253258 )
@@ -267,6 +272,12 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
267272 cellgeoms = grid[CellGeometries]
268273 ncells = num_cells (grid)
269274 nnodes = num_nodes (grid)
275+ text_color = UnicodePlots. ansi_color (:normal )
276+ if nnodes < resolution[1 ] / 2
277+ for j in 1 : nnodes
278+ UnicodePlots. annotate! (canvas, coords[1 , j], 0.5 , " •" , text_color, false )
279+ end
280+ end
270281 for j in 1 : ncells
271282 cen = local_celledgenodes (cellgeoms[j])
272283 r = cellregions[j]
@@ -279,9 +290,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
279290 )
280291 end
281292 end
282- for j in 1 : nnodes
283- UnicodePlots. annotate! (canvas, coords[1 , j], 0.5 , " •" , text_color, false )
284- end
285293
286294 # plot boundary nodes with bregion_cmap colors
287295 bcmap = bregion_cmap (nbregions)
@@ -299,7 +307,7 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
299307 for j in 1 : nbfaces
300308 red, green, blue = UInt32 .(bcolors[bfaceregions[j]])
301309 uint_color = (red << 16 ) | (green << 8 ) | blue
302- UnicodePlots. annotate! (canvas, coords[1 , bfacenodes[1 , j]], 0.5 , " •" , UInt32 ( uint_color) , false )
310+ UnicodePlots. annotate! (canvas, coords[1 , bfacenodes[1 , j]], 0.5 , " •" , uint_color, false )
303311 end
304312
305313 plt = UnicodePlots. Plot (canvas; title = ctx[:title ], border = ctx[:border ])
@@ -311,7 +319,6 @@ function gridplot!(ctx, TP::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
311319
312320
313321 # corner coordinates
314- ex = extrema (view (coords, 1 , :))
315322 UnicodePlots. label! (plt, :bl , string (Float16 (ex[1 ])), UnicodePlots. ansi_color (UnicodePlots. BORDER_COLOR[]))
316323 UnicodePlots. label! (plt, :b , " x" )
317324 UnicodePlots. label! (plt, :br , string (Float16 (ex[2 ])), UnicodePlots. ansi_color (UnicodePlots. BORDER_COLOR[]))
@@ -364,7 +371,7 @@ function scalarplot!(
364371 yscale == :log && (yscale = :log10 )
365372 yscale == :symlog && (yscale = x -> sign (x) * (log10 (1 + abs (x))))
366373
367- color = UnicodePlots. ansi_color (Symbol ( ctx[:color ]) )
374+ color = UnicodePlots. ansi_color (ctx[:color ])
368375
369376 for ifunc in 1 : nfuncs
370377 func = funcs[ifunc]
0 commit comments