Skip to content

Add BarGraph widget & system usage showcase - #1409

Open
a-dmg wants to merge 4 commits into
elkowar:masterfrom
a-dmg:bar-graph
Open

Add BarGraph widget & system usage showcase#1409
a-dmg wants to merge 4 commits into
elkowar:masterfrom
a-dmg:bar-graph

Conversation

@a-dmg

@a-dmg a-dmg commented Nov 28, 2025

Copy link
Copy Markdown

Description

  • introduce a new widget bargraph, it uses dotted bar to show the evolution of a value over time.
  • add freq_avg to EWW_CPU builtin constant
  • add EWW_HOSTNAME constant

Usage

CPU frequency

(defwidget cpu-usage []
	(box :class "widget-box" :orientation "v" :space-evenly false
		(box :class ""
			(label :halign "start"
				:limit-width 25
				:text "Cpu")
			(label :halign "end"
				:text "${round(EWW_CPU.avg, 2)} ${round((EWW_CPU.freq_avg/1000), 2)}Ghz"))
		(bargraph
			:hexpand true :vexpand true 
			:gradiant-style "fire"
			:value {EWW_CPU.avg}
			:min 0.0
			:max 100.0
			:time-range 150000
			:radius 2
			:dynamic false)
))

Network usage

(defwidget net-usage []
	(box :class "widget-box" :orientation "v" :space-evenly false
		(box :class ""
			(eventbox
				:onclick "eww update IFACE_IDX=${IFACE_IDX + 1 == arraylength(IFACE) ? 0 : IFACE_IDX + 1}"
				:onrightclick "eww update IFACE_IDX=${IFACE_IDX == 0 ? arraylength(IFACE)-1 : IFACE_IDX - 1}"
				(label :class ""
					:halign "start"
					:text "  ${IFACE[IFACE_IDX]}"))
			(label :halign "center"
				:text "Upload ${formatbytes(ceil(EWW_NET["${IFACE[IFACE_IDX]}"].NET_UP))}")
			(label :class ""
				:halign "end"
				:text "Download  ${formatbytes(ceil(EWW_NET["${IFACE[IFACE_IDX]}"].NET_DOWN))}"))
		(box :orientation "v" :hexpand true :vexpand true 
			(bargraph
				:hexpand true :vexpand true 
				:value {EWW_NET["${IFACE[IFACE_IDX]}"].NET_DOWN}
				:gradiant-style "dracula"
				:time-range 150000
				:radius 2
				:dynamic true)
			(bargraph
				:hexpand true :vexpand true 
				:value {EWW_NET["${IFACE[IFACE_IDX]}"].NET_UP}
				:flip-y false
				:gradiant-style "dracula"
				:time-range 150000
				:radius 2
				:dynamic true))
))

Showcase

System usage in a btop like fashion:

widget

Additional Notes

  • The implementation is based on the existing graph widget
  • The spacing between dots is configurable via time-range and radius which could be confusing at first...

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented. (I hope so...)
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes. (not sure if I need to)
  • I used cargo fmt to automatically format all code before committing

This commit introduces a new widget `bargraph`, it uses dotted bar to
show evolution of a value over time. It is inspired from btop.
@coderPaddyS

Copy link
Copy Markdown

I've tried this bar-graph feature and it is a) working as expected and b) a nice addition to my bar adding a cpu utilization history. It would be nice if this is added in the near future.

@gwenhael-le-moine

Copy link
Copy Markdown

The screenshots look good.

One nitpick I have is what does adding EWW_HOSTNAME have to do with this? Especially when we can already use get_env("HOSTNAME")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants