Package Exports
- cli-graph
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cli-graph) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

CLI Graph
Easily draw function graphs in text mode.
Installation
$ npm install cli-graphExample
// Dependencies
var CliGraph = require("../lib");
// Create a new function graph
var g1 = new CliGraph({
height: 20
, width: 20
, center: { y: 18 }
}).setFunction(function (x) {
return x * x / 5;
});
console.log(g1.toString());
// Another function
var g2 = new CliGraph({
height: 30
, width: 30
, marks: {
hAxis: "-"
, vAxis: "|"
, center: "+"
, point: "."
}
});
g2.setFunctionX(function (x) {
return x;
});
console.log(g2.toString());Running the script above we get the following output:
▲
│
• │ •
│
│
│
• │ •
│
│
• │ •
│
• │ •
│
• │ •
│
• │ •
│
• │ •
────────────────•─•─•─•─•──────────────▶
│
▲
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
------------------------------.----------------------------▶
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
Documentation
CliGraph(options)
Creates a new CliGraph instance.
Example:
var g = new CliGraph();Params
- Object
options: An object containing the following fields: height(Number): The graph height (default:40).width(Number): The graph width (default:60).aRatio(Number): The horizontal aspect ratio (default:2).center(Object): An object containing:x(Number): Thexorigin (default:width / 2)y(Number): Theyorigin (default:height / 2)
marks(Object): An object containing:hAxis(String): The character for drawing horizontal axis (default"─").vAxis(String): The character for drawing vertical axis (default "│").center(String): The character for axis intersection (default"┼").point(String): The character for drawing points (default"•").rightArrow(String): The character for drawing the right arrow (default"▶").topArrow(String): The character for drawing the top arrow (default"▲").background(String): The background character (default" ").
Return
- CliGraph The CliGraph instance.
addPoint(x, y)
Adds a point on the x and y coordinates.
Params
- Number
x: Thexcoordinate. - Number
y: Theycoordinate.
Return
- CliGraph The CliGraph instance.
toString()
Stringifies the graph.
Return
- String The stringified graph.
setFunctionX(foo, min, max)
Adds the function on the graph, iterating the x axis.
Params
- Function
foo: A function that receivesxas the first parameter and returns theyvalue. - Number
min: The minimumx(default: the lowest possible value). - Number
max: The maximumx.(default: the highest possible value).
Return
- CliGraph The CliGraph instance.
setFunctionY(foo, min, max)
Adds the function on the graph, iterating the y axis.
Params
- Function
foo: A function that receivesyas the first parameter and returns thexvalue. - Number
min: The minimumy(default: the lowest possible value). - Number
max: The maximumy.(default: the highest possible value).
Return
- CliGraph The CliGraph instance.
How to contribute
- File an issue in the repository, using the bug tracker, describing the contribution you'd like to make. This will help us to get you started on the right foot.
- Fork the project in your account and create a new branch:
your-great-feature. - Commit your changes in that branch.
- Open a pull request, and reference the initial issue in the pull request message.
License
See the LICENSE file.