usamap 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +5 -0
- data/lib/usa_counties_svg.rb +9 -6
- data/lib/usamap.rb +10 -5
- data/spec/spec_helper.rb +17 -0
- data/spec/usamap/usamap_spec.rb +36 -0
- metadata +29 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDdhOGExNjgxMzhkZjQ1M2UwNmZjOGJkNzBjNDYyZGE1ZGMxYjYxNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDk0NTMzNjVkYTQzYjU2NzU4NjJiMDI3M2U4ZGFmM2ExMDBkMTUzNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGY0M2FhMGE3N2Q4MjJjOTIyMzdhMjJkMDEwY2JlODc0MjMwODdjMWMzNDkz
|
10
|
+
ZTViN2JhZTZmMDVjMDU2MGU1YTMzZTM2NzljYzE4NzU1MGFlNjU2YWQ2NGYy
|
11
|
+
NzY2NWVlMGNjYzYzNzI0MzliYzAxMDIxM2YyYTk0OThiZDYwYTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjNkOWM1MGQ5MWI1MmNjOGEwODk2NzQ1NWYzNmI1NTVhNzkzNmQwZTgzZTQ5
|
14
|
+
YWE5YWNhYTNhN2M4YmQ1ZDA0NTAxYzhjMWNiZDI0NmE0ODc1ZmIyODA3Nzk4
|
15
|
+
NjNlMGE5N2M1MGQ0ZGQ4YmI2YzcyMzBkY2RjOTIzZGExMjc0NmY=
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) salemine.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
usamap
|
2
|
+
======
|
3
|
+
|
4
|
+
Create a colorized svg map of the USA using ruby. Plot ranges and colors using FIPS coordinates for US counties.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
~~~.ruby
|
9
|
+
gem install usamap
|
10
|
+
~~~
|
11
|
+
|
12
|
+
|
13
|
+
## Example Usage
|
14
|
+
|
15
|
+
~~~.ruby
|
16
|
+
require 'usamap'
|
17
|
+
|
18
|
+
colors = {}
|
19
|
+
colors[0..5] = '#CD5C5C'
|
20
|
+
colors[6..100] = 'blue'
|
21
|
+
|
22
|
+
stats = {}
|
23
|
+
stats['35001'] = 3 # 35001 is FIPS for Bernalillo, NM
|
24
|
+
stats['35049'] = 99 # 35049 is FIPS for Santa Fe, NM
|
25
|
+
|
26
|
+
my_map = USAmap.new(stats, colors)
|
27
|
+
puts my_map
|
28
|
+
~~~
|
29
|
+
|
30
|
+
|
31
|
+
## Example Output
|
32
|
+
|
33
|
+
|
34
|
+
![alt text](https://raw.github.com/wiki/salemine/usamap/nm_counties.png "Sample Map")
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
## Credits/Resources
|
43
|
+
SVG Map:
|
44
|
+
http://commons.wikimedia.org/wiki/File:Usa_counties_large.svg
|
45
|
+
|
46
|
+
|
47
|
+
FIPS Codes:
|
48
|
+
http://en.wikipedia.org/wiki/FIPS_county_code
|
49
|
+
|
50
|
+
|
51
|
+
## Inspiration
|
52
|
+
http://flowingdata.com/2009/11/12/how-to-make-a-us-county-thematic-map-using-free-tools/
|
53
|
+
|
54
|
+
|
55
|
+
|
data/Rakefile
ADDED
data/lib/usa_counties_svg.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module UsaCountiesSvg
|
2
|
+
# The blank SVG (Scalable Vector Graphics) map of the USA
|
3
|
+
def self.svg
|
4
|
+
@svg = <<-END_OF_SVG
|
3
5
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
4
6
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
5
7
|
|
@@ -35,7 +37,7 @@
|
|
35
37
|
</rdf:RDF>
|
36
38
|
</metadata>
|
37
39
|
<defs id='defs1930'></defs>
|
38
|
-
|
40
|
+
|
39
41
|
<style type='text/css' id='style_css_sheet'>
|
40
42
|
/*
|
41
43
|
* Below are Cascading Style Sheet (CSS) definitions in use in this file,
|
@@ -46,7 +48,7 @@
|
|
46
48
|
*
|
47
49
|
*
|
48
50
|
*/
|
49
|
-
|
51
|
+
|
50
52
|
.counties {fill:#d0d0d0;fill-rule:nonzero;stroke:#000000;stroke-width:0.178287;}
|
51
53
|
.State_Lines {fill:none;stroke:#221e1f;stroke-width:0.89143497;}
|
52
54
|
.separator {fill:none;stroke:#a9a9a9;stroke-width:2.3177309;}
|
@@ -12630,5 +12632,6 @@
|
|
12630
12632
|
class="separator"
|
12631
12633
|
id="#separator" />
|
12632
12634
|
</svg>
|
12633
|
-
|
12634
|
-
|
12635
|
+
END_OF_SVG
|
12636
|
+
end
|
12637
|
+
end
|
data/lib/usamap.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
-
require 'usa_counties_svg'
|
1
|
+
require File.join(File.dirname(__FILE__), 'usa_counties_svg')
|
2
2
|
|
3
|
+
# @author salemine <info@salemine.com>
|
3
4
|
class USAmap
|
4
|
-
|
5
|
-
|
5
|
+
include UsaCountiesSvg
|
6
|
+
# @param [Hash] stats_h stats to plot by county FIPS value eg stats_h ['35001'] = 3
|
7
|
+
# @param [Hash] colors_h colors to plot for numeric ranges eg colors_h [0..5] = '#CD5C5C'
|
6
8
|
def initialize(stats_h = {}, colors_h = {})
|
7
9
|
@stats_h, @colors_h = stats_h, colors_h
|
8
10
|
end
|
9
11
|
|
12
|
+
# == Returns:
|
13
|
+
# A colorized SVG (Scalable Vector Graphics) map of the USA
|
10
14
|
def to_s
|
11
15
|
css = ''
|
12
16
|
@stats_h.each do |fips, val|
|
13
17
|
colr = @colors_h.select { |range, hex| range.member?(val) }.values.first
|
14
18
|
css << ".c#{fips} {fill:#{colr}}\n"
|
15
19
|
end
|
16
|
-
|
20
|
+
svg = UsaCountiesSvg.svg
|
21
|
+
css.empty? ? svg : svg.gsub!(/\/\*CSS insertion point\*\//, "/*CSS insertion point*/\n#{css}")
|
17
22
|
end
|
18
|
-
|
23
|
+
|
19
24
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'usamap'
|
3
|
+
|
4
|
+
module Usamap
|
5
|
+
|
6
|
+
describe USAmap do
|
7
|
+
before(:each) do
|
8
|
+
@blank_svg = UsaCountiesSvg.svg
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "should be a blank map when instantiated without params" do
|
12
|
+
its(:to_s) { should == @blank_svg }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with color and stats hashes passed when instantiated" do
|
16
|
+
it "should insert one css class definition" do
|
17
|
+
colors = {}; colors[6..100] = 'blue'
|
18
|
+
stats = {}; stats['35049'] = 99
|
19
|
+
my_map = USAmap.new(stats, colors)
|
20
|
+
|
21
|
+
my_map.to_s.should include (".c35049 {fill:blue}")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be equal to the blank_svg with the css inserted" do
|
25
|
+
colors = {}; colors[6..100] = 'blue'
|
26
|
+
stats = {}; stats['35049'] = 99
|
27
|
+
my_map = USAmap.new(stats, colors)
|
28
|
+
blank_svg_tweaked = @blank_svg.gsub(/\/\*CSS insertion point\*\//, "/*CSS insertion point*/\n.c35049 {fill:blue}\n")
|
29
|
+
|
30
|
+
blank_svg_tweaked.should == my_map.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usamap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- salemine
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
13
|
-
dependencies:
|
14
|
-
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
description: Create a colorized svg map of the USA by county using FIPS coordinates
|
15
28
|
email: info@salemine.com
|
16
29
|
executables: []
|
17
30
|
extensions: []
|
@@ -19,29 +32,34 @@ extra_rdoc_files: []
|
|
19
32
|
files:
|
20
33
|
- lib/usamap.rb
|
21
34
|
- lib/usa_counties_svg.rb
|
35
|
+
- Rakefile
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/usamap/usamap_spec.rb
|
38
|
+
- README.md
|
39
|
+
- LICENSE.txt
|
22
40
|
homepage: https://github.com/salemine/usamap
|
23
|
-
licenses:
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
24
44
|
post_install_message:
|
25
45
|
rdoc_options: []
|
26
46
|
require_paths:
|
27
47
|
- lib
|
28
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
49
|
requirements:
|
31
50
|
- - ! '>='
|
32
51
|
- !ruby/object:Gem::Version
|
33
52
|
version: '0'
|
34
53
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
54
|
requirements:
|
37
55
|
- - ! '>='
|
38
56
|
- !ruby/object:Gem::Version
|
39
57
|
version: '0'
|
40
58
|
requirements: []
|
41
59
|
rubyforge_project:
|
42
|
-
rubygems_version:
|
60
|
+
rubygems_version: 2.0.3
|
43
61
|
signing_key:
|
44
|
-
specification_version:
|
45
|
-
summary:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Map of the USA in svg format. Plot colors via FIPS county coordinates.
|
46
64
|
test_files: []
|
47
65
|
has_rdoc:
|