Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions ext/GridVisualizeMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,16 @@ scenekwargs(ctx) = Dict(
:titlesize => ctx[:fontsize]
)

#scenekwargs(ctx)=()
scenekwargs_3(ctx) = Dict(
:xticklabelsize => 0.3 * ctx[:fontsize],
:yticklabelsize => 0.3 * ctx[:fontsize],
:zticklabelsize => 0.3 * ctx[:fontsize],
:xlabelsize => 0.5 * ctx[:fontsize],
:ylabelsize => 0.5 * ctx[:fontsize],
:zlabelsize => 0.5 * ctx[:fontsize],
:titlesize => ctx[:fontsize]
)


############################################################################################################
#1D grid
Expand Down Expand Up @@ -563,14 +572,14 @@ end

#######################################################################################
# 2D grid

# makescene_grid() used for 2D and 3D grids
function makescene_grid(ctx)
XMakie = ctx[:Plotter]
GL = XMakie.GridLayout(ctx[:figure])
GL[1, 1] = ctx[:scene]
ncol = length(ctx[:cmap])
nbcol = length(ctx[:bcmap])
# fontsize=0.5*ctx[:fontsize],ticklabelsize=0.5*ctx[:fontsize]

if ctx[:show_colorbar]
if ctx[:colorbar] == :vertical
GL[1, 2] = XMakie.Colorbar(
Expand All @@ -580,6 +589,8 @@ function makescene_grid(ctx)
ticks = 1:ncol,
width = 15,
label = "cell regions",
labelsize = 0.5 * ctx[:fontsize],
ticklabelsize = 0.5 * ctx[:fontsize],
)
GL[1, 3] = XMakie.Colorbar(
ctx[:figure];
Expand All @@ -588,6 +599,8 @@ function makescene_grid(ctx)
ticks = 1:nbcol,
width = 15,
label = "boundary regions",
labelsize = 0.5 * ctx[:fontsize],
ticklabelsize = 0.5 * ctx[:fontsize],
)
elseif ctx[:colorbar] == :horizontal
GL[2, 1] = XMakie.Colorbar(
Expand All @@ -597,6 +610,8 @@ function makescene_grid(ctx)
height = 15,
vertical = false,
label = "cell regions",
labelsize = 0.5 * ctx[:fontsize],
ticklabelsize = 0.5 * ctx[:fontsize],
)
GL[3, 1] = XMakie.Colorbar(
ctx[:figure];
Expand All @@ -605,6 +620,8 @@ function makescene_grid(ctx)
height = 15,
vertical = false,
label = "boundary regions",
labelsize = 0.5 * ctx[:fontsize],
ticklabelsize = 0.5 * ctx[:fontsize],
)
end
end
Expand Down Expand Up @@ -1006,7 +1023,10 @@ function makeaxis3d(ctx)
azimuth = ctx[:azim] * π / 180,
perspectiveness = ctx[:perspectiveness],
title = map(data -> data.t, ctx[:data]),
scenekwargs(ctx)...,
xlabel = ctx[:xlabel],
ylabel = ctx[:ylabel],
zlabel = ctx[:zlabel],
scenekwargs_3(ctx)...,
)
end
end
Expand All @@ -1031,28 +1051,47 @@ function makescene3d(ctx)
)
end
GL[1, 1] = ctx[:scene]
# Horizontal or vertical colorbar
# Add colorbar
if ctx[:show_colorbar]
if haskey(ctx, :crange)

# Configure range and ticks for linear or logarithmic scaling
islog = ctx[:colorscale] == :log
tickvalues = ctx[:colorbarticks]
colorbar_range = islog ? log10.(ctx[:crange]) : ctx[:crange]
colorbar_ticks = if islog
(
log10.(tickvalues),
["10^$(round(Int, log10(t)))" for t in tickvalues],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like the hardcoded String ticks here. Is there no legend mechnism in Makie?

If not: Can you use LaTeXStrings, such that 10^x is rendered as LaTeX?

)
else
map(d -> d.c, ctx[:data])
end
colorbar_tickformat = islog ? XMakie.Makie.automatic : "{:.2e}"

if ctx[:colorbar] == :vertical
GL[1, 2] = XMakie.Colorbar(
ctx[:figure];
colormap = ctx[:colormap],
colorrange = ctx[:crange],
ticks = map(d -> d.c, ctx[:data]),
tickformat = "{:.2e}",
colorrange = colorbar_range,
ticks = colorbar_ticks,
tickformat = colorbar_tickformat,
width = 15,
ticklabelsize = 0.5 * ctx[:fontsize],
labelsize = 0.5 * ctx[:fontsize],
label = get(ctx, :colorbarlabel, ""),
)
elseif ctx[:colorbar] == :horizontal
GL[2, 1] = XMakie.Colorbar(
ctx[:figure];
colormap = ctx[:colormap],
colorrange = ctx[:crange],
ticks = map(d -> d.c, ctx[:data]),
tickformat = "{:.2e}",
colorrange = colorbar_range,
ticks = colorbar_ticks,
tickformat = colorbar_tickformat,
height = 15,
ticklabelsize = 0.5 * ctx[:fontsize],
labelsize = 0.5 * ctx[:fontsize],
label = get(ctx, :colorbarlabel, ""),
vertical = false,
)
end
Expand Down Expand Up @@ -1283,7 +1322,14 @@ function scalarplot!(ctx, TP::Type{MakieType}, ::Type{Val{3}}, grids, parentgrid

function make_mesh(pts, fcs, vals, alpha)
if length(fcs) > 0
colors = XMakie.Makie.interpolated_getindex.((cmap,), vals, (crange,))
# Map values to colors using linear or logarithmic scaling
if ctx[:colorscale] == :log
vals_log = log10.(clamp.(vals, crange[1], crange[2]))
crange_log = log10.(crange)
colors = XMakie.Makie.interpolated_getindex.((cmap,), vals_log, (crange_log,))
else
colors = XMakie.Makie.interpolated_getindex.((cmap,), vals, (crange,))
end
if alpha < 1
colors = [
RGBA(colors[i].r, colors[i].g, colors[i].b, Float32(alpha)) for
Expand Down
1 change: 1 addition & 0 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function default_plot_kwargs()
:viridis,
"2D/3D contour plot color map (any from [ColorSchemes.jl](https://juliagraphics.github.io/ColorSchemes.jl/stable/basics/#Pre-defined-schemes))"
),
:colorscale => Pair(:linear, "Color scale for scalar plots (:linear or :log; :log requires positive color limits and ticks)"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about log10 and log2 ? I can image that both may be relevant. If the same mechanism can be re-used, than I suggest to allow for both bases.

:dim => Pair(1, "Data dimension for PlutoVista plot"),
:elev => Pair(30, "3D elevation angle (in degrees)"),
:elevation => Pair(0.0, "2D plot height factor for elevation"),
Expand Down
Loading