svg_plot_gen 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/svg_plot_gen.rb CHANGED
@@ -12,8 +12,9 @@ class Svg_Plot_Gen
12
12
  opt :template, "Output a template SVG file that contains [SPLIT] markers where a path and display attribute can be inserted. See README.md", :default => false
13
13
  opt :width, "The width of the output plot in pixels", :default => 960
14
14
  opt :height, "The height of the output plot in pixels", :default => 380
15
- opt :y_first, "Sets the value at which the y axis starts", :default => 0
16
- opt :y_last, "Set the value at which the y axis ends", :default => 5
15
+ opt :y_first, "Sets the value at which the y axis starts", :default => 0.to_f
16
+ opt :y_step, "Sets the height of each division on the y axis", :default => 1.to_f
17
+ opt :y_last, "Sets the value at which the y axis ends", :default => 5.to_f
17
18
  opt :log, "Sets the y axis to a logarithmic scale. `y_first` and `y_last` now refer to powers of 10", :default => false
18
19
  opt :x_text, "The x-axis label", :default => 'x-axis'
19
20
  opt :y_text, "The y-axis label", :default => 'y-axis'
@@ -81,28 +82,39 @@ class Svg_Plot_Gen
81
82
  # Build up our x-axis labels for a 24 hour period
82
83
  xlabels = (0..24).step(2).map { |hour| [['00', (hour%24).to_s].join[-2..-1], ':00'].join }.zip(xlines.select { |k, v| v }.map { |k, v| k })
83
84
 
85
+ y_range = (opts.y_first..opts.y_last).step(opts.y_step)
86
+
84
87
  # Generates the values for a logarithmic scale
85
88
  if opts.log
86
89
  # Work out the y-positions of the horizonal lines and ticks
87
- ylines = Hash[(opts.y_first..opts.y_last)
88
- .map { |y| (y < opts.y_last ? [1, 2.5, 5, 7.5] : [1])
90
+ ylines = Hash[y_range
91
+ .map { |y| (y < opts.y_last ?
92
+ [1, 2.5, 5, 7.5].map { |i| i*opts.y_step } :
93
+ [1])
89
94
  .map { |m| [Math.log10((10**y)*m), m==1] } }
90
95
  .flatten(1)
91
96
  .map { |y| [(yend - (y[0] - opts.y_first)*(ylen.to_f/(opts.y_last - opts.y_first))).round(1), y[1]] }]
92
97
  # Build up our y-axis labels
93
- ylabels = (opts.y_first..opts.y_last)
98
+ ylabels = y_range
94
99
  .map{ |i| 10**i }
95
100
  .map{ |i| i <= 10000 ? ("%d" % i) : ("%.0e" % i) }
96
- .zip(ylines.select { |k ,v| v }.map { |k, v| k })
101
+ .zip(ylines
102
+ .select { |k ,v| v } # Select only major ticks
103
+ .map { |k, v| k })
97
104
  else # Generate the values for a linear scale
98
105
  # Work out the y-positions of the horizonal lines and ticks
99
- ylines = Hash[(opts.y_first..opts.y_last)
100
- .map { |y| (y < opts.y_last ? [0, 0.25, 0.5, 0.75] : [0])
106
+ ylines = Hash[y_range
107
+ .map { |y| (y < opts.y_last ?
108
+ [0, 0.25, 0.5, 0.75].map { |i| i*opts.y_step } :
109
+ [0])
101
110
  .map { |m| [y+m, m==0] } }
102
111
  .flatten(1)
103
112
  .map { |y| [(yend - (y[0] - opts.y_first)*(ylen.to_f/(opts.y_last - opts.y_first))).round(1), y[1]] }]
104
113
  # Build up our y-axis labels
105
- ylabels = (opts.y_first..opts.y_last).zip(ylines.select { |k ,v| v }.map { |k, v| k })
114
+ ylabels = y_range
115
+ .zip(ylines
116
+ .select { |k, v| v } # Select only major ticks
117
+ .map { |k, v| k })
106
118
  end
107
119
 
108
120
  # Output some useful info about the plot we're generating to stderr
data/svg_plot_gen.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "svg_plot_gen"
3
3
  s.summary = "Creates the axes and gridlines for a graph in SVG. Perfect for creating a static background to which live data can be added."
4
- s.version = "1.0.0"
4
+ s.version = "1.1.0"
5
5
  s.date = Time.now.strftime('%Y-%m-%d')
6
6
  s.author = "Richard Meadows"
7
7
  s.homepage = "https://github.com/richardeoin/svg-plot-gen"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg_plot_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-16 00:00:00.000000000 Z
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &18785000 !ruby/object:Gem::Requirement
16
+ requirement: &13606140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18785000
24
+ version_requirements: *13606140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &18908040 !ruby/object:Gem::Requirement
27
+ requirement: &13605120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18908040
35
+ version_requirements: *13605120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: color
38
- requirement: &18907380 !ruby/object:Gem::Requirement
38
+ requirement: &13603720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '1.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *18907380
46
+ version_requirements: *13603720
47
47
  description:
48
48
  email:
49
49
  executables: