@socketsecurity/cli-with-sentry 0.15.55 → 0.15.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +2 -2
- package/dist/cli.js +24 -24
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +49 -29
- package/dist/constants.js.map +1 -1
- package/dist/{shadow-bin.js → shadow-npm-bin.js} +6 -6
- package/dist/shadow-npm-bin.js.map +1 -0
- package/dist/{shadow-inject.js → shadow-npm-inject.js} +1 -1
- package/dist/shadow-npm-inject.js.map +1 -0
- package/dist/types/constants.d.mts +9 -5
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/utils.js +5 -5
- package/dist/utils.js.map +1 -1
- package/external/@coana-tech/cli/cli.mjs +122 -7
- package/external/blessed-contrib/lib/layout/grid.js +400 -32
- package/external/blessed-contrib/lib/widget/charts/bar.js +8338 -67
- package/external/blessed-contrib/lib/widget/charts/line.js +17861 -196
- package/external/blessed-contrib/lib/widget/table.js +140 -121
- package/package.json +12 -11
- package/dist/shadow-bin.js.map +0 -1
- package/dist/shadow-inject.js.map +0 -1
- package/external/blessed-contrib/index.js +0 -28
- package/external/blessed-contrib/lib/layout/carousel.js +0 -74
- package/external/blessed-contrib/lib/server-utils.js +0 -73
- package/external/blessed-contrib/lib/utils.js +0 -73
- package/external/blessed-contrib/lib/widget/canvas.js +0 -51
- package/external/blessed-contrib/lib/widget/charts/stacked-bar.js +0 -218
- package/external/blessed-contrib/lib/widget/donut.js +0 -149
- package/external/blessed-contrib/lib/widget/gauge-list.js +0 -106
- package/external/blessed-contrib/lib/widget/gauge.js +0 -125
- package/external/blessed-contrib/lib/widget/lcd.js +0 -451
- package/external/blessed-contrib/lib/widget/log.js +0 -33
- package/external/blessed-contrib/lib/widget/map.js +0 -86
- package/external/blessed-contrib/lib/widget/markdown.js +0 -64
- package/external/blessed-contrib/lib/widget/picture.js +0 -66
- package/external/blessed-contrib/lib/widget/sparkline.js +0 -58
- package/external/blessed-contrib/lib/widget/tree.js +0 -167
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var x256 = require('x256');
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Recursively merge properties of two objects
|
|
7
|
-
*/
|
|
8
|
-
function MergeRecursive(obj1, obj2) {
|
|
9
|
-
if (obj1==null) {
|
|
10
|
-
return obj2;
|
|
11
|
-
}
|
|
12
|
-
if (obj2==null) {
|
|
13
|
-
return obj1;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
for (var p in obj2) {
|
|
17
|
-
try {
|
|
18
|
-
// property in destination object set; update its value
|
|
19
|
-
if ( obj2[p].constructor==Object ) {
|
|
20
|
-
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
|
|
21
|
-
|
|
22
|
-
} else {
|
|
23
|
-
obj1[p] = obj2[p];
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
} catch(e) {
|
|
28
|
-
// property in destination object not set; create it and set its value
|
|
29
|
-
obj1[p] = obj2[p];
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return obj1;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function getTypeName(thing){
|
|
39
|
-
if(thing===null)return '[object Null]'; // special case
|
|
40
|
-
return Object.prototype.toString.call(thing);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function abbreviateNumber(value) {
|
|
44
|
-
var newValue = value;
|
|
45
|
-
if (value >= 1000) {
|
|
46
|
-
var suffixes = ['', 'k', 'm', 'b','t'];
|
|
47
|
-
var suffixNum = Math.floor( (''+value).length/3 );
|
|
48
|
-
var shortValue = '';
|
|
49
|
-
for (var precision = 2; precision >= 1; precision--) {
|
|
50
|
-
shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
|
|
51
|
-
var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
|
|
52
|
-
if (dotLessShortValue.length <= 2) {
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
newValue = shortValue+suffixes[suffixNum];
|
|
57
|
-
}
|
|
58
|
-
return newValue;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getColorCode(color) {
|
|
62
|
-
if (Array.isArray(color) && color.length == 3) {
|
|
63
|
-
return x256(color[0],color[1],color[2]);
|
|
64
|
-
} else {
|
|
65
|
-
return color;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.MergeRecursive = MergeRecursive;
|
|
70
|
-
exports.getTypeName = getTypeName;
|
|
71
|
-
exports.abbreviateNumber = abbreviateNumber;
|
|
72
|
-
exports.getColorCode = getColorCode;
|
|
73
|
-
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Box = require('../../../blessed/lib/widgets/box')
|
|
4
|
-
, InnerCanvas = require('drawille-canvas-blessed-contrib').Canvas
|
|
5
|
-
, Node = require('../../../blessed/lib/widgets/node');
|
|
6
|
-
|
|
7
|
-
function Canvas(options, canvasType) {
|
|
8
|
-
|
|
9
|
-
var self = this;
|
|
10
|
-
|
|
11
|
-
if (!(this instanceof Node)) {
|
|
12
|
-
return new Canvas(options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
options = options || {};
|
|
16
|
-
this.options = options;
|
|
17
|
-
Box.call(this, options);
|
|
18
|
-
|
|
19
|
-
this.on('attach', function() {
|
|
20
|
-
self.calcSize();
|
|
21
|
-
|
|
22
|
-
self._canvas = new InnerCanvas(this.canvasSize.width, this.canvasSize.height, canvasType);
|
|
23
|
-
self.ctx = self._canvas.getContext();
|
|
24
|
-
|
|
25
|
-
if (self.options.data) {
|
|
26
|
-
self.setData(self.options.data);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Canvas.prototype = Object.create(Box.prototype);
|
|
32
|
-
|
|
33
|
-
Canvas.prototype.type = 'canvas';
|
|
34
|
-
|
|
35
|
-
Canvas.prototype.calcSize = function() {
|
|
36
|
-
this.canvasSize = {width: this.width*2-12, height: this.height*4};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
Canvas.prototype.clear = function() {
|
|
40
|
-
this.ctx.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
Canvas.prototype.render = function() {
|
|
44
|
-
|
|
45
|
-
this.clearPos(true);
|
|
46
|
-
var inner = this.ctx._canvas.frame();
|
|
47
|
-
this.setContent(inner);
|
|
48
|
-
return this._render();
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
module.exports = Canvas;
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Box = require('../../../../blessed/lib/widgets/box')
|
|
4
|
-
, Node = require('../../../../blessed/lib/widgets/node')
|
|
5
|
-
, Canvas = require('../canvas')
|
|
6
|
-
, utils = require('../../utils.js');
|
|
7
|
-
|
|
8
|
-
function StackedBar(options) {
|
|
9
|
-
if (!(this instanceof Node)) {
|
|
10
|
-
return new StackedBar(options);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
var self = this;
|
|
14
|
-
Canvas.call(this, options, require('ansi-term'));
|
|
15
|
-
|
|
16
|
-
this.options.barWidth = this.options.barWidth || 6;
|
|
17
|
-
this.options.barSpacing = this.options.barSpacing || 9;
|
|
18
|
-
|
|
19
|
-
if ((this.options.barSpacing - this.options.barWidth) < 3) {
|
|
20
|
-
this.options.barSpacing = this.options.barWidth + 3;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.options.xOffset = this.options.xOffset==null? 5 : this.options.xOffset;
|
|
24
|
-
if (this.options.showText === false)
|
|
25
|
-
this.options.showText = false;
|
|
26
|
-
else
|
|
27
|
-
this.options.showText = true;
|
|
28
|
-
|
|
29
|
-
this.options.legend = this.options.legend || {};
|
|
30
|
-
if (this.options.showLegend === false)
|
|
31
|
-
this.options.showLegend = false;
|
|
32
|
-
else
|
|
33
|
-
this.options.showLegend = true;
|
|
34
|
-
|
|
35
|
-
this.on('attach', function() {
|
|
36
|
-
if (self.options.data) {
|
|
37
|
-
self.setData(self.options.data);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
StackedBar.prototype = Object.create(Canvas.prototype);
|
|
43
|
-
|
|
44
|
-
StackedBar.prototype.calcSize = function() {
|
|
45
|
-
this.canvasSize = {width: this.width-2, height: this.height};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
StackedBar.prototype.getSummedBars = function(bars) {
|
|
49
|
-
var res = [];
|
|
50
|
-
bars.forEach(function(stackedValues) {
|
|
51
|
-
var sum = stackedValues.reduce(function(a,b) {
|
|
52
|
-
return a + b;
|
|
53
|
-
} , 0);
|
|
54
|
-
res.push(sum);
|
|
55
|
-
});
|
|
56
|
-
return res;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
StackedBar.prototype.setData = function(bars) {
|
|
60
|
-
|
|
61
|
-
if (!this.ctx) {
|
|
62
|
-
throw 'error: canvas context does not exist. setData() for bar charts must be called after the chart has been added to the screen via screen.append()';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.clear();
|
|
66
|
-
|
|
67
|
-
var summedBars = this.getSummedBars(bars.data);
|
|
68
|
-
var maxBarValue = Math.max.apply(Math, summedBars);
|
|
69
|
-
if (this.options.maxValue)
|
|
70
|
-
maxBarValue = Math.max(maxBarValue, this.options.maxValue);
|
|
71
|
-
var x = this.options.xOffset;
|
|
72
|
-
for (var i = 0; i < bars.data.length; i++) {
|
|
73
|
-
this.renderBar(x, bars.data[i], summedBars[i], maxBarValue, bars.barCategory[i]);
|
|
74
|
-
x += this.options.barSpacing;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.addLegend(bars, x);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
StackedBar.prototype.renderBar = function(x, bar, curBarSummedValue, maxBarValue, category) {
|
|
81
|
-
/*
|
|
82
|
-
var c = this.ctx
|
|
83
|
-
c.strokeStyle = 'red';
|
|
84
|
-
c.fillRect(0,7,4,0)
|
|
85
|
-
c.strokeStyle = 'blue';
|
|
86
|
-
c.fillRect(0,4,4,1)
|
|
87
|
-
c.strokeStyle = 'green';
|
|
88
|
-
c.fillRect(5,7,4,2)
|
|
89
|
-
return
|
|
90
|
-
*/
|
|
91
|
-
//first line is for label
|
|
92
|
-
const BUFFER_FROM_TOP = 2;
|
|
93
|
-
const BUFFER_FROM_BOTTOM = (this.options.border ? 2 : 0) + (this.options.showText ? 1 : 0);
|
|
94
|
-
|
|
95
|
-
var c = this.ctx;
|
|
96
|
-
c.strokeStyle = 'normal';
|
|
97
|
-
c.fillStyle = 'white';
|
|
98
|
-
if (this.options.labelColor)
|
|
99
|
-
c.fillStyle = this.options.labelColor;
|
|
100
|
-
if (this.options.showText) {
|
|
101
|
-
c.fillText(category, x + 1, this.canvasSize.height - BUFFER_FROM_BOTTOM);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (curBarSummedValue < 0) return;
|
|
105
|
-
var maxBarHeight = this.canvasSize.height - BUFFER_FROM_TOP - BUFFER_FROM_BOTTOM;
|
|
106
|
-
var currentBarHeight = Math.round(maxBarHeight * (curBarSummedValue / maxBarValue));
|
|
107
|
-
//start painting from bottom of bar, section by section
|
|
108
|
-
var y = maxBarHeight + BUFFER_FROM_TOP;
|
|
109
|
-
var availableBarHeight = currentBarHeight;
|
|
110
|
-
for (var i=0; i < bar.length; i++) {
|
|
111
|
-
var currStackHeight = this.renderBarSection(
|
|
112
|
-
x,
|
|
113
|
-
y,
|
|
114
|
-
bar[i],
|
|
115
|
-
curBarSummedValue,
|
|
116
|
-
currentBarHeight,
|
|
117
|
-
availableBarHeight,
|
|
118
|
-
this.options.barBgColor[i]);
|
|
119
|
-
y -= currStackHeight;
|
|
120
|
-
availableBarHeight -= currStackHeight;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
StackedBar.prototype.renderBarSection = function(
|
|
125
|
-
x,
|
|
126
|
-
y,
|
|
127
|
-
data,
|
|
128
|
-
curBarSummedValue,
|
|
129
|
-
currentBarHeight,
|
|
130
|
-
availableBarHeight,
|
|
131
|
-
bg) {
|
|
132
|
-
var c = this.ctx;
|
|
133
|
-
|
|
134
|
-
var currStackHeight = currentBarHeight <= 0?
|
|
135
|
-
0 :
|
|
136
|
-
Math.min(
|
|
137
|
-
availableBarHeight, //round() can make total stacks excceed curr bar height so we limit it
|
|
138
|
-
Math.round(currentBarHeight * (data / curBarSummedValue))
|
|
139
|
-
);
|
|
140
|
-
c.strokeStyle = bg;
|
|
141
|
-
|
|
142
|
-
if (currStackHeight>0) {
|
|
143
|
-
var calcY = y - currStackHeight;
|
|
144
|
-
/*fillRect starts from the point bottom of start point so we compensate*/
|
|
145
|
-
var calcHeight = Math.max(0, currStackHeight-1);
|
|
146
|
-
c.fillRect(
|
|
147
|
-
x,
|
|
148
|
-
calcY,
|
|
149
|
-
this.options.barWidth,
|
|
150
|
-
calcHeight
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
c.fillStyle = 'white';
|
|
154
|
-
if (this.options.barFgColor)
|
|
155
|
-
c.fillStyle = this.options.barFgColor;
|
|
156
|
-
if (this.options.showText) {
|
|
157
|
-
var str = utils.abbreviateNumber(data.toString());
|
|
158
|
-
c.fillText(
|
|
159
|
-
str,
|
|
160
|
-
Math.floor(x + this.options.barWidth/2 + str.length/2),
|
|
161
|
-
calcY + Math.round(calcHeight/2));
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return currStackHeight;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
StackedBar.prototype.getOptionsPrototype = function() {
|
|
169
|
-
return { barWidth: 1
|
|
170
|
-
, barSpacing: 1
|
|
171
|
-
, xOffset: 1
|
|
172
|
-
, maxValue: 1
|
|
173
|
-
, barBgColor: 's'
|
|
174
|
-
, data: { barCategory: ['s']
|
|
175
|
-
, stackedCategory: ['s']
|
|
176
|
-
, data: [ [ 1] ]
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
StackedBar.prototype.addLegend = function(bars, x) {
|
|
184
|
-
var self = this;
|
|
185
|
-
if (!self.options.showLegend) return;
|
|
186
|
-
if (self.legend) self.remove(self.legend);
|
|
187
|
-
var legendWidth = self.options.legend.width || 15;
|
|
188
|
-
self.legend = new Box({
|
|
189
|
-
height: bars.stackedCategory.length+2,
|
|
190
|
-
top: 1,
|
|
191
|
-
width: legendWidth,
|
|
192
|
-
left: x,
|
|
193
|
-
content: '',
|
|
194
|
-
fg: 'green',
|
|
195
|
-
tags: true,
|
|
196
|
-
border: {
|
|
197
|
-
type: 'line',
|
|
198
|
-
fg: 'black'
|
|
199
|
-
},
|
|
200
|
-
style: {
|
|
201
|
-
fg: 'blue',
|
|
202
|
-
},
|
|
203
|
-
screen: self.screen
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
var legandText = '';
|
|
207
|
-
var maxChars = legendWidth-2;
|
|
208
|
-
for (var i=0; i<bars.stackedCategory.length; i++) {
|
|
209
|
-
var color = utils.getColorCode(self.options.barBgColor[i]);
|
|
210
|
-
legandText += '{'+color+'-fg}'+ bars.stackedCategory[i].substring(0, maxChars)+'{/'+color+'-fg}\r\n';
|
|
211
|
-
}
|
|
212
|
-
self.legend.setContent(legandText);
|
|
213
|
-
self.append(self.legend);
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
StackedBar.prototype.type = 'bar';
|
|
217
|
-
|
|
218
|
-
module.exports = StackedBar;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Node = require('../../../blessed/lib/widgets/node')
|
|
4
|
-
, Canvas = require('./canvas');
|
|
5
|
-
|
|
6
|
-
function Donut(options) {
|
|
7
|
-
if (!(this instanceof Node)) {
|
|
8
|
-
return new Donut(options);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
options = options || {};
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.options.stroke = options.stroke || 'magenta';
|
|
14
|
-
this.options.fill = options.fill || 'white';
|
|
15
|
-
this.options.radius = options.radius || 14;
|
|
16
|
-
this.options.arcWidth = options.arcWidth || 4;
|
|
17
|
-
this.options.spacing = options.spacing || 2;
|
|
18
|
-
this.options.yPadding = options.yPadding || 2;
|
|
19
|
-
this.options.remainColor = options.remainColor || 'black';
|
|
20
|
-
this.options.data = options.data || [];
|
|
21
|
-
|
|
22
|
-
Canvas.call(this, options);
|
|
23
|
-
|
|
24
|
-
var self = this;
|
|
25
|
-
this.on('attach', function() {
|
|
26
|
-
this.setData(self.options.data);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Donut.prototype = Object.create(Canvas.prototype);
|
|
31
|
-
|
|
32
|
-
Donut.prototype.calcSize = function() {
|
|
33
|
-
this.canvasSize = {width: Math.round(this.width*2-5), height: this.height*4-12};
|
|
34
|
-
if (this.canvasSize.width % 2 == 1)
|
|
35
|
-
this.canvasSize.width--;
|
|
36
|
-
if (this.canvasSize.height % 4 != 1)
|
|
37
|
-
this.canvasSize.height += (this.canvasSize.height % 4);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
Donut.prototype.type = 'donut';
|
|
41
|
-
|
|
42
|
-
var cos = Math.cos;
|
|
43
|
-
var sin = Math.sin;
|
|
44
|
-
var pi = 3.141592635;
|
|
45
|
-
Donut.prototype.setData = function(data){
|
|
46
|
-
this.update(data);
|
|
47
|
-
};
|
|
48
|
-
Donut.prototype.update = function(data) {
|
|
49
|
-
|
|
50
|
-
if (!this.ctx) {
|
|
51
|
-
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()';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var c = this.ctx;
|
|
55
|
-
c.save();
|
|
56
|
-
c.translate(0,-this.options.yPadding);
|
|
57
|
-
|
|
58
|
-
c.strokeStyle = this.options.stroke;
|
|
59
|
-
c.fillStyle = this.options.fill;
|
|
60
|
-
|
|
61
|
-
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height);
|
|
62
|
-
|
|
63
|
-
var cheight = this.canvasSize.height;
|
|
64
|
-
var cwidth = this.canvasSize.width;
|
|
65
|
-
|
|
66
|
-
function makeRound(percent, radius, width, cx, cy, color){
|
|
67
|
-
var s = 0;
|
|
68
|
-
var points = 370;
|
|
69
|
-
c.strokeStyle = color || 'green';
|
|
70
|
-
while(s<radius){
|
|
71
|
-
if (s < (radius - width)) {
|
|
72
|
-
s++;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
var slice = 2 * pi / points;
|
|
76
|
-
c.beginPath();
|
|
77
|
-
var p = parseFloat(percent*360);
|
|
78
|
-
for(var i = 0;i<=points;i++){
|
|
79
|
-
if (i>p) continue;
|
|
80
|
-
var si = i-90;
|
|
81
|
-
var a = slice * si;
|
|
82
|
-
c.lineTo(Math.round(cx+s*cos(a)), Math.round(cy+s*sin(a)));
|
|
83
|
-
}
|
|
84
|
-
c.stroke();
|
|
85
|
-
c.closePath();
|
|
86
|
-
s++;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var donuts = data.length;
|
|
91
|
-
var radius = this.options.radius;
|
|
92
|
-
var width = this.options.arcWidth;
|
|
93
|
-
var remainColor = this.options.remainColor;
|
|
94
|
-
|
|
95
|
-
var middle = cheight / 2;
|
|
96
|
-
var spacing = (cwidth - (donuts * radius * 2)) / (donuts + 1);
|
|
97
|
-
|
|
98
|
-
function drawDonut(label, percent, radius, width, cxx, middle, color, percentAltNumber){
|
|
99
|
-
makeRound(100, radius, width, cxx, middle, remainColor );
|
|
100
|
-
makeRound(percent, radius, width, cxx, middle, color);
|
|
101
|
-
var ptext = percentAltNumber ? percentAltNumber.toFixed(0) : parseFloat(percent*100).toFixed(0) + '%';
|
|
102
|
-
c.fillText(ptext, cxx - Math.round(parseFloat((c.measureText(ptext).width)/2)) + 3, middle);
|
|
103
|
-
c.fillText(label, cxx - Math.round(parseFloat((c.measureText(label).width)/2)) + 3, (middle + radius) + 5);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function makeDonut(stat, which){
|
|
107
|
-
var left = radius + (spacing * which) + (radius * 2 * (which - 1));
|
|
108
|
-
var percent = stat.percent;
|
|
109
|
-
if (percent > 1.001){
|
|
110
|
-
percent = parseFloat(percent / 100).toFixed(2);
|
|
111
|
-
}
|
|
112
|
-
var label = stat.label;
|
|
113
|
-
var percentAltNumber = stat.percentAltNumber;
|
|
114
|
-
var color = stat.color || 'green';
|
|
115
|
-
var cxx = left;
|
|
116
|
-
drawDonut(label, percent, radius, width, cxx, middle, color, percentAltNumber);
|
|
117
|
-
}
|
|
118
|
-
function makeDonuts(stats){
|
|
119
|
-
for(var l = 0; l<=stats.length-1;l++){
|
|
120
|
-
makeDonut(stats[l], l+1);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (data.length){
|
|
125
|
-
makeDonuts(data);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this.currentData = data;
|
|
129
|
-
|
|
130
|
-
c.strokeStyle = 'magenta';
|
|
131
|
-
|
|
132
|
-
c.restore();
|
|
133
|
-
return;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
Donut.prototype.getOptionsPrototype = function() {
|
|
137
|
-
return {
|
|
138
|
-
spacing: 1,
|
|
139
|
-
yPadding: 1,
|
|
140
|
-
radius: 1,
|
|
141
|
-
arcWidth: 1,
|
|
142
|
-
data: [ { color: 'red', percent: '50', label: 'a'}
|
|
143
|
-
, { color: 'blue', percent: '20', label: 'b'}
|
|
144
|
-
, { color: 'yellow', percent: '80', label: 'c'}
|
|
145
|
-
]
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
module.exports = Donut;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Node = require('../../../blessed/lib/widgets/node')
|
|
4
|
-
, Canvas = require('./canvas');
|
|
5
|
-
|
|
6
|
-
function GaugeList(options) {
|
|
7
|
-
if (!(this instanceof Node)) {
|
|
8
|
-
return new GaugeList(options);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
var self = this;
|
|
12
|
-
|
|
13
|
-
options = options || {};
|
|
14
|
-
self.options = options;
|
|
15
|
-
self.options.stroke = options.stroke || 'magenta';
|
|
16
|
-
self.options.fill = options.fill || 'white';
|
|
17
|
-
self.options.data = options.data || [];
|
|
18
|
-
self.options.showLabel = options.showLabel !== false;
|
|
19
|
-
self.options.gaugeSpacing = options.gaugeSpacing || 0;
|
|
20
|
-
self.options.gaugeHeight = options.gaugeHeight || 1;
|
|
21
|
-
|
|
22
|
-
Canvas.call(this, options, require('ansi-term'));
|
|
23
|
-
|
|
24
|
-
this.on('attach', function() {
|
|
25
|
-
var gauges = this.gauges = self.options.gauges;
|
|
26
|
-
this.setGauges(gauges);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
GaugeList.prototype = Object.create(Canvas.prototype);
|
|
32
|
-
|
|
33
|
-
GaugeList.prototype.calcSize = function() {
|
|
34
|
-
this.canvasSize = {width: this.width-2, height: this.height};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
GaugeList.prototype.type = 'gauge';
|
|
38
|
-
|
|
39
|
-
GaugeList.prototype.setData = function() {
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
GaugeList.prototype.setGauges = function(gauges) {
|
|
43
|
-
|
|
44
|
-
if (!this.ctx) {
|
|
45
|
-
throw 'error: canvas context does not exist. setData() for gauges must be called after the gauge has been added to the screen via screen.append()';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var c = this.ctx;
|
|
49
|
-
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height);
|
|
50
|
-
|
|
51
|
-
for (var i=0; i<gauges.length; i++) {
|
|
52
|
-
this.setSingleGauge(gauges[i], i);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
GaugeList.prototype.setSingleGauge = function(gauge, offset) {
|
|
58
|
-
|
|
59
|
-
var colors = ['green','magenta','cyan','red','blue'];
|
|
60
|
-
var stack = gauge.stack;
|
|
61
|
-
|
|
62
|
-
var c = this.ctx;
|
|
63
|
-
var leftStart = 3;
|
|
64
|
-
var textLeft = 5;
|
|
65
|
-
|
|
66
|
-
c.strokeStyle='normal';
|
|
67
|
-
c.fillStyle='white';
|
|
68
|
-
c.fillText(offset.toString(), 0, offset*(this.options.gaugeHeight+this.options.gaugeSpacing));
|
|
69
|
-
|
|
70
|
-
for (var i = 0; i < stack.length; i++) {
|
|
71
|
-
var currentStack = stack[i];
|
|
72
|
-
|
|
73
|
-
var percent;
|
|
74
|
-
if (typeof(currentStack) == typeof({})){
|
|
75
|
-
percent = currentStack.percent;
|
|
76
|
-
} else {
|
|
77
|
-
percent = currentStack;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
c.strokeStyle = currentStack.stroke || colors[(i%colors.length)]; // use specified or choose from the array of colors
|
|
81
|
-
c.fillStyle = this.options.fill;//'white'
|
|
82
|
-
|
|
83
|
-
textLeft = 5;
|
|
84
|
-
|
|
85
|
-
var width = percent/100*(this.canvasSize.width-5);
|
|
86
|
-
|
|
87
|
-
c.fillRect(leftStart, offset*(this.options.gaugeHeight+this.options.gaugeSpacing), width, this.options.gaugeHeight-1);
|
|
88
|
-
|
|
89
|
-
textLeft = (width / 2) - 1;
|
|
90
|
-
// if (textLeft)
|
|
91
|
-
var textX = leftStart+textLeft;
|
|
92
|
-
|
|
93
|
-
if ((leftStart+width)<textX) {
|
|
94
|
-
c.strokeStyle = 'normal';
|
|
95
|
-
}
|
|
96
|
-
if (gauge.showLabel) c.fillText(percent+'%', textX, 3);
|
|
97
|
-
|
|
98
|
-
leftStart += width;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
GaugeList.prototype.getOptionsPrototype = function() {
|
|
103
|
-
return {percent: 10};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
module.exports = GaugeList;
|