Skip to content

Commit

Permalink
feat: Initial check-in
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 13, 2024
1 parent 0cb4517 commit 2d9ed4c
Show file tree
Hide file tree
Showing 14 changed files with 2,716 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "ViTest: Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**", "**/node_modules/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "--test-timeout=600000", "${relativeFile}"],
"cwd": "${fileWorkspaceFolder}",
"smartStep": true,
"console": "integratedTerminal"
}
]
}
119 changes: 118 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,119 @@
# thistogram
# Thistogram

A simple text based histogram generator.

## Usage

### Histogram

<!--- @@inject: samples/histogram.js --->

```js
import { histogram } from 'thistogram';

const data = [
['one', 1],
['two', 2],
['three', 3],
];
const hist = histogram(data, { width: 40, maxLabelWidth: 5, title: 'Numbers', headers: ['Label', 'Value'] });
console.log(hist);
```

<!--- @@inject-end: samples/histogram.js --->

Result:

<!--- @@inject: static/histogram.txt --->

```
Numbers
Label ┃ ┃ Value
━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━
one ┃████████▋ ┃ 1
two ┃█████████████████▎ ┃ 2
three ┃██████████████████████████┃ 3
```

<!--- @@inject-end: static/histogram.txt --->

### Point-Min-Max Chart

<!--- @@inject: samples/temperature.js --->

```js
import { histogram } from 'thistogram';

const data = [
['Jan', 2, 1, 6],
['Feb', 2, 0, 6],
['Mar', 4, 2, 10],
['Apr', 8, 4, 13],
['May', 12, 8, 17],
['Jun', 16, 12, 20],
['Jul', 18, 13, 22],
['Aug', 18, 13, 23],
['Sep', 14, 10, 19],
['Oct', 10, 6, 15],
['Nov', 6, 4, 10],
['Dec', 3, 2, 7],
];
const graph = histogram(data, {
width: 80,
maxLabelWidth: 5,
title: 'Temperature Degrees C',
type: 'point-min-max',
headers: ['Month', 'Avg', 'Min', 'Max'],
});
console.log(graph);
```

<!--- @@inject-end: samples/temperature.js --->

<!--- @@inject: static/temperature.txt --->

```
Temperature Degrees C
Month ┃ ┃ Avg ┃ Min ┃ Max
━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━╋━━━━━╋━━━━
Jan ┃ ┣━━●━━━━━━━━┫ ┃ 2 ┃ 1 ┃ 6
Feb ┃┣━━━━●━━━━━━━━┫ ┃ 2 ┃ 0 ┃ 6
Mar ┃ ┣━━━━●━━━━━━━━━━━━━┫ ┃ 4 ┃ 2 ┃ 10
Apr ┃ ┣━━━━━━━━●━━━━━━━━━━━┫ ┃ 8 ┃ 4 ┃ 13
May ┃ ┣━━━━━━━━━●━━━━━━━━━━━┫ ┃ 12 ┃ 8 ┃ 17
Jun ┃ ┣━━━━━━━━●━━━━━━━━━┫ ┃ 16 ┃ 12 ┃ 20
Jul ┃ ┣━━━━━━━━━━━●━━━━━━━━━┫ ┃ 18 ┃ 13 ┃ 22
Aug ┃ ┣━━━━━━━━━━━●━━━━━━━━━━━┫┃ 18 ┃ 13 ┃ 23
Sep ┃ ┣━━━━━━━━●━━━━━━━━━━━┫ ┃ 14 ┃ 10 ┃ 19
Oct ┃ ┣━━━━━━━━━●━━━━━━━━━━━┫ ┃ 10 ┃ 6 ┃ 15
Nov ┃ ┣━━━●━━━━━━━━━┫ ┃ 6 ┃ 4 ┃ 10
Dec ┃ ┣━●━━━━━━━━━┫ ┃ 3 ┃ 2 ┃ 7
```

<!--- @@inject-end: static/temperature.txt --->

## Examples

```
Sine
0 ┃██▊ ┃ 0.00
1 ┃█████▌ ┃ 0.17
2 ┃████████▎ ┃ 0.34
3 ┃██████████▉ ┃ 0.50
4 ┃█████████████▏ ┃ 0.64
5 ┃███████████████▏ ┃ 0.77
6 ┃████████████████▊ ┃ 0.87
7 ┃██████████████████ ┃ 0.94
8 ┃██████████████████▊┃ 0.98
9 ┃███████████████████┃ 1.00
10 ┃██████████████████▊┃ 0.98
11 ┃██████████████████ ┃ 0.94
12 ┃████████████████▊ ┃ 0.87
13 ┃███████████████▏ ┃ 0.77
14 ┃█████████████▏ ┃ 0.64
15 ┃██████████▉ ┃ 0.50
16 ┃████████▎ ┃ 0.34
17 ┃█████▌ ┃ 0.17
18 ┃██▊ ┃ 0.00
19 ┃▏ ┃ -0.17
```
9 changes: 9 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "0.2"
ignorePaths: []
dictionaryDefinitions: []
dictionaries: []
words:
- histo
- thistogram
ignoreWords: []
import: []
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "thistogram",
"version": "1.0.0",
"description": "A simple text based histogram generator",
"type": "module",
"module": "dist/index.js",
"exports": {
".": "./dist/index.js"
},
"scripts": {
"build": "tsc -p .",
"test": "vitest run",
"run:samples": "cd samples && pnpm i && pnpm run:samples",
"update-readme": "pnpm run:samples && inject-markdown README.md"
},
"keywords": [
"histogram",
"Unicode"
],
"author": "Street Side Software",
"license": "MIT",
"devDependencies": {
"@tsconfig/node18": "^18.2.2",
"inject-markdown": "^3.0.0",
"typescript": "^5.3.3",
"vitest": "^1.2.2"
},
"files": [
"dist/**/*.js",
"!**/*.test.*",
"!**/*.map.*"
]
}
Loading

0 comments on commit 2d9ed4c

Please sign in to comment.