For whatever reason, I was enamored with Alex Chan's snippet of code where a key-value pair list is turned into a passable bar chart for quick demonstration purposes. When writing a blog post mentioning the number of books I've read I wanted to quickly visualize the values, but didn't want to spend too much time on it. The solution above worked wonders! But I wanted the same thing without having to actually open a terminal (heresy, I know), thus this thing was born: the charting solution that might not suit you π
Try the same link as in the demo above, https://gobarchar.usrme.xyz/?2012=8&2013=6&2014=8&2015=14, or just load the site without any parameters to get random data.
- Send data and get chart back
- Perform calculation for average to the nearest integer
- Perform calculation for sum of all values
- Sort ascending or descending, or don't sort at all
- Add the
sort
query parameter and pass eitherasc
ordesc
as the value - The default is to keep the rows ordered as the query parameters are
- Add the
- Replace
%20
HTML entity with a space- Add the
spaces
query parameter and passyes
as the value- Any other value will be disregarded
- The default is to not do any replacing
- Add the
- Display a custom title for the chart to make sharing charts better
- Add the
title
query parameter and any value you want- For
curl
requests the value needs to be HTML encoded- Something like the following could be used to automate this:
curl "http://localhost:8080/?February=5&March=20&title=$(echo 'Title with spaces in it' | python3 -c 'import urllib.parse,sys; print(urllib.parse.quote(sys.stdin.read().strip()))')"
- Alternatively, after rendering the chart with the title in the browser, just copy the generated link from the page
- Something like the following could be used to automate this:
- For
- Add the
(Excuse the pun). Instead of installing the thing, you can also access the same functionality using the instance hosted on Fly at https://gobarchar.usrme.xyz/:
$ curl https://gobarchar.usrme.xyz/
April 7 ββ
February 88 βββββββββββββββββββββββ
June 16 ββββ
March 99 βββββββββββββββββββββββββ
October 19 βββββ
September 98 βββββββββββββββββββββββββ
Avg. 55 ββββββββββββββ
Total 327 βββββββββββββββββββββββββ
Loading the page without any query parameters randomly chooses some data and will do so upon every reload; a link will be presented at the bottom to link to the data. The site should always be available for usage, but if it's not then do open up an issue and I'll see what I can do.
After installation, execute gobarchar
, which by default starts a web server listening on port 8080, though you can specify a different port through the PORT
environment variable. Once the web server is running, you can use something like curl
to perform requests:
$ gobarchar &
[1] 32357
2024/07/26 12:23:13 listening on: 8080
$ curl localhost:8080
2024/07/26 12:23:16 completed in: 87.958Β΅s
August 32 ββββββββββββββββ
February 50 βββββββββββββββββββββββββ
July 7 ββββ
March 6 βββ
November 44 ββββββββββββββββββββββ
September 8 ββββ
Avg. 24.50 βββββββββββββ
Total 147 βββββββββββββββββββββββββ
If no query parameters are provided then random data is generated. The "completed in" log line isn't a part of the chart output, but rather the result of using job control and having the standard output of a background process being interleaved with the standard output of a foreground process.
- using
go install
:
go install github.com/usrme/gobarchar/cmd/...@latest
-
download a binary from the releases page
-
build it yourself (requires Go 1.17+):
git clone https://github.com/usrme/gobarchar.git
cd gobarchar
go build -o gobarchar cmd/gobarchar/main.go
rm -f "${GOPATH}/bin/gobarchar"
rm -rf "${GOPATH}/pkg/mod/github.com/usrme/gobarchar*"
Heavily inspired by the 'Drawing ASCII bar charts' blog post by Alex Chan. If there was any prior art that pretty much does the same thing (present an ASCII chart based on query parameters or request payload), then I honestly wasn't aware of it and just created this for fun.