Comparing version 0.0.3 to 0.1.0
@@ -9,4 +9,19 @@ var babar = require('../lib/babar'); | ||
height: 10, | ||
color: 'green', | ||
yFractions: 1 | ||
})); | ||
console.log(babar([ | ||
[0, 9], | ||
[1, 20], | ||
[2, 33], | ||
[3, 20], | ||
[4, 12], | ||
[5, 10], | ||
[6, 63], | ||
[7, 21] | ||
], { | ||
width: 80, | ||
height: 10, | ||
color: 'yellow', | ||
maxY: 100 | ||
})); |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var avgBkt, bucketize, createBkt, drawChart, drawRow, drawRowChart, drawRowLabel, minMax, minMaxBkt, normalizeBkt, pointsMinMaxUniqueX, roundToFixed, tc, | ||
var avgBkt, bucketize, createBkt, drawChart, drawRow, drawRowChart, drawRowLabel, minMax, minMaxBkt, normalizeBkt, pointsMinMaxUniqueX, tc, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -14,8 +14,2 @@ | ||
roundToFixed = function(val, fractions) { | ||
var m; | ||
m = Math.pow(10, fractions); | ||
return (Math.round(m * val) / m).toFixed(fractions); | ||
}; | ||
pointsMinMaxUniqueX = function(points) { | ||
@@ -153,6 +147,12 @@ var maxX, maxY, minX, minY, valX, _ref; | ||
bucketize = function(points, numBkts, minX, diffX, h) { | ||
bucketize = function(points, numBkts, minX, diffX, minY, maxY, h) { | ||
var bkt, diff, max, min, _ref; | ||
bkt = avgBkt(createBkt(points, numBkts, minX, diffX)); | ||
_ref = minMaxBkt(bkt), min = _ref.min, max = _ref.max; | ||
if (maxY) { | ||
max = maxY; | ||
} | ||
if (minY) { | ||
min = minY; | ||
} | ||
diff = max - min; | ||
@@ -172,3 +172,3 @@ return { | ||
} | ||
_ref3 = [options.caption, (_ref = options.color) != null ? _ref : 'cyan', (_ref1 = options.width) != null ? _ref1 : 80, (_ref2 = options.height) != null ? _ref2 : 15, options.xFractions, options.yFractions], caption = _ref3[0], color = _ref3[1], width = _ref3[2], height = _ref3[3], xFractions = _ref3[4], yFractions = _ref3[5]; | ||
_ref3 = [options.caption, (_ref = options.color) != null ? _ref : 'cyan', (_ref1 = options.width) != null ? _ref1 : 80, (_ref2 = options.height) != null ? _ref2 : 15, options.xFractions, options.yFractions, options.minX, options.maxX, options.minY, options.maxY], caption = _ref3[0], color = _ref3[1], width = _ref3[2], height = _ref3[3], xFractions = _ref3[4], yFractions = _ref3[5], minX = _ref3[6], maxX = _ref3[7], minY = _ref3[8], maxY = _ref3[9]; | ||
if (color !== 'ascii') { | ||
@@ -178,2 +178,14 @@ require('colors'); | ||
_ref4 = pointsMinMaxUniqueX(points), minX = _ref4.minX, maxX = _ref4.maxX, minY = _ref4.minY, maxY = _ref4.maxY, uniqueX = _ref4.uniqueX; | ||
if (options.minX) { | ||
minX = options.minX; | ||
} | ||
if (options.maxX) { | ||
maxX = options.maxX; | ||
} | ||
if (options.minY) { | ||
minY = options.minY; | ||
} | ||
if (options.maxY) { | ||
maxY = options.maxY; | ||
} | ||
_ref5 = [maxX - minX, maxY - minY], diffX = _ref5[0], diffY = _ref5[1]; | ||
@@ -184,3 +196,3 @@ height -= 1 + !!caption; | ||
} | ||
lblYW = 1 + Math.max(roundToFixed(minY, yFractions).length, roundToFixed(maxY, yFractions).length); | ||
lblYW = 1 + Math.max(minY.toFixed(yFractions).length, maxY.toFixed(yFractions).length); | ||
width -= lblYW; | ||
@@ -192,6 +204,6 @@ numBkts = Math.min(uniqueX, width - lblYW); | ||
} | ||
_ref6 = bucketize(points, numBkts, minX, diffX, height), bkt = _ref6.bkt, min = _ref6.min, max = _ref6.max, diff = _ref6.diff; | ||
_ref6 = bucketize(points, numBkts, minX, diffX, minY, maxY, height), bkt = _ref6.bkt, min = _ref6.min, max = _ref6.max, diff = _ref6.diff; | ||
lblY = []; | ||
for (v = _i = _ref7 = height - 1; _ref7 <= 0 ? _i <= 0 : _i >= 0; v = _ref7 <= 0 ? ++_i : --_i) { | ||
lbl = roundToFixed(min + diff * v / (height - 1), yFractions); | ||
lbl = (min + diff * v / (height - 1)).toFixed(yFractions); | ||
lblY.unshift(lbl); | ||
@@ -201,3 +213,3 @@ } | ||
for (u = _j = 0; 0 <= numBkts ? _j < numBkts : _j > numBkts; u = 0 <= numBkts ? ++_j : --_j) { | ||
lbl = roundToFixed(minX + u * diffX / (numBkts - 1), xFractions); | ||
lbl = (minX + u * diffX / (numBkts - 1)).toFixed(xFractions); | ||
lblXW = Math.max(lblXW, lbl.length); | ||
@@ -221,3 +233,3 @@ } | ||
u = x * lblXI; | ||
lbl = roundToFixed(minX + u * diffX / (numBkts - 1), xFractions); | ||
lbl = (minX + u * diffX / (numBkts - 1)).toFixed(xFractions); | ||
out += lbl; | ||
@@ -224,0 +236,0 @@ out += tc(bktW * lblXI - lbl.length, ' '); |
{ | ||
"name": "babar", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "CLI bar charts", | ||
"main": "lib/babar.js", | ||
"scripts": { | ||
"build:lib": "coffee -o lib -c src/babar.coffee", | ||
"clean": "rimraf lib coverage", | ||
"preversion": "npm run clean", | ||
"version": "npm run build:lib", | ||
"postversion": "git push && git push --tags && npm run clean", | ||
"prepublish": "npm run clean && npm run build:lib", | ||
"dev": "coffee --watch -o lib/ -c src/babar.coffee", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -29,4 +36,5 @@ }, | ||
"devDependencies": { | ||
"coffee-script": "~1.6.3" | ||
"coffee-script": "~1.6.3", | ||
"rimraf": "^2.5.4" | ||
} | ||
} |
@@ -34,3 +34,5 @@ # Babar | ||
npm install babar | ||
```bash | ||
npm install babar | ||
``` | ||
@@ -41,17 +43,20 @@ ## Usage | ||
var babar = require('babar'); | ||
```js | ||
var babar = require('babar'); | ||
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]])); | ||
``` | ||
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]])); | ||
While it does its best to render the data automatically, you can also pass along some options. | ||
var babar = require('babar'); | ||
```js | ||
var babar = require('babar'); | ||
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], { | ||
color: 'green', | ||
width: 40, | ||
height: 10, | ||
color: 'green', | ||
yFractions: 1 | ||
})); | ||
console.log(babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], { | ||
color: 'green', | ||
width: 40, | ||
height: 10, | ||
maxY: 10, | ||
yFractions: 1 | ||
})); | ||
``` | ||
@@ -66,2 +71,6 @@ ## Options | ||
* **yFractions**: number of fractions for y labels, does its best by default | ||
* **minX**: minimum x value for x axle | ||
* **maxX**: maximum x value for x axle | ||
* **minY**: minimum y value for y axle (negative values not supported yet) | ||
* **maxY**: maximum y value for y axle | ||
@@ -68,0 +77,0 @@ ## License |
Sorry, the diff of this file is not supported yet
29513
9
249
98
2