Created
January 31, 2019 17:50
-
-
Save jefcolbi/0f6af17013b8e95af70aab2b8d9802ef to your computer and use it in GitHub Desktop.
graph in landscape to portrait
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mk.app import App | |
from mk.manager import ScreenManager, register_screen | |
from mk.screen import Screen | |
from kivy.clock import Clock | |
from kivy.lang import Builder | |
from kivy.logger import Logger | |
from kivy.garden.graph import Graph, MeshLinePlot, SmoothLinePlot | |
import itertools | |
from math import sin, cos, pi | |
from random import randrange, randint | |
from kivy.utils import get_color_from_hex as rgb | |
@register_screen('report_graph') | |
class ReportGraph(Screen): | |
def __init__(self, *args, **kwargs): | |
self.past_days = kwargs.pop('past_days', 7) | |
super(ReportGraph, self).__init__(**kwargs) | |
def on_create(self, event, *args): | |
colors = itertools.cycle([rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')]) | |
graph_theme = {'label_options': | |
{'color': rgb('444444'), # color of tick labels and titles | |
'bold': True}, | |
'background_color': rgb('f8f8f2'), # back ground color of canvas | |
'tick_color': rgb('808080'), # ticks and grid | |
'border_color': rgb('808080')} # border drawn around each graph | |
self.graph = Graph( | |
xlabel='Day', | |
ylabel='Score', | |
x_ticks_minor=1, | |
x_ticks_major= self.past_days // 7, | |
y_ticks_major=1, | |
y_grid_label=True, | |
x_grid_label=True, | |
padding=5, | |
xlog=False, | |
ylog=False, | |
x_grid=False, | |
y_grid=False, | |
xmin=-1*self.past_days, | |
xmax=-1, | |
ymin=0, | |
ymax=10, | |
**graph_theme) | |
plot = SmoothLinePlot(color=next(colors)) | |
plot.points = [(x, randint(1,10)) for x in range(-1*self.past_days, 0)] | |
# for efficiency, the x range matches xmin, xmax | |
self.graph.add_plot(plot) | |
plot = MeshLinePlot(color=next(colors)) | |
plot.points = [(x, randint(1,10)) for x in range(-1*self.past_days, 0)] | |
self.graph.add_plot(plot) | |
self.plot = plot # this is the moving graph, so keep a reference | |
self.add_widget(self.graph) | |
if __name__ == "__main__": | |
class RoutinesApp(App): | |
def build(self): | |
return ReportGraph(past_days=31) | |
root = RoutinesApp() | |
root.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment