Comments (4)
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.
For those who get similar behavior - https://discord.com/channels/423249981340778496/670954391641128960/971412939850543105
from akivymd.
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.
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)
- No module named 'kivymd.components' HOT 1
- Disable - Swipe - akivymd-SwipeMenu
- How to Use kivymd-components/akivymd in buildozer HOT 4
- AKBarChart is not showing all the y values correctly HOT 1
- Turn the ScrollView in AKToolbarLayout to RecycleView HOT 2
- Allow more Exposure to MDIcon in AKBottomNaviagtion(2)
- Smallest value bar doesn't plot.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from akivymd.