@socketsecurity/cli-with-sentry 0.14.137 → 0.14.138
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/dist/blessed/LICENSE +20 -0
- package/dist/blessed/lib/alias.js +519 -0
- package/dist/blessed/lib/blessed.js +32 -0
- package/dist/blessed/lib/colors.js +490 -0
- package/dist/blessed/lib/events.js +195 -0
- package/dist/blessed/lib/gpmclient.js +245 -0
- package/dist/blessed/lib/helpers.js +170 -0
- package/dist/blessed/lib/keys.js +512 -0
- package/dist/blessed/lib/program.js +4530 -0
- package/dist/blessed/lib/tput.js +3111 -0
- package/dist/blessed/lib/unicode.js +912 -0
- package/dist/blessed/lib/widget.js +60 -0
- package/dist/blessed/lib/widgets/ansiimage.js +173 -0
- package/dist/blessed/lib/widgets/bigtext.js +170 -0
- package/dist/blessed/lib/widgets/box.js +34 -0
- package/dist/blessed/lib/widgets/button.js +62 -0
- package/dist/blessed/lib/widgets/checkbox.js +95 -0
- package/dist/blessed/lib/widgets/element.js +2871 -0
- package/dist/blessed/lib/widgets/filemanager.js +223 -0
- package/dist/blessed/lib/widgets/form.js +301 -0
- package/dist/blessed/lib/widgets/image.js +71 -0
- package/dist/blessed/lib/widgets/input.js +34 -0
- package/dist/blessed/lib/widgets/layout.js +249 -0
- package/dist/blessed/lib/widgets/line.js +59 -0
- package/dist/blessed/lib/widgets/list.js +652 -0
- package/dist/blessed/lib/widgets/listbar.js +452 -0
- package/dist/blessed/lib/widgets/listtable.js +265 -0
- package/dist/blessed/lib/widgets/loading.js +88 -0
- package/dist/blessed/lib/widgets/log.js +82 -0
- package/dist/blessed/lib/widgets/message.js +145 -0
- package/dist/blessed/lib/widgets/node.js +314 -0
- package/dist/blessed/lib/widgets/overlayimage.js +794 -0
- package/dist/blessed/lib/widgets/progressbar.js +166 -0
- package/dist/blessed/lib/widgets/prompt.js +127 -0
- package/dist/blessed/lib/widgets/question.js +129 -0
- package/dist/blessed/lib/widgets/radiobutton.js +62 -0
- package/dist/blessed/lib/widgets/radioset.js +36 -0
- package/dist/blessed/lib/widgets/screen.js +2485 -0
- package/dist/blessed/lib/widgets/scrollablebox.js +415 -0
- package/dist/blessed/lib/widgets/scrollabletext.js +35 -0
- package/dist/blessed/lib/widgets/table.js +383 -0
- package/dist/blessed/lib/widgets/terminal.js +452 -0
- package/dist/blessed/lib/widgets/text.js +35 -0
- package/dist/blessed/lib/widgets/textarea.js +376 -0
- package/dist/blessed/lib/widgets/textbox.js +79 -0
- package/dist/blessed/lib/widgets/video.js +130 -0
- package/dist/blessed/usr/fonts/AUTHORS +1 -0
- package/dist/blessed/usr/fonts/LICENSE +94 -0
- package/dist/blessed/usr/fonts/README +340 -0
- package/dist/blessed/usr/fonts/ter-u14b.json +17826 -0
- package/dist/blessed/usr/fonts/ter-u14n.json +17826 -0
- package/dist/blessed/usr/linux +0 -0
- package/dist/blessed/usr/windows-ansi +0 -0
- package/dist/blessed/usr/xterm +0 -0
- package/dist/blessed/usr/xterm-256color +0 -0
- package/dist/blessed/usr/xterm.termcap +243 -0
- package/dist/blessed/usr/xterm.terminfo +1977 -0
- package/dist/blessed/vendor/tng.js +1876 -0
- package/dist/blessed-contrib/LICENSE.md +21 -0
- package/dist/blessed-contrib/lib/layout/carousel.js +82 -0
- package/dist/blessed-contrib/lib/layout/grid.js +46 -0
- package/dist/blessed-contrib/lib/server-utils.js +83 -0
- package/dist/blessed-contrib/lib/utils.js +73 -0
- package/dist/blessed-contrib/lib/widget/canvas.js +52 -0
- package/dist/blessed-contrib/lib/widget/charts/bar.js +99 -0
- package/dist/blessed-contrib/lib/widget/charts/line.js +311 -0
- package/dist/blessed-contrib/lib/widget/charts/stacked-bar.js +245 -0
- package/dist/blessed-contrib/lib/widget/donut.js +183 -0
- package/dist/blessed-contrib/lib/widget/gauge-list.js +111 -0
- package/dist/blessed-contrib/lib/widget/gauge.js +127 -0
- package/dist/blessed-contrib/lib/widget/lcd.js +497 -0
- package/dist/blessed-contrib/lib/widget/log.js +32 -0
- package/dist/blessed-contrib/lib/widget/map.js +97 -0
- package/dist/blessed-contrib/lib/widget/markdown.js +68 -0
- package/dist/blessed-contrib/lib/widget/picture.js +61 -0
- package/dist/blessed-contrib/lib/widget/sparkline.js +66 -0
- package/dist/blessed-contrib/lib/widget/table.js +141 -0
- package/dist/blessed-contrib/lib/widget/tree.js +179 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/index.js +6 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/license +21 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/package.json +64 -0
- package/dist/blessed-contrib/node_modules/ansi-regex/readme.md +39 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/index.js +67 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/license +21 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/package.json +50 -0
- package/dist/blessed-contrib/node_modules/ansi-styles/readme.md +86 -0
- package/dist/blessed-contrib/node_modules/chalk/index.js +118 -0
- package/dist/blessed-contrib/node_modules/chalk/license +21 -0
- package/dist/blessed-contrib/node_modules/chalk/package.json +70 -0
- package/dist/blessed-contrib/node_modules/chalk/readme.md +213 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/index.js +13 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/license +21 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/package.json +41 -0
- package/dist/blessed-contrib/node_modules/escape-string-regexp/readme.md +27 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/index.js +8 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/license +21 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/package.json +57 -0
- package/dist/blessed-contrib/node_modules/strip-ansi/readme.md +33 -0
- package/dist/blessed-contrib/node_modules/supports-color/index.js +52 -0
- package/dist/blessed-contrib/node_modules/supports-color/license +21 -0
- package/dist/blessed-contrib/node_modules/supports-color/package.json +49 -0
- package/dist/blessed-contrib/node_modules/supports-color/readme.md +36 -0
- package/dist/cli.js +9 -8
- package/dist/cli.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/shadow-npm-inject.js +2 -2
- package/dist/shadow-npm-inject.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Node = require('../../../blessed/lib/widgets/node'),
|
|
3
|
+
Canvas = require('./canvas')
|
|
4
|
+
|
|
5
|
+
function Donut(options) {
|
|
6
|
+
if (!(this instanceof Node)) {
|
|
7
|
+
return new Donut(options)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
options = options || {}
|
|
11
|
+
this.options = options
|
|
12
|
+
this.options.stroke = options.stroke || 'magenta'
|
|
13
|
+
this.options.fill = options.fill || 'white'
|
|
14
|
+
this.options.radius = options.radius || 14
|
|
15
|
+
this.options.arcWidth = options.arcWidth || 4
|
|
16
|
+
this.options.spacing = options.spacing || 2
|
|
17
|
+
this.options.yPadding = options.yPadding || 2
|
|
18
|
+
this.options.remainColor = options.remainColor || 'black'
|
|
19
|
+
this.options.data = options.data || []
|
|
20
|
+
|
|
21
|
+
Canvas.call(this, options)
|
|
22
|
+
|
|
23
|
+
const self = this
|
|
24
|
+
this.on('attach', function () {
|
|
25
|
+
this.setData(self.options.data)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Donut.prototype = Object.create(Canvas.prototype)
|
|
30
|
+
|
|
31
|
+
Donut.prototype.calcSize = function () {
|
|
32
|
+
this.canvasSize = {
|
|
33
|
+
width: Math.round(this.width * 2 - 5),
|
|
34
|
+
height: this.height * 4 - 12
|
|
35
|
+
}
|
|
36
|
+
if (this.canvasSize.width % 2 == 1) {
|
|
37
|
+
this.canvasSize.width--
|
|
38
|
+
}
|
|
39
|
+
if (this.canvasSize.height % 4 != 1) {
|
|
40
|
+
this.canvasSize.height += this.canvasSize.height % 4
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Donut.prototype.type = 'donut'
|
|
45
|
+
|
|
46
|
+
const cos = Math.cos
|
|
47
|
+
const sin = Math.sin
|
|
48
|
+
const pi = 3.141592635
|
|
49
|
+
Donut.prototype.setData = function (data) {
|
|
50
|
+
this.update(data)
|
|
51
|
+
}
|
|
52
|
+
Donut.prototype.update = function (data) {
|
|
53
|
+
if (!this.ctx) {
|
|
54
|
+
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()'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const c = this.ctx
|
|
58
|
+
c.save()
|
|
59
|
+
c.translate(0, -this.options.yPadding)
|
|
60
|
+
|
|
61
|
+
c.strokeStyle = this.options.stroke
|
|
62
|
+
c.fillStyle = this.options.fill
|
|
63
|
+
|
|
64
|
+
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height)
|
|
65
|
+
|
|
66
|
+
const cheight = this.canvasSize.height
|
|
67
|
+
const cwidth = this.canvasSize.width
|
|
68
|
+
|
|
69
|
+
function makeRound(percent, radius, width, cx, cy, color) {
|
|
70
|
+
let s = 0
|
|
71
|
+
const points = 370
|
|
72
|
+
c.strokeStyle = color || 'green'
|
|
73
|
+
while (s < radius) {
|
|
74
|
+
if (s < radius - width) {
|
|
75
|
+
s++
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
const slice = (2 * pi) / points
|
|
79
|
+
c.beginPath()
|
|
80
|
+
const p = parseFloat(percent * 360)
|
|
81
|
+
for (let i = 0; i <= points; i++) {
|
|
82
|
+
if (i > p) {
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
const si = i - 90
|
|
86
|
+
const a = slice * si
|
|
87
|
+
c.lineTo(Math.round(cx + s * cos(a)), Math.round(cy + s * sin(a)))
|
|
88
|
+
}
|
|
89
|
+
c.stroke()
|
|
90
|
+
c.closePath()
|
|
91
|
+
s++
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const donuts = data.length
|
|
96
|
+
const radius = this.options.radius
|
|
97
|
+
const width = this.options.arcWidth
|
|
98
|
+
const remainColor = this.options.remainColor
|
|
99
|
+
|
|
100
|
+
const middle = cheight / 2
|
|
101
|
+
const spacing = (cwidth - donuts * radius * 2) / (donuts + 1)
|
|
102
|
+
|
|
103
|
+
function drawDonut(
|
|
104
|
+
label,
|
|
105
|
+
percent,
|
|
106
|
+
radius,
|
|
107
|
+
width,
|
|
108
|
+
cxx,
|
|
109
|
+
middle,
|
|
110
|
+
color,
|
|
111
|
+
percentAltNumber
|
|
112
|
+
) {
|
|
113
|
+
makeRound(100, radius, width, cxx, middle, remainColor)
|
|
114
|
+
makeRound(percent, radius, width, cxx, middle, color)
|
|
115
|
+
const ptext = percentAltNumber
|
|
116
|
+
? percentAltNumber.toFixed(0)
|
|
117
|
+
: parseFloat(percent * 100).toFixed(0) + '%'
|
|
118
|
+
c.fillText(
|
|
119
|
+
ptext,
|
|
120
|
+
cxx - Math.round(parseFloat(c.measureText(ptext).width / 2)) + 3,
|
|
121
|
+
middle
|
|
122
|
+
)
|
|
123
|
+
c.fillText(
|
|
124
|
+
label,
|
|
125
|
+
cxx - Math.round(parseFloat(c.measureText(label).width / 2)) + 3,
|
|
126
|
+
middle + radius + 5
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function makeDonut(stat, which) {
|
|
131
|
+
const left = radius + spacing * which + radius * 2 * (which - 1)
|
|
132
|
+
let percent = stat.percent
|
|
133
|
+
if (percent > 1.001) {
|
|
134
|
+
percent = parseFloat(percent / 100).toFixed(2)
|
|
135
|
+
}
|
|
136
|
+
const label = stat.label
|
|
137
|
+
const percentAltNumber = stat.percentAltNumber
|
|
138
|
+
const color = stat.color || 'green'
|
|
139
|
+
const cxx = left
|
|
140
|
+
drawDonut(
|
|
141
|
+
label,
|
|
142
|
+
percent,
|
|
143
|
+
radius,
|
|
144
|
+
width,
|
|
145
|
+
cxx,
|
|
146
|
+
middle,
|
|
147
|
+
color,
|
|
148
|
+
percentAltNumber
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
function makeDonuts(stats) {
|
|
152
|
+
for (let l = 0; l <= stats.length - 1; l++) {
|
|
153
|
+
makeDonut(stats[l], l + 1)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (data.length) {
|
|
158
|
+
makeDonuts(data)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.currentData = data
|
|
162
|
+
|
|
163
|
+
c.strokeStyle = 'magenta'
|
|
164
|
+
|
|
165
|
+
c.restore()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Donut.prototype.getOptionsPrototype = function () {
|
|
170
|
+
return {
|
|
171
|
+
spacing: 1,
|
|
172
|
+
yPadding: 1,
|
|
173
|
+
radius: 1,
|
|
174
|
+
arcWidth: 1,
|
|
175
|
+
data: [
|
|
176
|
+
{ color: 'red', percent: '50', label: 'a' },
|
|
177
|
+
{ color: 'blue', percent: '20', label: 'b' },
|
|
178
|
+
{ color: 'yellow', percent: '80', label: 'c' }
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = Donut
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Node = require('../../../blessed/lib/widgets/node'),
|
|
3
|
+
Canvas = require('./canvas')
|
|
4
|
+
|
|
5
|
+
function GaugeList(options) {
|
|
6
|
+
if (!(this instanceof Node)) {
|
|
7
|
+
return new GaugeList(options)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const self = this
|
|
11
|
+
|
|
12
|
+
options = options || {}
|
|
13
|
+
self.options = options
|
|
14
|
+
self.options.stroke = options.stroke || 'magenta'
|
|
15
|
+
self.options.fill = options.fill || 'white'
|
|
16
|
+
self.options.data = options.data || []
|
|
17
|
+
self.options.showLabel = options.showLabel !== false
|
|
18
|
+
self.options.gaugeSpacing = options.gaugeSpacing || 0
|
|
19
|
+
self.options.gaugeHeight = options.gaugeHeight || 1
|
|
20
|
+
|
|
21
|
+
Canvas.call(this, options, require('ansi-term'))
|
|
22
|
+
|
|
23
|
+
this.on('attach', function () {
|
|
24
|
+
const gauges = (this.gauges = self.options.gauges)
|
|
25
|
+
this.setGauges(gauges)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
GaugeList.prototype = Object.create(Canvas.prototype)
|
|
30
|
+
|
|
31
|
+
GaugeList.prototype.calcSize = function () {
|
|
32
|
+
this.canvasSize = { width: this.width - 2, height: this.height }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
GaugeList.prototype.type = 'gauge'
|
|
36
|
+
|
|
37
|
+
GaugeList.prototype.setData = function () {}
|
|
38
|
+
|
|
39
|
+
GaugeList.prototype.setGauges = function (gauges) {
|
|
40
|
+
if (!this.ctx) {
|
|
41
|
+
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()'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const c = this.ctx
|
|
45
|
+
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height)
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < gauges.length; i++) {
|
|
48
|
+
this.setSingleGauge(gauges[i], i)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
GaugeList.prototype.setSingleGauge = function (gauge, offset) {
|
|
53
|
+
const colors = ['green', 'magenta', 'cyan', 'red', 'blue']
|
|
54
|
+
const stack = gauge.stack
|
|
55
|
+
|
|
56
|
+
const c = this.ctx
|
|
57
|
+
let leftStart = 3
|
|
58
|
+
let textLeft = 5
|
|
59
|
+
|
|
60
|
+
c.strokeStyle = 'normal'
|
|
61
|
+
c.fillStyle = 'white'
|
|
62
|
+
c.fillText(
|
|
63
|
+
offset.toString(),
|
|
64
|
+
0,
|
|
65
|
+
offset * (this.options.gaugeHeight + this.options.gaugeSpacing)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < stack.length; i++) {
|
|
69
|
+
const currentStack = stack[i]
|
|
70
|
+
|
|
71
|
+
let percent
|
|
72
|
+
if (typeof currentStack == typeof {}) {
|
|
73
|
+
percent = currentStack.percent
|
|
74
|
+
} else {
|
|
75
|
+
percent = currentStack
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
c.strokeStyle = currentStack.stroke || colors[i % colors.length] // use specified or choose from the array of colors
|
|
79
|
+
c.fillStyle = this.options.fill //'white'
|
|
80
|
+
|
|
81
|
+
textLeft = 5
|
|
82
|
+
|
|
83
|
+
const width = (percent / 100) * (this.canvasSize.width - 5)
|
|
84
|
+
|
|
85
|
+
c.fillRect(
|
|
86
|
+
leftStart,
|
|
87
|
+
offset * (this.options.gaugeHeight + this.options.gaugeSpacing),
|
|
88
|
+
width,
|
|
89
|
+
this.options.gaugeHeight - 1
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
textLeft = width / 2 - 1
|
|
93
|
+
// if (textLeft)
|
|
94
|
+
const textX = leftStart + textLeft
|
|
95
|
+
|
|
96
|
+
if (leftStart + width < textX) {
|
|
97
|
+
c.strokeStyle = 'normal'
|
|
98
|
+
}
|
|
99
|
+
if (gauge.showLabel) {
|
|
100
|
+
c.fillText(percent + '%', textX, 3)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
leftStart += width
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
GaugeList.prototype.getOptionsPrototype = function () {
|
|
108
|
+
return { percent: 10 }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = GaugeList
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Node = require('../../../blessed/lib/widgets/node'),
|
|
3
|
+
Canvas = require('./canvas')
|
|
4
|
+
|
|
5
|
+
function Gauge(options) {
|
|
6
|
+
if (!(this instanceof Node)) {
|
|
7
|
+
return new Gauge(options)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const self = this
|
|
11
|
+
|
|
12
|
+
options = options || {}
|
|
13
|
+
self.options = options
|
|
14
|
+
self.options.stroke = options.stroke || 'magenta'
|
|
15
|
+
self.options.fill = options.fill || 'white'
|
|
16
|
+
self.options.data = options.data || []
|
|
17
|
+
self.options.showLabel = options.showLabel !== false
|
|
18
|
+
|
|
19
|
+
Canvas.call(this, options, require('ansi-term'))
|
|
20
|
+
|
|
21
|
+
this.on('attach', function () {
|
|
22
|
+
if (self.options.stack) {
|
|
23
|
+
const stack = (this.stack = self.options.stack)
|
|
24
|
+
this.setStack(stack)
|
|
25
|
+
} else {
|
|
26
|
+
const percent = (this.percent = self.options.percent || 0)
|
|
27
|
+
this.setData(percent)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Gauge.prototype = Object.create(Canvas.prototype)
|
|
33
|
+
|
|
34
|
+
Gauge.prototype.calcSize = function () {
|
|
35
|
+
this.canvasSize = { width: this.width - 2, height: this.height }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Gauge.prototype.type = 'gauge'
|
|
39
|
+
|
|
40
|
+
Gauge.prototype.setData = function (data) {
|
|
41
|
+
if (typeof data == typeof [] && data.length > 0) {
|
|
42
|
+
this.setStack(data)
|
|
43
|
+
} else if (typeof data == typeof 1) {
|
|
44
|
+
this.setPercent(data)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Gauge.prototype.setPercent = function (percent) {
|
|
49
|
+
if (!this.ctx) {
|
|
50
|
+
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()'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const c = this.ctx
|
|
54
|
+
|
|
55
|
+
c.strokeStyle = this.options.stroke //'magenta'
|
|
56
|
+
c.fillStyle = this.options.fill //'white'
|
|
57
|
+
|
|
58
|
+
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height)
|
|
59
|
+
if (percent < 1.001) {
|
|
60
|
+
percent = percent * 100
|
|
61
|
+
}
|
|
62
|
+
const width = (percent / 100) * (this.canvasSize.width - 3)
|
|
63
|
+
c.fillRect(1, 2, width, 2)
|
|
64
|
+
|
|
65
|
+
const textX = 7
|
|
66
|
+
if (width < textX) {
|
|
67
|
+
c.strokeStyle = 'normal'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (this.options.showLabel) {
|
|
71
|
+
c.fillText(Math.round(percent) + '%', textX, 3)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Gauge.prototype.setStack = function (stack) {
|
|
76
|
+
const colors = ['green', 'magenta', 'cyan', 'red', 'blue']
|
|
77
|
+
|
|
78
|
+
if (!this.ctx) {
|
|
79
|
+
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()'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const c = this.ctx
|
|
83
|
+
let leftStart = 1
|
|
84
|
+
let textLeft = 5
|
|
85
|
+
c.clearRect(0, 0, this.canvasSize.width, this.canvasSize.height)
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < stack.length; i++) {
|
|
88
|
+
const currentStack = stack[i]
|
|
89
|
+
|
|
90
|
+
let percent
|
|
91
|
+
if (typeof currentStack == typeof {}) {
|
|
92
|
+
percent = currentStack.percent
|
|
93
|
+
} else {
|
|
94
|
+
percent = currentStack
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
c.strokeStyle = currentStack.stroke || colors[i % colors.length] // use specified or choose from the array of colors
|
|
98
|
+
c.fillStyle = this.options.fill //'white'
|
|
99
|
+
|
|
100
|
+
textLeft = 5
|
|
101
|
+
if (percent < 1.001) {
|
|
102
|
+
percent = percent * 100
|
|
103
|
+
}
|
|
104
|
+
const width = (percent / 100) * (this.canvasSize.width - 3)
|
|
105
|
+
|
|
106
|
+
c.fillRect(leftStart, 2, width, 2)
|
|
107
|
+
|
|
108
|
+
textLeft = width / 2 - 1
|
|
109
|
+
// if (textLeft)
|
|
110
|
+
const textX = leftStart + textLeft
|
|
111
|
+
|
|
112
|
+
if (leftStart + width < textX) {
|
|
113
|
+
c.strokeStyle = 'normal'
|
|
114
|
+
}
|
|
115
|
+
if (this.options.showLabel) {
|
|
116
|
+
c.fillText(percent + '%', textX, 3)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
leftStart += width
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Gauge.prototype.getOptionsPrototype = function () {
|
|
124
|
+
return { percent: 10 }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = Gauge
|