Skip to content

Commit 8cf4856

Browse files
committed
ascii-62: add bar charts
1 parent 4500e80 commit 8cf4856

File tree

12 files changed

+1285
-182
lines changed

12 files changed

+1285
-182
lines changed

README.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
**Simple ASCII Chart** is a TypeScript package for creating customizable ASCII charts in the terminal. It supports two-dimensional data, multiple series, custom colors, and formatters, making it a versatile solution for terminal-based data visualization.
99

10-
[Interactive demo.](https://simple-ascii-chart.vercel.app/)
10+
[Playground and documentation](https://simple-ascii-chart.vercel.app/)
11+
[NPM](https://www.npmjs.com/package/simple-ascii-chart)
1112

1213
## Installation
1314

@@ -25,9 +26,14 @@ import plot from 'simple-ascii-chart';
2526
const graph = plot(input, settings);
2627
```
2728

29+
## CLI
30+
31+
[CLI tool is available too](https://github.com/gtktsc/simple-ascii-chart-cli)
32+
[NPM](https://www.npmjs.com/package/simple-ascii-chart-cli)
33+
2834
## Playground
2935

30-
Create charts interactively in the [playground](https://simple-ascii-chart.vercel.app/).
36+
Create charts interactively in the [playground](https://simple-ascii-chart.vercel.app/playground).
3137

3238
## API Endpoint
3339

@@ -108,10 +114,13 @@ Customize the `plot` function with a variety of settings:
108114
| `yLabel` | Label for the y-axis. |
109115
| `thresholds` | Defines threshold lines or points with optional colors at specific x or y coordinates. |
110116
| `fillArea` | Fills the area under each line, suitable for area charts. |
117+
| `barChart` | Draws bar chart. |
118+
| `horizontalBarChart`| Draws horizontal bar chart. |
111119
| `hideXAxis` | Hides the x-axis. |
112120
| `hideYAxis` | Hides the y-axis. |
113121
| `symbols` | Symbols for customizing the chart’s appearance, including axis, background, and chart symbols. |
114122
| `legend` | Configuration for a legend, showing series names and position options (`left`, `right`, `top`, `bottom`). |
123+
| `debugMode` | Enables debug mode (`default = false`). |
115124

116125
### Advanced Settings
117126

@@ -864,3 +873,100 @@ Expected Output:
864873
└┬───┬───┬───┬────┬───┬───┬───┬▶
865874
1 2 3 4 5 6 7 8
866875
```
876+
877+
### Bar chart
878+
879+
Input:
880+
881+
```typescript
882+
plot(
883+
[
884+
[0, 3],
885+
[1, 2],
886+
[2, 3],
887+
[3, 4],
888+
[4, -2],
889+
[5, -5],
890+
[6, 2],
891+
[7, 0],
892+
],
893+
{
894+
title: 'bar chart with axis',
895+
barChart: true,
896+
showTickLabel: true,
897+
width: 40,
898+
axisCenter: [0, 0],
899+
},
900+
);
901+
```
902+
903+
Expected Output:
904+
905+
```bash
906+
bar chart with axis
907+
▲ █
908+
4┤ █ █
909+
3┤ █ █ █ █
910+
2┤ █ █ █ █
911+
1┤ █ █ █ █ █
912+
0┤─────┬────┬─────┬────┬─────┬────┬─────┬─▶
913+
-1┤ 1 2 3 4 5 6 7
914+
-2┤ █
915+
-3┤ █
916+
-4┤ █
917+
-5┤
918+
919+
```
920+
921+
### Bar chart
922+
923+
Input:
924+
925+
```typescript
926+
plot(
927+
[
928+
[0, 3],
929+
[1, 2],
930+
[2, 3],
931+
[3, 4],
932+
[4, -2],
933+
[5, -5],
934+
[6, 2],
935+
[7, 0],
936+
],
937+
{
938+
horizontalBarChart: true,
939+
showTickLabel: true,
940+
width: 40,
941+
height: 20,
942+
axisCenter: [3, 1],
943+
},
944+
);
945+
```
946+
947+
Expected Output:
948+
949+
```bash
950+
951+
4┤
952+
953+
████████████████3┤
954+
955+
██████████2┤████████████████
956+
957+
┬─────┬────┬────1┤────┬─────┬────┬─────┬─▶
958+
0 1 2 3 4 5 6 7
959+
0┤██████████████████████
960+
961+
-1┤
962+
963+
-2┤
964+
│█████
965+
-3┤
966+
967+
-4┤
968+
969+
970+
-5┤███████████
971+
972+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "simple-ascii-chart",
3-
"version": "4.1.1",
3+
"version": "4.2.0",
44
"description": "Simple ascii chart generator",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"start": "tsc-watch -p tsconfig.json --preserveWatchOutput -w --onSuccess 'node ./dist/index.js'",
9+
"examples": "tsc-watch -p tsconfig.json --preserveWatchOutput -w --onSuccess 'node ./dist/examples.js'",
910
"lint": "eslint .",
1011
"lint:fix": "eslint . --fix",
1112
"test": "jest --coverage",

0 commit comments

Comments
 (0)