summaryrefslogtreecommitdiffstats
path: root/src/fringlib/fringrenderer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/fringlib/fringrenderer.py')
-rw-r--r--src/fringlib/fringrenderer.py77
1 files changed, 34 insertions, 43 deletions
diff --git a/src/fringlib/fringrenderer.py b/src/fringlib/fringrenderer.py
index fb9a876..60256e5 100644
--- a/src/fringlib/fringrenderer.py
+++ b/src/fringlib/fringrenderer.py
@@ -2,26 +2,31 @@ import cairo
import pango
from math import *
from fringwalker import sum_list
+from fringutil import *
import os
class Hotspot:
- def __init__(self, minpos, maxpos, path, size, percentage):
- self.minx,self.miny = minpos
- self.maxx,self.maxy = maxpos
+ def __init__(self, is_dir, path, size, value):
+ self.is_dir = is_dir
self.path = path
self.size = size
- self.percentage = percentage
+ self.value = value
+ self.percentage = value*100
-class Segment:
+class SideLink(Hotspot):
- def __init__(self, start, end, path, size):
- self.start, self.end = start, end
- self.path = path
- self.size = size
+ def __init__(self, is_dir, path, size, value, minpos, maxpos):
+ Hotspot.__init__(self, is_dir, path, size, value)
+
+ self.minx,self.miny = minpos
+ self.maxx,self.maxy = maxpos
+
+class Segment(Hotspot):
- def percentage(self):
- return self.end - self.start
+ def __init__(self, is_dir, path, size, start, end):
+ Hotspot.__init__(self, is_dir, path, size, end-start)
+ self.start, self.end = start, end
class FringRenderer:
@@ -37,12 +42,12 @@ class FringRenderer:
self.LABEL_UNTIL_RING = 0
- self.hotspots = []
+ self.side_links = []
self.lookup_data = []
def prepare_layouts(self,ctx):
self.linklayout = ctx.create_layout()
- self.linklayout.set_font_description(pango.FontDescription("sans 10"))
+ self.linklayout.set_font_description(pango.FontDescription("sans 8"))
def draw_segment(self,ctx, ring, start_angle, end_angle, start_hue, end_hue, data, previouspath=""):
@@ -50,7 +55,7 @@ class FringRenderer:
if ring == 0:
self.lookup_data = []
- self.hotspots = []
+ self.side_links = []
while len(self.lookup_data) <= ring:
self.lookup_data.append([])
@@ -59,7 +64,7 @@ class FringRenderer:
ctx.move_to(CENTERX, CENTERY)
if ring == 0:
- self._draw_centered_text(ctx, self._pretty_size(data.the_sum))
+ self._draw_centered_text(ctx, pretty_size(data.the_sum))
n = len(data.data)
i = 0
@@ -77,7 +82,7 @@ class FringRenderer:
if end-start >= .01:
p = previouspath+os.sep+fn
- self.lookup_data[ring].append(Segment(start, end, p, value))
+ self.lookup_data[ring].append(Segment(isinstance(d, sum_list), p, value, start, end))
v = start_hue + (end_hue-start_hue)*1.0*i/n
color = self._choose_color(start_hue + (end_hue-start_hue)*1.0*i/n, ring)
@@ -131,33 +136,34 @@ class FringRenderer:
# write path name and register a hotspot
ctx.move_to(x+xmod,y)
- # register a hotspot ONLY if directory
+ # draw the side link label
if isinstance(d, sum_list):
ctx.set_source_rgb(0,0,1)
- width,height = self._draw_centered_text(ctx, fn, align_x)
- if align_x == 0: width *= -1
- self.__register_hotspot(p,value,end-start,x,y+(height/2),x+(width),y-(height/2))
-
+ width,height = self._draw_centered_text(ctx, fn + "/", align_x)
else:
ctx.set_source_rgb(0.5,0.5,0.5)
width,height = self._draw_centered_text(ctx, fn, align_x)
+ if align_x == 0:
+ width *= -1
+
+ self.__register_side_link(isinstance(d, sum_list),p,value,end-start,x,y+(height/2),x+(width),y-(height/2))
if ring <= self.LABEL_UNTIL_RING:
ctx.move_to(*middle)
ctx.set_source_rgb(0, 0, 0)
# write relative and absolute disk usage
- self._draw_centered_text2(ctx, "%.0f%%" % ((end-start)*100), self._pretty_size(value))
+ self._draw_centered_text2(ctx, "%.0f%%" % ((end-start)*100), pretty_size(value))
last = end
i += 1
def get_hotspot_at(self,x,y):
- for h in self.hotspots:
+ for h in self.side_links:
if x >= h.minx and x <= h.maxx and \
y >= h.miny and y <= h.maxy:
- return (h.path, h.size, h.percentage)
+ return h
def sqr(x):
return x*x
@@ -185,15 +191,12 @@ class FringRenderer:
p = int(maxidx*v) # Initial estimation
while True:
- assert p >= minidx
- assert p <= maxidx
-
d = data[p]
if v <= d.start:
maxidx = p-1
elif v <= d.end:
- return (d.path, d.size, d.percentage())
+ return d
else:
minidx = p+1
@@ -205,12 +208,12 @@ class FringRenderer:
if np == p:
return None
- p = np
+ p = np # Funny!
- def __register_hotspot(self,path,size,percentage,x0,y0,x1,y1):
+ def __register_side_link(self,is_dir,path,size,value,x0,y0,x1,y1):
if x1 < x0: x0,x1 = x1,x0 # swap
if y1 < y0: y0,y1 = y1,y0
- self.hotspots.append(Hotspot( (x0,y0), (x1,y1), path, size, percentage ))
+ self.side_links.append(SideLink(is_dir, path, size, value, (x0,y0), (x1,y1)))
def hsv2rgb(self,h,s,v):
if s<=0:
@@ -235,18 +238,6 @@ class FringRenderer:
return l.the_sum
return l
-
- def _pretty_size(self,size):
- if size >= 1024*1024*1024:
- return "%.1f GiB" % round(size/1024/1024/1024.0)
- elif size >= 1024*1024:
- return "%.1f MiB" % round(size/1024/1024.0)
- elif size >= 1024:
- return "%.1f KiB" % round(size/1024.0)
- else:
- return "%u B" % size
-
-
def _choose_color(self,v, ring):
color = self.hsv2rgb(v, .61, 1-ring*0.1)
return color[0]/256.0, color[1]/256.0, color[2]/256.0,