@@ -8,7 +8,7 @@ module GridVisualizeUnicodePlotsExt
88import GridVisualize: initialize!, gridplot!, scalarplot!, bregion_cmap, region_cmap
99using GridVisualize: UnicodePlotsType
1010using UnicodePlots: UnicodePlots
11- using ExtendableGrids: Coordinates, ON_CELLS, ON_FACES, ON_EDGES, CellNodes, FaceNodes, BFaceNodes, CellGeometries, CellRegions, BFaceRegions, num_cells, num_nodes, local_celledgenodes, num_bfaceregions, num_cellregions, num_targets
11+ using ExtendableGrids: Coordinates, simplexgrid, ON_CELLS, ON_FACES, ON_EDGES, CellNodes, FaceNodes, BFaceNodes, CellGeometries, CellRegions, BFaceRegions, num_cells, num_nodes, local_celledgenodes, num_bfaceregions, num_cellregions, num_targets, interpolate!
1212using Colors: Colors, RGB, RGBA
1313
1414initialize! (p, :: Type{UnicodePlotsType} ) = nothing
@@ -291,19 +291,72 @@ function scalarplot!(
291291 resolution = ctx[:size ]
292292 ylim = ctx[:limits ]
293293
294+ if ylim[1 ] > ylim[2 ]
295+ # try to find limits automatically
296+ ylim = (minimum ([minimum (func) for func in funcs]), maximum ([maximum (func) for func in funcs]))
297+ end
298+
294299 plt = ctx[:clear ] ? nothing : ctx[:figure ]
295300 for ifunc in 1 : nfuncs
296301 func = funcs[ifunc]
297302 grid = grids[ifunc]
298303 coord = grid[Coordinates] * ctx[:gridscale ]
299304 if ifunc == 1
300- plt = lineplot (coord[1 , :], func; ylim, xlabel = " x" , name = ctx[:label ], height = resolution[2 ], width = resolution[1 ])
305+ plt = UnicodePlots . lineplot (coord[1 , :], func; ylim, xlabel = " x" , name = ctx[:label ], height = resolution[2 ], width = resolution[1 ])
301306 else
302- lineplot! (plt, coord[1 , :], func; name = ctx[:label ])
307+ UnicodePlots . lineplot! (plt, coord[1 , :], func; name = ctx[:label ])
303308 end
304309 end
305310
306311 return plt
307312end
308313
314+
315+ function scalarplot! (
316+ ctx,
317+ :: Type{UnicodePlotsType} ,
318+ :: Type{Val{2}} ,
319+ grids,
320+ parentgrid,
321+ funcs
322+ )
323+
324+ func = funcs[1 ]
325+ resolution = ctx[:size ]
326+ ylim = ctx[:limits ]
327+ colormap = ctx[:colormap ]
328+
329+ if ylim[1 ] > ylim[2 ]
330+ # try to find limits automatically
331+ ylim = (minimum ([minimum (func) for func in funcs]), maximum ([maximum (func) for func in funcs]))
332+ end
333+
334+ coords = grids[1 ][Coordinates]
335+ ex = extrema (view (coords, 1 , :))
336+ ey = extrema (view (coords, 2 , :))
337+
338+ X = LinRange (ex[1 ], ex[2 ], resolution[1 ])
339+ Y = LinRange (ey[1 ], ey[2 ], resolution[2 ])
340+ xgrid_plot = simplexgrid (X, Y)
341+
342+ # interpolate data onto plot_grid
343+ I = zeros (Float64, num_nodes (xgrid_plot))
344+ interpolate! (I, xgrid_plot, func, grids[1 ]; eps = 1.0e-14 , not_in_domain_value = NaN , trybrute = true )
345+
346+ plt = ctx[:clear ] ? nothing : ctx[:figure ]
347+ plt = UnicodePlots. heatmap (
348+ reshape (I, (resolution[1 ], resolution[2 ]))' ,
349+ xlabel = " x" ,
350+ ylabel = " y" ,
351+ xfact = (ex[2 ] - ex[1 ]) / (resolution[1 ] - 1 ),
352+ yfact = (ey[2 ] - ey[1 ]) / (resolution[2 ] - 1 ),
353+ xoffset = ex[1 ],
354+ yoffset = ey[1 ],
355+ title = ctx[:title ],
356+ colormap = colormap,
357+ )
358+
359+ return plt
360+ end
361+
309362end # module
0 commit comments