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 via NodeJS in Terminal.
Installation
$ npm install cli-graph
Example
// 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.setFunction(function (x) {
return x;
});
console.log(g2.toString());
Running the script above we get the following output:
▲
│
• │ •
│
│
│
• │ •
│
│
• │ •
│
• │ •
│
• │ •
│
• │ •
│
• │ •
────────────────•─•─•─•─•──────────────▶
│
▲
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
| .
------------------------------.----------------------------▶
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
Documentation
new 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
).center
(Object): An object containing:x
(Number): Thex
origin (default:width / 2
)y
(Number): They
origin (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
: Thex
coordinate. - Number
y
: They
coordinate.
Return
- CliGraph The CliGraph instance.
toString()
Stringifies the graph.
Return
- String The stringified graph.
setFunction(foo, min, max)
Adds the function on the graph.
Params
- Function
foo
: A function that receivesx
as the first parameter and returns they
value. - Number
min
: The minimumx
(default: the lowest possible value). - Number
max
: The maximumx
.(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.