forked from artynusov/MacTimeLog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphView.py
More file actions
91 lines (67 loc) · 2.8 KB
/
Copy pathGraphView.py
File metadata and controls
91 lines (67 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# GraphView.py
# View for displaying charts
# `
# Copyright 2009 Artem Yunusov. All rights reserved.
#
from Foundation import *
from AppKit import *
from Charts import CocoaHorizontalBarChart, Bar, Header
class GraphView(NSView):
"""View for displaying Charts"""
_data = []
_scale = 10
_convFunction = None
scrollView = None
def initWithFrame_(self, frame):
self = super(GraphView, self).initWithFrame_(frame)
if self:
pass
return self
def _fillBackground(self, width, height):
NSColor.colorWithCalibratedRed_green_blue_alpha_(0.95,0.95,0.95, 1.0).setFill()
drawingPath = NSBezierPath.bezierPath()
drawingPath.appendBezierPathWithRect_(NSMakeRect(1, 1, width - 2, height - 2))
drawingPath.fill()
def isFlipped(self):
return True
def setScrollView(self, sv):
self.scrollView = sv
def setData(self, rawData, dataType):
pt = NSMakePoint(0.0, 0.0)
self.scrollView.documentView().scrollPoint_(pt)
data = []
oliveGradient = ((0.90,0.92,0.85, 1.0), (0.81,0.83,0.76, 1.0))
grayGradient = ((0.6,0.6,0.6, 1.0), (0.70,0.70,0.70, 1.0))
someGradient = ((0.90,0.71,0.54, 0.9), (1.,0.81,0.64, 0.9))
getColor = lambda t: oliveGradient if t =="work" else grayGradient
if dataType == "tasks":
for k in rawData.keys():
data.append(Header(k))
for task, sec in rawData[k]:
data.append(Bar(task, sec, gradient=oliveGradient))
else:
for task, sec in rawData:
gradient = someGradient if dataType == "projects" else grayGradient
data.append(Bar(task.replace("**", ""), sec, gradient=gradient))
self._data = data
def setScale(self, scale):
self._scale = scale
def setConversionFunction(self, conv):
self._convFunction = conv
def drawRect_(self, rect):
width = self.frame().size.width
height = self.frame().size.height
chart = CocoaHorizontalBarChart(width, self._scale)
self._fillBackground(width, height)
if self._convFunction:
chart.setConversionFunction(self._convFunction)
chart.setData(self._data)
chart.draw()
if chart.height() >= height:
b = self.frame()
self.setFrame_(NSMakeRect(b.origin.x, b.origin.y, b.size.width, chart.height()))
elif self.scrollView:
b = self.scrollView.frame()
self.setFrame_(NSMakeRect(b.origin.x, b.origin.y, b.size.width-20, b.size.height-10))
self.setNeedsDisplay_(True)