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 poelzi@159: local quorum = args.quorum and args.quorum * args.width / args.max_value or nil poelzi@159: local length = 0 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 poelzi@159: if quorum and quorum < length + value then poelzi@159: local dlength = math.max(quorum - length - 1, 0) poelzi@159: if dlength > 0 then poelzi@159: ui.container{ poelzi@159: attr = { poelzi@159: style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";", poelzi@159: }, poelzi@159: content = function() slot.put(" ") end poelzi@159: } poelzi@159: end poelzi@159: ui.container{ poelzi@159: attr = { bsw@500: class = "quorum", poelzi@159: style = "width: 1px; background-color: " .. (args.quorum_color or "blue") ..";", poelzi@159: }, bsw@500: content = function() slot.put("") end poelzi@159: } poelzi@159: length = dlength + 1 poelzi@159: value = value - dlength poelzi@159: quorum = nil poelzi@159: end poelzi@159: length = length + 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