tty-pie 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +34 -34
- data/lib/tty-pie.rb +1 -1
- data/lib/tty/pie.rb +9 -9
- data/lib/tty/pie/data_item.rb +5 -5
- data/lib/tty/pie/version.rb +1 -1
- metadata +11 -39
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/examples/basic.rb +0 -12
- data/examples/fill.rb +0 -12
- data/examples/format.rb +0 -16
- data/spec/spec_helper.rb +0 -31
- data/spec/unit/add_spec.rb +0 -29
- data/spec/unit/color_spec.rb +0 -104
- data/spec/unit/fill_spec.rb +0 -47
- data/spec/unit/legend_spec.rb +0 -167
- data/spec/unit/render_spec.rb +0 -74
- data/spec/unit/reset_spec.rb +0 -23
- data/spec/unit/update_spec.rb +0 -31
- data/tasks/console.rake +0 -9
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-pie.gemspec +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3514ee6f5b698d2e61ba5e69fb79b2dcf854166b7dec6b295d4c407e793b46b
|
4
|
+
data.tar.gz: c6e1d14ca8c5f843ecf381db1485077744c30aaeac32e91e1a1f7b28daf0c8ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e94b9f2cbfde5e456c2bfd5a3d32c19ae33d8446d449b1c1fa7d2378a4ca91ecb4bc220f1161570f24b9810ddf9a8f489621ccbd9719a2d4c90790a2acbf95
|
7
|
+
data.tar.gz: 3be4437f36f739a7bc6a071ee0b6346f3b4713525eb7369963a2328b67c27dc4eaef574069850f9b146d534851a06aaa341259556f2579baf36519c615621bf1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.4.0] - 2020-07-04
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change gemspec to remove test and example artefacts
|
7
|
+
* Change to update pastel dependency
|
8
|
+
|
3
9
|
## [v0.3.0] - 2019-08-02
|
4
10
|
|
5
11
|
### Changed
|
@@ -29,6 +35,7 @@
|
|
29
35
|
|
30
36
|
* Initial implementation and release
|
31
37
|
|
38
|
+
[v0.4.0]: https://github.com/piotrmurach/tty-pie/compare/v0.3.0...v0.4.0
|
32
39
|
[v0.3.0]: https://github.com/piotrmurach/tty-pie/compare/v0.2.0...v0.3.0
|
33
40
|
[v0.2.0]: https://github.com/piotrmurach/tty-pie/compare/v0.1.0...v0.2.0
|
34
41
|
[v0.1.0]: https://github.com/piotrmurach/tty-pie/compare/v0.1.0
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
Add this line to your application's Gemfile:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
gem
|
33
|
+
gem "tty-pie"
|
34
34
|
```
|
35
35
|
|
36
36
|
And then execute:
|
@@ -60,10 +60,10 @@ To render a pie chart you need to provide an array of data items:
|
|
60
60
|
|
61
61
|
```ruby
|
62
62
|
data = [
|
63
|
-
{ name:
|
64
|
-
{ name:
|
65
|
-
{ name:
|
66
|
-
{ name:
|
63
|
+
{ name: "BTC", value: 5977, color: :bright_yellow, fill: "*" },
|
64
|
+
{ name: "BCH", value: 3045, color: :bright_green, fill: "x" },
|
65
|
+
{ name: "LTC", value: 2030, color: :bright_magenta, fill: "@" },
|
66
|
+
{ name: "ETH", value: 2350, color: :bright_cyan, fill: "+" }
|
67
67
|
]
|
68
68
|
```
|
69
69
|
|
@@ -109,10 +109,10 @@ For example, the following will result in four slices in a pie chart:
|
|
109
109
|
|
110
110
|
```ruby
|
111
111
|
data = [
|
112
|
-
{ name:
|
113
|
-
{ name:
|
114
|
-
{ name:
|
115
|
-
{ name:
|
112
|
+
{ name: "BTC", value: 5977 },
|
113
|
+
{ name: "BCH", value: 3045 },
|
114
|
+
{ name: "LTC", value: 2030 },
|
115
|
+
{ name: "ETH", value: 2350 }
|
116
116
|
]
|
117
117
|
```
|
118
118
|
|
@@ -120,10 +120,10 @@ However, the above data slices will be displayed without any color. Use `:color`
|
|
120
120
|
|
121
121
|
```ruby
|
122
122
|
data = [
|
123
|
-
{ name:
|
124
|
-
{ name:
|
125
|
-
{ name:
|
126
|
-
{ name:
|
123
|
+
{ name: "BTC", value: 5977, color: :bright_yellow },
|
124
|
+
{ name: "BCH", value: 3045, color: :bright_green },
|
125
|
+
{ name: "LTC", value: 2030, color: :bright_magenta },
|
126
|
+
{ name: "ETH", value: 2350, color: :bright_cyan }
|
127
127
|
]
|
128
128
|
```
|
129
129
|
|
@@ -131,10 +131,10 @@ To further make your chart readable consider making pie chart slices visible by
|
|
131
131
|
|
132
132
|
```ruby
|
133
133
|
data = [
|
134
|
-
{ name:
|
135
|
-
{ name:
|
136
|
-
{ name:
|
137
|
-
{ name:
|
134
|
+
{ name: "BTC", value: 5977, color: :bright_yellow, fill: "*" },
|
135
|
+
{ name: "BCH", value: 3045, color: :bright_green, fill: "x" },
|
136
|
+
{ name: "LTC", value: 2030, color: :bright_magenta, fill: "@" },
|
137
|
+
{ name: "ETH", value: 2350, color: :bright_cyan, fill: "+" }
|
138
138
|
]
|
139
139
|
```
|
140
140
|
|
@@ -150,10 +150,10 @@ Alternatively, you can delay adding data later with `add` or `<<` methods:
|
|
150
150
|
|
151
151
|
```ruby
|
152
152
|
pie_chart = TTY::Pie.new
|
153
|
-
pie_chart << { name:
|
154
|
-
pie_chart << { name:
|
155
|
-
pie_chart << { name:
|
156
|
-
pie_chart << { name:
|
153
|
+
pie_chart << { name: "BTC", value: 5977, color: :bright_yellow, fill: "*" }
|
154
|
+
pie_chart << { name: "BCH", value: 3045, color: :bright_green, fill: "x" }
|
155
|
+
pie_chart << { name: "LTC", value: 2030, color: :bright_magenta, fill: "@" }
|
156
|
+
pie_chart << { name: "ETH", value: 2350, color: :bright_cyan, fill: "+" }
|
157
157
|
```
|
158
158
|
|
159
159
|
### 2.2 add
|
@@ -162,8 +162,8 @@ You can also set data for the pie chart using the `add` or `<<` method calls. On
|
|
162
162
|
|
163
163
|
```ruby
|
164
164
|
pie_chart = TTY::Pie.new
|
165
|
-
pie_chart << { name:
|
166
|
-
pie_chart << { name:
|
165
|
+
pie_chart << { name: "BTC", value: 5977, color: :bright_yellow, fill: "*" }
|
166
|
+
pie_chart << { name: "BCH", value: 3045, color: :bright_green, fill: "x" }
|
167
167
|
...
|
168
168
|
```
|
169
169
|
|
@@ -173,14 +173,14 @@ To replace current data completely with the new use `update`:
|
|
173
173
|
|
174
174
|
```ruby
|
175
175
|
data = [
|
176
|
-
{ name:
|
177
|
-
{ name:
|
176
|
+
{ name: "BTC", value: 5977, color: :bright_yellow, fill: "*" },
|
177
|
+
{ name: "BCH", value: 3045, color: :bright_green, fill: "x" }
|
178
178
|
]
|
179
179
|
pie_chart = TTY::Pie.new(data: data)
|
180
180
|
|
181
181
|
new_data = [
|
182
|
-
{ name:
|
183
|
-
{ name:
|
182
|
+
{ name: "BTC", value: 3400, color: :bright_yellow, fill: "*" },
|
183
|
+
{ name: "BCH", value: 1200, color: :bright_green, fill: "x" },
|
184
184
|
]
|
185
185
|
|
186
186
|
pie_chart.update(new_data)
|
@@ -226,9 +226,9 @@ Provided the following data:
|
|
226
226
|
|
227
227
|
```ruby
|
228
228
|
data = [
|
229
|
-
{ name:
|
230
|
-
{ name:
|
231
|
-
{ name:
|
229
|
+
{ name: "BTC", value: 5977, fill: "*" },
|
230
|
+
{ name: "BCH", value: 3045, fill: "+" },
|
231
|
+
{ name: "LTC", value: 2030, fill: "x" }
|
232
232
|
]
|
233
233
|
```
|
234
234
|
|
@@ -280,9 +280,9 @@ Given data items:
|
|
280
280
|
|
281
281
|
```ruby
|
282
282
|
data = [
|
283
|
-
{ name:
|
284
|
-
{ name:
|
285
|
-
{ name:
|
283
|
+
{ name: "BTC", value: 5977.12345, fill: "*" },
|
284
|
+
{ name: "BCH", value: 3045.2, fill: "+" },
|
285
|
+
{ name: "LTC", value: 2030.444, fill: "x" }
|
286
286
|
]
|
287
287
|
```
|
288
288
|
|
@@ -347,7 +347,7 @@ The currency can be further customised using `:precision` and `:delimiter` keys:
|
|
347
347
|
legend: {
|
348
348
|
format: "%<label>s %<name>s $%<currency>s (%<percent>.0f%%)",
|
349
349
|
precision: 3,
|
350
|
-
delimiter:
|
350
|
+
delimiter: "*"
|
351
351
|
}
|
352
352
|
```
|
353
353
|
|
data/lib/tty-pie.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "tty/pie"
|
data/lib/tty/pie.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "pastel"
|
4
|
+
require "tty-cursor"
|
5
5
|
|
6
|
-
require_relative
|
7
|
-
require_relative
|
6
|
+
require_relative "pie/data_item"
|
7
|
+
require_relative "pie/version"
|
8
8
|
|
9
9
|
module TTY
|
10
10
|
class Pie
|
11
11
|
FULL_CIRCLE_DEGREES = 360
|
12
12
|
|
13
|
-
POINT_SYMBOL =
|
13
|
+
POINT_SYMBOL = "•"
|
14
14
|
|
15
15
|
LEGEND_LINE_SPACE = 1
|
16
16
|
|
@@ -35,7 +35,7 @@ module TTY
|
|
35
35
|
# Create pie chart
|
36
36
|
#
|
37
37
|
# @example
|
38
|
-
# data = [ { name:
|
38
|
+
# data = [ { name: "BTC", value: 5977, fill: "*" } ]
|
39
39
|
# pie_chart = TTY::Pie.new(data: data, radius: 2)
|
40
40
|
#
|
41
41
|
# @param [Array[Hash]] data
|
@@ -120,7 +120,7 @@ module TTY
|
|
120
120
|
# @api public
|
121
121
|
def render
|
122
122
|
items = data_items
|
123
|
-
return
|
123
|
+
return "" if items.empty?
|
124
124
|
angles = data_angles(items)
|
125
125
|
output = []
|
126
126
|
|
@@ -135,7 +135,7 @@ module TTY
|
|
135
135
|
width = (Math.sqrt(radius * radius - y * y) * aspect_ratio).round
|
136
136
|
width = width.zero? ? (radius / aspect_ratio).round : width
|
137
137
|
|
138
|
-
output <<
|
138
|
+
output << " " * (center_x - width) if top.nil?
|
139
139
|
(-width..width).each do |x|
|
140
140
|
angle = radian_to_degree(Math.atan2(x, y))
|
141
141
|
item = items[select_data_item(angle, angles)]
|
@@ -155,7 +155,7 @@ module TTY
|
|
155
155
|
end
|
156
156
|
if labels_range.include?(y)
|
157
157
|
if top.nil?
|
158
|
-
output <<
|
158
|
+
output << " " * ((center_x - (left.to_i + width)) + label_horiz_space)
|
159
159
|
end
|
160
160
|
output << labels[label_offset + y / label_vert_space]
|
161
161
|
end
|
data/lib/tty/pie/data_item.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pastel"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
class Pie
|
7
7
|
# Encapsulates a single data item
|
8
8
|
class DataItem
|
9
|
-
LABEL_FORMAT =
|
9
|
+
LABEL_FORMAT = "%<label>s %<name>s %<percent>.2f%%"
|
10
10
|
|
11
11
|
attr_accessor :name
|
12
12
|
|
@@ -49,7 +49,7 @@ module TTY
|
|
49
49
|
def to_label(legend)
|
50
50
|
pattern = legend && legend[:format] || LABEL_FORMAT
|
51
51
|
precision = legend && legend[:precision] || 2
|
52
|
-
delimiter = legend && legend[:delimiter] ||
|
52
|
+
delimiter = legend && legend[:delimiter] || ","
|
53
53
|
|
54
54
|
label = color ? @pastel.decorate(fill, color) : fill
|
55
55
|
currency = number_to_currency(value, precision: precision,
|
@@ -68,8 +68,8 @@ module TTY
|
|
68
68
|
# @return [String]
|
69
69
|
#
|
70
70
|
# @api private
|
71
|
-
def number_to_currency(value, precision: 2, delimiter:
|
72
|
-
whole, part = value.to_s.split(
|
71
|
+
def number_to_currency(value, precision: 2, delimiter: ",")
|
72
|
+
whole, part = value.to_s.split(".")
|
73
73
|
unless part.nil?
|
74
74
|
part = format("%.#{precision}f", part.to_f / 10**part.size)[1..-1]
|
75
75
|
end
|
data/lib/tty/pie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-pie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tty-cursor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.7'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.5'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.5'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,41 +68,27 @@ dependencies:
|
|
82
68
|
version: '3.0'
|
83
69
|
description: Draw pie charts in your terminal window.
|
84
70
|
email:
|
85
|
-
-
|
71
|
+
- piotr@piotrmurach.com
|
86
72
|
executables: []
|
87
73
|
extensions: []
|
88
|
-
extra_rdoc_files:
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- CHANGELOG.md
|
77
|
+
- LICENSE.txt
|
89
78
|
files:
|
90
79
|
- CHANGELOG.md
|
91
80
|
- LICENSE.txt
|
92
81
|
- README.md
|
93
|
-
- Rakefile
|
94
|
-
- bin/console
|
95
|
-
- bin/setup
|
96
|
-
- examples/basic.rb
|
97
|
-
- examples/fill.rb
|
98
|
-
- examples/format.rb
|
99
82
|
- lib/tty-pie.rb
|
100
83
|
- lib/tty/pie.rb
|
101
84
|
- lib/tty/pie/data_item.rb
|
102
85
|
- lib/tty/pie/version.rb
|
103
|
-
- spec/spec_helper.rb
|
104
|
-
- spec/unit/add_spec.rb
|
105
|
-
- spec/unit/color_spec.rb
|
106
|
-
- spec/unit/fill_spec.rb
|
107
|
-
- spec/unit/legend_spec.rb
|
108
|
-
- spec/unit/render_spec.rb
|
109
|
-
- spec/unit/reset_spec.rb
|
110
|
-
- spec/unit/update_spec.rb
|
111
|
-
- tasks/console.rake
|
112
|
-
- tasks/coverage.rake
|
113
|
-
- tasks/spec.rake
|
114
|
-
- tty-pie.gemspec
|
115
86
|
homepage: https://piotrmurach.github.io/tty
|
116
87
|
licenses:
|
117
88
|
- MIT
|
118
89
|
metadata:
|
119
90
|
allowed_push_host: https://rubygems.org
|
91
|
+
bug_tracker_uri: https://github.com/piotrmurach/tty-pie/issues
|
120
92
|
changelog_uri: https://github.com/piotrmurach/tty-pie/blob/master/CHANGELOG.md
|
121
93
|
documentation_uri: https://www.rubydoc.info/gems/tty-pie
|
122
94
|
homepage_uri: https://piotrmurach.github.io/tty
|
@@ -136,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
108
|
- !ruby/object:Gem::Version
|
137
109
|
version: '0'
|
138
110
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.1.2
|
140
112
|
signing_key:
|
141
113
|
specification_version: 4
|
142
114
|
summary: Draw pie charts in your terminal window.
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "tty/pie"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/examples/basic.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-pie'
|
2
|
-
|
3
|
-
data = [
|
4
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow },
|
5
|
-
{ name: 'BCH', value: 3045, color: :bright_green },
|
6
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta },
|
7
|
-
{ name: 'ETH', value: 2350, color: :bright_cyan }
|
8
|
-
]
|
9
|
-
|
10
|
-
pie = TTY::Pie.new(data: data, radius: 10)
|
11
|
-
|
12
|
-
puts pie
|
data/examples/fill.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-pie'
|
2
|
-
|
3
|
-
data = [
|
4
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow, fill: '*' },
|
5
|
-
{ name: 'BCH', value: 3045, color: :bright_green, fill: 'x' },
|
6
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta, fill: '@' },
|
7
|
-
{ name: 'ETH', value: 2350, color: :bright_cyan, fill: '+' }
|
8
|
-
]
|
9
|
-
|
10
|
-
pie = TTY::Pie.new(data: data, radius: 10)
|
11
|
-
|
12
|
-
puts pie
|
data/examples/format.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require_relative '../lib/tty-pie'
|
2
|
-
|
3
|
-
data = [
|
4
|
-
{ name: 'BTC', value: 5977, color: :yellow },
|
5
|
-
{ name: 'BCH', value: 3045, color: :green },
|
6
|
-
{ name: 'LTC', value: 2030, color: :magenta },
|
7
|
-
]
|
8
|
-
|
9
|
-
pie = TTY::Pie.new(
|
10
|
-
data: data,
|
11
|
-
legend: {
|
12
|
-
format: "%<label>s %<name>s $%<currency>s (%<percent>.0f%%)"
|
13
|
-
}
|
14
|
-
)
|
15
|
-
|
16
|
-
puts pie
|
data/spec/spec_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
if ENV['COVERAGE'] || ENV['TRAVIS']
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
Coveralls::SimpleCov::Formatter
|
10
|
-
]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
command_name 'spec'
|
14
|
-
add_filter 'spec'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require "bundler/setup"
|
19
|
-
require "tty/pie"
|
20
|
-
|
21
|
-
RSpec.configure do |config|
|
22
|
-
# Enable flags like --only-failures and --next-failure
|
23
|
-
# config.example_status_persistence_file_path = ".rspec_status"
|
24
|
-
|
25
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
26
|
-
config.disable_monkey_patching!
|
27
|
-
|
28
|
-
config.expect_with :rspec do |c|
|
29
|
-
c.syntax = :expect
|
30
|
-
end
|
31
|
-
end
|
data/spec/unit/add_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, '#add' do
|
4
|
-
it "adds additional item" do
|
5
|
-
data = [ { name: 'BTC', value: 5977, fill: '*' } ]
|
6
|
-
|
7
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
8
|
-
pie << { name: 'BCH', value: 3045, fill: '+' }
|
9
|
-
pie << { name: 'LTC', value: 2030, fill: 'x' }
|
10
|
-
|
11
|
-
output = pie.render
|
12
|
-
|
13
|
-
expect(output).to eq([
|
14
|
-
" x** * BTC 54.08%\n",
|
15
|
-
" +xx****\n",
|
16
|
-
"++++***** + BCH 27.55%\n",
|
17
|
-
" +++****\n",
|
18
|
-
" +** x LTC 18.37%\n"
|
19
|
-
].join)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "adds item without modifying original data source" do
|
23
|
-
data = [ { name: 'BTC', value: 5977, fill: '*' } ]
|
24
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
25
|
-
pie << { name: 'BCH', value: 3045, fill: '+' }
|
26
|
-
|
27
|
-
expect(data).to match([a_hash_including(name: 'BTC')])
|
28
|
-
end
|
29
|
-
end
|
data/spec/unit/color_spec.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, ':color option' do
|
4
|
-
it "renders a pie chart without colors" do
|
5
|
-
data = [
|
6
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
7
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
8
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
9
|
-
]
|
10
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
11
|
-
|
12
|
-
output = pie.render
|
13
|
-
|
14
|
-
expect(output).to eq([
|
15
|
-
" x** * BTC 54.08%\n",
|
16
|
-
" +xx****\n",
|
17
|
-
"++++***** + BCH 27.55%\n",
|
18
|
-
" +++****\n",
|
19
|
-
" +** x LTC 18.37%\n"
|
20
|
-
].join)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "renders a pie chart with colors as a parameter" do
|
24
|
-
data = [
|
25
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
26
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
27
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
28
|
-
]
|
29
|
-
pie = TTY::Pie.new(data: data, radius: 2, colors: %i[yellow green magenta])
|
30
|
-
|
31
|
-
output = pie.render
|
32
|
-
expected_output = [
|
33
|
-
" \e[35mx\e[0m\e[33m*\e[0m\e[33m*\e[0m \e[33m*\e[0m BTC 54.08%\n",
|
34
|
-
" \e[32m+\e[0m\e[35mx\e[0m\e[35mx\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\n",
|
35
|
-
"\e[32m+\e[0m\e[32m+\e[0m\e[32m+\e[0m\e[32m+\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m \e[32m+\e[0m BCH 27.55%\n",
|
36
|
-
" \e[32m+\e[0m\e[32m+\e[0m\e[32m+\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\e[33m*\e[0m\n",
|
37
|
-
" \e[32m+\e[0m\e[33m*\e[0m\e[33m*\e[0m \e[35mx\e[0m LTC 18.37%\n"
|
38
|
-
].join
|
39
|
-
expect(output).to eq(expected_output)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "renders a pie chart with colors" do
|
43
|
-
data = [
|
44
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow },
|
45
|
-
{ name: 'BCH', value: 3045, color: :bright_green },
|
46
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta }
|
47
|
-
]
|
48
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
49
|
-
|
50
|
-
output = pie.render
|
51
|
-
|
52
|
-
expect(output).to eq([
|
53
|
-
" \e[95m•\e[0m\e[93m•\e[0m\e[93m•\e[0m",
|
54
|
-
" \e[93m•\e[0m BTC 54.08%\n",
|
55
|
-
" \e[92m•\e[0m\e[95m•\e[0m\e[95m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\n",
|
56
|
-
"\e[92m•\e[0m\e[92m•\e[0m\e[92m•\e[0m\e[92m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m",
|
57
|
-
" \e[92m•\e[0m BCH 27.55%\n",
|
58
|
-
" \e[92m•\e[0m\e[92m•\e[0m\e[92m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\e[93m•\e[0m\n",
|
59
|
-
" \e[92m•\e[0m\e[93m•\e[0m\e[93m•\e[0m",
|
60
|
-
" \e[95m•\e[0m LTC 18.37%\n"
|
61
|
-
].join)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "renders a pie chart with legend and cursor positioning" do
|
65
|
-
data = [
|
66
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow },
|
67
|
-
{ name: 'BCH', value: 3045, color: :bright_green },
|
68
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta }
|
69
|
-
]
|
70
|
-
pie = TTY::Pie.new(data: data, radius: 2, left: 50, top: 10)
|
71
|
-
|
72
|
-
output = pie.render
|
73
|
-
|
74
|
-
expect(output).to eq([
|
75
|
-
"\e[11;54H\e[95m•\e[0m\e[11;55H\e[93m•\e[0m\e[11;56H\e[93m•\e[0m",
|
76
|
-
"\e[11;63H\e[93m•\e[0m BTC 54.08%\n",
|
77
|
-
"\e[12;52H\e[92m•\e[0m\e[12;53H\e[95m•\e[0m\e[12;54H\e[95m•\e[0m\e[12;55H\e[93m•\e[0m\e[12;56H\e[93m•\e[0m\e[12;57H\e[93m•\e[0m\e[12;58H\e[93m•\e[0m\e[12;63H\n",
|
78
|
-
"\e[13;51H\e[92m•\e[0m\e[13;52H\e[92m•\e[0m\e[13;53H\e[92m•\e[0m\e[13;54H\e[92m•\e[0m\e[13;55H\e[93m•\e[0m\e[13;56H\e[93m•\e[0m\e[13;57H\e[93m•\e[0m\e[13;58H\e[93m•\e[0m\e[13;59H\e[93m•\e[0m",
|
79
|
-
"\e[13;63H\e[92m•\e[0m BCH 27.55%\n",
|
80
|
-
"\e[14;52H\e[92m•\e[0m\e[14;53H\e[92m•\e[0m\e[14;54H\e[92m•\e[0m\e[14;55H\e[93m•\e[0m\e[14;56H\e[93m•\e[0m\e[14;57H\e[93m•\e[0m\e[14;58H\e[93m•\e[0m\e[14;63H\n",
|
81
|
-
"\e[15;54H\e[92m•\e[0m\e[15;55H\e[93m•\e[0m\e[15;56H\e[93m•\e[0m",
|
82
|
-
"\e[15;63H\e[95m•\e[0m LTC 18.37%\n"
|
83
|
-
].join)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "renders a pie chart without legend and with cursor positioning" do
|
87
|
-
data = [
|
88
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow },
|
89
|
-
{ name: 'BCH', value: 3045, color: :bright_green },
|
90
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta }
|
91
|
-
]
|
92
|
-
pie = TTY::Pie.new(data: data, radius: 2, left: 50, top: 10, legend: false)
|
93
|
-
|
94
|
-
output = pie.render
|
95
|
-
|
96
|
-
expect(output).to eq([
|
97
|
-
"\e[11;54H\e[95m•\e[0m\e[11;55H\e[93m•\e[0m\e[11;56H\e[93m•\e[0m\n",
|
98
|
-
"\e[12;52H\e[92m•\e[0m\e[12;53H\e[95m•\e[0m\e[12;54H\e[95m•\e[0m\e[12;55H\e[93m•\e[0m\e[12;56H\e[93m•\e[0m\e[12;57H\e[93m•\e[0m\e[12;58H\e[93m•\e[0m\n",
|
99
|
-
"\e[13;51H\e[92m•\e[0m\e[13;52H\e[92m•\e[0m\e[13;53H\e[92m•\e[0m\e[13;54H\e[92m•\e[0m\e[13;55H\e[93m•\e[0m\e[13;56H\e[93m•\e[0m\e[13;57H\e[93m•\e[0m\e[13;58H\e[93m•\e[0m\e[13;59H\e[93m•\e[0m\n",
|
100
|
-
"\e[14;52H\e[92m•\e[0m\e[14;53H\e[92m•\e[0m\e[14;54H\e[92m•\e[0m\e[14;55H\e[93m•\e[0m\e[14;56H\e[93m•\e[0m\e[14;57H\e[93m•\e[0m\e[14;58H\e[93m•\e[0m\n",
|
101
|
-
"\e[15;54H\e[92m•\e[0m\e[15;55H\e[93m•\e[0m\e[15;56H\e[93m•\e[0m\n",
|
102
|
-
].join)
|
103
|
-
end
|
104
|
-
end
|
data/spec/unit/fill_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, ':fill option' do
|
4
|
-
let(:data) {
|
5
|
-
[
|
6
|
-
{ name: 'BTC', value: 5977, color: :bright_yellow, fill: '*' },
|
7
|
-
{ name: 'BCH', value: 3045, color: :bright_green, fill: '+' },
|
8
|
-
{ name: 'LTC', value: 2030, color: :bright_magenta, fill: 'x' }
|
9
|
-
]
|
10
|
-
}
|
11
|
-
|
12
|
-
it "renders a pie chart with custom fill per data item" do
|
13
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
14
|
-
|
15
|
-
output = pie.render
|
16
|
-
|
17
|
-
expect(output).to eq([
|
18
|
-
" \e[95mx\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
19
|
-
" \e[93m*\e[0m BTC 54.08%\n",
|
20
|
-
" \e[92m+\e[0m\e[95mx\e[0m\e[95mx\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\n\e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
21
|
-
" \e[92m+\e[0m BCH 27.55%\n",
|
22
|
-
" \e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\n",
|
23
|
-
" \e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
24
|
-
" \e[95mx\e[0m LTC 18.37%\n"
|
25
|
-
].join)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "renders with custom fill chars per instance" do
|
29
|
-
data_without_fill = data.map { |item| item.delete(:fill); item }
|
30
|
-
pie = TTY::Pie.new(data: data_without_fill, radius: 2, fill: %w[* + x])
|
31
|
-
|
32
|
-
output = pie.render
|
33
|
-
|
34
|
-
expected_output = [
|
35
|
-
" \e[95mx\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
36
|
-
" \e[93m*\e[0m BTC 54.08%\n",
|
37
|
-
" \e[92m+\e[0m\e[95mx\e[0m\e[95mx\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\n\e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
38
|
-
" \e[92m+\e[0m BCH 27.55%\n",
|
39
|
-
" \e[92m+\e[0m\e[92m+\e[0m\e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\e[93m*\e[0m\n",
|
40
|
-
" \e[92m+\e[0m\e[93m*\e[0m\e[93m*\e[0m",
|
41
|
-
" \e[95mx\e[0m LTC 18.37%\n"
|
42
|
-
|
43
|
-
].join
|
44
|
-
|
45
|
-
expect(output).to eq(expected_output)
|
46
|
-
end
|
47
|
-
end
|
data/spec/unit/legend_spec.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, ':legend option' do
|
4
|
-
it "renders legend at default location with 1 line separator" do
|
5
|
-
data = [
|
6
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
7
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
8
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
9
|
-
]
|
10
|
-
|
11
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
12
|
-
|
13
|
-
output = pie.render
|
14
|
-
|
15
|
-
expect(output).to eq([
|
16
|
-
" x** * BTC 54.08%\n",
|
17
|
-
" +xx****\n",
|
18
|
-
"++++***** + BCH 27.55%\n",
|
19
|
-
" +++****\n",
|
20
|
-
" +** x LTC 18.37%\n"
|
21
|
-
].join)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "renders legend next to chart without any line separator" do
|
25
|
-
data = [
|
26
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
27
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
28
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
29
|
-
]
|
30
|
-
|
31
|
-
pie = TTY::Pie.new(data: data, radius: 2, legend: {left: 0, line: 0})
|
32
|
-
|
33
|
-
output = pie.render
|
34
|
-
|
35
|
-
expect(output).to eq([
|
36
|
-
" x**\n",
|
37
|
-
" +xx**** * BTC 54.08%\n",
|
38
|
-
"++++*****+ BCH 27.55%\n",
|
39
|
-
" +++**** x LTC 18.37%\n",
|
40
|
-
" +**\n"
|
41
|
-
].join)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "renders legend at custom location with line separator" do
|
45
|
-
data = [
|
46
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
47
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
48
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
49
|
-
]
|
50
|
-
|
51
|
-
pie = TTY::Pie.new(data: data, radius: 3, legend: {left: 10, line: 2})
|
52
|
-
|
53
|
-
output = pie.render
|
54
|
-
|
55
|
-
expect(output).to eq([
|
56
|
-
" x** * BTC 54.08%\n",
|
57
|
-
" xxxx*****\n",
|
58
|
-
"++++xx*******\n",
|
59
|
-
"++++++******* + BCH 27.55%\n",
|
60
|
-
"++++++*******\n",
|
61
|
-
" ++++*****\n",
|
62
|
-
" +** x LTC 18.37%\n"
|
63
|
-
].join)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "renders legend next to chart without any line separator" do
|
67
|
-
data = [
|
68
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
69
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
70
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
71
|
-
]
|
72
|
-
|
73
|
-
pie = TTY::Pie.new(data: data, left: 2, top: 2, radius: 2, legend: {left: 2, line: 0})
|
74
|
-
|
75
|
-
output = pie.render
|
76
|
-
|
77
|
-
expected_output = [
|
78
|
-
"\e[3;6Hx\e[3;7H*\e[3;8H*\e[3;13H\n",
|
79
|
-
"\e[4;4H+\e[4;5Hx\e[4;6Hx\e[4;7H*\e[4;8H*\e[4;9H*\e[4;10H*\e[4;13H* BTC 54.08%\n",
|
80
|
-
"\e[5;3H+\e[5;4H+\e[5;5H+\e[5;6H+\e[5;7H*\e[5;8H*\e[5;9H*\e[5;10H*\e[5;11H*\e[5;13H+ BCH 27.55%\n",
|
81
|
-
"\e[6;4H+\e[6;5H+\e[6;6H+\e[6;7H*\e[6;8H*\e[6;9H*\e[6;10H*\e[6;13Hx LTC 18.37%\n",
|
82
|
-
"\e[7;6H+\e[7;7H*\e[7;8H*\e[7;13H\n"
|
83
|
-
].join
|
84
|
-
|
85
|
-
expect(output).to eq(expected_output)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "renders legend with a custom format" do
|
89
|
-
data = [
|
90
|
-
{ name: 'BTC', value: 5977, fill: '*' },
|
91
|
-
{ name: 'BCH', value: 3045, fill: '+' },
|
92
|
-
{ name: 'LTC', value: 2030, fill: 'x' }
|
93
|
-
]
|
94
|
-
|
95
|
-
pie = TTY::Pie.new(
|
96
|
-
data: data,
|
97
|
-
radius: 2,
|
98
|
-
legend: {
|
99
|
-
format: "%<label>s %<name>s %<value>d (%<percent>.2f%%)"
|
100
|
-
}
|
101
|
-
)
|
102
|
-
|
103
|
-
output = pie.render
|
104
|
-
|
105
|
-
expect(output).to eq([
|
106
|
-
" x** * BTC 5977 (54.08%)\n",
|
107
|
-
" +xx****\n",
|
108
|
-
"++++***** + BCH 3045 (27.55%)\n",
|
109
|
-
" +++****\n",
|
110
|
-
" +** x LTC 2030 (18.37%)\n"
|
111
|
-
].join)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "renders legend with a custom format & value as currency" do
|
115
|
-
data = [
|
116
|
-
{ name: 'BTC', value: 5977.12345, fill: '*' },
|
117
|
-
{ name: 'BCH', value: 3045.2, fill: '+' },
|
118
|
-
{ name: 'LTC', value: 2030.444, fill: 'x' }
|
119
|
-
]
|
120
|
-
|
121
|
-
pie = TTY::Pie.new(
|
122
|
-
data: data,
|
123
|
-
radius: 2,
|
124
|
-
legend: {
|
125
|
-
format: "%<label>s %<name>s $%<currency>s (%<percent>.0f%%)"
|
126
|
-
}
|
127
|
-
)
|
128
|
-
|
129
|
-
output = pie.render
|
130
|
-
|
131
|
-
expect(output).to eq([
|
132
|
-
" x** * BTC $5,977.12 (54%)\n",
|
133
|
-
" +xx****\n",
|
134
|
-
"++++***** + BCH $3,045.20 (28%)\n",
|
135
|
-
" +++****\n",
|
136
|
-
" +** x LTC $2,030.44 (18%)\n"
|
137
|
-
].join)
|
138
|
-
end
|
139
|
-
|
140
|
-
it "renders legend with a custom format and currency precision & delimiter" do
|
141
|
-
data = [
|
142
|
-
{ name: 'BTC', value: 5977.12345, fill: '*' },
|
143
|
-
{ name: 'BCH', value: 3045.2, fill: '+' },
|
144
|
-
{ name: 'LTC', value: 2030.444, fill: 'x' }
|
145
|
-
]
|
146
|
-
|
147
|
-
pie = TTY::Pie.new(
|
148
|
-
data: data,
|
149
|
-
radius: 2,
|
150
|
-
legend: {
|
151
|
-
format: "%<label>s %<name>s $%<currency>s (%<percent>.0f%%)",
|
152
|
-
precision: 3,
|
153
|
-
delimiter: '*'
|
154
|
-
}
|
155
|
-
)
|
156
|
-
|
157
|
-
output = pie.render
|
158
|
-
|
159
|
-
expect(output).to eq([
|
160
|
-
" x** * BTC $5*977.123 (54%)\n",
|
161
|
-
" +xx****\n",
|
162
|
-
"++++***** + BCH $3*045.200 (28%)\n",
|
163
|
-
" +++****\n",
|
164
|
-
" +** x LTC $2*030.444 (18%)\n"
|
165
|
-
].join)
|
166
|
-
end
|
167
|
-
end
|
data/spec/unit/render_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, '#render' do
|
4
|
-
let(:data) {
|
5
|
-
[
|
6
|
-
{ name: 'BTC', value: 5977 },
|
7
|
-
{ name: 'BCH', value: 3045 },
|
8
|
-
{ name: 'LTC', value: 2030 }
|
9
|
-
]
|
10
|
-
}
|
11
|
-
|
12
|
-
it "renders chart with no data" do
|
13
|
-
pie = TTY::Pie.new(data: [], radius: 2)
|
14
|
-
|
15
|
-
expect(pie.render).to eq('')
|
16
|
-
end
|
17
|
-
|
18
|
-
it "renders a pie chart with legend and without cursor positioning" do
|
19
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
20
|
-
|
21
|
-
output = pie.render
|
22
|
-
|
23
|
-
expect(output).to eq([
|
24
|
-
" ••• • BTC 54.08%\n",
|
25
|
-
" •••••••\n",
|
26
|
-
"••••••••• • BCH 27.55%\n",
|
27
|
-
" •••••••\n",
|
28
|
-
" ••• • LTC 18.37%\n"
|
29
|
-
].join)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "renders a pie chart without legend and without cursor positioning" do
|
33
|
-
pie = TTY::Pie.new(data: data, radius: 2, legend: false)
|
34
|
-
|
35
|
-
output = pie.render
|
36
|
-
|
37
|
-
expect(output).to eq([
|
38
|
-
" •••\n",
|
39
|
-
" •••••••\n",
|
40
|
-
"•••••••••\n",
|
41
|
-
" •••••••\n",
|
42
|
-
" •••\n"
|
43
|
-
].join)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "render a pie chart with legend and cursor positioning" do
|
47
|
-
pie = TTY::Pie.new(data: data, radius: 2, left: 50, top: 10)
|
48
|
-
|
49
|
-
output = pie.render
|
50
|
-
|
51
|
-
expect(output).to eq([
|
52
|
-
"\e[11;54H•\e[11;55H•\e[11;56H•\e[11;63H• BTC 54.08%\n",
|
53
|
-
"\e[12;52H•\e[12;53H•\e[12;54H•\e[12;55H•\e[12;56H•\e[12;57H•\e[12;58H•\e[12;63H\n",
|
54
|
-
"\e[13;51H•\e[13;52H•\e[13;53H•\e[13;54H•\e[13;55H•\e[13;56H•\e[13;57H•\e[13;58H•\e[13;59H•\e[13;63H• BCH 27.55%\n",
|
55
|
-
"\e[14;52H•\e[14;53H•\e[14;54H•\e[14;55H•\e[14;56H•\e[14;57H•\e[14;58H•\e[14;63H\n",
|
56
|
-
"\e[15;54H•\e[15;55H•\e[15;56H•",
|
57
|
-
"\e[15;63H• LTC 18.37%\n"
|
58
|
-
].join)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "render a pie chart without legend and with cursor positioning" do
|
62
|
-
pie = TTY::Pie.new(data: data, radius: 2, left: 50, top: 10, legend: false)
|
63
|
-
|
64
|
-
output = pie.render
|
65
|
-
|
66
|
-
expect(output).to eq([
|
67
|
-
"\e[11;54H\•\e[11;55H•\e[11;56H•\n",
|
68
|
-
"\e[12;52H\•\e[12;53H•\e[12;54H•\e[12;55H•\e[12;56H•\e[12;57H•\e[12;58H•\n",
|
69
|
-
"\e[13;51H\•\e[13;52H•\e[13;53H•\e[13;54H•\e[13;55H•\e[13;56H•\e[13;57H•\e[13;58H•\e[13;59H•\n",
|
70
|
-
"\e[14;52H\•\e[14;53H•\e[14;54H•\e[14;55H•\e[14;56H•\e[14;57H•\e[14;58H•\n",
|
71
|
-
"\e[15;54H\•\e[15;55H•\e[15;56H•\n",
|
72
|
-
].join)
|
73
|
-
end
|
74
|
-
end
|
data/spec/unit/reset_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, '#reset' do
|
4
|
-
it "resets current data" do
|
5
|
-
data = [ { name: 'BTC', value: 5977, fill: '*' } ]
|
6
|
-
|
7
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
8
|
-
|
9
|
-
output = pie.render
|
10
|
-
|
11
|
-
expect(output).to eq([
|
12
|
-
" ***\n",
|
13
|
-
" *******\n",
|
14
|
-
"********* * BTC 100.00%\n",
|
15
|
-
" *******\n",
|
16
|
-
" ***\n"
|
17
|
-
].join)
|
18
|
-
|
19
|
-
pie.reset
|
20
|
-
|
21
|
-
expect(pie.render).to eq('')
|
22
|
-
end
|
23
|
-
end
|
data/spec/unit/update_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Pie, '#update' do
|
4
|
-
it "updates current data" do
|
5
|
-
data = [ { name: 'BTC', value: 5977, fill: '*' } ]
|
6
|
-
|
7
|
-
pie = TTY::Pie.new(data: data, radius: 2)
|
8
|
-
|
9
|
-
output = pie.render
|
10
|
-
|
11
|
-
expect(output).to eq([
|
12
|
-
" ***\n",
|
13
|
-
" *******\n",
|
14
|
-
"********* * BTC 100.00%\n",
|
15
|
-
" *******\n",
|
16
|
-
" ***\n"
|
17
|
-
].join)
|
18
|
-
|
19
|
-
pie.update([{name: 'LTC', value: 2030, fill: 'x'}])
|
20
|
-
|
21
|
-
output = pie.render
|
22
|
-
|
23
|
-
expect(output).to eq([
|
24
|
-
" xxx\n",
|
25
|
-
" xxxxxxx\n",
|
26
|
-
"xxxxxxxxx x LTC 100.00%\n",
|
27
|
-
" xxxxxxx\n",
|
28
|
-
" xxx\n"
|
29
|
-
].join)
|
30
|
-
end
|
31
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/tty-pie.gemspec
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require "tty/pie/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "tty-pie"
|
7
|
-
spec.version = TTY::Pie::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
spec.summary = %q{Draw pie charts in your terminal window.}
|
11
|
-
spec.description = %q{Draw pie charts in your terminal window.}
|
12
|
-
spec.homepage = "https://piotrmurach.github.io/tty"
|
13
|
-
spec.license = "MIT"
|
14
|
-
if spec.respond_to?(:metadata)
|
15
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
-
spec.metadata["changelog_uri"] = "https://github.com/piotrmurach/tty-pie/blob/master/CHANGELOG.md"
|
17
|
-
spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/tty-pie"
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/piotrmurach/tty-pie"
|
20
|
-
end
|
21
|
-
spec.files = Dir['{lib,spec,examples}/**/*.rb']
|
22
|
-
spec.files += Dir['{bin,tasks}/*', 'tty-pie.gemspec']
|
23
|
-
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
24
|
-
spec.require_paths = ["lib"]
|
25
|
-
|
26
|
-
spec.required_ruby_version = '>= 2.0.0'
|
27
|
-
|
28
|
-
spec.add_dependency 'pastel', '~> 0.7.3'
|
29
|
-
spec.add_dependency 'tty-cursor', '~> 0.7'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'bundler', '>= 1.5'
|
32
|
-
spec.add_development_dependency 'rake'
|
33
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
-
end
|