forked from kroitor/asciichart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
150 lines (109 loc) · 5.15 KB
/
index.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<title>asciichart</title>
<script src="asciichart.js"></script>
<script type="text/javascript">
//-----------------------------------------------------------------------------
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0) + '\n\n')
//-----------------------------------------------------------------------------
var s1 = new Array (120)
for (var i = 0; i < s1.length; i++)
s1[i] = 15 * Math.cos (i * ((Math.PI * 8) / s1.length))
console.log (asciichart.plot (s1, { height: 6 }) + '\n\n')
//-----------------------------------------------------------------------------
var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2) + '\n\n')
//-----------------------------------------------------------------------------
var width = 60
var line = "\n" + '='.repeat (width + 9) + "\n"
console.log ("\nbasic\n")
var s0 = new Array (width)
for (var i = 0; i < s0.length; i++)
s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
console.log (line)
console.log ("configuring / scale to desired height\n")
var config = {
padding: ' ', // padding string for label formatting (can be overrided)
offset: 3, // axis offset from the left (min 2)
height: 10, // any height you want
format: function (x, i) {
return (' ' + x.toFixed (2)).slice (-' '.length)
}
}
var s = []
for (var i = 0; i < width; i++)
s[i] = 15 * Math.cos (i * ((Math.PI * 8) / width)) // values range from -15 to +15
console.log (asciichart.plot (s, config)) // this rescales the graph to ±3 lines
console.log (line)
console.log ("auto-range\n")
var s2 = new Array (width)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2) + "\n")
console.log (line)
console.log ("single value\n")
var s3 = new Array (width)
for (i = 0; i < width; i++)
s3[i] = 1.0
console.log (asciichart.plot (s3) + "\n")
// test multiple
console.log (line)
console.log ("multiple disjoint array test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = arr1[i] + 2
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple
console.log (line)
console.log ("multiple intersecting arrays test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
console.log (asciichart.plot ([ arr1, arr2 ]))
// test multiple colored
console.log (line)
console.log ("multiple intersecting arrays with colors test\n")
var arr1 = new Array (width)
for (var i = 0; i < arr1.length; i++)
arr1[i] = 5 * Math.sin (i * ((Math.PI * 4) / arr1.length))
var arr2 = new Array (width)
for (var i = 0; i < arr2.length; i++)
arr2[i] = 5 * Math.sin (Math.PI + i * ((Math.PI * 4) / arr2.length))
var arr3 = new Array (width)
for (var i = 0; i < arr3.length; i++)
arr3[i] = 5 - i * 0.2
var arr4 = new Array (width)
for (var i = 0; i < arr4.length; i++)
arr4[i] = 10 + 5 * Math.cos (i * ((Math.PI * 4) / arr1.length))
var config = {
colors: [
asciichart.blue,
asciichart.green,
asciichart.magenta,
asciichart.red
]
}
var series = [ arr1, arr2, arr3, arr4 ]
console.log (asciichart.plot (series, config))
</script>
</head>
<body>
</body>
</html>