bsw/jbe@0: function ui.bargraph(args) bsw/jbe@19: local text = "" bsw/jbe@19: for i, bar in ipairs(args.bars) do bsw/jbe@19: if #text > 0 then bsw/jbe@19: text = text .. " / " bsw/jbe@19: end bsw/jbe@19: text = text .. tostring(bar.value) bsw/jbe@19: end bsw/jbe@0: ui.container{ bsw/jbe@0: attr = { bsw/jbe@19: class = args.class or "bargraph", bsw/jbe@19: title = tostring(text) bsw/jbe@0: }, bsw/jbe@0: content = function() bsw/jbe@19: local at_least_one_bar = false bsw/jbe@0: for i, bar in ipairs(args.bars) do bsw@2: if bar.value > 0 then bsw/jbe@19: at_least_one_bar = true bsw/jbe@4: local value = bar.value * args.width / args.max_value bsw@2: ui.container{ bsw@2: attr = { bsw@2: style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";", bsw@2: }, bsw@2: content = function() slot.put(" ") end bsw@2: } bsw@2: end bsw/jbe@0: end bsw/jbe@19: if not at_least_one_bar then bsw/jbe@19: slot.put(" ") bsw/jbe@19: end bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: end