blessed-contrib
Advanced tools
@@ -6,3 +6,3 @@ var blessed = require('blessed') | ||
| function Canvas(options, canvasType) { | ||
| function Canvas(options, canvasType) { | ||
@@ -44,6 +44,6 @@ var self = this | ||
| Canvas.prototype.render = function() { | ||
| Canvas.prototype.render = function() { | ||
| this.clearPos(true); | ||
| var inner = this.ctx._canvas.frame() | ||
| var inner = this.ctx._canvas.frame() | ||
| this.setContent(inner) | ||
@@ -53,2 +53,2 @@ return this._render(); | ||
| module.exports = Canvas | ||
| module.exports = Canvas |
@@ -37,3 +37,3 @@ var blessed = require('blessed') | ||
| Line.prototype.setData = function(data) { | ||
| if (!this.ctx) { | ||
@@ -120,15 +120,33 @@ throw "error: canvas context does not exist. setData() for line charts must be called after the chart has been added to the screen via screen.append()" | ||
| } | ||
| function formatYLabel(value, max, numLabels, wholeNumbersOnly) { | ||
| function abbreviateNumber(value) { | ||
| var newValue = value; | ||
| if (value >= 1000) { | ||
| var suffixes = ["", "k", "m", "b","t"]; | ||
| var suffixNum = Math.floor( (""+value).length/3 ); | ||
| var shortValue = ''; | ||
| for (var precision = 2; precision >= 1; precision--) { | ||
| shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision)); | ||
| var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,''); | ||
| if (dotLessShortValue.length <= 2) { break; } | ||
| } | ||
| if (shortValue % 1 != 0) shortNum = shortValue.toFixed(1); | ||
| newValue = shortValue+suffixes[suffixNum]; | ||
| } | ||
| return newValue; | ||
| } | ||
| function formatYLabel(value, max, numLabels, wholeNumbersOnly, abbreviate) { | ||
| var fixed = (max/numLabels<1 && value!=0 && !wholeNumbersOnly) ? 2 : 0 | ||
| return value.toFixed(fixed) | ||
| var res = value.toFixed(fixed) | ||
| return abbreviate?abbreviateNumber(res):res | ||
| } | ||
| function getMaxXLabelPadding(numLabels, wholeNumbersOnly) { | ||
| function getMaxXLabelPadding(numLabels, wholeNumbersOnly, abbreviate) { | ||
| var max = getMaxY() | ||
| return formatYLabel(max, max, numLabels, wholeNumbersOnly).length * 2; | ||
| return formatYLabel(max, max, numLabels, wholeNumbersOnly, abbreviate).length * 2; | ||
| } | ||
| if (getMaxXLabelPadding(this.options.numYLabels, this.options.wholeNumbersOnly) > xLabelPadding) { | ||
| if (getMaxXLabelPadding(this.options.numYLabels, this.options.wholeNumbersOnly, this.options.abbreviate) > xLabelPadding) { | ||
| xLabelPadding = getMaxXLabelPadding(this.options.numYLabels); | ||
@@ -143,3 +161,3 @@ }; | ||
| var maxLength = 0; | ||
| for(var i = 0; i < labels.length; i++) { | ||
@@ -152,3 +170,3 @@ if(labels[i] === undefined) { | ||
| } | ||
| return maxLength; | ||
@@ -204,3 +222,3 @@ } | ||
| for(var i = 0; i < maxY; i += yLabelIncrement) { | ||
| c.fillText(formatYLabel(i, maxY, this.options.numYLabels, this.options.wholeNumbersOnly), xPadding - xLabelPadding, getYPixel(i)); | ||
| c.fillText(formatYLabel(i, maxY, this.options.numYLabels, this.options.wholeNumbersOnly, this.options.abbreviate), xPadding - xLabelPadding, getYPixel(i)); | ||
| } | ||
@@ -267,3 +285,3 @@ | ||
| }] | ||
| } | ||
@@ -270,0 +288,0 @@ } |
+1
-1
| { | ||
| "name": "blessed-contrib", | ||
| "version": "2.3.7", | ||
| "version": "2.3.8", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
74435
1.2%1636
1.11%