Alright, I’ve updated Makie, and the original code works. However, it doesn’t work when I try to animate them. E.g.,
using GLMakie
fig = Figure()
COLORS = [
"#7143E0",
"#0A9A84",
"#171A2F",
"#F30F0F",
"#465F00",
"#701B80",
]
fracax = Axis(fig[1,1]; width = 50, limits = (0,1,0,1))
barpos = Observable(fill(0.5, length(COLORS)))
stacks = Observable(collect(1:length(COLORS)))
heights = Observable(fill(0.1, length(COLORS)))
colors = Observable(to_color.(COLORS))
barplot!(fracax, barpos, heights; width = 1, gap = 0, stack=stacks, color = colors)
display(fig)
# New fractions coming in
heights.val = [0.1, 0.2]
barpos.val = [0.5 for k in 1:2]
stacks.val = collect(1:2)
colors.val = [to_color(COLORS[k]) for k in 1:2]
# Works:
notify.((heights, barpos, stacks, colors))
# New fractions coming in
heights.val = [0.1, 0.2, 0.5]
barpos.val = [0.5 for k in 1:3]
stacks.val = collect(1:3)
colors.val = [to_color(COLORS[k]) for k in 1:3]
# Errors:
notify.((heights, barpos, stacks, colors))
the last line will error with
ERROR: BoundsError: attempt to access 2-element Vector{Int64} at index [[1, 2, 3]]
Stacktrace:
[1] throw_boundserror(A::Vector{Int64}, I::Tuple{Vector{Int64}})
@ Base .\abstractarray.jl:703
[2] checkbounds
@ .\abstractarray.jl:668 [inlined]
[3] _getindex
@ .\multidimensional.jl:874 [inlined]
[4] getindex
@ .\abstractarray.jl:1236 [inlined]
[5] stack_grouped_from_to(i_stack::Vector{Int64}, y::Vector{Float32}, grp::NamedTuple{(:x,), Tuple{Vector{Float64}}})
@ Makie C:\Users\datse\.julia\packages\Makie\D0WIp\src\basic_recipes\barplot.jl:119
[6] (::Makie.var"#calculate_bars#433"{Observable{Vector{ColorTypes.RGBA{Float32}}}, Observable{Vector{Vec{2, Float32}}}, Observable{Vector{Vec{2, Float32}}}, Observable{Vector{Tuple{String, Point{2, Float32}}}}})(xy::Vector{Point{2, Float32}}, fillto::MakieCore.Automatic, offset::Float64, width::Int64, dodge::MakieCore.Automatic, n_dodge::MakieCore.Automatic, gap::Int64, dodge_gap::Float64, stack::Vector{Int64}, dir::Symbol, bar_labels::Nothing, flip_labels_at::Float64, label_color::Symbol, color_over_background::MakieCore.Automatic, color_over_bar::MakieCore.Automatic, label_formatter::typeof(Makie.bar_label_formatter), label_offset::Int64) @ Makie C:\Users\datse\.julia\packages\Makie\D0WIp\src\basic_recipes\barplot.jl:230
So there is some indexing problem, or I am not using notify
correctly.