chart

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2024 License: MIT Imports: 10 Imported by: 0

README

chart

A command-line tool for rendering bar charts that can be displayed directly in the terminal or in text-based files like Markdown.

Usage

By default, chart accepts line-based data with a numeric value and label text separated by a space or common tabular symbols. It also tolerates additional whitespace, empty lines, common punctuation, and currency symbols:

$ cat examples/quarterly-stats.csv
18.67,2021-Q1
19.45,2021-Q2
20.89,2021-Q3
21.34,2021-Q4
21.78,2022-Q1
22.45,2022-Q2
23.89,2022-Q3
24.34,2022-Q4
23.54,2023-Q1
24.78,2023-Q2
25.89,2023-Q3
26.34,2023-Q4
28.15,2024-Q1
25.44,2023-Q2
$ chart -i examples/quarterly-stats.csv
2021-Q1 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 18.67
2021-Q2 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 19.45
2021-Q3 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 20.89
2021-Q4 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 21.34
2022-Q1 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 21.78
2022-Q2 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 22.45
2022-Q3 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 23.89
2022-Q4 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 24.34
2023-Q1 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 23.54
2023-Q2 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25.44
2023-Q3 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25.89
2023-Q4 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 26.34
2024-Q1 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 28.15

You can also chart the occurrences of lines using the -c/--count flag:

$ cat examples/count-occurrences.txt
Three
Two
Four
Five
Four
One
Three
Three
Five
Two
Five
Four
Five
Four
Five
$ chart -i examples/count-occurrences.txt --count
Three ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
  Two ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
 Four ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 4
 Five ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5
  One ▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1
Piping data

Pipes allow you to feed data to chart, making it easy to chart the output of other terminal commands. For example, if you have a file with newline-delimited JSON data from a source code security scanner, you can chart statistics on identified CWEs. Process the data with jq, count the lines with sort and uniq, and pipe it into chart for visualization:

$ jq -r '.cwe' examples/sast-findings.jsonld | sort | uniq -c | chart
CWE-200 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
 CWE-22 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-23 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-248 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-284 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-307 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-312 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-327 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-362 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-400 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-434 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-502 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-532 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-601 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-611 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-676 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-78 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 6
 CWE-79 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
CWE-798 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-89 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
CWE-918 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-94 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5
Sorting and ordering

By default, the chart displays bars in the order of insertion. This is usually fine, but sorting the chart differently can make the data easier to read and understand. Let's order the CWE chart by label:

$ jq -r '.cwe' examples/sast-findings.jsonld | sort | uniq -c | chart --sort label
CWE-200 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
 CWE-22 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-23 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-248 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-284 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-307 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-312 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-327 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-362 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-400 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-434 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-502 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-532 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-601 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-611 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-676 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-78 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 6
 CWE-79 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
CWE-798 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-89 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
CWE-918 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-94 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5

The chart is now sorted alphabetically, but it's more natural for this data to be sorted by the numbers in the CWE identifiers. By using labelnum as the sorting option, numeric characters are extracted from the labels and sorted as integers:

$ jq -r '.cwe' examples/sast-findings.jsonld | sort | uniq -c | chart --sort labelnum
 CWE-22 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-23 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-78 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 6
 CWE-79 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
 CWE-89 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
 CWE-94 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5
CWE-200 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-248 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-284 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-307 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-312 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-327 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-362 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-400 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-434 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-502 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-532 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-601 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-611 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-676 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-798 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-918 ▇▇▇▇▇▇▇▇▇▇ 1

You can also sort the chart by value and specify the order. Let's sort by value in descending order to easily identify the most and least common weaknesses:

$ jq -r '.cwe' examples/sast-findings.jsonld | sort | uniq -c | chart --sort value --desc
 CWE-89 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
 CWE-79 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7
 CWE-78 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 6
 CWE-94 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 5
CWE-327 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-312 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 3
CWE-532 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-200 ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
CWE-918 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-798 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-676 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-611 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-601 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-502 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-434 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-400 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-362 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-307 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-284 ▇▇▇▇▇▇▇▇▇▇ 1
CWE-248 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-23 ▇▇▇▇▇▇▇▇▇▇ 1
 CWE-22 ▇▇▇▇▇▇▇▇▇▇ 1
Scaling

Sometimes, smaller values are overshadowed by larger values in the distribution:

$ cat examples/statistics.txt
1.2    Sales leads
3.8    Conversion rate
12.6   Monthly subs
34.9   Quarterly revenue
79.4   Client meetings
158.2  Product launches
367.1  Employees
952.5  Support calls
2764.8 Website traffic
7360.4 Marketing budget
$ chart -i examples/statistics.txt
      Sales leads ▏ 1.2
  Conversion rate ▏ 3.8
     Monthly subs ▏ 12.6
