pbosetti-flotr 1.3.4 → 1.3.5
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/README.markdown +3 -4
- data/examples/sincos.rb +2 -2
- data/lib/flotr.rb +56 -1
- metadata +2 -2
data/README.markdown
CHANGED
@@ -18,12 +18,11 @@ The following code produces the flotr.html file located in the root project fold
|
|
18
18
|
|
19
19
|
# Push data into the two series
|
20
20
|
100.times do |i|
|
21
|
-
sin
|
22
|
-
cos
|
21
|
+
sin << [i, Math::sin(Math::PI / 100 * i)]
|
22
|
+
cos << [i, Math::cos(Math::PI / 100 * i)]
|
23
23
|
end
|
24
24
|
|
25
|
-
plot << sin
|
26
|
-
plot << cos
|
25
|
+
plot << sin << cos
|
27
26
|
plot.show
|
28
27
|
|
29
28
|
At the moment, the Flotr::Plot.plot method automatically opens the plot within a browser window under OS X and Windows. On other platforms (Linux) you have to open the generated file by hands.
|
data/examples/sincos.rb
CHANGED
@@ -10,8 +10,8 @@ sin = Flotr::Data.new(:label => "Sin(x)", :color => "red")
|
|
10
10
|
cos = Flotr::Data.new(:label => "Cos(x)", :color => "blue")
|
11
11
|
|
12
12
|
100.times do |i|
|
13
|
-
cos
|
14
|
-
sin
|
13
|
+
cos << [i, Math::cos(Math::PI / 100 * i)]
|
14
|
+
sin << [i, Math::sin(Math::PI / 100 * i)]
|
15
15
|
end
|
16
16
|
|
17
17
|
plot = Flotr::Plot.new("Test plot")
|
data/lib/flotr.rb
CHANGED
@@ -13,16 +13,28 @@ class String
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
=begin rdoc
|
17
|
+
Flotr namespace.
|
18
|
+
=end
|
16
19
|
module Flotr
|
17
20
|
BASENAME = File.dirname(__FILE__)
|
18
21
|
OUTPUT_FILE = "flotr.html"
|
19
22
|
STD_TEMPLATE = "zooming.rhtml"
|
20
23
|
|
24
|
+
|
25
|
+
=begin rdoc
|
26
|
+
Series to be plotted are instance of the Flotr::Data class. Initialize a new
|
27
|
+
Data object with a set of OPTIONS, then add points with the << method.
|
28
|
+
=end
|
21
29
|
class Data
|
22
30
|
OPTIONS = [:color, :label, :lines, :bars, :points, :hints, :shadowSize]
|
23
31
|
attr_accessor *OPTIONS
|
24
32
|
attr_accessor :data
|
25
33
|
|
34
|
+
=begin rdoc
|
35
|
+
Creates a new serie of points. opts is a Hash with a subset of the keys
|
36
|
+
given in OPTIONS.
|
37
|
+
=end
|
26
38
|
def initialize(opts={})
|
27
39
|
@data = []
|
28
40
|
opts.each do |k,v|
|
@@ -34,6 +46,9 @@ module Flotr
|
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
49
|
+
=begin rdoc
|
50
|
+
Provides a JavaScript-formatted description of the data array.
|
51
|
+
=end
|
37
52
|
def inspect
|
38
53
|
options = ""
|
39
54
|
OPTIONS.each do |o|
|
@@ -44,17 +59,32 @@ module Flotr
|
|
44
59
|
"{ #{options}data: #{@data.inspect}}"
|
45
60
|
end
|
46
61
|
|
62
|
+
=begin rdoc
|
63
|
+
Adds other to the data array. other must be a two element array like [0,0].
|
64
|
+
=end
|
47
65
|
def <<(other)
|
66
|
+
other = other.to_a
|
67
|
+
raise ArgumentError unless other[0].kind_of? Numeric
|
68
|
+
raise ArgumentError unless other[1].kind_of? Numeric
|
48
69
|
@data << other
|
49
70
|
end
|
50
71
|
|
51
72
|
end
|
52
73
|
|
74
|
+
=begin rdoc
|
75
|
+
The Plot object. Serves as a container for the data series (Data objects)
|
76
|
+
and for the plot options. Call the plot/show methods to generate the
|
77
|
+
plot file Flotr::OUTPUT_FILE.
|
78
|
+
=end
|
53
79
|
class Plot
|
54
80
|
attr_accessor :series, :title, :comment, :template, :options
|
55
81
|
attr_accessor :width, :height
|
56
82
|
attr_accessor :label, :xlim, :ylim
|
57
83
|
|
84
|
+
=begin rdoc
|
85
|
+
Creates a new plot. You only have to provide a title for the plot, that
|
86
|
+
will (probably) be used as a page title by the active template.
|
87
|
+
=end
|
58
88
|
def initialize(title = "Flotr Plot")
|
59
89
|
@title = title
|
60
90
|
@template = "#{BASENAME}/#{STD_TEMPLATE}"
|
@@ -64,14 +94,28 @@ module Flotr
|
|
64
94
|
@label = @xlim = @ylim = {}
|
65
95
|
end
|
66
96
|
|
97
|
+
=begin rdoc
|
98
|
+
Lists the available standard templates. These are .rhtml files located in
|
99
|
+
the lib floder inside the gem. The extension .rhtml is dropped.
|
100
|
+
=end
|
67
101
|
def std_templates
|
68
102
|
Dir.glob("#{BASENAME}/*.rhtml").map {|f| File.basename(f, ".rhtml")}
|
69
103
|
end
|
70
104
|
|
105
|
+
=begin rdoc
|
106
|
+
Selects the active template. It has to be one of those included in the
|
107
|
+
result of the std_templates method.
|
108
|
+
=end
|
71
109
|
def std_template=(template)
|
110
|
+
raise "Template #{template} does not exist!" unless self.std_templates.include?(template)
|
72
111
|
@template = "#{BASENAME}/#{template}.rhtml"
|
73
112
|
end
|
74
|
-
|
113
|
+
|
114
|
+
=begin rdoc
|
115
|
+
Returns the currently selected standard template, or nil if the active
|
116
|
+
template is a custom one. Use Plot#template=(full/path/to/template.rhtml)
|
117
|
+
to set a custom template.
|
118
|
+
=end
|
75
119
|
def std_template
|
76
120
|
if File.dirname(@template) == BASENAME
|
77
121
|
File.basename(@template, ".rhtml")
|
@@ -80,6 +124,10 @@ module Flotr
|
|
80
124
|
end
|
81
125
|
end
|
82
126
|
|
127
|
+
=begin rdoc
|
128
|
+
Generates the html file containing the plot and fires up a preferred
|
129
|
+
browser window with the plot loaded.
|
130
|
+
=end
|
83
131
|
def plot
|
84
132
|
eruby = Erubis::Eruby.new(File.read(@template))
|
85
133
|
File.open(OUTPUT_FILE, 'w') do |f|
|
@@ -97,6 +145,10 @@ module Flotr
|
|
97
145
|
|
98
146
|
alias show plot
|
99
147
|
|
148
|
+
=begin rdoc
|
149
|
+
Adds a Data serie to the Plot. It also returns self, so multiple calls
|
150
|
+
can be concatenated as in plot << series1 << series2 << series3.
|
151
|
+
=end
|
100
152
|
def <<(serie)
|
101
153
|
if serie.instance_of? Data
|
102
154
|
@series << serie
|
@@ -105,6 +157,9 @@ module Flotr
|
|
105
157
|
end
|
106
158
|
end
|
107
159
|
|
160
|
+
=begin rdoc
|
161
|
+
Provides a JavaScript-formatted description of the all the series.
|
162
|
+
=end
|
108
163
|
def inspect
|
109
164
|
data = @series.map {|s| s.inspect}
|
110
165
|
"[ #{data*', '} ]"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbosetti-flotr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Bosetti
|
@@ -41,7 +41,7 @@ files:
|
|
41
41
|
- lib/layout.css
|
42
42
|
- lib/zooming.rhtml
|
43
43
|
- examples/sincos.rb
|
44
|
-
has_rdoc:
|
44
|
+
has_rdoc: true
|
45
45
|
homepage: http://github.com/pbosetti/flotr
|
46
46
|
post_install_message:
|
47
47
|
rdoc_options:
|