I’m trying to recreate the tutorial from “doggo dot jl” Youtube: [02x10] GLMakie Interactive Widgets: Sliders, Buttons & Menus
But im stuck at the labelslidergrid! function()
I get the error message: ERROR: MethodError: no method matching length(::Observable{Any})
even the example from the help through that error:
ls = labelslidergrid!(scene, ["Voltage", "Ampere"], Ref(0:0.1:100); format = x -> "$(x)V")
layout[1, 1] = ls.layout
So i dont know what i’m doing wrong.
I’m using Julia 1.9.0 in VScode v1.78.2
and there ist the tutorial code:
using GLMakie
GLMakie.activate!()
################################################################################
# Sliders
################################################################################
# initialize plot
fig = Figure(resolution = (3840, 2160))
# add axis
ax1 = fig[1, 1] = Axis(fig,
# borders
aspect = 1,
# title
title = "Sliders Tutorial",
titlegap = 48, titlesize = 60,
# x-axis
xautolimitmargin = (0, 0), xgridwidth = 2, xticklabelsize = 36,
xticks = LinearTicks(20), xticksize = 18,
# y-axis
yautolimitmargin = (0, 0), ygridwidth = 2, yticklabelpad = 14,
yticklabelsize = 36, yticks = LinearTicks(20), yticksize = 18
)
# darken axes
vlines!(ax1, [0], linewidth = 2)
hlines!(ax1, [0], linewidth = 2)
lsgrid = labelslidergrid!(fig,
["scale", "x-reference", "y-reference"], #edited from original
Ref(LinRange(-10:0.01:10));
formats = [x -> "$(round(x, digits = 2))"],
labelkw = Dict([(:fontsize, 30)]),
sliderkw = Dict([(:linewidth, 24)]),
valuekw = Dict([(:fontsize, 30)])
)
# set starting position for slope
set_close_to!(lsgrid.sliders[1], 1.0)
# layout sliders
sl_sublayout = GridLayout(height = 150)
fig[2, 1] = sl_sublayout
fig[2, 1] = lsgrid.layout
# draw a function
x = -10:0.01:10
m = @lift($scale .* x.^2) #quadratic function #edited from original
line1 = lines!(ax1, x, m, color = :blue, linewidth = 5) #edited from original
# create listeners
scale = lsgrid.sliders[1].value #edited from original
xreference = lsgrid.sliders[2].value #edited from original
yreference = lsgrid.sliders[3].value #added
# xreference, yreference are Float32s
# but for arrows! below we need vectors of Float32s, so we promote them here
# arrow base points
xbase = @lift([$xreference])
ybase = @lift([$yreference])
#new multi-variable scalar-valued functions
p(x,y,scale) = (x + scale * y-1)^2/(scale^2) #added
z(x,y,scale) = cbrt(-p(x,y,scale)/2) #added
# arrow head points
# note: here we also return vectors
xhead = lift(xreference, yreference, scale) do x, y, s
return [ x/1 + 2*s * z(x,y,s) ]
end
yhead = lift(xreference, yreference, scale) do x, y, s
return [ y + z(x,y,s) ]
end
arrows!(ax1, xbase, ybase, xhead, yhead)
display(fig)
PS: I knwo they changed the textsize to fontsize. Is there somthing else importent it missed to change?