Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Thresholds and Colors #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abrist
Copy link

@abrist abrist commented Feb 20, 2017

Inspiration and Attribution:

Shout out to Alexandre Pretto Nunes (https://github.com/apretto)! Alexandre's PR (206a69d) with the "fire" palette was the inspiration behind these features. Much thanks!

Additional shout out to user79743 for the ansi color table code from: http://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes

Thank you both kindly!

Description:

I use sparkline every day. Usually to provide quick and dirty graphs for spot checking peaks/valleys in data returned from various tools' apis (splunk, tealeaf, etc).
Many of these tools can also return thresholds with the data and I often find that min/max must be checked in order to understand the scale of the peaks vs. valleys.
Additionally, I like ansi colors in general - bash is life.

This commit provides a middle class (eat the rich) feature set to compel spark's output to be more pleasant on the eyes and potentially speed up analysis of data from the shell.

Features: Graph Name/Title, Threshold, Threshold Color, Threshold Inversion, Ansi Color Table, and Color Palettes

Feature Details:

Graph Name/Title (-n "<graph_name>"): Optional graph header with customizable title and min/max value.
-- usage example: ./spark -n "The Graph Title"

Color Palette (-p <color_palette|ansi_csv): Multiple pre-existing palettes to add color to each tick. Palettes can also be specified as an 8 element comma-seperated list of ansi integer color codes (to be passed to tput).

  • Built-in color palettes: fire, ice, earth, smoke, pride, lolcat
    -- usage example: ./spark -p ice
  • Customizable color palette: Comma-separated 8 element list ansi color codes (0-255)
    -- usage example: ./spark -p 212,213,214,215,216,217,218,219

Threshold Value (-t <threshold_value>): All values greater than or equal (or less than or equal with the inversion switch - see below) to the threshold value will result in ticks of the specified threshold color (see below).

Threshold Color (-c <color|ansi_integer>): Apply color to all ticks for values exceeding threshold. This will override any colors specified in the color palette. As with the color palette option, the threshold color option supports ansi integer color codes.
-- usage example: ./spark -c red -t 5
-- usage example: ./spark -c 1 -t 5

Threshold Inversion (-i): Invert the threshold logic from "greater than or equal" to "less than or equal".
-- usage example: ./spark -c red -t 5 -i

Ansi Color Table (-a): Output a table of ansi colors for ease of color lookups.
-- usage example: ./spark -a

Inspiration and Attribution:

Shout out to Alexandre Pretto Nunes (https://github.com/apretto)!  Alexandre's PR (holman@206a69d) with the "fire" palette was the inspiration behind these features.  Much thanks!

Additional shout out to user79743 for the ansi color table code from:  http://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes
Thank you kindly!

Description:

I use sparkline every day.  Usually to provide quick and dirty graphs for spot checking peaks/valleys in data returned from various tools' apis (splunk, tealeaf, etc).
Many of these tools can also return thresholds with the data and I often find that min/max must be checked in order to understand the scale of the peaks vs. valleys.
Additionally, I like ansi colors in general - bash is life.

This commit provides a middle class (eat the rich) feature set to compel spark's output to be more pleasant on the eyes and potentially speed up analysis of data from the shell.

Features: Graph Name/Title, Threshold, Threshold Color, Threshold Inversion, Ansi Color Table, and Color Palettes

Feature Details:

Graph Name/Title (-n "<graph_name>"): Optional graph header with customizable title and min/max value.
-- usage example:  ./spark -n "The Graph Title" <data>

Color Palette (-p <color_palette|ansi_csv): Multiple pre-existing palettes to add color to each tick.  Palettes can also be specified as an 8 element comma-seperated list of ansi integer color codes (to be passed to tput).
- Built-in color palettes: fire, ice, earth, smoke, pride, lolcat
-- usage example:  ./spark -p ice <data>
- Customizable color palette: Comma-separated 8 element list ansi color codes (0-255)
-- usage example:  ./spark -p 212,213,214,215,216,217,218,219 <data>

Threshold Value (-t <threshold_value>): All values greater than or equal (or less than or equal with the inversion switch - see below) to the threshold value will result in ticks of the specified threshold color (see below).

Threshold Color (-c <color|ansi_integer>): Apply color to all ticks for values exceeding threshold.  This will override any colors specified in the color palette.  As with the color palette option, the threshold color option supports ansi integer color codes.
-- usage example:  ./spark -c red -t 5 <data>
-- usage example:  ./spark -c 1 -t 5 <data>

Threshold Inversion (-i): Invert the threshold logic from "greater than or equal" to "less than or equal".
-- usage example:  ./spark -c red -t 5 -i

Ansi Color Table (-a): Output a table of ansi colors for ease of color lookups.
-- usage example:  ./spark -a
@abrist
Copy link
Author

abrist commented Feb 20, 2017

screen shot 2017-02-20 at 5 01 32 pm
screen shot 2017-02-20 at 5 00 27 pm

@abrist
Copy link
Author

abrist commented Feb 20, 2017

Also, it looks like the travis tests are failing, but ./test works on my side:
screen shot 2017-02-20 at 5 24 22 pm

@abrist abrist mentioned this pull request Feb 24, 2017
@Nebuchadrezzar
Copy link

This is a fantastic enhancement. When its going to be accepted?

@kbrock
Copy link

kbrock commented Sep 23, 2019

this is very cool. but it sure adds a bunch to the code. sigh

@abrist
Copy link
Author

abrist commented Sep 23, 2019

I actually have added more recently - including a switch for different output syntax for escaping properly for PS1 support. At this point maybe I should fork?

@kbrock
Copy link

kbrock commented Sep 23, 2019

@abrist at this point - maybe bash is not the right language?

100 lines -> 240 lines is a bit

I also wanted to compare 2 spark lines, and color based upon what had changed from previous values. So there seems to be a lot of different ways to color sparklines.


For me, a sparkline is a simple/small graph that plots multiple data sets on the same graph. The x is linked between the two graphing functions but it has 2 different y values. (one for each function)

Said another way, it displays 2+ different values in a single graph. It can use color, background color, opacity, height, symbols, and many other things to get the effect.

the original graph just did one function - and that is displayed with height.
But it did the min/max normalization, which is very nice.

Your talking about adding another variable by using foreground color. (can probably do opacity depending upon the author)

I do wonder if it makes sense to pass in the second data set like the first is passed in.
Then each data set can have thresholds for colors. If passing in the data is simplified and the implementation is less than 100 lines, then the idea is good, If not, then please scrap my suggestion immediately. ;)

CORRECTION: You are adding color to make the existing dataset easier to understand. Introducing thresholds may make the user interface easier to code. (that way the normalization is not the job of the author)


I did notice there is https://github.com/rrrene/sparkr but that too has been abandoned. There is probably a node project as well if that is your language of choice. (looks like you are a C person)

It would be nice if you could incorporate with one of those projects and/or ask to take over them if you have a bunch of ideas.

also interestingly, it looks like the ruby project does the data approach similar to how I proposed.

@abrist
Copy link
Author

abrist commented Sep 24, 2019

@kbrock I agree that there are more projects in more robust languages out there, though I am partial to bash as it has little in the way of dependencies. My additions were aimed at providing a better interface for understanding the data. The color palettes were just a fun extra. I probably won't pick up an orphaned project to implement these features as they are working fine for my needs in my fork's branch. I do think I will update it at some point with a few of the more recent additions.

I do like your suggestions for more data points, either for better granularity of ticks (by color), or even to superimpose multiple data points per tick. But, that is definitely out of scope for my current needs. These days I mostly use a pleasant color palette, thresholds, and the PS1 syntax addition I have yet to commit.

Edit: I do not shy away from long shell scripts, though I do understand why most folk are reticent about shell script lengths. It is my suspicion that this PR is still open due to the number of line additions in the diff, and I am alright with that. To each their own :) FOSS is wonderful in this regard.

@abrist
Copy link
Author

abrist commented Sep 24, 2019

Here is a preview of some of the options added recently:

This is the current options in my local branch, additions include:

  • Custom tick characters
  • High/Low range
  • PS1 Syntax
  • Graph title separated from graph min/max
  • Rework of the _colorize function for testing

Screen Shot 2019-09-24 at 4 25 31 PM

Example of PS1 syntax in action:
Screen Shot 2019-09-24 at 4 25 54 PM

The code associated with PS1 syntax:
Screen Shot 2019-09-24 at 4 26 32 PM

Anyways, the script is now almost 300 lines (with comments), so this is moving further away from a "simple" shell script.

Cheers :)

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