How to correctly pick the index of heatmap cell?

My goal is to click the cell in heatmap and got its index.
image
Currently it is implemented the following way

on(events(f).mousebutton, priority = 2) do event
        if event.button == Mouse.left && event.action == Mouse.press
            i = 0
            _, i = pick(ax.scene)
            i = i - size(m, 1) - 2
        end
    end

And indexing is done by pick() and it is implemented weirdly:
image
Do you know how to change it so it will take one color cell as an index, not half of one and half of another cells?

It seems it somehow related with tick position

The indices are related to the vertices of the primitives used to render, some kind of mesh I guess. Have a look at how DataInspector converts this information, maybe it helps Makie.jl/src/interaction/inspector.jl at f51eb527806e184690b577e17e630e9c9c521cb9 · MakieOrg/Makie.jl · GitHub

This worked!

  on(events(f).mousebutton, priority = 1) do event
        if event.button == Mouse.left && event.action == Mouse.press
            i = 0
            plot, i = pick(ax.scene)
            a = DataInspector(plot)
            pos = Makie.position_on_plot(plot, -1, apply_transform = false)[Vec(1, 2)]
            b = Makie._pixelated_getindex(plot[1][], plot[2][], plot[3][], pos, true)
            chan_i[] = b[1]
            var_i[] = b[2]
            println(chan_i[], ' ', var_i[])
        end
    end
    f

1 Like