ascii_chart 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/LICENSE +0 -0
- data/README.md +4 -3
- data/Rakefile +0 -0
- data/ascii_chart.gemspec +1 -0
- data/{example.png → assets/example.png} +0 -0
- data/lib/ascii_chart.rb +3 -48
- data/lib/ascii_chart/line.rb +56 -0
- data/lib/ascii_chart/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3864cbaab7d21686c4a31476522d8d2913306d9ed3f4f73e31c30a867545f06b
|
4
|
+
data.tar.gz: b3464bd7f7858d91dba68f0cf9a58729ef904a859322f89f257dc3574ca61cf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95dba8237a4df45e9b75e807cf1207c8b389139791a1f7ed2d73a48824d1316fc97a17a23278707f1bd9cc179ee30cf30a1b6fcdc638ce55a37d56db3135d7f
|
7
|
+
data.tar.gz: fda27ad97ad4da66f7eccfdf8e7d42726d01051b5aa858daa43baea87137f29c288374e55e8b6b71e73bc540935f79e6fc9e9616a651ebeb9bd322e51119efd8
|
data/.gitignore
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# AsciiChart
|
2
2
|
|
3
|
-
[](https://coveralls.io/github/zhustec/ascii_chart)
|
3
|
+
[](https://travis-ci.com/zhustec/ascii_chart)
|
5
4
|
[](https://rubygems.org/gems/ascii_chart)
|
5
|
+
[](https://coveralls.io/github/zhustec/ascii_chart)
|
6
|
+
[](https://depfu.com/repos/zhustec/ascii_chart)
|
6
7
|
[](https://github.com/zhustec/ascii_chart/blob/master/LICENSE)
|
7
8
|
|
8
|
-
Nice-looking lightweight console ASCII line charts ╭┈╯. Port of kroitor/asciichart.
|
9
|
+
Nice-looking lightweight console ASCII line charts ╭┈╯. Port of [kroitor/asciichart](https://github.com/kroitor/asciichart).
|
9
10
|
|
10
11
|
## Installation
|
11
12
|
|
data/Rakefile
CHANGED
File without changes
|
data/ascii_chart.gemspec
CHANGED
File without changes
|
data/lib/ascii_chart.rb
CHANGED
@@ -1,53 +1,8 @@
|
|
1
1
|
require 'ascii_chart/version'
|
2
|
+
require 'ascii_chart/line'
|
2
3
|
|
3
4
|
module AsciiChart
|
4
|
-
|
5
|
-
|
6
|
-
offset: 3,
|
7
|
-
format: '%8.2f ',
|
8
|
-
height: nil
|
9
|
-
}
|
10
|
-
|
11
|
-
def plot(series, options = {})
|
12
|
-
max, min = series.max, series.min
|
13
|
-
interval = (max - min).abs
|
14
|
-
|
15
|
-
options = DEFAULTS.merge(height: interval).merge(options)
|
16
|
-
offset = options[:offset]
|
17
|
-
radio = options[:height].to_f / interval
|
18
|
-
|
19
|
-
intmax, intmin = (max * radio).floor, (min * radio).ceil
|
20
|
-
rows = (intmax - intmin).abs
|
21
|
-
width = series.length + offset
|
22
|
-
|
23
|
-
result = (0..rows).map { [' '] * width }
|
24
|
-
|
25
|
-
(intmin..intmax).each do |y|
|
26
|
-
label = options[:format] % (max - (((y - intmin) * interval).to_f / rows))
|
27
|
-
result[y - intmin][[offset - label.length, 0].max] = label
|
28
|
-
result[y - intmin][offset - 1] = y == 0 ? '┼' : '┤'
|
29
|
-
end
|
30
|
-
|
31
|
-
highest = (series.first * radio - intmin).to_i
|
32
|
-
result[rows - highest][offset - 1] = '┼'
|
33
|
-
|
34
|
-
(0...series.length - 1).each do |x|
|
35
|
-
_curr = ((series[x + 0] * radio).round - intmin).to_i
|
36
|
-
_next = ((series[x + 1] * radio).round - intmin).to_i
|
37
|
-
|
38
|
-
if _curr == _next
|
39
|
-
result[rows - _curr][x + offset] = '-'
|
40
|
-
else
|
41
|
-
result[rows - _curr][x + offset] = _curr > _next ? '╮' : '╯'
|
42
|
-
result[rows - _next][x + offset] = _curr > _next ? '╰' : '╭'
|
43
|
-
|
44
|
-
([_curr, _next].min + 1...[_curr, _next].max).each do |y|
|
45
|
-
result[rows - y][x + offset] = '|'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
result.map(&:join).join("\n")
|
51
|
-
end
|
5
|
+
def self.plot(series, options = {})
|
6
|
+
Line.new(series, options).plot
|
52
7
|
end
|
53
8
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AsciiChart
|
2
|
+
class Line
|
3
|
+
DEFAULTS = {
|
4
|
+
offset: 3,
|
5
|
+
format: '%8.2f ',
|
6
|
+
height: nil
|
7
|
+
}
|
8
|
+
|
9
|
+
def initialize(series, options = {})
|
10
|
+
@series = series
|
11
|
+
@options = DEFAULTS.merge(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def plot
|
15
|
+
max, min = @series.max, @series.min
|
16
|
+
interval = (max - min).abs
|
17
|
+
|
18
|
+
@options[:height] ||= interval
|
19
|
+
radio = @options[:height].to_f / interval
|
20
|
+
offset = @options[:offset]
|
21
|
+
|
22
|
+
intmax, intmin = (max * radio).ceil, (min * radio).floor
|
23
|
+
rows = (intmax - intmin).abs
|
24
|
+
width = @series.length + offset
|
25
|
+
|
26
|
+
result = (0..rows).map { [' '] * width }
|
27
|
+
|
28
|
+
(intmin..intmax).each do |y|
|
29
|
+
label = @options[:format] % (max - (((y - intmin) * interval).to_f / rows))
|
30
|
+
result[y - intmin][[offset - label.length, 0].max] = label
|
31
|
+
result[y - intmin][offset - 1] = y == 0 ? '┼' : '┤'
|
32
|
+
end
|
33
|
+
|
34
|
+
highest = (@series.first * radio - intmin).to_i
|
35
|
+
result[rows - highest][offset - 1] = '┼'
|
36
|
+
|
37
|
+
(0...@series.length - 1).each do |x|
|
38
|
+
_curr = ((@series[x + 0] * radio).round - intmin).to_i
|
39
|
+
_next = ((@series[x + 1] * radio).round - intmin).to_i
|
40
|
+
|
41
|
+
if _curr == _next
|
42
|
+
result[rows - _curr][x + offset] = '-'
|
43
|
+
else
|
44
|
+
result[rows - _curr][x + offset] = _curr > _next ? '╮' : '╯'
|
45
|
+
result[rows - _next][x + offset] = _curr > _next ? '╰' : '╭'
|
46
|
+
|
47
|
+
([_curr, _next].min + 1...[_curr, _next].max).each do |y|
|
48
|
+
result[rows - y][x + offset] = '|'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
result.map(&:join).join("\n")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ascii_chart/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascii_chart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhustec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
55
69
|
description: Nice-looking lightweight console ASCII line charts ┈╯
|
56
70
|
email:
|
57
71
|
- zhustec@foxmail.com
|
@@ -66,8 +80,9 @@ files:
|
|
66
80
|
- README.md
|
67
81
|
- Rakefile
|
68
82
|
- ascii_chart.gemspec
|
69
|
-
- example.png
|
83
|
+
- assets/example.png
|
70
84
|
- lib/ascii_chart.rb
|
85
|
+
- lib/ascii_chart/line.rb
|
71
86
|
- lib/ascii_chart/version.rb
|
72
87
|
homepage: https://github.com/zhustec/ascii_chart
|
73
88
|
licenses:
|