samhendley-scruffy 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scruffy/components/data_markers.rb +12 -1
- data/lib/scruffy/components/graphs.rb +2 -0
- data/lib/scruffy/components/grid.rb +20 -3
- data/lib/scruffy/components/value_markers.rb +7 -15
- data/lib/scruffy/graph.rb +9 -4
- data/lib/scruffy/graph_state.rb +1 -0
- data/lib/scruffy/helpers.rb +1 -0
- data/lib/scruffy/helpers/layer_container.rb +24 -2
- data/lib/scruffy/helpers/marker_helper.rb +23 -0
- data/lib/scruffy/helpers/point_container.rb +44 -15
- data/lib/scruffy/layers.rb +2 -1
- data/lib/scruffy/layers/base.rb +22 -11
- data/lib/scruffy/layers/scatter.rb +13 -5
- data/lib/scruffy/layers/stacked.rb +1 -1
- data/lib/scruffy/renderers/standard.rb +2 -1
- data/lib/scruffy/version.rb +1 -1
- data/test/graph_creation_test.rb +26 -7
- metadata +4 -11
@@ -2,8 +2,19 @@ module Scruffy
|
|
2
2
|
module Components
|
3
3
|
|
4
4
|
class DataMarkers < Base
|
5
|
-
|
5
|
+
|
6
|
+
include Scruffy::Helpers::Marker
|
7
|
+
|
8
|
+
attr_accessor :markers
|
9
|
+
|
6
10
|
def draw(svg, bounds, options={})
|
11
|
+
if (options[:point_markers].nil? || options[:point_markers].empty?) && options[:calculate_markers]
|
12
|
+
markers = (options[:markers] || self.markers) || 5
|
13
|
+
options[:point_markers] = []
|
14
|
+
each_marker(markers, options[:min_key], options[:max_key], bounds[:width], options, :key_formatter) do |label, x|
|
15
|
+
options[:point_markers] << label
|
16
|
+
end
|
17
|
+
end
|
7
18
|
unless options[:point_markers].nil?
|
8
19
|
point_distance = bounds[:width] / (options[:point_markers].size - 1).to_f
|
9
20
|
|
@@ -26,6 +26,8 @@ module Scruffy
|
|
26
26
|
layer_options[:index] = idx
|
27
27
|
layer_options[:min_value] = options[:min_value]
|
28
28
|
layer_options[:max_value] = options[:max_value]
|
29
|
+
layer_options[:min_key] = options[:min_key]
|
30
|
+
layer_options[:max_key] = options[:max_key]
|
29
31
|
layer_options[:complexity] = options[:complexity]
|
30
32
|
layer_options[:size] = [bounds[:width], bounds[:height]]
|
31
33
|
layer_options[:color] = layer.preferred_color || layer.color || options[:theme].next_color
|
@@ -3,14 +3,31 @@ module Scruffy
|
|
3
3
|
class Grid < Base
|
4
4
|
attr_accessor :markers
|
5
5
|
|
6
|
+
include Scruffy::Helpers::Marker
|
7
|
+
|
6
8
|
def draw(svg, bounds, options={})
|
7
9
|
markers = (options[:markers] || self.markers) || 5
|
8
10
|
|
9
11
|
stroke_width = options[:stroke_width]
|
10
12
|
|
11
|
-
(
|
12
|
-
|
13
|
-
|
13
|
+
each_marker(markers, options[:min_value], options[:max_value], bounds[:height], options, :value_formatter) do |label, y|
|
14
|
+
svg.line(:x1 => 0, :y1 => y, :x2 => bounds[:width], :y2 => y, :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class VGrid < Base
|
20
|
+
attr_accessor :markers
|
21
|
+
|
22
|
+
include Scruffy::Helpers::Marker
|
23
|
+
|
24
|
+
def draw(svg, bounds, options={})
|
25
|
+
markers = (options[:key_markers] || self.markers) || 5
|
26
|
+
|
27
|
+
stroke_width = options[:stroke_width]
|
28
|
+
|
29
|
+
each_marker(markers, options[:min_key], options[:max_key], bounds[:width], options, :key_formatter) do |label, x|
|
30
|
+
svg.line(:x1 => x, :y1 => 0, :x2 => x, :y2 => bounds[:height], :style => "stroke: #{options[:theme].marker.to_s}; stroke-width: #{stroke_width};")
|
14
31
|
end
|
15
32
|
end
|
16
33
|
end
|
@@ -1,31 +1,23 @@
|
|
1
1
|
module Scruffy
|
2
2
|
module Components
|
3
3
|
class ValueMarkers < Base
|
4
|
-
attr_accessor :markers
|
5
4
|
|
5
|
+
include Scruffy::Helpers::Marker
|
6
|
+
|
7
|
+
attr_accessor :markers
|
8
|
+
|
6
9
|
def draw(svg, bounds, options={})
|
7
10
|
markers = (options[:markers] || self.markers) || 5
|
8
|
-
all_values = []
|
9
|
-
|
10
|
-
(0...markers).each do |idx|
|
11
|
-
marker = ((1 / (markers - 1).to_f) * idx) * bounds[:height]
|
12
|
-
all_values << (options[:max_value] - options[:min_value]) * ((1 / (markers - 1).to_f) * idx) + options[:min_value]
|
13
|
-
end
|
14
11
|
|
15
|
-
(
|
16
|
-
|
17
|
-
marker_value = (options[:max_value] - options[:min_value]) * ((1 / (markers - 1).to_f) * idx) + options[:min_value]
|
18
|
-
marker_value = options[:value_formatter].route_format(marker_value, idx, options.merge({:all_values => all_values})) if options[:value_formatter]
|
19
|
-
|
20
|
-
svg.text( marker_value.to_s,
|
12
|
+
each_marker(markers, options[:min_value], options[:max_value], bounds[:height], options, :value_formatter) do |label, y|
|
13
|
+
svg.text( label,
|
21
14
|
:x => bounds[:width],
|
22
|
-
:y => (bounds[:height] -
|
15
|
+
:y => (bounds[:height] - y),
|
23
16
|
'font-size' => relative(8),
|
24
17
|
'font-family' => options[:theme].font_family,
|
25
18
|
:fill => ((options.delete(:marker_color_override) || options[:theme].marker) || 'white').to_s,
|
26
19
|
'text-anchor' => 'end')
|
27
20
|
end
|
28
|
-
|
29
21
|
end
|
30
22
|
end
|
31
23
|
end
|
data/lib/scruffy/graph.rb
CHANGED
@@ -80,10 +80,12 @@ module Scruffy
|
|
80
80
|
|
81
81
|
# Delegating these getters to the internal state object.
|
82
82
|
def_delegators :internal_state, :title, :theme, :default_type,
|
83
|
-
:point_markers, :value_formatter, :rasterizer
|
83
|
+
:point_markers, :value_formatter, :rasterizer,
|
84
|
+
:key_formatter
|
84
85
|
|
85
86
|
def_delegators :internal_state, :title=, :theme=, :default_type=,
|
86
|
-
:point_markers=, :value_formatter=, :rasterizer
|
87
|
+
:point_markers=, :value_formatter=, :rasterizer=,
|
88
|
+
:key_formatter=
|
87
89
|
|
88
90
|
attr_reader :renderer # Writer defined below
|
89
91
|
|
@@ -112,6 +114,7 @@ module Scruffy
|
|
112
114
|
self.renderer = Scruffy::Renderers::Standard.new
|
113
115
|
self.rasterizer = Scruffy::Rasterizers::RMagickRasterizer.new
|
114
116
|
self.value_formatter = Scruffy::Formatters::Number.new
|
117
|
+
self.key_formatter = Scruffy::Formatters::Number.new
|
115
118
|
|
116
119
|
%w(title theme layers default_type value_formatter point_markers rasterizer).each do |arg|
|
117
120
|
self.send("#{arg}=".to_sym, options.delete(arg.to_sym)) unless options[arg.to_sym].nil?
|
@@ -136,14 +139,16 @@ module Scruffy
|
|
136
139
|
def render(options = {})
|
137
140
|
options[:theme] ||= theme
|
138
141
|
options[:value_formatter] ||= value_formatter
|
142
|
+
options[:key_formatter] ||= key_formatter
|
139
143
|
options[:point_markers] ||= point_markers
|
140
144
|
options[:size] ||= (options[:width] ? [options[:width], (options.delete(:width) * 0.6).to_i] : [600, 360])
|
141
145
|
options[:title] ||= title
|
142
146
|
options[:layers] ||= layers
|
143
|
-
options[:min_value] ||= bottom_value(:padded)
|
147
|
+
options[:min_value] ||= bottom_value #(:padded)
|
144
148
|
options[:max_value] ||= top_value
|
149
|
+
options[:min_key] ||= bottom_key
|
150
|
+
options[:max_key] ||= top_key
|
145
151
|
options[:graph] ||= self
|
146
|
-
|
147
152
|
|
148
153
|
# Removed for now.
|
149
154
|
# Added for making smaller fonts more legible, but may not be needed after all.
|
data/lib/scruffy/graph_state.rb
CHANGED
data/lib/scruffy/helpers.rb
CHANGED
@@ -76,15 +76,37 @@ module Scruffy::Helpers
|
|
76
76
|
# If the lowest value is greater than zero, then the padding will not cross the zero line, preventing
|
77
77
|
# negative values from being introduced into the graph purely due to padding.
|
78
78
|
def bottom_value(padding=nil) # :nodoc:
|
79
|
-
botval = layers.inject(
|
79
|
+
botval = layers.inject(0) do |min, layer|
|
80
|
+
(min = ((min > layer.bottom_value) ? layer.bottom_value : min)) unless layer.bottom_value.nil?
|
81
|
+
min
|
82
|
+
end
|
80
83
|
above_zero = (botval > 0)
|
81
|
-
botval = (botval - ((top_value - botval) * 0.15))
|
84
|
+
botval = (botval - ((top_value - botval) * 0.15)) if padding == :padded
|
82
85
|
|
83
86
|
# Don't introduce negative values solely due to padding.
|
84
87
|
# A user-provided value must be negative before padding will extend into negative values.
|
85
88
|
(above_zero && botval < 0) ? 0 : botval
|
86
89
|
end
|
87
90
|
|
91
|
+
def bottom_key(padding=nil)
|
92
|
+
return 0 unless layers.any?
|
93
|
+
min = layers[0].bottom_key
|
94
|
+
layers.each do |layer|
|
95
|
+
min = layer.bottom_key if min.nil? && !layer.bottom_key.nil?
|
96
|
+
(min = ((min > layer.bottom_key) ? layer.bottom_key : min)) unless layer.bottom_key.nil?
|
97
|
+
end
|
98
|
+
min
|
99
|
+
end
|
100
|
+
|
101
|
+
def top_key(padding=nil)
|
102
|
+
return 1 unless layers.any?
|
103
|
+
max = layers[0].top_key
|
104
|
+
layers.each do |layer|
|
105
|
+
max = layer.top_key if max.nil? && !layer.top_key.nil?
|
106
|
+
(max = ((max < layer.top_key) ? layer.top_key : max)) unless layer.top_key.nil?
|
107
|
+
end
|
108
|
+
max
|
109
|
+
end
|
88
110
|
|
89
111
|
protected
|
90
112
|
def to_camelcase(type) # :nodoc:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Scruffy::Helpers
|
2
|
+
|
3
|
+
module Marker
|
4
|
+
|
5
|
+
def each_marker(markers, min, max, width, options, format_key)
|
6
|
+
all_values = []
|
7
|
+
|
8
|
+
(0...markers).each do |idx|
|
9
|
+
percent = idx.to_f / (markers-1)
|
10
|
+
all_values << (max - min) * percent + min
|
11
|
+
end
|
12
|
+
|
13
|
+
all_values.size.times do |idx|
|
14
|
+
location = idx.to_f * width/(markers-1)
|
15
|
+
marker_value = all_values[idx]
|
16
|
+
marker_value = options[format_key].route_format(marker_value, idx, options.merge({:all_values => all_values})) if options[format_key]
|
17
|
+
|
18
|
+
yield marker_value, location
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -8,27 +8,27 @@ module Scruffy::Helpers
|
|
8
8
|
# Allows all standard point operations to be called on both Array and Hash
|
9
9
|
module PointContainer
|
10
10
|
def self.extended point_set
|
11
|
-
point_set.extend(const_get(point_set.class.to_s))
|
11
|
+
point_set.extend(const_get("#{point_set.class.to_s}_ext"))
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def sortable(values)
|
15
15
|
values.find_all { |v| v.respond_to? :<=> }
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def summable(values)
|
19
19
|
values.find_all { |v| v.respond_to? :+ }
|
20
20
|
end
|
21
21
|
|
22
22
|
def maximum_value
|
23
|
-
|
23
|
+
sortable(values).sort.last
|
24
24
|
end
|
25
25
|
|
26
26
|
def minimum_value
|
27
|
-
|
27
|
+
sortable(values).sort.first
|
28
28
|
end
|
29
29
|
|
30
30
|
def sum
|
31
|
-
|
31
|
+
summable(values).inject(0) { |sum, i| sum += i }
|
32
32
|
end
|
33
33
|
|
34
34
|
def inject_with_index memo
|
@@ -40,24 +40,53 @@ module Scruffy::Helpers
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
def minimum_key
|
44
|
+
sortable(keys).sort.first
|
45
|
+
end
|
46
|
+
|
47
|
+
def maximum_key
|
48
|
+
sortable(keys).sort.last
|
49
|
+
end
|
50
|
+
|
51
|
+
module Array_ext
|
44
52
|
def values
|
45
|
-
self
|
53
|
+
return self unless is_coordinate_list?
|
54
|
+
collect { |x,y| y}
|
55
|
+
end
|
56
|
+
|
57
|
+
def keys
|
58
|
+
return [0,size-1] unless is_coordinate_list?
|
59
|
+
collect { |x,y| x}
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_coordinate_list?
|
63
|
+
if any? && first.is_a?(Array) && first.size == 2
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
|
69
|
+
def each_point(&block)
|
70
|
+
if is_coordinate_list?
|
71
|
+
each{|x,y|block.call(x,y)}
|
72
|
+
else
|
73
|
+
size.times{|k|block.call(k,self[k])}
|
74
|
+
end
|
46
75
|
end
|
47
76
|
end
|
48
77
|
|
49
|
-
module
|
50
|
-
def
|
51
|
-
|
78
|
+
module Hash_ext
|
79
|
+
def is_coordinate_list?
|
80
|
+
true
|
52
81
|
end
|
53
82
|
|
54
|
-
def
|
55
|
-
|
83
|
+
def each_point(&block)
|
84
|
+
keys.sort.each{|k|block.call(k,self[k])}
|
56
85
|
end
|
57
86
|
|
58
87
|
def inject memo
|
59
|
-
|
60
|
-
memo = yield memo, self[
|
88
|
+
keys.sort.each do |k|
|
89
|
+
memo = yield memo, self[k]
|
61
90
|
end
|
62
91
|
memo
|
63
92
|
end
|
data/lib/scruffy/layers.rb
CHANGED
data/lib/scruffy/layers/base.rb
CHANGED
@@ -68,6 +68,7 @@ module Scruffy::Layers
|
|
68
68
|
options[:relativestroke] ||= false
|
69
69
|
|
70
70
|
@options = options
|
71
|
+
|
71
72
|
end
|
72
73
|
|
73
74
|
# Builds SVG code for this graph using the provided Builder object.
|
@@ -75,7 +76,7 @@ module Scruffy::Layers
|
|
75
76
|
# rendering responsibilities to Base#draw.
|
76
77
|
#
|
77
78
|
# svg:: a Builder object used to create SVG code.
|
78
|
-
def render(svg, options
|
79
|
+
def render(svg, options)
|
79
80
|
setup_variables(options)
|
80
81
|
coords = generate_coordinates(options)
|
81
82
|
|
@@ -123,6 +124,16 @@ module Scruffy::Layers
|
|
123
124
|
def bottom_value
|
124
125
|
@relevant_data ? points.minimum_value : nil
|
125
126
|
end
|
127
|
+
|
128
|
+
# The highest data point on this layer, or nil if relevant_data == false
|
129
|
+
def bottom_key
|
130
|
+
@relevant_data ? points.minimum_key : nil
|
131
|
+
end
|
132
|
+
|
133
|
+
# The lowest data point on this layer, or nil if relevant_data == false
|
134
|
+
def top_key
|
135
|
+
@relevant_data ? points.maximum_key : nil
|
136
|
+
end
|
126
137
|
|
127
138
|
# The sum of all values
|
128
139
|
def sum_values
|
@@ -144,20 +155,20 @@ module Scruffy::Layers
|
|
144
155
|
# just a best guess, and can be overridden or thrown away (for example, this is overridden
|
145
156
|
# in pie charting and bar charts).
|
146
157
|
def generate_coordinates(options = {})
|
147
|
-
|
158
|
+
|
159
|
+
dy = height.to_f / (options[:max_value] - options[:min_value])
|
160
|
+
dx = width.to_f / (options[:max_key] - options[:min_key])
|
148
161
|
|
149
|
-
|
150
|
-
|
162
|
+
ret = []
|
163
|
+
points.each_point do |x, y|
|
164
|
+
if y
|
165
|
+
x_coord = dx * (x.to_f - options[:min_key])
|
166
|
+
y_coord = dy * (y.to_f - options[:min_value])
|
151
167
|
|
152
|
-
|
153
|
-
relative_percent = ((point == min_value) ? 0 : ((point - min_value) / (max_value - min_value).to_f))
|
154
|
-
y_coord = (height - (height * relative_percent))
|
155
|
-
|
156
|
-
memo << [x_coord, y_coord]
|
168
|
+
ret << [x_coord, height - y_coord]
|
157
169
|
end
|
158
|
-
|
159
|
-
memo
|
160
170
|
end
|
171
|
+
return ret
|
161
172
|
end
|
162
173
|
|
163
174
|
# Converts a percentage into a pixel value, relative to the height.
|
@@ -7,15 +7,23 @@ module Scruffy::Layers
|
|
7
7
|
# Simple scatter graph
|
8
8
|
class Scatter < Base
|
9
9
|
|
10
|
+
include Scruffy::Helpers::Marker
|
11
|
+
|
10
12
|
# Renders scatter graph.
|
11
13
|
def draw(svg, coords, options={})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
options.merge!(@options)
|
16
|
+
|
17
|
+
if options[:shadow]
|
18
|
+
svg.g(:class => 'shadow', :transform => "translate(#{relative(0.5)}, #{relative(0.5)})") {
|
19
|
+
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last + relative(0.9), :r => relative(2),
|
20
|
+
:style => "stroke-width: #{relative(2)}; stroke: black; opacity: 0.35;" ) }
|
21
|
+
}
|
22
|
+
end
|
16
23
|
|
17
24
|
coords.each { |coord| svg.circle( :cx => coord.first, :cy => coord.last, :r => relative(2),
|
18
25
|
:style => "stroke-width: #{relative(2)}; stroke: #{color.to_s}; fill: #{color.to_s}" ) }
|
19
26
|
end
|
20
27
|
end
|
21
|
-
end
|
28
|
+
end
|
29
|
+
|
@@ -31,7 +31,7 @@ module Scruffy::Layers
|
|
31
31
|
# Overrides Base#render to fiddle with layers' points to achieve a stacked effect.
|
32
32
|
def render(svg, options = {})
|
33
33
|
#TODO ensure this works with new points
|
34
|
-
current_points = points
|
34
|
+
current_points = points
|
35
35
|
|
36
36
|
layers.each do |layer|
|
37
37
|
real_points = layer.points
|
@@ -7,6 +7,7 @@ module Scruffy::Renderers
|
|
7
7
|
components << Scruffy::Components::Viewport.new(:view, :position => [2, 26], :size => [89, 66]) do |graph|
|
8
8
|
graph << Scruffy::Components::ValueMarkers.new(:values, :position => [0, 2], :size => [18, 89])
|
9
9
|
graph << Scruffy::Components::Grid.new(:grid, :position => [20, 0], :size => [80, 89], :stroke_width => 1)
|
10
|
+
graph << Scruffy::Components::VGrid.new(:vgrid, :position => [20, 0], :size => [80, 89], :stroke_width => 1)
|
10
11
|
graph << Scruffy::Components::DataMarkers.new(:labels, :position => [20, 92], :size => [80, 8])
|
11
12
|
graph << Scruffy::Components::Graphs.new(:graphs, :position => [20, 0], :size => [80, 89])
|
12
13
|
end
|
@@ -30,7 +31,7 @@ module Scruffy::Renderers
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def grids
|
33
|
-
[component(:view).component(:grid)]
|
34
|
+
[component(:view).component(:grid),component(:view).component(:vgrid)]
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
data/lib/scruffy/version.rb
CHANGED
data/test/graph_creation_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'test_helper'
|
3
3
|
|
4
4
|
class SimpleTheme < Scruffy::Themes::Base
|
5
5
|
def initialize
|
@@ -12,6 +12,13 @@ class SimpleTheme < Scruffy::Themes::Base
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
$make_png = true
|
16
|
+
begin
|
17
|
+
require 'RMagick'
|
18
|
+
rescue LoadError
|
19
|
+
$make_png = nil
|
20
|
+
end
|
21
|
+
|
15
22
|
class GraphCreationTest < Test::Unit::TestCase
|
16
23
|
BASE_DIR = File.dirname(__FILE__)
|
17
24
|
WEBSITE_DIR = BASE_DIR + "/../website/images/graphs"
|
@@ -29,7 +36,7 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
29
36
|
}
|
30
37
|
|
31
38
|
graph.render :to => "#{WEBSITE_DIR}/pie_test.svg"
|
32
|
-
graph.render :width => 400, :to => "#{WEBSITE_DIR}/pie_test.png", :as => 'png'
|
39
|
+
graph.render :width => 400, :to => "#{WEBSITE_DIR}/pie_test.png", :as => 'png' if $make_png
|
33
40
|
end
|
34
41
|
|
35
42
|
def test_create_line
|
@@ -40,7 +47,7 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
40
47
|
graph.add :line, 'Example', [20, 100, 70, 30, 106]
|
41
48
|
|
42
49
|
graph.render :to => "#{WEBSITE_DIR}/line_test.svg"
|
43
|
-
graph.render :width => 400, :to => "#{WEBSITE_DIR}/line_test.png", :as => 'png'
|
50
|
+
graph.render :width => 400, :to => "#{WEBSITE_DIR}/line_test.png", :as => 'png' if $make_png
|
44
51
|
end
|
45
52
|
|
46
53
|
|
@@ -50,7 +57,7 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
50
57
|
graph.renderer = Scruffy::Renderers::Standard.new
|
51
58
|
graph.add :bar, 'Example', [20, 100, 70, 30, 106]
|
52
59
|
graph.render :to => "#{WEBSITE_DIR}/bar_test.svg"
|
53
|
-
graph.render :width => 400, :to => "#{WEBSITE_DIR}/bar_test.png", :as => 'png'
|
60
|
+
graph.render :width => 400, :to => "#{WEBSITE_DIR}/bar_test.png", :as => 'png' if $make_png
|
54
61
|
end
|
55
62
|
|
56
63
|
def test_split
|
@@ -67,7 +74,7 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
67
74
|
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
68
75
|
|
69
76
|
graph.render :to => "#{WEBSITE_DIR}/split_test.svg"
|
70
|
-
graph.render :width => 500, :to => "#{WEBSITE_DIR}/split_test.png", :as => 'png'
|
77
|
+
graph.render :width => 500, :to => "#{WEBSITE_DIR}/split_test.png", :as => 'png' if $make_png
|
71
78
|
end
|
72
79
|
|
73
80
|
def test_stacking
|
@@ -81,7 +88,7 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
81
88
|
end
|
82
89
|
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
83
90
|
graph.render :to => "#{WEBSITE_DIR}/stacking_test.svg"
|
84
|
-
graph.render :width => 500, :to => "#{WEBSITE_DIR}/stacking_test.png", :as => 'png'
|
91
|
+
graph.render :width => 500, :to => "#{WEBSITE_DIR}/stacking_test.png", :as => 'png' if $make_png
|
85
92
|
end
|
86
93
|
|
87
94
|
def test_multi_layered
|
@@ -96,6 +103,18 @@ class GraphCreationTest < Test::Unit::TestCase
|
|
96
103
|
graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56], :categories => [:top_left, :bottom_right]
|
97
104
|
graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
|
98
105
|
graph.render :to => "#{WEBSITE_DIR}/multi_test.svg"
|
99
|
-
graph.render :width => 500, :to => "#{WEBSITE_DIR}/multi_test.png", :as => 'png'
|
106
|
+
graph.render :width => 500, :to => "#{WEBSITE_DIR}/multi_test.png", :as => 'png' if $make_png
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_scatter
|
110
|
+
graph = Scruffy::Graph.new
|
111
|
+
graph.title = "Some Kind of Information"
|
112
|
+
graph.renderer = Scruffy::Renderers::Standard.new
|
113
|
+
|
114
|
+
graph.add :scatter, 'Stephanie', {0 => 0, 1 => 1, 2 => 4, 3 => 9, 4 => 8, 5 => 10, 6 => 12, 7 => 3, 8 => 13}
|
115
|
+
graph.add :line, 'Artiom', {-3 => 2, 1.5 => 6, 2 => 4.5, 15 => -4}, :dots => true
|
116
|
+
graph.add :scatter, 'Sam', [[-3,15], [1.5,18], [2,9], [15,6]]
|
117
|
+
graph.render :to => "#{WEBSITE_DIR}/scatter_test.svg"
|
118
|
+
graph.render :width => 500, :to => "#{WEBSITE_DIR}/scatter_test.png", :as => 'png' if $make_png
|
100
119
|
end
|
101
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samhendley-scruffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brasten Sager
|
@@ -24,16 +24,6 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 2.0.0
|
26
26
|
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: hoe
|
29
|
-
type: :runtime
|
30
|
-
version_requirement:
|
31
|
-
version_requirements: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 1.7.0
|
36
|
-
version:
|
37
27
|
description: Scruffy is a Ruby library for generating high quality, good looking graphs. It is designed to be easy to use and highly customizable.
|
38
28
|
email:
|
39
29
|
- brasten@nagilum.com
|
@@ -66,6 +56,7 @@ files:
|
|
66
56
|
- lib/scruffy/helpers/point_container.rb
|
67
57
|
- lib/scruffy/helpers/layer_container.rb
|
68
58
|
- lib/scruffy/helpers/meta.rb
|
59
|
+
- lib/scruffy/helpers/marker_helper.rb
|
69
60
|
- lib/scruffy/components.rb
|
70
61
|
- lib/scruffy/graph_state.rb
|
71
62
|
- lib/scruffy/components/style_info.rb
|
@@ -94,8 +85,10 @@ files:
|
|
94
85
|
- lib/scruffy/layers.rb
|
95
86
|
- lib/scruffy.rb
|
96
87
|
- LICENCE.txt
|
88
|
+
- History.txt
|
97
89
|
- README.txt
|
98
90
|
- CHANGES.txt
|
91
|
+
- Manifest.txt
|
99
92
|
has_rdoc: true
|
100
93
|
homepage: http://scruffy.rubyforge.org
|
101
94
|
post_install_message:
|