pippa 0.2.1 → 0.3.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTRlZmYwYjQzOTAyZTg2NTZlY2MxYjUwZDFkODcwNDg4YmU4MWVhZQ==
5
+ data.tar.gz: !binary |-
6
+ OWI2Zjk5YmQ0MWI0NWI5OGZhOWMwZTQwYTVlMTg5MzkwOTk4NzY3Nw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWJiNDhkZGM3M2M5MDY2ODI0NGY1M2MyNDE1Y2UzMmJlMzAyZTY3Njg4MDNh
10
+ MTdiODY3MzNmNWVjNjIxOTNiZThjNjZiNzI5OWMyOTQ2MzJjMTc3MTAzYmNk
11
+ OTExYmVmMjljYmFiZGMwNWJjOGIxMzYzZTc3ZTVkYjUyMzYxMGY=
12
+ data.tar.gz: !binary |-
13
+ MTk1NmZlODNjNmRlNDZkZTRiNjhlZGI0OWIwM2RlNGIwZGFkYWI4YWNmMTEx
14
+ MTg3OWM0YWI2OGJmMzE5YjRmMTkwZTg4ZWVhMWNmNGQzNjAzNDM1MjNjNTUy
15
+ ZTY1YjU1ZmY0ZGQ1ZGYzOTZmNThmYzRiZTJmMDFhMDgxY2U1NjI=
@@ -70,6 +70,12 @@ module Pippa
70
70
  class Map
71
71
  include Magick
72
72
 
73
+ # Dot shape. Either :square (default) or :circle
74
+ attr_accessor :dot_kind
75
+
76
+ # Boolean saying whether to merge markers to eliminate overlaps during rendering.
77
+ attr_accessor :merge
78
+
73
79
  # Width of the map image in pixels
74
80
  attr_reader :width
75
81
 
@@ -112,7 +118,8 @@ module Pippa
112
118
 
113
119
  # Render if we're making a change and then set a flag indicating
114
120
  # whether anti-aliasing will be performed in next render.
115
- # Default is false.
121
+ # Default is false. We don't handle this in method_missing because
122
+ # we need to detect boolean equivalence, not equality.
116
123
  def anti_alias=(val) # :nodoc:
117
124
  val = !!val
118
125
  return val if val == @anti_alias
@@ -142,6 +149,8 @@ module Pippa
142
149
  @fill_opacity = 0.85
143
150
  @stroke_width = 1
144
151
  @anti_alias = false
152
+ @dot_kind = :square
153
+ @merge = false
145
154
  @dots = []
146
155
 
147
156
  # Look up global info or return if none.
@@ -230,35 +239,41 @@ module Pippa
230
239
  end
231
240
  alias_method :add_dot_at_zip, :add_at_zip
232
241
 
242
+ TWO_SQRT_1_PI = 2 * Math.sqrt(1 / Math::PI)
243
+
244
+ def merged_dots
245
+ require 'lulu'
246
+ list = Lulu::MarkerList.new
247
+ list.set_info(@dot_kind, @point_size)
248
+ @dots.each {|dot| list.add(*dot) }
249
+ list.merge
250
+ list.markers
251
+ end
252
+
233
253
  # Force rendering of all dots added so far onto the map.
234
254
  # Then forget them so they're never rendered again.
235
255
  def render
236
256
  return if @image.nil? || @dots.empty?
237
- @dots.sort! {|a, b| b[2] <=> a[2] } # by area, smallest last
238
- gc = new_gc
239
- if @anti_alias
240
- @dots.each do |x, y, area|
241
- side = @point_size * Math.sqrt(area)
242
- if side <= 1
243
- gc.point(x, y)
244
- else
245
- h = 0.5 * side
246
- x1 = x - h
247
- y1 = y - h
248
- gc.rectangle(x1, y1, x1 + side, y1 + side)
249
- end
250
- end
257
+ if @merge
258
+ @dots = merged_dots
251
259
  else
252
- @dots.each do |x, y, area|
253
- side = @point_size * Math.sqrt(area)
254
- x, y, side = x.round, y.round, side.round
255
- if side <= 1
256
- gc.point(x, y)
260
+ @dots.sort! {|a, b| b[2] <=> a[2] } # by area, smallest last
261
+ end
262
+ gc = new_gc
263
+ @dots.each do |x, y, area|
264
+ diam = @point_size * Math.sqrt(area)
265
+ diam *= TWO_SQRT_1_PI if @dot_kind == :circle
266
+ x, y, diam = x.round, y.round, diam.round unless @anti_alias
267
+ if diam <= 1
268
+ gc.point(x, y)
269
+ else
270
+ if @dot_kind == :circle
271
+ gc.circle(x, y, x + diam / 2, y)
257
272
  else
258
- h = side / 2
273
+ h = diam / 2
259
274
  x1 = x - h
260
275
  y1 = y - h
261
- gc.rectangle(x1, y1, x1 + side, y1 + side)
276
+ gc.rectangle(x1, y1, x1 + diam, y1 + diam)
262
277
  end
263
278
  end
264
279
  end
@@ -266,7 +281,6 @@ module Pippa
266
281
  @dots = []
267
282
  end
268
283
 
269
-
270
284
  # Return true iff we respond to given method. Takes care of to_???
271
285
  # and write_???? converters and writers of graphic formats.
272
286
  def respond_to? (sym, include_private = false)
@@ -321,12 +335,15 @@ module Pippa
321
335
  end
322
336
 
323
337
  # Make a map showing all the zip codes in the USA with
324
- # dots of random size. Also a couple of additional dots.
325
- def self.zipcode_map
338
+ # dots of fixed area. Also a couple of additional dots.
339
+ def self.zipcode_map(dot_kind = :circle)
326
340
  generator = Random.new(42) # Force same on every run for testing.
327
341
  m = Map.new('USA')
342
+ m.point_size = 1.5
343
+ m.dot_kind = dot_kind
344
+ m.merge = true
328
345
  Pippa.zips.each_key.each do |zip|
329
- m.add_at_zip(zip, generator.rand(4) ** 2)
346
+ m.add_at_zip(zip, 1)
330
347
  end
331
348
  m.fill = 'red'
332
349
  m.fill_opacity = 1
@@ -336,8 +353,8 @@ module Pippa
336
353
  end
337
354
 
338
355
  # Write the test map produced by +zipcode_map+ as png and jpg files.
339
- def self.write_zipcode_maps
340
- m = zipcode_map
356
+ def self.write_zipcode_maps(dot_kind = :circle)
357
+ m = zipcode_map(dot_kind)
341
358
  File.open('spec/data/zipcodes.png', 'wb') { |f| f.write(m.to_png) }
342
359
  m.write_jpg('spec/data/zipcodes.jpg')
343
360
  end
@@ -354,6 +371,7 @@ module Pippa
354
371
  gc.stroke(@stroke)
355
372
  gc.fill_opacity(@fill_opacity)
356
373
  gc.stroke_width(@stroke_width)
374
+ gc.stroke_antialias(@anti_alias)
357
375
  gc
358
376
  end
359
377
 
@@ -1,5 +1,5 @@
1
1
  # Bundler auto-generated mixin for gem version.
2
2
  module Pippa
3
3
  # Current version of Pippa
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -25,7 +25,7 @@ and writes files in any supported ImageMagick graphic format.}
25
25
  spec.test_files = spec.files.grep(%r{^spec/})
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- # Make work on earlier versions, but this is where testing has been performed.
28
+ # May work on earlier versions, but this is where testing has been performed.
29
29
  spec.add_development_dependency "bundler", "~> 1.3"
30
30
  spec.add_development_dependency "rake", "~> 10.1"
31
31
  spec.add_development_dependency "rspec", "~> 2.14"
Binary file
Binary file
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pippa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gene Ressler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: ruby-prof
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rmagick
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -157,27 +146,26 @@ homepage: https://github.com/gene-ressler/pippa/wiki
157
146
  licenses:
158
147
  - GPL-3.0
159
148
  - RUC
149
+ metadata: {}
160
150
  post_install_message:
161
151
  rdoc_options: []
162
152
  require_paths:
163
153
  - lib
164
154
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
155
  requirements:
167
156
  - - ! '>='
168
157
  - !ruby/object:Gem::Version
169
158
  version: '0'
170
159
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
160
  requirements:
173
161
  - - ! '>='
174
162
  - !ruby/object:Gem::Version
175
163
  version: '0'
176
164
  requirements: []
177
165
  rubyforge_project:
178
- rubygems_version: 1.8.23
166
+ rubygems_version: 2.2.2
179
167
  signing_key:
180
- specification_version: 3
168
+ specification_version: 4
181
169
  summary: Reimplements some parts of the plot-latlon utility from CAIDA (http://www.caida.org).
182
170
  test_files:
183
171
  - spec/data/zipcodes.jpg