# GLMakie & Observables with GeometryBasis or user defined types

**URL:** https://discourse.julialang.org/t/glmakie-observables-with-geometrybasis-or-user-defined-types/97851
**Category:** Specific Domains
**Tags:** plotting, glmakie, observables
**Created:** [April 24, 2023, 10:36am UTC](https://discourse.julialang.org/t/glmakie-observables-with-geometrybasis-or-user-defined-types/97851 "2023-04-24T10:36:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mpirke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpirke/32/44837_2.png) [@mpirke](https://discourse.julialang.org/u/mpirke)
#### Post date: [April 24, 2023, 10:36am UTC](https://discourse.julialang.org/t/glmakie-observables-with-geometrybasis-or-user-defined-types/97851/1 "2023-04-24T10:36:31Z")

</div>

Hey out there!

I have a question concerning Makie and the use of Observables. Here’s what I liked to do:

```julia
using GLMakie, GeometryBasics
mutable struct foo{T}
    x::Vector{T}
    r::T 
end

function makefig(foo::foo)
    x = Observable(Point2f(foo.a, foo.b))
    r = Observable(foo.r)
    fig, ax, s = poly(Circle(x, r), color=:pink)

    fig, ax, x, r
end

```

Now I want to change the Center and the radius of the circle to change as Im changing x, r like that:

```julia
fooo = foo([1.0, 1.0], 1.0)
fig, ax, x, r = makefig(fooo)
x[] = [1.0, 1.5]
r[] = 0.5

```

But this does not work because there is no method for Circle from GeometryBasics. However if I add a new method for my case like this it again does not update.

Now my question would be how to make this work or whether there is an easier way where I could define own mutable structs as observables and by mutating them the plot changes.

Thanks for any help!

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [April 24, 2023, 11:43am UTC](https://discourse.julialang.org/t/glmakie-observables-with-geometrybasis-or-user-defined-types/97851/2 "2023-04-24T11:43:42Z")

</div>

It helps if you give the exact code that you run: if I run your code I get `type foo has no field a`. Also it helps to have the exact error message. Fixing the previous error, the error message becomes `no method matching (Circle)(::Observable{Point{2, Float32}}, ::Observable{Float64})`.

Indeed there is no method to make a `Circle` from observable values. But you can use the [`@lift` macro](https://docs.makie.org/stable/documentation/nodes/index.html#shorthand_macro_for_lift) to make an observable `Circle` from observable center and radius. This seems to work for me:

```julia
using GLMakie
using GeometryBasics

mutable struct foo{T}
    x::Vector{T}
    r::T 
end

function makefig(foo::foo)
    x = Observable(Point2f(foo.x[1], foo.x[2]))
    r = Observable(foo.r)
    c = @lift(Circle($x, $r))
    fig, ax, s = poly(c, color=:pink)

    fig, ax, x, r
end

fooo = foo([1.0, 1.0], 1.0)
fig, ax, x, r = makefig(fooo)
x[] = [1.0, 1.5]
r[] = 0.5
fig

```

---

<div class="post-metadata">

### Author: ![mpirke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpirke/32/44837_2.png) [@mpirke](https://discourse.julialang.org/u/mpirke)
#### Post date: [April 24, 2023, 11:55am UTC](https://discourse.julialang.org/t/glmakie-observables-with-geometrybasis-or-user-defined-types/97851/3 "2023-04-24T11:55:43Z")

</div>

Ah Im an idiot, should have rerun the whole thing than I would have seen that I copied some old code.  
I appreciate very much that you helped even with my stupid mistake! Thanks!

Yes that’s work for me aswell! Now I also unterstand how to use the @lift macro! Thanks a lot!
