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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4da2755eb0417c5b0c4745ba3c48731b7885b976
4
- data.tar.gz: aa2f198109cf7b2778a0e96a373d26f28747c613
3
+ metadata.gz: 517daea21634f29dd222d42af3d3aa64a64c6b98
4
+ data.tar.gz: ffa37ef3e28ae074513ba0f0537536ac451ad27d
5
5
  SHA512:
6
- metadata.gz: aeb9f5516f4c5f4636158833639d369a1ab67c9b2b1a7a5beda73d13512a6fb78c981372c608ac13abf11171c51f22b0892a3caf6db58bece66418bce3111ae8
7
- data.tar.gz: c7500f8d6819e229ef05890ace09bc27b66d597afd71bae33bd83adab7ff4b2a692e54dda9fdf18850ca4bbd5b9fa9b6f4a10117308d2c5e9c2c301962ee61db
6
+ metadata.gz: d5ddd1b7c0c6dd1eb54995f6d0a044ac7e5ea3c482af110b18daa3584ac922631d59d9114fe52d89f9a3980853aadd139a0169687ea85f65992235d4bd8fe7b6
7
+ data.tar.gz: c5b1ff625d1ae535f63d71c67df43c69da01b939a9c518fb9e84492e0d5a3005a56861ba2eb376a43bb645f216f957516a314cbd1fdf7a7df8403d616189e4aa
@@ -1,15 +1,15 @@
1
1
  class Charts::BarChart::Bar
2
- attr_reader :graph, :data_value, :set_nr, :bar_nr_in_set
2
+ attr_reader :chart, :data_value, :set_nr, :bar_nr_in_set
3
3
 
4
- def initialize(graph, data_value, set_nr, bar_nr_in_set)
5
- @graph = graph
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
- graph.renderer.rect x, y, width, height, fill: graph.colors[set_nr], class: 'bar'
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 bar_number_in_graph
32
- set_nr + bar_nr_in_set * graph.set_count
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
- graph.outer_margin
7
+ chart.outer_margin
8
8
  end
9
9
 
10
10
  def x_offset
11
- graph.inner_width * [data_value, graph.base_line].min
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
- graph.outer_margin + graph.bar_margin + graph.group_margin * bar_nr_in_set
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
- graph.bar_outer_width * bar_number_in_graph
23
+ chart.bar_outer_width * bar_number_in_chart
24
24
  end
25
25
 
26
26
  def width
27
- graph.inner_width * (data_value - graph.base_line).abs
27
+ chart.inner_width * (data_value - chart.base_line).abs
28
28
  end
29
29
 
30
30
  def height
31
- graph.bar_inner_width.floor.to_i
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
- graph.outer_margin + graph.bar_margin + graph.group_margin * bar_nr_in_set
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
- graph.bar_outer_width * bar_number_in_graph
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
- graph.outer_margin
19
+ chart.outer_margin
20
20
  end
21
21
 
22
22
  def y_offset
23
- graph.inner_height * [(1 - data_value), (1 - graph.base_line)].min
23
+ chart.inner_height * [(1 - data_value), (1 - chart.base_line)].min
24
24
  end
25
25
 
26
26
  def width
27
- graph.bar_inner_width.floor.to_i
27
+ chart.bar_inner_width.floor.to_i
28
28
  end
29
29
 
30
30
  def height
31
- graph.inner_height * (data_value - graph.base_line).abs
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 :graph, :value
2
+ attr_accessor :chart, :value
3
3
 
4
- def initialize(graph, value)
5
- @graph = graph
4
+ def initialize(chart, value)
5
+ @chart = chart
6
6
  @value = value
7
7
  end
8
8
 
9
9
  def draw
10
- graph.renderer.line x1, y1, x2, y2, graph.renderer.grid_line_style
11
- graph.renderer.text label_text, label_x, label_y, label_style
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 graph.spread_order_of_magnitude <= 0
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
- graph.outer_margin
3
+ chart.outer_margin
4
4
  end
5
5
 
6
6
  def x2
7
- graph.width - graph.outer_margin
7
+ chart.width - chart.outer_margin
8
8
  end
9
9
 
10
10
  def y1
11
- graph.outer_margin + graph.inner_height * (1 - graph.normalize(value))
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 + graph.renderer.font_size / 3
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
- graph.outer_margin
3
+ chart.outer_margin
4
4
  end
5
5
 
6
6
  def y2
7
- graph.outer_margin + graph.inner_height
7
+ chart.outer_margin + chart.inner_height
8
8
  end
9
9
 
10
10
  def x1
11
- graph.outer_margin + graph.inner_width * graph.normalize(value)
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 + graph.renderer.font_size + 5
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
- graph.render
12
+ chart.render
12
13
  else
13
- puts graph.render
14
+ puts chart.render
14
15
  end
15
16
  end
16
17
 
17
- def graph
18
+ def dispatch
18
19
  if type == :txt
19
- SymbolCountChart.new(data, graph_options)
20
+ SymbolCountChart.new(data, chart_options)
20
21
  elsif [:svg, :png, :jpg, :gif].include? type
21
22
  if style == :circle
22
- CircleCountChart.new(data, graph_options)
23
+ CircleCountChart.new(data, chart_options)
23
24
  elsif style == :cross
24
- CrossCountChart.new(data, graph_options)
25
+ CrossCountChart.new(data, chart_options)
25
26
  elsif style == :manikin
26
- ManikinCountChart.new(data, graph_options)
27
+ ManikinCountChart.new(data, chart_options)
27
28
  elsif style == :bar
28
- BarChart.new(data, graph_options)
29
+ BarChart.new(data, chart_options)
29
30
  elsif style == :pie
30
- PieChart.new(data, graph_options)
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 graph_options
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 graph if only one data set is provided
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 graph style: #{STYLES.join(', ')} (circle, cross and manikin are count graphs)"
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 graphs)',
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 graphs)',
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 graphs only)'
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 graphs only)'
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
@@ -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
- if options[:colors]
24
- unless options[:colors].is_a? Array
25
- raise ArgumentError.new('colors not an array')
26
- end
27
- if options[:colors].any? and data.count > options[:colors].count
28
- raise ArgumentError.new('not enough colors')
29
- end
30
- end
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[:labels].any? and data.count > options[:labels].count
36
- raise ArgumentError.new('not enough labels')
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 :graph
2
+ attr_reader :chart
3
3
 
4
- def initialize(graph)
5
- @graph = graph
6
- if graph.type == :svg
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 = graph.options[: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(graph.width, graph.height) do |canvas|
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(graph.width, graph.height) do |canvas|
42
+ rvg.rvg(chart.width, chart.height) do |canvas|
43
43
  yield(canvas).styles(style)
44
44
  end
45
45
  end
@@ -4,7 +4,7 @@ module Charts::Renderer::SvgRenderer
4
4
  attr_reader :svg
5
5
 
6
6
  def pre_draw
7
- @svg = SVG.new width: graph.width, height: graph.height
7
+ @svg = SVG.new width: chart.width, height: chart.height
8
8
  end
9
9
 
10
10
  def print
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.9
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 graphics with ruby as SVG, JPG or PNG
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: []