Skip to content

Commit

Permalink
feat: resizable cpu/mem charts
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfisher committed Feb 3, 2018
1 parent bd00acd commit 484f981
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/UILayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createTopCalculator() {
};
}

class UI extends EventEmitter {
class UILayout extends EventEmitter {
constructor({command, dashboard, version}) {
super();

Expand Down Expand Up @@ -222,4 +222,4 @@ class UI extends EventEmitter {
}
}

module.exports = UI;
module.exports = UILayout;
2 changes: 1 addition & 1 deletion src/ui/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Header {

_render() {
const content = [
`{bold}${this.command}{/bold} `,
`{bold}${blessed.escape(this.command)}{/bold} `,
`[PID: {bold}${this.pid}{/bold}]`,
`[uptime: {bold}${this.time}{/bold}]`,
'{|}',
Expand Down
19 changes: 14 additions & 5 deletions src/ui/SparklineChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ class SparklineChart {
this.screen = screen;
this.props = props;

this._dataArray = [];

this._init();
this._render();

this.screen.on('resize', () => {
this._init();
this._render();
});
}

_init() {
const countLimit = Math.max(this.screen.width - this.title.length - this.valuePadding, 1);

this._dataArray = new Array(countLimit).fill(0);
let oldDataArray = this._dataArray;
if (oldDataArray.length > countLimit) {
oldDataArray = this._dataArray.slice(-countLimit);
}

// first one is allways 100% for the right 0-maxValue scale
this._dataArray[0] = this.maxValue;
this._dataArray = new Array(countLimit - oldDataArray.length).fill(0).concat(oldDataArray);
}

_render(value = 0) {
const graphString = sparkline(this._dataArray)
// first one is allways 100% for the right 0-maxValue scale
const graphString = sparkline([this.maxValue].concat(this._dataArray.slice(1)))
.split('')
.map((s, i) => {
if (i === 0) {
Expand Down Expand Up @@ -73,7 +83,6 @@ class SparklineChart {

this._dataArray.push(validatedValue);
this._dataArray.shift();
this._dataArray[0] = this.maxValue;
this._render(validatedValue);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/scriptLoadCpuMemWithChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function run(title) {

console.log(`Parent process pid: ${process.pid}`);

const cpuCount = os.cpus().length;
const subprocessCount = os.cpus().length - 2 || 1;

for (let i = 0; i < cpuCount - 1 || i === 0; i++) {
for (let i = 0; i < subprocessCount; i++) {
run(i + 1);
}

0 comments on commit 484f981

Please sign in to comment.