From 6da3c9304ae0ed4176cfa2f5272d91784089dc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Wed, 23 Jan 2019 05:11:12 +0700 Subject: [PATCH] Update stack graph example --- README.md | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b91fff6..7068dc2 100644 --- a/README.md +++ b/README.md @@ -739,27 +739,21 @@ vicious.register(uptimewidget, vicious.widgets.uptime, "$1 $2:$3", 61) #### Stacked graph -Stacked graphs (aka multigraphs) are not handled by Vicious at the moment, as -it's hard to pass on color index arguments elegantly. But they are not -unusable, far from it. +Stacked graphs are handled specially by Vicious: `format` functions passed to +the corresponding widget types must return an array instead of a string. ```lua -ctext = wibox.widget.textbox() -cgraph = awful.widget.graph() -cgraph:set_width(100):set_height(20) -cgraph:set_stack(true):set_max_value(100) -cgraph:set_background_color("#494B4F") -cgraph:set_stack_colors({ "#FF5656", "#88A175", "#AECF96" }) -vicious.register(ctext, vicious.widgets.cpu, +cpugraph = wibox.widget.graph() +cpugraph:set_stack(true) +cpugraph:set_stack_colors({"red", "yellow", "green", "blue"}) +vicious.register(cpugraph, vicious.widgets.cpu, function (widget, args) - cgraph:add_value(args[2], 1) -- Core 1, color 1 - cgraph:add_value(args[3], 2) -- Core 2, color 2 - cgraph:add_value(args[4], 3) -- Core 3, color 3 + return {args[2], args[3], args[4], args[5]} end, 3) ``` -The snipet above enables graph stacking/multigraph and plots usage of all three -CPU cores on a single graph. The textbox `ctext` is just an empty placeholder. +The snipet above enables graph stacking/multigraph and plots usage of all four +CPU cores on a single graph. #### Substitute widget types' symbols