Giter Site home page Giter Site logo

Comments (4)

HeaTTheatR avatar HeaTTheatR commented on July 24, 2024

Any widget in the RecycleView in which the content is dynamically changed must be managed manually in the apply_selection method.

    def apply_selection(self, rv, index, is_selected, _index=None):
        """
        Called when an item in the list is displayed on the screen.
        Sets the highlight color of the card.
        """

        self.selected = is_selected
        if is_selected:
            self.bg_select_game_card = self.app.theme_cls.primary_color
            self.label_color = (1, 1, 1, 1)
        else:
            self.bg_select_game_card = self.app.theme_cls.bg_normal
            self.label_color = get_color_from_hex("#929292")

from akivymd.

HeaTTheatR avatar HeaTTheatR commented on July 24, 2024

For those who get similar behavior - https://discord.com/channels/423249981340778496/670954391641128960/971412939850543105

from akivymd.

HeaTTheatR avatar HeaTTheatR commented on July 24, 2024
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.factory import Factory as F
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from icecream import ic
from kivy.metrics import dp,sp
from graphs import AKBarChart


Builder.load_string("""
<Barchart>
    size_hint_y: None
    height: dp(200)
    label_size: sp(12)
    bg_color: 202/255,202/255,202/255,1
    bars_color: 128/255,0,0,1
    labels_color: 0,0,0,1
    anim: True
    on_y_values: self.update()

<ScreenOne>:
    rv: rv.__self__
    RecycleView:
        id: rv
        viewclass: 'Barchart'
        data: root.data
        RecycleBoxLayout:
            size_hint: (1, None)
            height: self.minimum_height
            padding: dp(10)
            spacing: dp(20)
            orientation: 'vertical'
            default_size_hint: 1, None
            default_size: None, dp(200)
""")

class Barchart(AKBarChart, RecycleDataViewBehavior):
    x_values = F.ListProperty([1, 2, 3, 4, 5])
    y_values = F.ListProperty([1, 2, 3, 4, 5])
    id = F.NumericProperty()

    def refresh_view_attrs(self, rv, index, data):
        self.x_values = data['x_values']
        self.y_values = data['y_values']
        return super().refresh_view_attrs(rv, index, data)

data = [
    {   
        'x_values': [i, i + 1, i + 2, i + 3],
        'y_values': [10*i, 20*i, 30*i, 40*i],
    } for i in range(9)
] 

class ScreenOne(F.Screen):
    data = data

class MyApp(MDApp):
    def build(self):
        return ScreenOne()

MyApp().run()

https://discord.com/channels/423249981340778496/670954391641128960/971494348057366599

from akivymd.

FilipeMarch avatar FilipeMarch commented on July 24, 2024

As @tuยฎtle explained, the missing piece was updating the chart every time that y_values changes. This can be achieved with the addition of a single line on <BarChart>: on_y_values: self.update()

Final code looks like this:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.factory import Factory as F
from graphs import AKBarChart

Builder.load_string("""
<Barchart>
    size_hint_y: None
    height: dp(200)
    label_size: sp(12)
    bg_color: 202/255,202/255,202/255,1
    bars_color: 128/255,0,0,1
    labels_color: 0,0,0,1
    anim: True
    on_y_values: self.update()

<ScreenOne>:
    RecycleView:
        viewclass: 'Barchart'
        data: root.data
        RecycleBoxLayout:
            size_hint: (1, None)
            height: self.minimum_height
            padding: dp(10)
            spacing: dp(20)
            orientation: 'vertical'
            default_size_hint: 1, None
            default_size: None, dp(200)
""")

class Barchart(AKBarChart):
    pass

data = [
    {   
        'x_values': [i, i + 1, i + 2, i + 3],
        'y_values': [10*i, 20*i, 30*i, 40*i],
    } for i in range(9)
] 

class ScreenOne(F.Screen):
    data = data

class MyApp(MDApp):
    def build(self):
        return ScreenOne()

MyApp().run()```

from akivymd.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.