charts 0.0.9 → 0.0.10
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/lib/charts/bar_chart/bar/bar.rb +6 -6
- data/lib/charts/bar_chart/bar/horizontal_bar.rb +6 -6
- data/lib/charts/bar_chart/bar/vertical_bar.rb +6 -6
- data/lib/charts/bar_chart/grid/grid_line.rb +6 -6
- data/lib/charts/bar_chart/grid/horizontal_grid_line.rb +4 -4
- data/lib/charts/bar_chart/grid/vertical_grid_line.rb +4 -4
- data/lib/charts/bin/dispatcher.rb +12 -11
- data/lib/charts/bin/opt_parser.rb +6 -6
- data/lib/charts/chart.rb +10 -13
- data/lib/charts/renderer/renderer.rb +5 -5
- data/lib/charts/renderer/rvg_renderer.rb +2 -2
- data/lib/charts/renderer/svg_renderer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 517daea21634f29dd222d42af3d3aa64a64c6b98
|
4
|
+
data.tar.gz: ffa37ef3e28ae074513ba0f0537536ac451ad27d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5ddd1b7c0c6dd1eb54995f6d0a044ac7e5ea3c482af110b18daa3584ac922631d59d9114fe52d89f9a3980853aadd139a0169687ea85f65992235d4bd8fe7b6
|
7
|
+
data.tar.gz: c5b1ff625d1ae535f63d71c67df43c69da01b939a9c518fb9e84492e0d5a3005a56861ba2eb376a43bb645f216f957516a314cbd1fdf7a7df8403d616189e4aa
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class Charts::BarChart::Bar
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :chart, :data_value, :set_nr, :bar_nr_in_set
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(chart, data_value, set_nr, bar_nr_in_set)
|
5
|
+
@chart = chart
|
6
6
|
@data_value = data_value
|
7
7
|
@set_nr = set_nr
|
8
8
|
@bar_nr_in_set = bar_nr_in_set
|
9
9
|
end
|
10
10
|
|
11
11
|
def draw
|
12
|
-
|
12
|
+
chart.renderer.rect x, y, width, height, fill: chart.colors[set_nr], class: 'bar'
|
13
13
|
end
|
14
14
|
|
15
15
|
def x
|
@@ -28,7 +28,7 @@ class Charts::BarChart::Bar
|
|
28
28
|
raise NotImplementedError
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
set_nr + bar_nr_in_set *
|
31
|
+
def bar_number_in_chart
|
32
|
+
set_nr + bar_nr_in_set * chart.set_count
|
33
33
|
end
|
34
34
|
end
|
@@ -4,11 +4,11 @@ class Charts::BarChart::HorizontalBar < Charts::BarChart::Bar
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def x_margin
|
7
|
-
|
7
|
+
chart.outer_margin
|
8
8
|
end
|
9
9
|
|
10
10
|
def x_offset
|
11
|
-
|
11
|
+
chart.inner_width * [data_value, chart.base_line].min
|
12
12
|
end
|
13
13
|
|
14
14
|
def y
|
@@ -16,18 +16,18 @@ class Charts::BarChart::HorizontalBar < Charts::BarChart::Bar
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def y_margin
|
19
|
-
|
19
|
+
chart.outer_margin + chart.bar_margin + chart.group_margin * bar_nr_in_set
|
20
20
|
end
|
21
21
|
|
22
22
|
def y_offset
|
23
|
-
|
23
|
+
chart.bar_outer_width * bar_number_in_chart
|
24
24
|
end
|
25
25
|
|
26
26
|
def width
|
27
|
-
|
27
|
+
chart.inner_width * (data_value - chart.base_line).abs
|
28
28
|
end
|
29
29
|
|
30
30
|
def height
|
31
|
-
|
31
|
+
chart.bar_inner_width.floor.to_i
|
32
32
|
end
|
33
33
|
end
|
@@ -4,11 +4,11 @@ class Charts::BarChart::VerticalBar < Charts::BarChart::Bar
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def x_margin
|
7
|
-
|
7
|
+
chart.outer_margin + chart.bar_margin + chart.group_margin * bar_nr_in_set
|
8
8
|
end
|
9
9
|
|
10
10
|
def x_offset
|
11
|
-
|
11
|
+
chart.bar_outer_width * bar_number_in_chart
|
12
12
|
end
|
13
13
|
|
14
14
|
def y
|
@@ -16,18 +16,18 @@ class Charts::BarChart::VerticalBar < Charts::BarChart::Bar
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def y_margin
|
19
|
-
|
19
|
+
chart.outer_margin
|
20
20
|
end
|
21
21
|
|
22
22
|
def y_offset
|
23
|
-
|
23
|
+
chart.inner_height * [(1 - data_value), (1 - chart.base_line)].min
|
24
24
|
end
|
25
25
|
|
26
26
|
def width
|
27
|
-
|
27
|
+
chart.bar_inner_width.floor.to_i
|
28
28
|
end
|
29
29
|
|
30
30
|
def height
|
31
|
-
|
31
|
+
chart.inner_height * (data_value - chart.base_line).abs
|
32
32
|
end
|
33
33
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class Charts::Grid::GridLine
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :chart, :value
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
4
|
+
def initialize(chart, value)
|
5
|
+
@chart = chart
|
6
6
|
@value = value
|
7
7
|
end
|
8
8
|
|
9
9
|
def draw
|
10
|
-
|
11
|
-
|
10
|
+
chart.renderer.line x1, y1, x2, y2, chart.renderer.grid_line_style
|
11
|
+
chart.renderer.text label_text, label_x, label_y, label_style
|
12
12
|
end
|
13
13
|
|
14
14
|
def x1
|
@@ -36,7 +36,7 @@ class Charts::Grid::GridLine
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def label_text
|
39
|
-
if
|
39
|
+
if chart.spread_order_of_magnitude <= 0
|
40
40
|
value.to_f
|
41
41
|
else
|
42
42
|
value
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class Charts::Grid::HorizontalGridLine < Charts::Grid::GridLine
|
2
2
|
def x1
|
3
|
-
|
3
|
+
chart.outer_margin
|
4
4
|
end
|
5
5
|
|
6
6
|
def x2
|
7
|
-
|
7
|
+
chart.width - chart.outer_margin
|
8
8
|
end
|
9
9
|
|
10
10
|
def y1
|
11
|
-
|
11
|
+
chart.outer_margin + chart.inner_height * (1 - chart.normalize(value))
|
12
12
|
end
|
13
13
|
|
14
14
|
def y2
|
@@ -20,7 +20,7 @@ class Charts::Grid::HorizontalGridLine < Charts::Grid::GridLine
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def label_y
|
23
|
-
y1 +
|
23
|
+
y1 + chart.renderer.font_size / 3
|
24
24
|
end
|
25
25
|
|
26
26
|
def label_style
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class Charts::Grid::VerticalGridLine < Charts::Grid::GridLine
|
2
2
|
def y1
|
3
|
-
|
3
|
+
chart.outer_margin
|
4
4
|
end
|
5
5
|
|
6
6
|
def y2
|
7
|
-
|
7
|
+
chart.outer_margin + chart.inner_height
|
8
8
|
end
|
9
9
|
|
10
10
|
def x1
|
11
|
-
|
11
|
+
chart.outer_margin + chart.inner_width * chart.normalize(value)
|
12
12
|
end
|
13
13
|
|
14
14
|
def x2
|
@@ -16,7 +16,7 @@ class Charts::Grid::VerticalGridLine < Charts::Grid::GridLine
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def label_y
|
19
|
-
y2 +
|
19
|
+
y2 + chart.renderer.font_size + 5
|
20
20
|
end
|
21
21
|
|
22
22
|
def label_x
|
@@ -1,33 +1,34 @@
|
|
1
1
|
module Charts
|
2
2
|
class Dispatcher
|
3
|
-
attr_reader :options
|
3
|
+
attr_reader :options, :chart
|
4
4
|
|
5
5
|
def initialize(options)
|
6
6
|
@options = options
|
7
|
+
@chart = dispatch
|
7
8
|
end
|
8
9
|
|
9
10
|
def render
|
10
11
|
if options[:filename]
|
11
|
-
|
12
|
+
chart.render
|
12
13
|
else
|
13
|
-
puts
|
14
|
+
puts chart.render
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def dispatch
|
18
19
|
if type == :txt
|
19
|
-
SymbolCountChart.new(data,
|
20
|
+
SymbolCountChart.new(data, chart_options)
|
20
21
|
elsif [:svg, :png, :jpg, :gif].include? type
|
21
22
|
if style == :circle
|
22
|
-
CircleCountChart.new(data,
|
23
|
+
CircleCountChart.new(data, chart_options)
|
23
24
|
elsif style == :cross
|
24
|
-
CrossCountChart.new(data,
|
25
|
+
CrossCountChart.new(data, chart_options)
|
25
26
|
elsif style == :manikin
|
26
|
-
ManikinCountChart.new(data,
|
27
|
+
ManikinCountChart.new(data, chart_options)
|
27
28
|
elsif style == :bar
|
28
|
-
BarChart.new(data,
|
29
|
+
BarChart.new(data, chart_options)
|
29
30
|
elsif style == :pie
|
30
|
-
PieChart.new(data,
|
31
|
+
PieChart.new(data, chart_options)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -36,7 +37,7 @@ module Charts
|
|
36
37
|
options[:data]
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
+
def chart_options
|
40
41
|
options.select do |key, _value|
|
41
42
|
[
|
42
43
|
:background_color,
|
@@ -31,7 +31,7 @@ class Charts::OptParser
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def post_process_options
|
34
|
-
# force 2-dimensional array for bar
|
34
|
+
# force 2-dimensional array for bar chart if only one data set is provided
|
35
35
|
if options[:style] == :bar and !options[:data].first.is_a? Array
|
36
36
|
options[:data] = [options[:data]]
|
37
37
|
end
|
@@ -88,7 +88,7 @@ class Charts::OptParser
|
|
88
88
|
'-s STYLE',
|
89
89
|
'--style STYLE',
|
90
90
|
STYLES,
|
91
|
-
"Choose the
|
91
|
+
"Choose the chart style: #{STYLES.join(', ')} (circle, cross and manikin are count charts)"
|
92
92
|
) do |style|
|
93
93
|
options[:style] = style
|
94
94
|
end
|
@@ -129,7 +129,7 @@ class Charts::OptParser
|
|
129
129
|
end
|
130
130
|
opts.on(
|
131
131
|
'-w WIDTH',
|
132
|
-
'--width WIDTH (not for count
|
132
|
+
'--width WIDTH (not for count charts)',
|
133
133
|
Integer,
|
134
134
|
'Sets the image width'
|
135
135
|
) do |width|
|
@@ -137,7 +137,7 @@ class Charts::OptParser
|
|
137
137
|
end
|
138
138
|
opts.on(
|
139
139
|
'-h HEIGHT',
|
140
|
-
'--height HEIGHT (not for count
|
140
|
+
'--height HEIGHT (not for count charts)',
|
141
141
|
Integer,
|
142
142
|
'Sets the image height'
|
143
143
|
) do |height|
|
@@ -146,14 +146,14 @@ class Charts::OptParser
|
|
146
146
|
opts.on(
|
147
147
|
'--item-width WIDTH',
|
148
148
|
Integer,
|
149
|
-
'Sets the width of the individual item (count
|
149
|
+
'Sets the width of the individual item (count charts only)'
|
150
150
|
) do |item_width|
|
151
151
|
options[:item_width] = item_width
|
152
152
|
end
|
153
153
|
opts.on(
|
154
154
|
'--item-height HEIGHT',
|
155
155
|
Integer,
|
156
|
-
'Sets the height of the individual item (count
|
156
|
+
'Sets the height of the individual item (count charts only)'
|
157
157
|
) do |item_height|
|
158
158
|
options[:item_height] = item_height
|
159
159
|
end
|
data/lib/charts/chart.rb
CHANGED
@@ -20,20 +20,17 @@ class Charts::Chart
|
|
20
20
|
if options[:outer_margin] and !options[:outer_margin].is_a?(Numeric)
|
21
21
|
raise ArgumentError.new('outer_margin not a number')
|
22
22
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if options[:labels]
|
32
|
-
unless options[:labels].is_a? Array
|
33
|
-
raise ArgumentError.new('labels not an array')
|
23
|
+
validate_array_and_count(data, options, :colors)
|
24
|
+
validate_array_and_count(data, options, :labels)
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_array_and_count(data, options, key)
|
28
|
+
if options[key]
|
29
|
+
unless options[key].is_a? Array
|
30
|
+
raise ArgumentError.new("#{ key } not an array")
|
34
31
|
end
|
35
|
-
if options[
|
36
|
-
raise ArgumentError.new(
|
32
|
+
if options[key].any? and data.count > options[key].count
|
33
|
+
raise ArgumentError.new("not enough #{ key }")
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Charts::Renderer
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :chart
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
if
|
4
|
+
def initialize(chart)
|
5
|
+
@chart = chart
|
6
|
+
if chart.type == :svg
|
7
7
|
extend Charts::Renderer::SvgRenderer
|
8
8
|
else
|
9
9
|
extend Charts::Renderer::RvgRenderer
|
@@ -12,7 +12,7 @@ class Charts::Renderer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def post_draw
|
15
|
-
filename =
|
15
|
+
filename = chart.options[:filename]
|
16
16
|
if filename
|
17
17
|
save filename
|
18
18
|
else
|
@@ -4,7 +4,7 @@ module Charts::Renderer::RvgRenderer
|
|
4
4
|
attr_reader :rvg
|
5
5
|
|
6
6
|
def pre_draw
|
7
|
-
@rvg = Magick::RVG.new(
|
7
|
+
@rvg = Magick::RVG.new(chart.width, chart.height) do |canvas|
|
8
8
|
canvas.background_fill = 'white'
|
9
9
|
end
|
10
10
|
end
|
@@ -39,7 +39,7 @@ module Charts::Renderer::RvgRenderer
|
|
39
39
|
|
40
40
|
def canvas(style)
|
41
41
|
style.delete(:class)
|
42
|
-
rvg.rvg(
|
42
|
+
rvg.rvg(chart.width, chart.height) do |canvas|
|
43
43
|
yield(canvas).styles(style)
|
44
44
|
end
|
45
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eike Send
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '2.0'
|
42
|
-
description: Create charts, graphs and info
|
42
|
+
description: Create charts, graphs and info chartics with ruby as SVG, JPG or PNG
|
43
43
|
images
|
44
44
|
email: charts@eike.se
|
45
45
|
executables: []
|