@@ -34,27 +34,29 @@ function gridplot!(ctx, ::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
3434
3535 # determine resolution
3636 resolution = ctx[:size ]
37+ legend_space = 4
38+ aspect = ctx[:aspect ] * resolution[1 ] / (resolution[1 ] + legend_space)
39+
3740 if (true ) # auto scale feature, do we want this?
3841 wx = ex[2 ] - ex[1 ]
3942 wy = ey[2 ] - ey[1 ]
4043 rescale = wx / wy * (resolution[1 ] / (2 * resolution[2 ]))
4144 if rescale > 1
42- resolution = (resolution[1 ] * ctx[ : aspect] , Int (ceil (resolution[2 ] / rescale)))
45+ resolution = (resolution[1 ] * aspect, Int (ceil (resolution[2 ] / rescale)))
4346 else
44- resolution = (Int (ceil (resolution[1 ] * ctx[ : aspect] / rescale)), resolution[2 ])
47+ resolution = (Int (ceil (resolution[1 ] * aspect / rescale)), resolution[2 ])
4548 end
4649 end
4750
4851 # create UnicodePlots.Canvas
49- legend_space = 6
50- padding = 0
51- ex = (ex[1 ] - padding, ex[2 ] + padding)
52- ey = (ey[1 ] - padding * 2 , ey[2 ] + padding * 0.25 )
52+ padding = 0.1 * max (ex[2 ] - ex[1 ], ey[2 ] - ey[1 ])
53+ ex = (ex[1 ] - 2 * padding, ex[2 ] + 0.5 * padding)
54+ ey = (ey[1 ] - padding, ey[2 ] + padding)
5355 CanvasType = UnicodePlots. BrailleCanvas # should this be a changeable parameter ?
5456 canvas = CanvasType (
5557 resolution[2 ], resolution[1 ] + legend_space, # number of rows and columns (characters)
5658 origin_y = ey[1 ], origin_x = ex[1 ], # position in virtual space
57- height = (ey[2 ] - ey[1 ]) / (resolution[1 ] / (resolution[1 ] + legend_space)), width = ex[2 ] - ex[1 ]; blend = false
59+ height = (ey[2 ] - ey[1 ]) / (resolution[1 ] / (resolution[1 ] + legend_space)), width = ex[2 ] - ex[1 ]; blend = false , border = :black
5860 )
5961
6062 # # plot all edges in the grid
@@ -143,8 +145,16 @@ function gridplot!(ctx, ::Type{UnicodePlotsType}, ::Type{Val{2}}, grid)
143145 )
144146 end
145147
146- region_legend! (canvas, " cell regions:" , 1 , 1 , colors)
147- region_legend! (canvas, " bface regions:" , 1 , 2 , bcolors)
148+ region_legend! (canvas, " cell regions: " , 2 , 1 , colors)
149+ region_legend! (canvas, " bface regions:" , 2 , 2 , bcolors)
150+
151+ # corner coordinates
152+ ex = extrema (view (coords, 1 , :))
153+ ey = extrema (view (coords, 2 , :))
154+ UnicodePlots. annotate! (canvas, ex[1 ], ey[1 ], " $(ex[1 ]) " , UInt32 (0 ), false ; valign = :top )
155+ UnicodePlots. annotate! (canvas, ex[2 ], ey[1 ], " $(ex[2 ]) " , UInt32 (0 ), false ; valign = :top , halign = :right )
156+ UnicodePlots. annotate! (canvas, ex[1 ] - 1.5 * padding, ey[1 ], " $(ey[1 ]) " , UInt32 (0 ), false ; halign = :left )
157+ UnicodePlots. annotate! (canvas, ex[1 ] - 1.5 * padding, ey[2 ], " $(ey[2 ]) " , UInt32 (0 ), false ; halign = :left )
148158
149159 # plot
150160 plot = UnicodePlots. Plot (canvas; title = ctx[:title ])
@@ -161,7 +171,7 @@ function region_legend!(canvas, title, x, y, colors)
161171 red, green, blue = UInt32 .(colors[r])
162172 uint_color = (red << 16 ) | (green << 8 ) | blue
163173 reg_string = " $r "
164- for (i, char) in enumerate ( reg_string)
174+ for char in reg_string
165175 startx += 1
166176 UnicodePlots. char_point! (canvas, startx, y, char, uint_color, false )
167177 end
@@ -189,10 +199,12 @@ function gridplot!(ctx, ::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
189199 end
190200
191201 # determine resolution
192- resolution = (ctx[:size ][1 ], 4 )
202+ resolution = (ctx[:size ][1 ], 5 )
193203
194204 # create UnicodePlots.Canvas
195205 legend_space = 6
206+ padding = 0.05 * (ex[2 ] - ex[1 ])
207+ ex = (ex[1 ] - padding, ex[2 ] + padding)
196208 CanvasType = UnicodePlots. BrailleCanvas # should this be a changeable parameter ?
197209 canvas = CanvasType (
198210 resolution[2 ], resolution[1 ] + legend_space, # number of rows and columns (characters)
@@ -222,17 +234,17 @@ function gridplot!(ctx, ::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
222234 for k in 1 : size (cen, 2 )
223235 UnicodePlots. lines! (
224236 canvas,
225- coords[1 , cellnodes[cen[1 , k], j]], 0.125 ,
226- coords[1 , cellnodes[cen[2 , k], j]], 0.125 ;
237+ coords[1 , cellnodes[cen[1 , k], j]], 0.375 ,
238+ coords[1 , cellnodes[cen[2 , k], j]], 0.375 ;
227239 color = colors[r]
228240 )
229241 end
230242 end
231243 for j in 1 : nnodes
232244 UnicodePlots. lines! (
233245 canvas,
234- coords[1 , j], 0.25 ,
235- coords[1 , j], 0.05 ;
246+ coords[1 , j], 0.45 ,
247+ coords[1 , j], 0.35 ;
236248 color = color
237249 )
238250 end
@@ -254,14 +266,19 @@ function gridplot!(ctx, ::Type{UnicodePlotsType}, ::Type{Val{1}}, grid)
254266 for j in 1 : nbfaces
255267 UnicodePlots. lines! (
256268 canvas,
257- coords[1 , bfacenodes[1 , j]], 0.25 ,
258- coords[1 , bfacenodes[1 , j]], 0.05 ;
269+ coords[1 , bfacenodes[1 , j]], 0.45 ,
270+ coords[1 , bfacenodes[1 , j]], 0.35 ;
259271 color = bcolors[bfaceregions[j]]
260272 )
261273 end
262274
263- region_legend! (canvas, " cell regions:" , 1 , 1 , colors)
264- region_legend! (canvas, " bface regions:" , 1 , 2 , bcolors)
275+ region_legend! (canvas, " cell regions: " , 2 , 1 , colors)
276+ region_legend! (canvas, " bface regions:" , 2 , 2 , bcolors)
277+
278+
279+ ex = extrema (view (coords, 1 , :))
280+ UnicodePlots. annotate! (canvas, 0 , 0.1 , " $(ex[1 ]) " , UInt32 (0 ), false )
281+ UnicodePlots. annotate! (canvas, ex[2 ], 0.1 , " $(ex[2 ]) " , UInt32 (0 ), false )
265282
266283 # plot
267284 plot = UnicodePlots. Plot (canvas; title = ctx[:title ])
0 commit comments