little_graphs 1.0.1 → 1.0.2
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.
- data/Gemfile +0 -1
- data/Gemfile.lock +1 -2
- data/lib/little_graphs.rb +6 -3
- data/little_graphs.gemspec +1 -1
- data/spec/litte_graphs_spec.rb +1 -1
- metadata +1 -1
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/little_graphs.rb
CHANGED
@@ -9,13 +9,16 @@ class LittleGraphs
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def draw(datapoints, filename = nil)
|
12
|
-
if filename.nil? then filename = "new.jpeg" end
|
13
12
|
coordinates = define_coordinates(datapoints)
|
14
13
|
|
15
14
|
f = QuickMagick::Image::solid(@width, @height, :white)
|
16
15
|
f.draw_polyline(coordinates, :fill => :white, :stroke => :blue)
|
17
16
|
|
18
|
-
|
17
|
+
if filename.nil?
|
18
|
+
f.to_blob
|
19
|
+
else
|
20
|
+
f.save(filename)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def define_coordinates(datapoints)
|
@@ -38,7 +41,7 @@ class LittleGraphs
|
|
38
41
|
height = @height - 5 # add a margin
|
39
42
|
point_space = height/(datapoints.max - datapoints.min)
|
40
43
|
|
41
|
-
datapoints.map { |datapoint| @height - datapoint * point_space }
|
44
|
+
datapoints.map { |datapoint| @height - datapoint * point_space - datapoints.min * point_space }
|
42
45
|
end
|
43
46
|
|
44
47
|
end
|
data/little_graphs.gemspec
CHANGED
data/spec/litte_graphs_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe LittleGraphs do
|
|
33
33
|
it 'finds x,y coordinates for 1D array' do
|
34
34
|
lg = LittleGraphs.new
|
35
35
|
coords = lg.define_coordinates([1, 2, 3, 4, 5])
|
36
|
-
|
36
|
+
coords.should == [5, 28, 25, 21, 45, 14, 65, 7, 85, 0]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|