Full Code of jstrace/chart for AI

master 27bef25d26a3 cached
7 files
5.0 KB
1.9k tokens
4 symbols
1 requests
Download .txt
Repository: jstrace/chart
Branch: master
Commit: 27bef25d26a3
Files: 7
Total size: 5.0 KB

Directory structure:
gitextract_qm5nh8ee/

├── .gitignore
├── History.md
├── Makefile
├── Readme.md
├── examples/
│   └── simple.js
├── index.js
└── package.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules/


================================================
FILE: History.md
================================================
1.3.3 / 2016-10-06
==================

 * Fix Incorrect dates in history

1.3.2 / 2016-10-06
==================

 * Fix size calculation

1.3.1 / 2016-09-09
==================

 * allow 0 padding

1.3.0 / 2016-09-09
==================

 * add option to set axis character
 * change default axis character to '.'


1.2.0 / 2016-09-05
==================

 * add options to set point characters
 * update docs
 * update repo link

1.1.1 / 2014-03-25
==================

 * rename

1.1.0 / 2014-02-27
==================

 * add excess head clipping for rolling data

1.0.1 / 2014-02-27
==================

 * bump array-matrix to try and get npm to work

1.2.0 / 2014-02-26
==================

 * add value mapping support

1.1.0 / 2014-02-26
==================

 * change to make .sort an option
 * docs


================================================
FILE: Makefile
================================================

test:
	@./node_modules/.bin/mocha \
		--require should \
		--reporter dot \
		--bail

.PHONY: test

================================================
FILE: Readme.md
================================================

# Chart

  Ascii bar chart for nodejs.

  ![](https://dl.dropboxusercontent.com/u/6396913/misc/Screen%20Shot%202014-02-27%20at%208.56.42%20AM.png)

## Installation

```
$ npm install jstrace/chart
```

## Example

 When `data` exceeds the available width the data will "roll" to the tail-end
 of the array. This may become an option in the future, but that's the default
 behaviour for now ;)

```js
var chart = require('chart');
var clear = require('clear');

var data = [1, 2, ...];

clear();
console.log(chart(data, {
  width: 130,
  height: 30,
  pointChar: '█',
  negativePointChar: '░'
}));
```

# License

  MIT


================================================
FILE: examples/simple.js
================================================

var chart = require('..');
var clear = require('clear');

var data = [
  1,
  5,
  5,
  13,
  3,
  2,
  0,
  2,
  34,
  22,
  15,
  12,
  8,
  4,
  3,
  6,
  18,
  -5,
  -15,
  -11,
  -23,
  -3,
  10,
  18,
  23,
  17,
  4,
  5,
  6,
  3,
  12,
  10,
  7,
  -4,
  17,
  30,
  27,
  25,
  23,
  16,
  14,
  12,
  8,
  6,
  4,
  2
];

clear();
console.log(chart(data));


================================================
FILE: index.js
================================================

/**
 * Module dependencies.
 */

var matrix = require('array-matrix');

/**
 * Expose `chart()`.
 */

module.exports = chart;

/**
 * Return ascii chart of `data`.
 *
 * - `width` total chart width [130]
 * - `height` total chart height [30]
 * - `padding` edge padding [3]
 * - `pointChar` character used to plot a point [█]
 * - `negativePointChar` character used to plot a negative point [░]
 * - `axisChar` character used to draw axis [.]
 *
 * @param {Array} data
 * @param {Object} [opts]
 * @return {String}
 * @api public
 */

function chart(data, opts) {
  opts = opts || {};

  // options
  var w = opts.width || 130;
  var h = opts.height || 30;
  var pc = opts.pointChar || '█';
  var nc = opts.negativePointChar || '░';
  var ac = opts.axisChar || '.';

  // padding
  var pad = typeof opts.padding === 'number' ? opts.padding : 3;
  w -= pad * 2;
  h -= pad * 2;

  // setup
  var out = matrix(w, h);
  var m = max(data) || 0;
  var label = Math.abs(m).toString();
  var labelw = label.length;
  var labelp = 1;

  // chart sizes void of padding etc
  var ch = h;
  var cw = w - labelw - labelp;

  // fill
  for (var y = 0; y < h; y++) {
    for (var x = 0; x < w; x++) {
      out[y][x] = ' ';
    }
  }

  // y-axis labels
  for (var i = 0; i < labelw; i++) {
    out[0][i] = label[i];
  }

  out[h - 1][labelw - labelp] = '0';

  // y-axis
  for (var y = 0; y < h; y++) {
    out[y][labelw + labelp] = ac;
  }

  // x-axis
  var x = labelw + labelp;
  while (x < w) {
    out[h - 1][x++] = ac;
    out[h - 1][x++] = ' ';
  }

  // strip excess from head
  // so that data may "roll"
  var space = Math.floor(w / 2) - 1;
  var excess = Math.max(0, data.length - space);
  if (excess) data = data.slice(excess);

  // plot data
  var x = labelw + labelp + 2;
  for (var i = 0; i < data.length; i++) {
    var d = data[i];
    var p = d / m;
    var y = Math.round((h - 2) * p);
    var c = y < 0 ? nc : pc;
    if (y < 0) y = -y;

    while (y--) {
      out[Math.abs(y - h) - 2][x] = c;
    }

    x += 2;
  }

  // Return string
  var str = string(out, h);
  return pad ? padding(str, pad) : str;
}

