Makie Observables

Hi,
I’m trying to use an interval slider to update xlims on a series plot but the xlims! function is not being triggered when the observables are being changed.

EndDate = Observable(500.0)
DateRange_is = IntervalSlider(fig[4,1],range = (0:100:600), startvalues=(100,500))
LabelText = lift(DateRange_is.interval) do int
    string(int[1]," , ",int[2])
    println("slider changed to ",int[1]," - ",int[2])
    StartDate[] = int[1]
    EndDate[] = int[2]
end
xlims!(Price_ax,StartDate[],EndDate[])

I get no errors but the xlims of the plot dont get updated unless I re-execute
xlims!(Price_ax,StartDate[],EndDate[]) I thought this line would automatically update the plot because I used observables as parameters.

The values StartDate and EndDate are getting updated correctly when the slider is moved but concerningly I noticed in the object browser that there are no listeners for the observables and that
If I change the xlims command to xlims!(Price_ax,StartDate,EndDate) I just get a type error…
ERROR: MethodError: Cannot convert an object of type Observable{Float64} to an object of type Float32

Can anyone tell me if my use case is appropriate and perhaps give me pointers to examples that use widgets and observables to trigger commands like xlims.

Thanks
Steve
Julia 1.6.2
Julia ext 1.4.3
vscode 1.61
Windows 10

Hi Steve,

To listen to observables use on for one observable or orany for multiple

onany(StartDate, EndDate) do start_date, end_date
    xlims!(Price_ax, start_date, end_date)
end

This is now listening for when the observable changes, and then passing the values into xlims with either of StartDate or EndDate changes, and you should see there are listeners for both observables.

Also if you use backticks around code in discourse posts its much easier to read! See

1 Like

You can just call xlims! in your existing lift of DateRange_is.interval.

What you did in xlims!(Price_ax,StartDate[], EndDate[]) was extracting the plain Int values from your two observables and feed them into the function, that doesn’t do any Observable magic. Functions have to be explicitly written to handle observables, and xlims! is not such a function, it doesn’t do any connections on its own. The functions that do that are almost exclusively plotting functions such as lines, scatter, etc.

1 Like

Thanks Max, that gives me a much better understanding of how to setup the listeners. Sorry about the format, fixed now.

1 Like

Thanks Jules, that makes sense. Is there some information on what methods support Observables or do I need to learn how to read the source files?
Thanks
Steve

Not really, but the plotting functions all do, input arguments and attributes. The rest usually doesn’t, unless specified in the docstring. Usually functions that do an action, like changing the x limits, will not take an observable. But you can set up your own observables that call such functions.