MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.42k stars 313 forks source link

`text` with colors as numbers does not propagate colormap updates #4226

Closed asinghvi17 closed 2 months ago

asinghvi17 commented 2 months ago

MWE:

using CairoMakie
f, a, p = text(fill("aa", 10); position = rand(Point2f, 10), color= 1:10)

iTerm2 Ue4wbN

p.colormap = :RdBu

iTerm2 E4Rs5Y

But, if I construct the textplot with colormap=:RdBu as a kwarg,

![iTerm2 TdjV9q](https://github.com/user-attachments/assets/df641db3-3726-47e6-8b3f-497180a11091)

additionally, if I trigger text layouting by

p[1][] = fill("bb", 10)

then the color becomes correct.

iTerm2 aPwEB7

asinghvi17 commented 2 months ago

The real issue here seems to be that p.calculated_colors is not updating correctly...tested by:

julia> on(p.calculated_colors) do c
       println(c)
       end
ObserverFunction defined at REPL[18]:2 operating on Observable(ColorMapping{1, Vector{Int64}, Vector{Float32}}(Observable([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), Observable(RGBA{Float32}[RGBA{Float32}(0.267004,0.004874,0.329415,1.0), RGBA{Float32}(0.26851,0.009605,0.335427,1.0), RGBA{Float32}(0.269944,0.014625,0.341379,1.0), RGBA{Float32}(0.271305,0.019942,0.347269,1.0), RGBA{Float32}(0.272594,0.025563,0.353093,1.0), RGBA{Float32}(0.273809,0.031497,0.358853,1.0), RGBA{Float32}(0.274952,0.037752,0.364543,1.0), RGBA{Float32}(0.276022,0.044167,0.370164,1.0), RGBA{Float32}(0.277018,0.050344,0.375715,1.0), RGBA{Float32}(0.277941,0.056324,0.381191,1.0)  …  RGBA{Float32}(0.906311,0.894855,0.098125,1.0), RGBA{Float32}(0.916242,0.896091,0.100717,1.0), RGBA{Float32}(0.926106,0.89733,0.104071,1.0), RGBA{Float32}(0.935904,0.89857,0.108131,1.0), RGBA{Float32}(0.945636,0.899815,0.112838,1.0), RGBA{Float32}(0.9553,0.901065,0.118128,1.0), RGBA{Float32}(0.964894,0.902323,0.123941,1.0), RGBA{Float32}(0.974417,0.90359,0.130215,1.0), RGBA{Float32}(0.983868,0.904867,0.136897,1.0), RGBA{Float32}(0.993248,0.906157,0.143936,1.0)]), Observable(RGBA{Float32}[RGBA{Float32}(0.267004,0.004874,0.329415,1.0), RGBA{Float32}(0.26851,0.009605,0.335427,1.0), RGBA{Float32}(0.269944,0.014625,0.341379,1.0), RGBA{Float32}(0.271305,0.019942,0.347269,1.0), RGBA{Float32}(0.272594,0.025563,0.353093,1.0), RGBA{Float32}(0.273809,0.031497,0.358853,1.0), RGBA{Float32}(0.274952,0.037752,0.364543,1.0), RGBA{Float32}(0.276022,0.044167,0.370164,1.0), RGBA{Float32}(0.277018,0.050344,0.375715,1.0), RGBA{Float32}(0.277941,0.056324,0.381191,1.0)  …  RGBA{Float32}(0.906311,0.894855,0.098125,1.0), RGBA{Float32}(0.916242,0.896091,0.100717,1.0), RGBA{Float32}(0.926106,0.89733,0.104071,1.0), RGBA{Float32}(0.935904,0.89857,0.108131,1.0), RGBA{Float32}(0.945636,0.899815,0.112838,1.0), RGBA{Float32}(0.9553,0.901065,0.118128,1.0), RGBA{Float32}(0.964894,0.902323,0.123941,1.0), RGBA{Float32}(0.974417,0.90359,0.130215,1.0), RGBA{Float32}(0.983868,0.904867,0.136897,1.0), RGBA{Float32}(0.993248,0.906157,0.143936,1.0)]), Observable{Function}(identity), Observable{Union{Nothing, Vector{Float64}}}(nothing), Observable([1.0, 10.0]), Observable{Union{MakieCore.Automatic, ColorTypes.RGBA{Float32}}}(Automatic()), Observable{Union{MakieCore.Automatic, ColorTypes.RGBA{Float32}}}(Automatic()), Observable(RGBA{Float32}(0.0,0.0,0.0,0.0)), Observable(continuous), Observable(Float32[1.0, 10.0]), Observable(Float32[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0])))

julia> p.colormap[] = :RdBu
:RdBu

julia> p
MakieCore.Text{Tuple{Vector{String}}}
asinghvi17 commented 2 months ago

Note for self: this is because the observable plot.calculated_colors never directly updates, so we have to look at its internal attributes. I recall that it used to update earlier though.

SimonDanisch commented 2 months ago

For the better or worse, plot.calculated_colors is not supposed to update, only it's internal observables update.

asinghvi17 commented 2 months ago

Is there a reason that's the case? Seems like that causes yet more type lock-in in the pipeline, since one can't switch from colors as numbers to colors directly...

SimonDanisch commented 2 months ago

You could never actually do that, since day one ;)