/**
 * Apply padding.
 */

function padding(str, n) {
  var linew = str.split('\n')[0].length;
  var line = Array(linew).join(' ') + '\n';

  // y
  str = Array(n).join(line) + str;
  str = str + Array(n).join(line);

  // x
  str = str.replace(/^/gm, Array(n).join(' '));
  return str;
}

/**
 * Convert matrix to a string.
 */

function string(out) {
  var buf = [];

  for (var i = 0; i < out.length; i++) {
    buf.push(out[i].join(''));
  }

  return buf.join('\n');
}

/**
 * Return max in array.
 */

function max(data) {
  var n = Math.abs(data[0]);

  for (var i = 1; i < data.length; i++) {
    n = Math.abs(data[i]) > n ? Math.abs(data[i]) : n;
  }

  return n;
}


================================================
FILE: package.json
================================================
{
  "name": "chart",
  "version": "1.3.3",
  "repository": "jstrace/chart",
  "description": "Ascii bar chart",
  "keywords": [
    "ascii",
    "chart",
    "bar",
    "stats",
    "data",
    "cli",
    "terminal"
  ],
  "dependencies": {
    "array-matrix": "1.0.0"
  },
  "devDependencies": {
    "mocha": "*",
    "should": "*",
    "bytes": "~0.2.1",
    "clear": "0.0.1"
  },
  "license": "MIT"
}
Download .txt
gitextract_qm5nh8ee/

├── .gitignore
├── History.md
├── Makefile
├── Readme.md
├── examples/
│   └── simple.js
├── index.js
└── package.json
Download .txt
SYMBOL INDEX (4 symbols across 1 files)

FILE: index.js
  function chart (line 30) | function chart(data, opts) {
  function padding (line 113) | function padding(str, n) {
  function string (line 130) | function string(out) {
  function max (line 144) | function max(data) {
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (6K chars).
[
  {
    "path": ".gitignore",
    "chars": 14,
    "preview": "node_modules/\n"
  },
  {
    "path": "History.md",
    "chars": 801,
    "preview": "1.3.3 / 2016-10-06\n==================\n\n * Fix Incorrect dates in history\n\n1.3.2 / 2016-10-06\n==================\n\n * Fix "
  },
  {
    "path": "Makefile",
    "chars": 99,
    "preview": "\ntest:\n\t@./node_modules/.bin/mocha \\\n\t\t--require should \\\n\t\t--reporter dot \\\n\t\t--bail\n\n.PHONY: test"
  },
  {
    "path": "Readme.md",
    "chars": 620,
    "preview": "\n# Chart\n\n  Ascii bar chart for nodejs.\n\n  ![](https://dl.dropboxusercontent.com/u/6396913/misc/Screen%20Shot%202014-02-"
  },
  {
    "path": "examples/simple.js",
    "chars": 369,
    "preview": "\nvar chart = require('..');\nvar clear = require('clear');\n\nvar data = [\n  1,\n  5,\n  5,\n  13,\n  3,\n  2,\n  0,\n  2,\n  34,\n "
  },
  {
    "path": "index.js",
    "chars": 2794,
    "preview": "\n/**\n * Module dependencies.\n */\n\nvar matrix = require('array-matrix');\n\n/**\n * Expose `chart()`.\n */\n\nmodule.exports = "
  },
  {
    "path": "package.json",
    "chars": 404,
    "preview": "{\n  \"name\": \"chart\",\n  \"version\": \"1.3.3\",\n  \"repository\": \"jstrace/chart\",\n  \"description\": \"Ascii bar chart\",\n  \"keywo"
  }
]

About this extraction

This page contains the full source code of the jstrace/chart GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (5.0 KB), approximately 1.9k tokens, and a symbol index with 4 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!