pbosetti-flotr 1.3.2 → 1.3.3
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/lib/flotr.rb +115 -0
- metadata +3 -3
- data/flotr.rb +0 -7
data/lib/flotr.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Paolo Bosetti on 2009-04-27.
|
4
|
+
# Copyright (c) 2009 University of Trento. All rights
|
5
|
+
# reserved.
|
6
|
+
require "rubygems"
|
7
|
+
require "erubis"
|
8
|
+
require "CGI"
|
9
|
+
|
10
|
+
class String
|
11
|
+
def escapeHTML
|
12
|
+
CGI.escapeHTML self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Flotr
|
17
|
+
BASENAME = File.dirname(__FILE__)
|
18
|
+
OUTPUT_FILE = "flotr.html"
|
19
|
+
STD_TEMPLATE = "zooming.rhtml"
|
20
|
+
|
21
|
+
class Data
|
22
|
+
OPTIONS = [:color, :label, :lines, :bars, :points, :hints, :shadowSize]
|
23
|
+
attr_accessor *OPTIONS
|
24
|
+
attr_accessor :data
|
25
|
+
|
26
|
+
def initialize(opts={})
|
27
|
+
@data = []
|
28
|
+
opts.each do |k,v|
|
29
|
+
if OPTIONS.include? k
|
30
|
+
self.send(k.to_s+'=', v)
|
31
|
+
else
|
32
|
+
warn "Warning: data option '#{k}' does not exist, ignored"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
options = ""
|
39
|
+
OPTIONS.each do |o|
|
40
|
+
if self.send o then
|
41
|
+
options += "#{o}: \"#{self.send o}\", "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
"{ #{options}data: #{@data.inspect}}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def <<(other)
|
48
|
+
@data << other
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class Plot
|
54
|
+
attr_accessor :series, :title, :comment, :template, :options
|
55
|
+
attr_accessor :width, :height
|
56
|
+
attr_accessor :label, :xlim, :ylim
|
57
|
+
|
58
|
+
def initialize(title = "Flotr Plot")
|
59
|
+
@title = title
|
60
|
+
@template = "#{BASENAME}/#{STD_TEMPLATE}"
|
61
|
+
@series = []
|
62
|
+
@options = {}
|
63
|
+
@width, @height = 600, 300
|
64
|
+
@label = @xlim = @ylim = {}
|
65
|
+
end
|
66
|
+
|
67
|
+
def std_templates
|
68
|
+
Dir.glob("#{BASENAME}/*.rhtml").map {|f| File.basename(f, ".rhtml")}
|
69
|
+
end
|
70
|
+
|
71
|
+
def std_template=(template)
|
72
|
+
@template = "#{BASENAME}/#{template}.rhtml"
|
73
|
+
end
|
74
|
+
|
75
|
+
def std_template
|
76
|
+
if File.dirname(@template) == BASENAME
|
77
|
+
File.basename(@template, ".rhtml")
|
78
|
+
else
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def plot
|
84
|
+
eruby = Erubis::Eruby.new(File.read(@template))
|
85
|
+
File.open(OUTPUT_FILE, 'w') do |f|
|
86
|
+
f.print eruby.result(binding())
|
87
|
+
end
|
88
|
+
case RUBY_PLATFORM
|
89
|
+
when /darwin/
|
90
|
+
exec "open \"#{OUTPUT_FILE}\""
|
91
|
+
when /mswin/
|
92
|
+
exec "start #{OUTPUT_FILE}"
|
93
|
+
else
|
94
|
+
puts "open #{OUTPUT_FILE} in your preferred brouser"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
alias show plot
|
99
|
+
|
100
|
+
def <<(serie)
|
101
|
+
if serie.instance_of? Data
|
102
|
+
@series << serie
|
103
|
+
else
|
104
|
+
raise ArgumentError
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def inspect
|
109
|
+
data = @series.map {|s| s.inspect}
|
110
|
+
"[ #{data*', '} ]"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Bosetti
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04
|
12
|
+
date: 2009-05-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,8 +31,8 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
-
- flotr.rb
|
35
34
|
- README.markdown
|
35
|
+
- lib/flotr.rb
|
36
36
|
has_rdoc: false
|
37
37
|
homepage: http://github.com/pbosetti/flotr
|
38
38
|
post_install_message:
|