mp-007 / kivy_matplotlib_widget

A fast matplotlib rendering for Kivy based on Kivy_matplotlib project and kivy scatter. Matplotlib used 'agg' backend
MIT License
33 stars 6 forks source link

Enhancements of the legend widget #14

Closed kubapilch closed 1 year ago

kubapilch commented 1 year ago

I have worked a bit with the Legend Widget and I have a couple of suggestions what can be improved or maybe better documented how to achieve.

mp-007 commented 1 year ago

Thanks for all the suggestions @kubapilch. For the last part, you can test the new twinx widget here (will be include in next pip version).

https://github.com/mp-007/kivy_matplotlib_widget/tree/main/example_twinx_experimental

kubapilch commented 1 year ago

@mp-007 I just tested it. It works great, I will wait till it's on pip before implementing it in my project.

mp-007 commented 1 year ago

@kubapilch when you say "changing the background color" and "text color", you are talking about the figure or the legend?

kubapilch commented 1 year ago

@kubapilch when you say "changing the background color" and "text color", you are talking about the figure or the legend?

I meant the legend. I changed the background color by doing

LegendRv:
  id: legend_wgt
  figure_wgt: figure_wgt
  size_hint_x: 0.3
  orientation: 'horizontal'
  canvas.before:
      Color:
          rgba: (1, 0, 1, 1)    
      Rectangle:
          pos: self.pos
          size: self.size

Maybe there is a way to bind the color to a property named ex. background_color that would just accept rgba. I feel like that would be much simpler and cleaner to use, like so:

LegendRv:
  id: legend_wgt
  figure_wgt: figure_wgt
  size_hint_x: 0.3
  orientation: 'horizontal'
  background_color: (1, 0, 1, 1)    

The same would go for the text color inside the legend, although here I had to modify the KV string inside legend_widget.py to change it.

Edit: orientation: 'horizontal' was my attempt to make the legend horizontal instead of vertical but this did not work. I also had to modify the legend_widget.py file and change both to 'horizontal' https://github.com/mp-007/kivy_matplotlib_widget/blob/5a9a55d8e23e7f70c62a709b43b3a359037b911b/kivy_matplotlib_widget/uix/legend_widget.py#L340-L347

mp-007 commented 1 year ago

@kubapilch I have add a new horizontal legend https://github.com/mp-007/kivy_matplotlib_widget/tree/main/example_legend_horizontal

kubapilch commented 1 year ago

@mp-007 That is really nice. I will wait with implementing anything till you release it on pip.

Would you consider contributions via pull-requests? I do not know if you would be interested in it, but I can try and make it into one widget that you control from a .kv file instead of two separates.

mp-007 commented 1 year ago

I am open to pull request but I think the legend widget should be a separate file. Otherwise, graph_widget.py, graph_widget_scatter and graph_widget_twinx should be only 1 file.

mp-007 commented 1 year ago

@kubapilch In my last commit 4b635f373cdca663c07dbd5ec4ff6b7635481b4a, I have add text_color property and background_color property.

mp-007 commented 1 year ago

@kubapilch if you need to create your figure in python (no kv) your can do this (modified main.py of basic exemple)


from kivy.utils import platform

#avoid conflict between mouse provider and touch (very important with touch device)
#no need for android platform
if platform != 'android':
    from kivy.config import Config
    Config.set('input', 'mouse', 'mouse,disable_on_activity')

from kivy.lang import Builder
from kivy.app import App
from graph_generator import GraphGenerator
from kivy.properties import ObjectProperty

KV = '''
Screen
    BoxLayout:
        orientation:'vertical'
        BoxLayout:
            size_hint_y:0.2
            Button:
                text:"home"
                on_release:app.home()
            ToggleButton:
                group:'touch_mode'
                state:'down'
                text:"pan" 
                on_release:
                    app.set_touch_mode('pan')
                    self.state='down'
            ToggleButton:
                group:'touch_mode'
                text:"zoom box"  
                on_release:
                    app.set_touch_mode('zoombox')
                    self.state='down' 
            ToggleButton:
                group:'touch_mode'
                text:"cursor"  
                on_release:
                    app.set_touch_mode('cursor')
                    self.state='down'                    

'''

class Test(App):
    lines = []
    figure_wgt=ObjectProperty(None)

    def build(self):      
        self.screen=Builder.load_string(KV)
        return self.screen

    def on_start(self, *args):
        mygraph = GraphGenerator()

        from graph_widget import MatplotFigure 

        self.figure_wgt = MatplotFigure()
        self.figure_wgt.figure = mygraph.fig
        self.screen.children[-1].add_widget(self.figure_wgt)

    def set_touch_mode(self,mode):
        self.figure_wgt.touch_mode=mode

    def home(self):

        self.figure_wgt.home()

Test().run()```
mp-007 commented 1 year ago

@kubapilch I have moved the missing documentation part into a new issue

kubapilch commented 1 year ago

@mp-007 Thanks for keeping me in the loop! It all looks great, I am not going to update the projects yet as we do not want to switch to GitHub commits in our poetry/requirements structure, will wait till full release on pip. I have subscribed to the project repo so I will get a notification.