ascii_chart 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f52bed3abbf751d780b2483c53812d87d9a85e6f04fd06eb4383cc1963bf81b
4
- data.tar.gz: 84744af2bac421d20c956bd669c5db05fc88e81254178124c2273a0041ef36da
3
+ metadata.gz: 3864cbaab7d21686c4a31476522d8d2913306d9ed3f4f73e31c30a867545f06b
4
+ data.tar.gz: b3464bd7f7858d91dba68f0cf9a58729ef904a859322f89f257dc3574ca61cf7
5
5
  SHA512:
6
- metadata.gz: cba6c5484aed3e4e336c1690e348da1c622fdaec59f7fa85020e84bd90f2fc83903e20624d75bc6e561f944a89a09cc919bbdec11b278a5111bb8bf0f1713589
7
- data.tar.gz: 1a84111bdee0f910ab5857cf04d140fc007c76d1895bc2dad93bbac823313584b621b89b3400c292a701d7e396fd7256f57dfdf215017b815e251e469642ce5e
6
+ metadata.gz: c95dba8237a4df45e9b75e807cf1207c8b389139791a1f7ed2d73a48824d1316fc97a17a23278707f1bd9cc179ee30cf30a1b6fcdc638ce55a37d56db3135d7f
7
+ data.tar.gz: fda27ad97ad4da66f7eccfdf8e7d42726d01051b5aa858daa43baea87137f29c288374e55e8b6b71e73bc540935f79e6fc9e9616a651ebeb9bd322e51119efd8
data/.gitignore CHANGED
File without changes
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
- [![Travis](https://img.shields.io/travis/zhustec/ascii_chart/master.svg?style=flat-square)](https://travis-ci.com/zhustec/ascii_chart)
4
- [![Coveralls github](https://img.shields.io/coveralls/github/zhustec/ascii_chart/master.svg?style=flat-square)](https://coveralls.io/github/zhustec/ascii_chart)
3
+ [![Travis](https://img.shields.io/travis/zhustec/ascii_chart.svg?style=flat-square)](https://travis-ci.com/zhustec/ascii_chart)
5
4
  [![Gem](https://img.shields.io/gem/v/ascii_chart.svg?style=flat-square)](https://rubygems.org/gems/ascii_chart)
5
+ [![Coveralls github](https://img.shields.io/coveralls/github/zhustec/ascii_chart/master.svg?style=flat-square)](https://coveralls.io/github/zhustec/ascii_chart)
6
+ [![Depfu](https://img.shields.io/depfu/zhustec/ascii_chart.svg?style=flat-square)](https://depfu.com/repos/zhustec/ascii_chart)
6
7
  [![license](https://img.shields.io/github/license/zhustec/ascii_chart.svg?style=flat-square)](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
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 1.16'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'pry-byebug', '~> 3.0'
28
29
  end
File without changes
@@ -1,53 +1,8 @@
1
1
  require 'ascii_chart/version'
2
+ require 'ascii_chart/line'
2
3
 
3
4
  module AsciiChart
4
- class << self
5
- DEFAULTS = {
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
@@ -1,3 +1,3 @@
1
1
  module AsciiChart
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-02 00:00:00.000000000 Z
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: