-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.js
90 lines (73 loc) · 2.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const bar = require('../lib/bar')
const pie = require('../lib/pie')
const bullet = require('../lib/bullet')
const donut = require('../lib/donut')
const gauge = require('../lib/gauge')
const scatter = require('../lib/scatter')
const { bg, fg } = require('../lib/utils')
// Scatter
const scatterData = []
for (let i = 1; i < 17; i++) {
i < 6 ? scatterData.push({ key: 'A', value: [i, i], style: fg('red', '*') })
: scatterData.push({ key: 'A', value: [i, 6], style: fg('red', '*') })
}
scatterData.push({ key: 'B', value: [2, 6], style: fg('blue', '# '), sides: [2, 2] })
scatterData.push({ key: 'C', value: [6, 9], style: bg('cyan', 2) })
console.log(scatter(scatterData, { legendGap: 18, width: 15 }) + '\n')
// Bar
const barData = [
{ key: 'A', value: 5, style: '*' },
{ key: 'B', value: 3, style: '+' },
{ key: 'C', value: 11 },
{ key: 'D', value: 1, style: bg('red') },
{ key: 'E', value: 5, style: bg('green') },
{ key: 'F', value: 7, style: bg('blue'), padding: 1 },
{ key: 'G', value: 0, style: bg('yellow') }
]
console.log(bar(barData))
// Pie
const pieData1 = [
{ key: 'A', value: 5, style: '* ' },
{ key: 'B', value: 10, style: '+ ' },
{ key: 'C', value: 10, style: '# ' },
{ key: 'D', value: 10, style: 'O ' }
]
const pieData2 = [
{ key: 'A', value: 5, style: bg('cyan', 2) },
{ key: 'B', value: 5, style: bg('yellow', 2) },
{ key: 'C', value: 5, style: bg('magenta', 2) },
{ key: 'D', value: 5, style: bg('white', 2) }
]
console.log(pie(pieData1, { left: 1 }))
console.log(pie(pieData2, { left: 1 }))
// Bullet
const bulletData = [
{ key: 'Month', value: 5 },
{ key: 'Week', value: 3, style: fg('red', '*') },
{ key: 'Day', value: 20, style: bg('blue'), barWidth: 1 },
{ key: 'Now', value: 15, style: bg('cyan'), barWidth: 1 }
]
console.log(bullet(bulletData, { style: '+', width: 30, barWidth: 2 }))
// Donut
const donutData1 = [
{ key: 'A', value: 10, style: fg('cyan', '+ ') },
{ key: 'B', value: 10, style: fg('red', '* ') }
]
const donutData2 = [
{ key: 'A', value: 20, style: bg('green', 2) },
{ key: 'B', value: 20, style: bg('blue', 2) },
{ key: 'C', value: 20, style: bg('yellow', 2) }
]
console.log(donut(donutData1, { left: 1 }))
console.log(donut(donutData2, { left: 1, gapChar: bg('yellow', 2) }))
// Gauge
const gaugeData1 = [
{ key: 'A', value: 0.5 }
]
const gaugeData2 = [
{ key: 'PR', value: 0.3 }
]
console.log(gauge(gaugeData1, { radius: 7 }))
console.log(gauge(gaugeData2, {
radius: 7, style: bg('green', 2), bgStyle: bg('magenta', 2)
}))