Quarterly revenue ▏ 34.9
  Client meetings ▇ 79.4
 Product launches ▇ 158.2
        Employees ▇▇▇ 367.1
    Support calls ▇▇▇▇▇▇▇ 952.5
  Website traffic ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2764.8
 Marketing budget ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7360.4

Using the --scale flag scales the chart logarithmically, improving readability in these situations:

$ chart -i examples/statistics.txt --scale
      Sales leads ▇▇▇▇▇ 1.2
  Conversion rate ▇▇▇▇▇▇▇▇▇▇ 3.8
     Monthly subs ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 12.6
Quarterly revenue ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 34.9
  Client meetings ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 79.4
 Product launches ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 158.2
        Employees ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 367.1
    Support calls ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 952.5
  Website traffic ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2764.8
 Marketing budget ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7360.4
Output formats

In addition to text-based charts, chart can generate Mermaid XY charts using the --mermaid flag:

$ chart -i examples/count-occurrences.txt --count --sort value --mermaid --title 'Occurrences'
xychart-beta
  title "Occurrences"
  x-axis ["One", "Two", "Three", "Four", "Five"]
  bar [1, 2, 3, 4, 5]

See the rendered chart here.

It can also generate a basic configuration for a Chart.js bar chart using the --chartjs flag:

$ chart -i examples/count-occurrences.txt --count --sort value --chartjs --title 'Occurrences'
// Chart.js configuration (https://www.chartjs.org/docs/latest/configuration/).
// Generated by chart (https://github.com/michenriksen/chart).
const config = {
  type: "bar",
  data: {
    datasets: [{
      data: [1,2,3,4,5],
    }],
    labels: ["One","Two","Three","Four","Five"],
  },
  options: {
    plugins: {
      title: {
        display: true,
        text: "Occurrences"
      }
    }
  }
}
Additional options

See chart --help for additional flags and options.

Installation

Download the latest pre-compiled binary for your operating system from the releases page.

If you have Go installed, you can also install the latest binary with:

go install github.com/michenriksen/chart/cmd/chart@latest

Similar tools

  • termgraph: A more powerful CLI tool, and the inspiration for chart, supporting multiple data sets, colors, and heat maps.
  • spark: Another CLI tool for rendering simple sparklines in the terminal.

Documentation

Index

Constants

View Source
const (
	DefaultSort          = SortNone
	DefaultSortDirection = OrderNone
	DefaultPrecision     = 2
)

Default option values.

Variables

This section is empty.

Functions

func ParseLine

func ParseLine(line string) (float64, string, error)

ParseLine parses a data line into its float64 value and label string.

The line is expected to have the following structure:

<numeric value> <label>

The function tolerates any kind of whitespace between the value and label, as well as currency symbols and punctuation.

Types

type Chart

type Chart struct {
	// contains filtered or unexported fields
}

Chart represents a simple bar chart.

func New

func New(opts ...ChartOption) (*Chart, error)

New creates a new Chart configured with given options.

func (*Chart) Add

func (c *Chart) Add(label string, value float64) *Chart

Add adds the number to a label's value. If label is not registered, it is added to the chart.

func (*Chart) Labels

func (c *Chart) Labels() []string

Labels returns chart labels sorted and ordered according to configuration.

func (*Chart) MaxLabel

func (c *Chart) MaxLabel() string

MaxLabel returns the longest chart label.

func (*Chart) MaxValue

func (c *Chart) MaxValue() float64

MaxValue returns the highest chart value.

func (*Chart) Set

func (c *Chart) Set(label string, value float64) *Chart

Set sets the value for a label.

func (*Chart) Value

func (c *Chart) Value(label string) (float64, error)

Value returns the value for a label. Returns an error if label does not exist.

type ChartOption

type ChartOption func(*Chart) error

ChartOption configures a Chart.

func WithPrecision

func WithPrecision(p int) ChartOption

WithPrecision configures a Chart with a precision for values.

func WithSorting

func WithSorting(sort SortOption, dir SortDirection) ChartOption

WithSorting configures a Chart with bar sorting options.

type Renderer

type Renderer interface {
	// Render renders the given chart and writes it to the writer.
	Render(*Chart, io.Writer) (int, error)
}

Renderer renders a chart to a writer.

type SortDirection

type SortDirection int

SortDirection represents a sorting direction for a Chart.

const (
	OrderNone SortDirection = iota // No ordering.
	OrderAsc                       // Ascending order.
	OrderDesc                      // Descending order.
)

type SortOption

type SortOption int

SortOption represents a sort option for a Chart.

const (
	SortNone           SortOption = iota // No sorting.
	SortByLabel                          // Sort by label alphabetically.
	SortByLabelNumeric                   // Sort by label numerically.
	SortByValue                          // Sort by value.
)

Directories

Path Synopsis
cmd
chart command
internal
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL