Add clear() function to awful.widget.graph and doc fixes (#847)

* awful.widget.graph: add clear() function.

* awful.widget.graph: doc fixes for add_value.
add_value did not show up in generated luadoc. And the value parameter does not need to be between 0 and 1.

* awful.widget.graph: local functions clear and add_value as methods of graph.
This commit is contained in:
Wolfgang Popp 2016-04-26 22:14:09 +02:00 committed by Daniel Hahler
parent ad304a2596
commit 76313263b6
1 changed files with 23 additions and 18 deletions

View File

@ -161,42 +161,46 @@ function graph.fit(_graph)
end
--- Add a value to the graph
-- @param _graph The graph.
-- @param value The value between 0 and 1.
--
-- @param value The value to be added to the graph
-- @param group The stack color group index.
local function add_value(_graph, value, group)
if not _graph then return end
function graph:add_value(value, group)
value = value or 0
local values = _graph._data.values
local max_value = _graph._data.max_value
local values = self._data.values
local max_value = self._data.max_value
value = math.max(0, value)
if not _graph._data.scale then
if not self._data.scale then
value = math.min(max_value, value)
end
if _graph._data.stack and group then
if not _graph._data.values[group]
or type(_graph._data.values[group]) ~= "table"
if self._data.stack and group then
if not self._data.values[group]
or type(self._data.values[group]) ~= "table"
then
_graph._data.values[group] = {}
self._data.values[group] = {}
end
values = _graph._data.values[group]
values = self._data.values[group]
end
table.insert(values, value)
local border_width = 0
if _graph._data.border_color then border_width = 2 end
if self._data.border_color then border_width = 2 end
-- Ensure we never have more data than we can draw
while #values > _graph._data.width - border_width do
while #values > self._data.width - border_width do
table.remove(values, 1)
end
_graph:emit_signal("widget::redraw_needed")
return _graph
self:emit_signal("widget::redraw_needed")
return self
end
--- Clear the graph.
function graph:clear()
self._data.values = {}
self:emit_signal("widget::redraw_needed")
return self
end
--- Set the graph height.
-- @param height The height to set.
@ -253,7 +257,8 @@ function graph.new(args)
_graph._data = { width = width, height = height, values = {}, max_value = 1 }
-- Set methods
_graph.add_value = add_value
_graph.add_value = graph["add_value"]
_graph.clear = graph["clear"]
_graph.draw = graph.draw
_graph.fit = graph.fit