3.0.1 β€’ Published 1 year ago

chartscii v3.0.1

Weekly downloads
54
License
MIT
Repository
github
Last release
1 year ago

Chartscii 3.0!

npm.io

npm.io

for command line usage see: chartscii-cli

Chartscii was rewritten from scratch in TypeScript! It includes many new features, improvements and rich formatting capabilities.

What’s new

βœ… Full width and height control.
βœ… New padding and barSize options!
βœ… New orientation option! vertical charts are here!
βœ… New rich styl3 formatting support!
βœ… New Emoji characters support! *

install

npm install chartscii

usage

chartscii accepts an array of data objects, with optional labels, and outputs an ascii bar chart.

usage example

import Chartscii from "chartscii";

const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const options = {
  title: "chartscii",
  width: 50,
  theme: "pastel",
  color: "pink",
  colorLabels: true,
  barSize: 2,
  orientation: "vertical"
};
const chart = new Chartscii(data, options);
console.log(char.create());

npm.io

Input

Chartscii accepts an array of data points to draw the chart.

This can be an array of numbers, or an array of chart points as explained below.

number[]

If you provide an array of numbers, chartscii will draw each bar using the provided values.

Value is scaled to width/height of chart, depending on the orientation option.

example

import Chartscii from "chartscii";

const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const chart = new Chartscii(data);
console.log(chart.create());

npm.io

ChartPoint[]

For maximum flexibility, provide an array of chart points. This will allow you to customize the following properties:

namedescriptiontypedefault
labelbar labelstringpoint.value
valuebar valuenumberN/A
colorbar colorstringoptions.color

example

import Chartscii from 'chartscii';

const data = [{ label: 'label', value: 2, color: 'pink' }, { label: 'label', value: 2, color: 'purple' }, { label: 'label', value: 2, color: 'marine' },];
const chart = new Chartscii(data, { colorLabels: true });
console.log(chart.create());

npm.io

Options

You can customize the look and size of the chart, as well as rich formatting for labels provided by styl3.

default options

Chartscii accepts customization options as a second argument and will merge the provided options with the following one:

const options: ChartOptions = {
  percentage: false,
  colorLabels: false,
  sort: false,
  reverse: false,
  naked: false,
  labels: true,
  color: undefined,
  fill: undefined,
  width: 100,
  height: 10,
  padding: 0,
  barSize: 1,
  title: "",
  char: "β–ˆ",
  orientation: "horizontal",
  theme: "",
  structure: {
    x: "═",
    y: "β•’",
    axis: "β•‘",
    topLeft: "β•”",
    bottomLeft: "β•š"
  }
};

customization options

namedescriptiontypedefault
percentagecalculate and show percentage databooleanfalse
colorLabelscolor labels with provided color per label, or color provided to optionbooleanfalse
sortsort the input databooleanfalse
reversereverse the input databooleanfalse
nakeddon’t print chart structure ascii charactersbooleanfalse
labelsshow labelsbooleantrue
colorfallback color or unified char bars colorstringundefined
filluse this character to fill remaining chart bar spacestringundefined
maxValuevalues are scaled proportionate to this value. otherwise the max will be calculated from the provided data.numberundefined
widthwidth of chartnumber100
heightheight of chartnumber10
paddingpadding between barsnumber0
barSizesize of each barnumber1
titlechart titlestringundefined
charuse this character to draw the chart barsstringβ–ˆ
orientationhorizontal or verticalstringhorizontal
themestyl3's themesstringundefined
structureuse these characters to draw the enclosing chart borders.object{ x: '═', y: 'β•’', bottomLeft: 'β•š', axis: 'β•‘', topLeft: 'β•”' }

chartscii + styl3 = ❀️

You can use styl3’s formatting for cool themes, built-in color names and rich label formatting.

You should check out styl3 for a full list of customization options.

example

const colors = [
  "red",
  "green",
  "yellow",
  "blue",
  "purple",
  "pink",
  "cyan",
  "orange"
];

const data = [];
for (let i = 0; i < colors.length; i++) {
  const color = colors[i];
  data.push({ value: i + 1, color, label: `@invert ${i}@`, theme: "pastel" });
}

const chart = new Chartscii(data, {
  fill: "β–‘",
  colorLabels: true,
  orientation: "vertical"
});

console.log(chart.create());

npm.io

examples

here are some examples of charts using styl3's formatting on the chart labels.

!TIP
you can run more examples from the ./examples/ directory of this repository using ts-node.
for example npx ts-node examples/loaders.ts

vertical

optionschart
beach theme with italic and bold labels with a bar size of 2npm.io
pastel theme with bold and underlined labels with padding of 2npm.io
lush theme with strikedout labels no padding and emojinpm.io
lush theme with underlined labels no padding and no axis structure charnpm.io
standard theme with dimmed and italic labels and padding 1npm.io
pastel theme with inverted and underlined labels with a dark fill characternpm.io

horizontal

optionschart
pastel theme with bold labels and percentagenpm.io
lush theme with inverted labels and naked chartnpm.io
beach theme with underlined labels and different structure charactersnpm.io
pastel theme with padding of 1 and custom charnpm.io
pastel theme with naked chart - can be used to create loadersnpm.io

Unicode issues

Unfortunately, there are some known issues with specific unicode characters width.
This means that some emoji/unicode characters renders as 2 characters wide (or more) instead of 1, which is not a problem in itself.
The problem is that Javscript determines this length as 1, which creates an issue with label alignment, or drawing the chart bars correctly.

!WARNING
If you have issues with label alignment, or the chart bars aren't spaced correctly - you are probably using an emoji/unicode character which produce the wrong width in javascript.

If you encounter this issue unfortunately the current solution is to simply use a different emoji.
(For example: πŸ”₯ works well while βœ… will result in a misaligned chart).
PRs for this problem are more than welcome.

2.1.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.1-dev

1 year ago

2.0.2-dev

1 year ago

2.0.0-dev

1 year ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.8

4 years ago

1.2.9

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.0.44

5 years ago

1.0.46

5 years ago

1.0.41

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago