Implement widget float_time into graph view
This commit is contained in:
1 parent
837fdd5018
commit
c4aff19051
3 files changed
+75
-4
No files matched your search
@@ -1,6 +1,7 @@
|
||||
from graph import Graph
|
||||
from tryton.common import hex2rgb, lighten
|
||||
import locale
|
||||
import math
|
||||
|
||||
|
||||
class Bar(Graph):
|
||||
@@ -51,11 +52,19 @@ class Bar(Graph):
|
||||
|
||||
highlight = False
|
||||
draw_bars = []
|
||||
yfields_float_time = [x.get('key', x['name']) for x in self.yfields
|
||||
if x.get('widget')]
|
||||
for bar in self.bars:
|
||||
if intersect(bar, event):
|
||||
if not bar.highlight:
|
||||
bar.highlight = True
|
||||
label = locale.format('%.2f', bar.yval, True)
|
||||
if bar.yname in yfields_float_time:
|
||||
label = '%02d:%02d' % (math.floor(abs(bar.yval)),
|
||||
round(abs(bar.yval) % 1 + 0.01, 2) * 60)
|
||||
if bar.yval < 0:
|
||||
label = '-' + label
|
||||
else:
|
||||
label = locale.format('%.2f', bar.yval, True)
|
||||
label += '\n'
|
||||
label += str(self.labels[bar.xname])
|
||||
self.popup.set_text(label)
|
||||
@@ -134,6 +143,21 @@ class VerticalBar(Bar):
|
||||
xlabels = super(VerticalBar, self).XLabels()
|
||||
return [(x[0] + (self.xscale / 2), x[1]) for x in xlabels]
|
||||
|
||||
def YLabels(self):
|
||||
ylabels = super(VerticalBar, self).YLabels()
|
||||
if len([x.get('key', x['name']) for x in self.yfields
|
||||
if x.get('widget')]) == len(self.yfields):
|
||||
|
||||
def format(val):
|
||||
val = eval(val)
|
||||
res = '%02d:%02d' % (math.floor(abs(val)),
|
||||
round(abs(val) % 1 + 0.01, 2) * 60)
|
||||
if val < 0:
|
||||
res = '-' + res
|
||||
return res
|
||||
return [(x[0], format(x[1])) for x in ylabels]
|
||||
return ylabels
|
||||
|
||||
def _getShadowRectangle(self, x, y, w, h):
|
||||
return (x-2, y-2, w+4, h+2)
|
||||
|
||||
@@ -180,6 +204,17 @@ class HorizontalBar(Bar):
|
||||
|
||||
def XLabels(self):
|
||||
ylabels = super(HorizontalBar, self).YLabels()
|
||||
if len([x.get('key', x['name']) for x in self.yfields
|
||||
if x.get('widget')]) == len(self.yfields):
|
||||
|
||||
def format(val):
|
||||
val = eval(val)
|
||||
res = '%02d:%02d' % (math.floor(abs(val)),
|
||||
round(abs(val) % 1 + 0.01, 2) * 60)
|
||||
if val < 0:
|
||||
res = '-' + res
|
||||
return res
|
||||
return [(x[0], format(x[1])) for x in ylabels]
|
||||
return [(x[0], x[1]) for x in ylabels]
|
||||
|
||||
def _getShadowRectangle(self, x, y, w, h):
|
||||
|
||||
@@ -111,13 +111,22 @@ class Line(Graph):
|
||||
|
||||
highlight = False
|
||||
draw_points = []
|
||||
yfields_float_time = [x.get('key', x['name']) for x in self.yfields
|
||||
if x.get('widget')]
|
||||
for point in self.points:
|
||||
if point == nearest[0] and nearest[1] < dia / 100:
|
||||
if not point.highlight:
|
||||
point.highlight = True
|
||||
label = keys2txt[point.yname]
|
||||
label += '\n'
|
||||
label += locale.format('%.2f', point.yval, True)
|
||||
if point.yname in yfields_float_time:
|
||||
val = '%02d:%02d' % (math.floor(abs(point.yval)),
|
||||
round(abs(point.yval) % 1 + 0.01, 2) * 60)
|
||||
if point.yval < 0:
|
||||
val = '-' + val
|
||||
label += val
|
||||
else:
|
||||
label += locale.format('%.2f', point.yval, True)
|
||||
label += '\n'
|
||||
label += str(self.labels[point.xname])
|
||||
self.popup.set_text(label)
|
||||
@@ -170,6 +179,21 @@ class Line(Graph):
|
||||
ids = self.ids[point.xname]
|
||||
self.action_keyword(ids, window)
|
||||
|
||||
def YLabels(self):
|
||||
ylabels = super(Line, self).YLabels()
|
||||
if len([x.get('key', x['name']) for x in self.yfields
|
||||
if x.get('widget')]) == len(self.yfields):
|
||||
|
||||
def format(val):
|
||||
val = eval(val)
|
||||
res = '%02d:%02d' % (math.floor(abs(val)),
|
||||
round(abs(val) % 1 + 0.01, 2) * 60)
|
||||
if val < 0:
|
||||
res = '-' + res
|
||||
return res
|
||||
return [(x[0], format(x[1])) for x in ylabels]
|
||||
return ylabels
|
||||
|
||||
|
||||
class Point(object):
|
||||
|
||||
|
||||
@@ -143,10 +143,22 @@ class Pie(Graph):
|
||||
if slice.startAngle <= angle <= slice.endAngle:
|
||||
if not slice.highlight:
|
||||
slice.highlight = True
|
||||
if self.yfields[0].get('widget') == 'float_time':
|
||||
val = slice.fraction * self.sum
|
||||
value = '%02d:%02d' % (math.floor(abs(val)),
|
||||
round(abs(val) % 1 + 0.01, 2) * 60)
|
||||
if val < 0:
|
||||
value = '-' + value
|
||||
sum = '%02d:%02d' % (math.floor(abs(self.sum)),
|
||||
round(abs(self.sum) % 1 + 0.01, 2) * 60)
|
||||
if self.sum < 0:
|
||||
sum = '-' + sum
|
||||
else:
|
||||
value = locale.format('%.2f', slice.fraction * self.sum)
|
||||
sum = locale.format('%.2f', self.sum)
|
||||
label = '%s (%s%%)\n%s/%s' % (self.labels[slice.xname],
|
||||
locale.format('%.2f', slice.fraction * 100),
|
||||
locale.format('%.2f', slice.fraction * self.sum),
|
||||
locale.format('%.2f', self.sum))
|
||||
value, sum)
|
||||
self.popup.set_text(label)
|
||||
self.queue_draw()
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user