Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ termgraph data/ex7.dat --color {green,magenta} --stacked

![Stacked Bar Chart](/docs/assets/barchart-stacked.svg)

### Count-first input

Termgraph accepts counts before text labels, so you can pipe the output of
`sort | uniq -c` directly into it:

```bash
printf '%s\n' 'update settings' 'create' 'update settings' | sort | uniq -c | termgraph
```

No extra flag or column-swapping command is needed. For example, `2 update settings`
is read as the label `update settings` with the value `2`.

With whitespace-separated input, numeric words inside a label are also read as
values. For labels such as `HTTP 404`, use a delimiter to keep the entire label in
one field, for example `2,HTTP 404`. A label that is entirely numeric is ambiguous
in count-first input; use the usual label-first order for those rows, such as
`404,2`. See [file and standard-input parsing](docs/data-class.md#file-and-standard-input-parsing)
for details.

### Calendar Heatmap

Calendar Heatmap, expects first column to be date in yyyy-mm-dd
Expand All @@ -116,8 +135,10 @@ $ termgraph --calendar --start-dt 2017-07-01 data/cal.dat

#### Command Line Interface

* Create data file with two columns either comma or space separated.
The first column is your labels, the second column is a numeric data
* Create a data file with labels and numeric values, separated by commas or
whitespace. Text labels can come before or after the values. If every field is
numeric, the first field is treated as the label. See the
[`sort | uniq -c` example](#count-first-input) for count-first input.

* termgraph [datafile]

Expand Down
33 changes: 32 additions & 1 deletion docs/data-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@ The constructor validates that:

## Methods

### File and standard-input parsing

`Data.from_file(filename, args)` reads a file, or standard input when `filename`
is `"-"`. The CLI uses the same parser. For example:

```python
data = Data.from_file("counts.dat", {"delim": ","})
```

By default, a row containing commas is split on commas; otherwise it is split on
whitespace. The CLI's `--delim` option, or the `delim` entry in `args`, selects a
different delimiter. Leading and trailing whitespace around fields is stripped.

A text label can appear before or after its numeric values. These two rows both
describe `update settings` with a value of `2`:

```text
update settings,2
2,update settings
```

Whitespace-separated `2 update settings` also works: consecutive non-numeric
fields form the label. This supports piping `sort | uniq -c` output directly to
`termgraph`, without a `--values-first` flag.

Fields that can be converted to a number are treated as values, so `2 HTTP 404`
would describe `HTTP` with two values, `2` and `404`. Use `2,HTTP 404` to keep the
text and number together as a single label field. If every field is numeric, the
first field is used as the label and the remaining fields are values: `404,2`
means label `404`, value `2`, not the reverse.

### Data Statistics

#### `find_min() -> Union[int, float]`
Expand Down Expand Up @@ -255,4 +286,4 @@ chart = BarChart(data, args)
chart.draw()
```

For more examples of using Data with different chart types, see the [Chart Classes Documentation](chart-classes.md).
For more examples of using Data with different chart types, see the [Chart Classes Documentation](chart-classes.md).
Loading