slicer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/slicer.rb +3 -0
- data/lib/slicer/slice.rb +18 -0
- data/lib/slicer/slicer.rb +43 -0
- data/lib/slicer/version.rb +3 -0
- metadata +48 -0
data/lib/slicer.rb
ADDED
data/lib/slicer/slice.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Slice
|
2
|
+
attr_accessor :name, :children, :colour, :value
|
3
|
+
|
4
|
+
alias_method :color, :colour
|
5
|
+
alias_method :color=, :colour=
|
6
|
+
|
7
|
+
def initialize(name = nil, color = nil, value = nil)
|
8
|
+
self.name = name
|
9
|
+
self.color = color
|
10
|
+
self.value = value
|
11
|
+
self.children = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def <<(slice)
|
15
|
+
self.children = [] if self.children.nil?
|
16
|
+
self.children << slice
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Slicer
|
2
|
+
|
3
|
+
#
|
4
|
+
# Pass an array of things and an array of Proc objects to operate on those things
|
5
|
+
# The block should yeild a hasmap where keys are names, values are the array of things that apply, such as
|
6
|
+
# { :general_admission => some_things, :vip => some_other_things }
|
7
|
+
#
|
8
|
+
|
9
|
+
cattr_accessor :color
|
10
|
+
@@color = 0x8B0000
|
11
|
+
|
12
|
+
def self.html_color(hex)
|
13
|
+
"#%06x" % hex
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.darker
|
17
|
+
@@color = @@color - 0x111111
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.lighter
|
21
|
+
@@color = @@color + 0x001C07
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.slice(root_slice, things, procs, current_depth=0)
|
25
|
+
root_slice ||= Slice.new("Root")
|
26
|
+
root_slice.children ||= []
|
27
|
+
|
28
|
+
unless procs.length == current_depth
|
29
|
+
map = procs[current_depth].call(things)
|
30
|
+
Array.wrap(map.keys).each do |kee|
|
31
|
+
current_slice = Slice.new(kee)
|
32
|
+
if(procs.length == current_depth+1)
|
33
|
+
current_slice.color = html_color(@@color)
|
34
|
+
lighter
|
35
|
+
current_slice.value = map[kee].length
|
36
|
+
end
|
37
|
+
root_slice.children << slice(current_slice, map[kee], procs, current_depth+1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
root_slice.children = nil if root_slice.children.empty?
|
41
|
+
root_slice
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slicer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gary Moore
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-26 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Slicing and dicing for d3 visualizations
|
15
|
+
email: gary.moore@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/slicer.rb
|
21
|
+
- lib/slicer/slicer.rb
|
22
|
+
- lib/slicer/slice.rb
|
23
|
+
- lib/slicer/version.rb
|
24
|
+
homepage: http://github.com/gmoore/slicer
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.10
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Slicing and dicing for d3 visualizations
|
48
|
+
test_files: []
|