menujuliainteractivemakie.jl

How to change color of mark on topoplot interactively?


I want to create interactive line- and topoplot depending on menu. I figured out how to make red the line chosen in menu, but it doesn't work for topoplot marks (black circles inside topoplot). I can change it manually (cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)), but how to do that interactively?

f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1:3, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")

N = 1:length(pos) #1:4 
hidespines!(ax, :t, :r) 
GLMakie.xlims!(-0.3, 1.2)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
times = range(-0.3, length=size(dat_e,2), step=1 ./ 128)

lines = Dict()
for i in N
    mean_trial = mean(dat_e[i,:,:],dims=2)[:,1]
    line = lines!(times, mean_trial, color = "black")
    lines[i] = line
end 
hidedecorations!(ax, label = false, ticks = false, ticklabels = false) 

topo_axis = Axis(f[2, 2], width = 178, height = 178, aspect = DataAspect())

Makie.xlims!(low = -0.2, high = 1.2)
Makie.ylims!(low = -0.2, high = 1.2)
topoMatrix = eegHeadMatrix(pos[N], (0.5, 0.5), 0.5)

cmap = Observable(collect(ColorScheme(range(colorant"black", colorant"black", length=30))))
#cmap[][4] = RGB{N0f8}(1.0,0.0,0.0) 
topo = eeg_topoplot!(topo_axis, N, # averaging all trial of 30 participants on Xth msec
    raw.ch_names[1:30]; 
    positions=pos, # produced  automatically from ch_names
    interpolation=NullInterpolator(),
    enlarge=1,
    #colorrange = (0, 1), # add the 0 for the white-first color
    colormap = cmap[],
    label_text=false)
hidedecorations!(current_axis())
hidespines!(current_axis())

num_prev = 0
menu = Menu(f[3, 2], options = raw.ch_names[1:30], default = nothing)#, default = "second")
on(menu.selection) do selected
    if selected != nothing
        num = findall(x->x==menu.selection[], raw.ch_names[1:30])[]     
        if num_prev != 0
            lines[num_prev].color = "black"
            cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
        end
        lines[num].color = "red"
        cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
        num_prev = num
    end
end
notify(menu.selection)
#print(cmap[])
f

enter image description here


Solution

  • We solved this by putting this string at the end of the menu.selection section:

    notify(lines)
    

    It works, because lines() automatically creates Observable.