From dfa69714f5a558cd929560b5cd0f6d61efef7e17 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 28 Jun 2016 17:25:36 -0400 Subject: [PATCH] piechart: Fix cache and update API --- widgets/piechart.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/widgets/piechart.lua b/widgets/piechart.lua index 5f8c5a5..2e100b5 100644 --- a/widgets/piechart.lua +++ b/widgets/piechart.lua @@ -40,10 +40,10 @@ local function compute_sum(data) end local function draw(self, context, cr, width, height) - if not self._data then return end + if not self._private.data then return end -- Load from cache - local cached = self._cache[width*123+height*89] + local cached = self._private.cache[width*123+height*89] if cached then cr:set_source_surface(cached) cr:paint() @@ -54,14 +54,14 @@ local function draw(self, context, cr, width, height) local cr2 = cairo.Context(img) local radius = (height > width and width or height) / 4 - local sum,start,count = compute_sum(self._data),0,0 - for k,v in pairs(self._data) do + local sum,start,count = compute_sum(self._private.data),0,0 + for k,v in pairs(self._private.data) do local end_angle = start + 2*math.pi*(v/sum) draw_pie(cr2,start,end_angle,radius,colors[math.mod(count,4)+1],width/2,height/2) draw_label(cr2,start+(end_angle-start)/2,radius,width/2,height/2,k) start,count = end_angle,count+1 end - self._cache[width*123+height*89] = img + self._private.cache[width*123+height*89] = img --Paint on the drawable cr:set_source_surface(img) @@ -69,16 +69,16 @@ local function draw(self, context, cr, width, height) end local function set_data(self,data) - self._cached = {} - self._data = data - self:emit_signal("widget::updated") + self._private.cache = {} + self._private.data = data + self:emit_signal("widget::redraw_needed") end local function new(data) if not colors then colors = {color(beautiful.fg_normal),color(beautiful.bg_alternate),color(beautiful.fg_focus),color(beautiful.bg_highlight)} end local im = wibox.widget.imagebox() im.draw,im.set_data = draw,set_data - im._cache = {} + im._private.cache = {} return im end