UNPKG

1.16 kBJavaScriptView Raw
1const utils = require('./utils')
2const { padMid, verifyData, PAD, EOL } = utils
3
4module.exports = (data, opts) => {
5 verifyData(data)
6
7 const newOpts = Object.assign({
8 radius: 5,
9 left: 2,
10 style: '# ',
11 bgStyle: '+ '
12 }, opts)
13
14 const { radius, left, style, bgStyle } = newOpts
15
16 let tmp; let result = PAD.repeat(left)
17
18 for (let i = -radius; i < 0; i++) {
19 for (let j = -radius; j < radius; j++) {
20 if (Math.pow(i, 2) + Math.pow(j, 2) < Math.pow(radius, 2)) {
21 if (Math.abs(i) > 2 || Math.abs(j) > 2) {
22 tmp = Math.atan2(i, j) * 1 / Math.PI + 1
23 result += tmp <= data[0].value ? (data[0].style || style) : bgStyle
24 } else {
25 if (j === 0 & i === -1) {
26 result += Math.round(data[0].value * 100)
27 continue
28 }
29
30 result += PAD.repeat(2)
31 }
32 } else {
33 result += PAD.repeat(2)
34 }
35 }
36
37 result += EOL + PAD.repeat(left)
38 }
39
40 result += PAD.repeat(radius - 2) + '0' + PAD.repeat(radius - 4) +
41 padMid(data[0].key, 11) +
42 PAD.repeat(radius - 4) +
43 '100'
44
45 return result
46}