changing plot line color in Graph flower

50 visningar
Hoppa till det första olästa meddelandet

husamal...@gmail.com

oläst,
30 nov. 2021 02:05:382021-11-30
till 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

oläst,
30 nov. 2021 11:21:402021-11-30
till 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

oläst,
30 nov. 2021 11:27:522021-11-30
till 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

oläst,
1 dec. 2021 03:31:572021-12-01
till Kivy users support
do you mean modify the source code of  LinePlot widget ?

Elliot Garbus

oläst,
1 dec. 2021 11:54:552021-12-01
till 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

oläst,
1 dec. 2021 16:28:512021-12-01
till 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

oläst,
1 dec. 2021 16:29:152021-12-01
till Kivy users support
Thanks in advance for any help

Elliot Garbus

oläst,
1 dec. 2021 21:32:442021-12-01
till 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!

Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden