gruff 0.2.3 → 0.2.4

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.
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -3,16 +3,17 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: gruff
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.3
7
- date: 2006-09-21 00:00:00 -07:00
6
+ version: 0.2.4
7
+ date: 2006-09-29 00:00:00 -07:00
8
8
  summary: Beautiful graphs for one or multiple datasets.
9
9
  require_paths:
10
10
  - lib
11
+ - test
11
12
  email: boss@topfunky.com
12
- homepage: http://www.topfunky.com
13
+ homepage: http://nubyonrails.com/pages/gruff
13
14
  rubyforge_project: gruff
14
- description: Make colorful graphs for use on websites or documents.
15
- autorequire: gruff
15
+ description: Beautiful graphs for one or multiple datasets. Can be used on websites or in documents.
16
+ autorequire:
16
17
  default_executable:
17
18
  bindir: bin
18
19
  has_rdoc: true
@@ -28,12 +29,11 @@ cert_chain:
28
29
  authors:
29
30
  - Geoffrey Grosenbach
30
31
  files:
31
- - Rakefile
32
- - README
33
32
  - CHANGELOG
33
+ - README.txt
34
34
  - MIT-LICENSE
35
- - lib/CocoaMagick.rb
36
- - lib/gruff
35
+ - Rakefile
36
+ - Manifest.txt
37
37
  - lib/gruff.rb
38
38
  - lib/gruff/area.rb
39
39
  - lib/gruff/bar.rb
@@ -48,24 +48,20 @@ files:
48
48
  - lib/gruff/side_stacked_bar.rb
49
49
  - lib/gruff/spider.rb
50
50
  - lib/gruff/stacked_bar.rb
51
- - assets/bubble.png
52
- - assets/city_scene
53
- - assets/pc306715.jpg
54
- - assets/plastik
55
- - test/area_test.rb
56
- - test/bar_test.rb
57
- - test/base_test.rb
51
+ - test/test_area.rb
52
+ - test/test_bar.rb
53
+ - test/test_base.rb
58
54
  - test/gruff_test_case.rb
59
- - test/legend_test.rb
60
- - test/line_test.rb
61
- - test/net_test.rb
55
+ - test/test_legend.rb
56
+ - test/test_line.rb
57
+ - test/test_net.rb
62
58
  - test/output
63
- - test/photo_test.rb
64
- - test/pie_test.rb
65
- - test/scene_test.rb
66
- - test/sidestacked_bar_test.rb
67
- - test/spider_test.rb
68
- - test/stacked_bar_test.rb
59
+ - test/test_photo.rb
60
+ - test/test_pie.rb
61
+ - test/test_scene.rb
62
+ - test/test_sidestacked_bar.rb
63
+ - test/test_spider.rb
64
+ - test/test_stacked_bar.rb
69
65
  test_files: []
70
66
 
71
67
  rdoc_options: []
@@ -76,7 +72,15 @@ executables: []
76
72
 
77
73
  extensions: []
78
74
 
79
- requirements:
80
- - none
81
- dependencies: []
75
+ requirements: []
82
76
 
77
+ dependencies:
78
+ - !ruby/object:Gem::Dependency
79
+ name: hoe
80
+ version_requirement:
81
+ version_requirements: !ruby/object:Gem::Version::Requirement
82
+ requirements:
83
+ - - ">"
84
+ - !ruby/object:Gem::Version
85
+ version: 0.0.0
86
+ version:
data/assets/bubble.png DELETED
Binary file
data/assets/pc306715.jpg DELETED
Binary file
data/lib/CocoaMagick.rb DELETED
@@ -1,311 +0,0 @@
1
- # CocoaMagick.rb
2
- # Tim Burks / RubyCocoa Resources http://www.rubycocoa.com
3
- #
4
- # This is a quick-and-dirty replacement for RMagic written specifically
5
- # for Geoffrey Grosenbach's "gruff" graphing package.
6
- # It uses RubyCocoa and the Cocoa API to draw the elements of gruff graphs.
7
- # It is FAR from comprehensive, but works for nearly all of the test cases
8
- # distributed with gruff. Tested with gruff 0.1.2.
9
- #
10
- # To use, change "require 'RMagick'"to "require 'CocoaMagick'" in gruff/base.rb.
11
- # You also must have RubyCocoa installed, preferably the most recent version.
12
- # This means you must also be running on a Mac, preferably with OS X 10.4 or later.
13
- # Due to a Cocoa limitation, this script must either be run by the user currently
14
- # logged into the console or as root.
15
- #
16
- # For help with RubyCocoa, visit "RubyCocoa Resources" at www.rubycocoa.com.
17
- # For more on gruff, see http://nubyonrails.com/pages/gruff
18
- #
19
- require 'osx/cocoa'
20
-
21
- def log(str)
22
- puts str if false
23
- end
24
-
25
- class OSX::NSImage
26
- def writePNG(filename)
27
- bits = OSX::NSBitmapImageRep.alloc.initWithData(self.TIFFRepresentation)
28
- data = bits.representationUsingType_properties(OSX::NSPNGFileType, nil)
29
- data.writeToFile_atomically(filename, false)
30
- end
31
- end
32
-
33
- class OSX::NSColor
34
- def self.colorWithName(name)
35
- log "colorWithName #{name}"
36
- if name[0..0] == "#"
37
- r = eval("0x"+name[1..2]) / 256.0
38
- g = eval("0x"+name[3..4]) / 256.0
39
- b = eval("0x"+name[5..6]) / 256.0
40
- colorWithDeviceRed_green_blue_alpha(r,g,b,1)
41
- elsif name == "transparent"
42
- OSX::NSColor.blackColor.colorWithAlphaComponent(0.0)
43
- elsif name == "grey"
44
- OSX::NSColor.colorWithDeviceRed_green_blue_alpha(0.5,0.5,0.5,1)
45
- else
46
- eval("OSX::NSColor.#{name}Color")
47
- end
48
- end
49
- end
50
-
51
- module Magick
52
- class Draw
53
- attr_accessor :pointsize, :fill, :stroke, :font_weight, :gravity, :font,
54
- :stroke_color, :fill_color, :stroke_width, :dasharray
55
- def stroke_and_fill(path)
56
- @stroke_color.colorWithAlphaComponent(@stroke_opacity).set
57
- path.stroke
58
- @fill_color.colorWithAlphaComponent(@fill_opacity).set
59
- path.fill
60
- end
61
- def initialize
62
- @fill = "white"
63
- @pointsize = 18
64
- @stroke_opacity = 1
65
- @fill_opacity = 1
66
- @stroke_width = 1
67
- @stroke_color = OSX::NSColor.colorWithName("grey")
68
- @fill_color = OSX::NSColor.colorWithName("grey")
69
- @stack = []
70
- OSX::NSBezierPath.setDefaultLineJoinStyle(OSX::NSRoundLineJoinStyle)
71
- OSX::NSBezierPath.setDefaultLineWidth(1)
72
- end
73
- def push
74
- log "Draw.push"
75
- @stack.push({ # add more if needed
76
- :fill_color => @fill_color,
77
- :stroke_color => @stroke_color,
78
- :dasharray => @dasharray,
79
- :dashcount => @dashcount,
80
- :stroke_width => @stroke_width
81
- })
82
- self
83
- end
84
- def pop
85
- log "Draw.pop"
86
- hash = @stack.pop
87
- hash.keys.each {|key| self.instance_variable_set("@"+key.to_s, hash[key])}
88
- self
89
- end
90
- def scale(x,y)
91
- log "scale #{x} #{y}"
92
- @scalex = x
93
- @scaley = y
94
- self
95
- end
96
- def string_attributes
97
- attributes = OSX::NSMutableDictionary.alloc.initWithCapacity_(10)
98
- attributes.setObject_forKey(OSX::NSColor.colorWithName(@fill),
99
- OSX.NSForegroundColorAttributeName)
100
- if @font_weight == BoldWeight
101
- attributes.setObject_forKey(OSX::NSFont.boldSystemFontOfSize(@pointsize),
102
- OSX.NSFontAttributeName)
103
- else
104
- attributes.setObject_forKey(OSX::NSFont.systemFontOfSize(@pointsize),
105
- OSX.NSFontAttributeName)
106
- end
107
- attributes
108
- end
109
- def get_type_metrics(a,text)
110
- log "get_type_metrics #{a} #{text.inspect}"
111
- attributes = string_attributes()
112
- metrics = TypeMetric.new
113
- size = OSX::NSString.stringWithString(text).sizeWithAttributes(attributes)
114
- metrics.width = size.width
115
- metrics
116
- end
117
- def annotate(image,width,height,x,y,text)
118
- log "annotate #{image} #{width} #{height} #{x} #{y} #{text}"
119
- attributes = string_attributes()
120
- string = OSX::NSString.stringWithString(text)
121
- size = string.sizeWithAttributes(attributes)
122
- if @gravity == EastGravity or @gravity == SouthEastGravity or @gravity == NorthEastGravity
123
- x = x + width - size.width/2
124
- elsif @gravity == CenterGravity or @gravity == NorthGravity or @gravity == SouthGravity
125
- x = x + width/2 - size.width/2
126
- end
127
- if @gravity == NorthGravity or @gravity == NorthEastGravity or @gravity == NorthWestGravity
128
- y = y + height - size.height
129
- elsif @gravity == CenterGravity or @gravity == EastGravity or @gravity == WestGravity
130
- y = y + height/2 - size.height/2
131
- else
132
- y = y - size.height/2
133
- end
134
- string.drawAtPoint_withAttributes([x,image.height-y-size.height], attributes)
135
- self
136
- end
137
- def stroke(color)
138
- log "stroke #{color}"
139
- @stroke_color = OSX::NSColor.colorWithName(color)
140
- self
141
- end
142
- def fill(color)
143
- log "fill #{color}"
144
- @fill_color = OSX::NSColor.colorWithName(color)
145
- self
146
- end
147
- def rectangle(a,b,c,d)
148
- log "rectangle #{a} #{b} #{c} #{d}"
149
- @fill_color.set
150
- OSX::NSRectFill([a*@scalex,$height-d*@scalex,(c-a)*@scalex,(d-b)*@scaley])
151
- self
152
- end
153
- def stroke_width(a)
154
- log "stroke_width #{a}"
155
- @stroke_width = a
156
- OSX::NSBezierPath.setDefaultLineWidth(a*@scalex)
157
- self
158
- end
159
- def line(a,b,c,d)
160
- log "line #{a} #{b} #{c} #{d}"
161
- @stroke_color.set
162
- path = OSX::NSBezierPath.bezierPath
163
- path.setLineDash_count_phase(@dasharray, @dashcount, 0) if @dasharray
164
- path.moveToPoint([a*@scalex,$height-b*@scaley])
165
- path.lineToPoint([c*@scalex,$height-d*@scaley])
166
- path.stroke
167
- self
168
- end
169
- def stroke_opacity(opacity)
170
- log "stroke_opacity #{opacity}"
171
- @stroke_opacity = opacity
172
- self
173
- end
174
- def stroke_color(color)
175
- stroke(color)
176
- self
177
- end
178
- def fill_opacity(opacity)
179
- @fill_opacity = opacity
180
- self
181
- end
182
- def stroke_dasharray(a, b)
183
- log "stroke_dasharray #{a} #{b}"
184
- @dashcount = 2
185
- @dasharray = [a,b].pack('f2')
186
- self
187
- end
188
- def circle(cx,cy,px,py)
189
- log "circle #{cx} #{cy} #{px} #{py}"
190
- r = Math::sqrt((cx-px)*(cx-px) + (cy-py)*(cy-py))
191
- path = OSX::NSBezierPath.bezierPathWithOvalInRect(
192
- [(cx-r)*@scalex,$height-(cy+r)*@scaley,2*r*@scalex,2*r*@scaley])
193
- stroke_and_fill(path)
194
- self
195
- end
196
- def ellipse(x, y, w, h, as, ae)
197
- log "ellipse #{x} #{y} #{w} #{h} #{as} #{ae}"
198
- push
199
- stroke_width(1)
200
- @fill_color = @stroke_color
201
- path = OSX::NSBezierPath.bezierPath
202
- center = [x*@scalex,$height-y*@scaley]
203
- path.moveToPoint(center)
204
- path.appendBezierPathWithArcWithCenter_radius_startAngle_endAngle(
205
- center,2*w*@scalex,-ae,-as)
206
- path.closePath
207
- stroke_and_fill(path)
208
- pop
209
- self
210
- end
211
- def polyline(*args)
212
- path = OSX::NSBezierPath.bezierPath
213
- path.moveToPoint([args[0]*@scalex,$height-args[1]*@scaley])
214
- i = 2
215
- while(i < args.length)
216
- path.lineToPoint([args[i]*@scalex,$height-args[i+1]*@scaley])
217
- i = i + 2
218
- end
219
- stroke_and_fill(path)
220
- self
221
- end
222
- def polygon(*args)
223
- path = OSX::NSBezierPath.bezierPath
224
- path.moveToPoint([args[0]*@scalex,$height-args[1]*@scaley])
225
- i = 2
226
- while(i < args.length)
227
- path.lineToPoint([args[i]*@scalex,$height-args[i+1]*@scaley])
228
- i = i + 2
229
- end
230
- path.closePath
231
- stroke_and_fill(path)
232
- self
233
- end
234
- def draw(a)
235
- log "draw #{a}"
236
- self
237
- end
238
- end
239
- class Image
240
- attr_accessor :image, :width, :height
241
- def initialize(width, height, fill=nil)
242
- log "Image.initialize #{width} #{height} #{fill}"
243
- @width = width
244
- @height = height
245
- @image = OSX::NSImage.alloc.initWithSize([width,height])
246
- @image.lockFocus
247
- if fill == nil
248
- OSX::NSColor.blackColor.set
249
- OSX::NSRectFill([0,0,width,height])
250
- elsif fill.class == Magick::GradientFill
251
- gradient = fill.image
252
- gradient.drawInRect_fromRect_operation_fraction([0,0,width,height],
253
- [0,0,gradient.size.width,gradient.size.height], OSX::NSCompositeCopy, 1.0)
254
- else
255
- fill.drawInRect_fromRect_operation_fraction([0,0,width,height],
256
- [0,0,fill.size.width,fill.size.height], OSX::NSCompositeCopy, 1.0)
257
- end
258
- $width = width
259
- $height = height
260
- self
261
- end
262
- def write(filename)
263
- log "Image.write #{filename}"
264
- @image.unlockFocus
265
- @image.writePNG(filename)
266
- self
267
- end
268
- def self.read(filename)
269
- log "Image.read #{filename}"
270
- image = OSX::NSImage.alloc.initWithContentsOfFile(filename)
271
- [Image.new(800,600,image)]
272
- end
273
- end
274
- class GradientFill
275
- attr_accessor :image
276
- def initialize(a,b,c,d,e,f)
277
- log "GradientFill.initialize #{a} #{b} #{c} #{d} #{e} #{f}"
278
- # There's no direct gradient fill support in Cocoa, so fake it
279
- resolution = 100 # increase this to reduce striping and increase run time...
280
- @image = OSX::NSImage.alloc.initWithSize([1,resolution])
281
- @image.lockFocus
282
- bottomColor = OSX::NSColor.colorWithName(f)
283
- topColor = OSX::NSColor.colorWithName(e)
284
- resolution.times {|i|
285
- bottomColor.blendedColorWithFraction_ofColor(i/(resolution - 1.0), topColor).set
286
- OSX::NSRectFill([0,i,1,i+1])
287
- }
288
- self
289
- end
290
- end
291
- class TypeMetric
292
- attr_accessor :width
293
- def initialize
294
- @width = 50
295
- end
296
- end
297
- NormalWeight = 400
298
- BoldWeight = 700
299
- WestGravity = :west
300
- EastGravity = :east
301
- CenterGravity = :center
302
- SouthGravity = :south
303
- NorthGravity = :north
304
- SouthWestGravity = :southwest
305
- NorthWestGravity = :northwest
306
- NorthEastGravity = :northeast
307
- SouthEastGravity = :southeast
308
- end
309
-
310
- # this prevents a warning from AppKit
311
- app = OSX::NSApplication.sharedApplication
data/test/photo_test.rb DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require File.dirname(__FILE__) + "/gruff_test_case"
4
-
5
- class TestGruffPhotoBar < GruffTestCase
6
-
7
- def setup
8
- @datasets = [
9
- [:Jimmy, [25, 36, 86, 39]],
10
- [:Charles, [80, 54, 67, 54]],
11
- # [:Charity, [0, nil, 100, 90]],
12
- ]
13
- end
14
-
15
- def test_bar_graph
16
- bar_graph_sized
17
- bar_graph_sized(400)
18
- end
19
-
20
-
21
- protected
22
-
23
- def bar_graph_sized(size=800)
24
- g = Gruff::PhotoBar.new(size)
25
- g.title = "Photo Bar Graph Test #{size}px"
26
- g.labels = {
27
- 0 => '5/6',
28
- 1 => '5/15',
29
- 2 => '5/24',
30
- 3 => '5/30',
31
- }
32
- @datasets.each do |data|
33
- g.data(*data)
34
- end
35
-
36
- g.theme = 'plastik'
37
-
38
- g.write("test/output/photo_plastik_#{size}.png")
39
- end
40
-
41
- end