Need to graph something? Happens to me all the time. And I need some very particular functionality. But that doesn’t mean I want to code it up every time I need it, nor should you have to. Python’s import library mechanism makes “canning” nearly any functionality you can imagine easy to do, and once canned… well, you know the drill. Import libraries are wonderful.So in this case, it was bar graphs I needed. Sometimes at the console, sometimes on web pages. aa_bargraph.py puts that together and makes it usable at several different levels of sophistication, at both the console (in text mode) and within the context of an HTML web page.
For that matter, you could use the text mode graphs on a text web page, but… well, that’s up to you.
Looking at the colored bars in the text mode example image to the right, those were done by adding my aa_ansiicolor.py library and setting a background color for the graphing and alt-graphing characters, which are then set to a space. The default, without color, is to use “=” for graphs, dashes, plus signs and vertical bars for the box (if you want a box.)Here, I called .setLineDrawChars() to get a nice-looking box; that depends on the terminal supporting those characters, but xterm, which is pretty much the most commonly used terminal out there, does — as you see here. So colored, solid bars and line-drawn boxes… not generally a problem. And you can always use “regular characters, or none, as you choose. See the dollar figures to the right of the bars? Yep, aa_bargraph.py did that as well.
All in all, it does what I wanted it to. I hope it’ll be of use to others as well.
Here’s the library, with built-in demos and examples.