changing plot line color in Graph flower

51 views
Skip to first unread message

husamal...@gmail.com

unread,
Nov 30, 2021, 2:05:38 AM11/30/21
to Kivy users support
the attached example is to use Graph flower now I want to change the color during the run time I mean update the color after creating the widget I simply tried to act like the color property is kivy property and change directly but is not work ?

Thanks in advance for any help 
test.py

Elliot Garbus

unread,
Nov 30, 2021, 11:21:40 AM11/30/21
to kivy-...@googlegroups.com

Taking a quick look at the source code for LinePlot, this is not a capability of the library.  You would need to add an on_color event to LinePlot and update the color.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/8bee019a-08d6-4c07-9c19-8521145d91f3n%40googlegroups.com.

 

Tobias HT

unread,
Nov 30, 2021, 11:27:52 AM11/30/21
to kivy-...@googlegroups.com
I've been using graph for a while now but I haven't thought of writing a graph which changes color at runtime. However I believe it can be done, you just have to implement the action yourself by subclassing the plot you want, implement the on_color property to update the graph canvas when a color changes. I'm sorry I can't elaborate more cause I've not tried it myself, but that would be the best way I think it can be done

husamal...@gmail.com

unread,
Dec 1, 2021, 3:31:57 AM12/1/21
to Kivy users support
do you mean modify the source code of  LinePlot widget ?

Elliot Garbus

unread,
Dec 1, 2021, 11:54:55 AM12/1/21
to kivy-...@googlegroups.com

Yes,  I am suggesting modifying the source code.  Another user made a good suggestion, derive a new class from LinePlot and see if you can make the modifications in the child class. 

husamal...@gmail.com

unread,
Dec 1, 2021, 4:28:51 PM12/1/21
to Kivy users support
can some one gives my  some hints

I tried this on Plot source code but its not working

def on_color(self.,instance,color):
    self.color.=color

the method I called but its not working

husamal...@gmail.com

unread,
Dec 1, 2021, 4:29:15 PM12/1/21
to Kivy users support
Thanks in advance for any help

Elliot Garbus

unread,
Dec 1, 2021, 9:32:44 PM12/1/21
to kivy-...@googlegroups.com

Looking at the source code for LinePlot(),

https://github.com/kivy-garden/garden.graph/blob/c83c7382c47d1e0568ea3b6d5edb11bfaa609953/__init__.py#L1212

 

The method, create_drawings, creates a RenderContext, and sets the color and the Line. 

 

I have not used a RenderContext and am not familiar with the underlying OpenGL technology – but this is what I would try:

Create a new class derived from LinePlot.

In your on_color handler, you will need to run the code from create_drawnings. (super().create_drawings()) Perhaps you will need to clear the render context prior.  A quick search of the docs – I did not see a way to clear the render context.  I don’t understand the relationship between the canvas and the render context.  Do some experiments start by changing the color from black to white and white to black.

 

Try using the self._grc.clear() method on the render context, the way in works on  a canvas.

Clear the render context then create a new one with the new color.

 

Good Luck!

Reply all
Reply to author
Forward
0 new messages