function Grid(options) {
if (!options.screen) throw "Error: A screen property must be specified in the grid options.\r\n" +
"Note: Release 2.0.0 has breaking changes. Please refer to the README or to https://github.com/yaronn
/blessed-contrib/issues/39"
this.options = options
this.options.dashboardMargin = this.options.dashboardMargin || 0
this.cellWidth = ((100 - this.options.dashboardMargin*2) / this.options.cols)
this.cellHeight = ((100 - this.options.dashboardMargin*2) / this.options.rows)
}...
A grid layout can auto position your elements in a grid layout.
When using a grid, you should not create the widgets, rather specify to the grid which widget to create and with which params.
Each widget can span multiple rows and columns.
`````javascript
var screen = blessed.screen()
var grid = new contrib.grid({rows: 12, cols: 12, screen: screen})
//grid.set(row, col, rowSpan, colSpan, obj, opts)
var map = grid.set(0, 0, 4, 4, contrib.map, {label: 'World Map'})
var box = grid.set(4, 4, 4, 4, blessed.box, {content: 'My Box'})
screen.render()
`````
...function Grid(options) {
if (!options.screen) throw "Error: A screen property must be specified in the grid options.\r\n" +
"Note: Release 2.0.0 has breaking changes. Please refer to the README or to https://github.com/yaronn
/blessed-contrib/issues/39"
this.options = options
this.options.dashboardMargin = this.options.dashboardMargin || 0
this.cellWidth = ((100 - this.options.dashboardMargin*2) / this.options.cols)
this.cellHeight = ((100 - this.options.dashboardMargin*2) / this.options.rows)
}...
A grid layout can auto position your elements in a grid layout.
When using a grid, you should not create the widgets, rather specify to the grid which widget to create and with which params.
Each widget can span multiple rows and columns.
`````javascript
var screen = blessed.screen()
var grid = new contrib.grid({rows: 12, cols: 12, screen: screen})
//grid.set(row, col, rowSpan, colSpan, obj, opts)
var map = grid.set(0, 0, 4, 4, contrib.map, {label: 'World Map'})
var box = grid.set(4, 4, 4, 4, blessed.box, {content: 'My Box'})
screen.render()
`````
...set = function (row, col, rowSpan, colSpan, obj, opts) {
if (obj instanceof Grid) {
throw "Error: A Grid is not allowed to be nested inside another grid.\r\n" +
"Note: Release 2.0.0 has breaking changes. Please refer to the README or to https://github.com/yaronn/blessed-contrib
/issues/39"
}
var top = row * this.cellHeight + this.options.dashboardMargin
var left = col * this.cellWidth + this.options.dashboardMargin
//var options = JSON.parse(JSON.stringify(opts));
var options = {}
options = utils.MergeRecursive(options, opts)
options.top = top + '%'
options.left = left + '%'
options.width = (this.cellWidth * colSpan - widgetSpacing) + "%"
options.height = (this.cellHeight * rowSpan - widgetSpacing) + "%"
if (!this.options.hideBorder)
options.border = {type: "line", fg: this.options.color || "cyan"}
var instance = obj(options)
this.options.screen.append(instance)
return instance
}...
Each widget can span multiple rows and columns.
`````javascript
var screen = blessed.screen()
var grid = new contrib.grid({rows: 12, cols: 12, screen: screen})
//grid.set(row, col, rowSpan, colSpan, obj, opts)
var map = grid.set(0, 0, 4, 4, contrib.map, {label: 'World Map'})
var box = grid.set(4, 4, 4, 4, blessed.box, {content: 'My Box'})
screen.render()
`````
### Carousel
...function MergeRecursive(obj1, obj2) {
if (obj1==null) return obj2
if (obj2==null) return obj1
for (var p in obj2) {
try {
// property in destination object set; update its value
if ( obj2[p].constructor==Object ) {
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch(e) {
// property in destination object not set; create it and set its value
obj1[p] = obj2[p];
}
}
return obj1;
}...
}
var top = row * this.cellHeight + this.options.dashboardMargin
var left = col * this.cellWidth + this.options.dashboardMargin
//var options = JSON.parse(JSON.stringify(opts));
var options = {}
options = utils.MergeRecursive(options, opts)
options.top = top + '%'
options.left = left + '%'
options.width = (this.cellWidth * colSpan - widgetSpacing) + "%"
options.height = (this.cellHeight * rowSpan - widgetSpacing) + "%"
if (!this.options.hideBorder)
options.border = {type: "line", fg: this.options.color || "cyan"}
...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;
}...
return max;
}
function formatYLabel(value, max, min, numLabels, wholeNumbersOnly, abbreviate) {
var fixed = (max/numLabels<1 && value!=0 && !wholeNumbersOnly) ? 2 : 0
var res = value.toFixed(fixed)
return abbreviate?utils.abbreviateNumber(res):res
}
function getMaxXLabelPadding(numLabels, wholeNumbersOnly, abbreviate, min) {
var max = getMaxY()
return formatYLabel(max, max, min, numLabels, wholeNumbersOnly, abbreviate).length * 2;
}
...function getColorCode(color) {
if (Array.isArray(color) && color.length == 3)
{
return x256(color[0],color[1],color[2]);
}
else
{
return color;
}
}...
screen: self.screen
});
var legandText = ""
var maxChars = legendWidth-2
for (var i=0; i<data.length; i++) {
var style = data[i].style || {}
var color = utils.getColorCode(style.line || self.options.style.line)
legandText += '{'+color+'-fg}'+ data[i].title.substring(0, maxChars)+'{/'+color+'-fg}\r\n'
}
self.legend.setContent(legandText)
self.append(self.legend)
}
//iteratee for lodash _.max
...function getTypeName(thing){
if(thing===null)return "[object Null]"; // special case
return Object.prototype.toString.call(thing);
}n/a