rubyvis 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +2 -0
- data/examples/area.rb +1 -1
- data/examples/area_interpolation.rb +8 -1
- data/examples/dendogram.rb +52 -0
- data/examples/line_interpolation.rb +10 -1
- data/examples/stacked_charts.rb +3 -1
- data/examples/sunburst.rb +6 -4
- data/lib/rubyvis.rb +1 -1
- data/lib/rubyvis/dom.rb +1 -1
- data/lib/rubyvis/internals.rb +15 -7
- data/lib/rubyvis/layout.rb +2 -0
- data/lib/rubyvis/layout/cluster.rb +203 -0
- data/lib/rubyvis/layout/hierarchy.rb +18 -13
- data/lib/rubyvis/layout/network.rb +104 -12
- data/lib/rubyvis/layout/partition.rb +1 -1
- data/lib/rubyvis/mark/shorcut_methods.rb +14 -0
- data/lib/rubyvis/sceneelement.rb +1 -1
- data/web/build_site.rb +2 -1
- data/web/examples.haml +1 -3
- data/web/index.haml +2 -2
- metadata +6 -4
- metadata.gz.sig +2 -3
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -15,6 +15,7 @@ examples/cars/cars_data.rb
|
|
15
15
|
examples/crimea/crimea_data.rb
|
16
16
|
examples/crimea/crimea_grouped_bar.rb
|
17
17
|
examples/crimea/crimea_line.rb
|
18
|
+
examples/dendogram.rb
|
18
19
|
examples/dot.rb
|
19
20
|
examples/first_protovis_api.rb
|
20
21
|
examples/first_rbp_api.rb
|
@@ -45,6 +46,7 @@ lib/rubyvis/histogram.rb
|
|
45
46
|
lib/rubyvis/internals.rb
|
46
47
|
lib/rubyvis/javascript_behaviour.rb
|
47
48
|
lib/rubyvis/layout.rb
|
49
|
+
lib/rubyvis/layout/cluster.rb
|
48
50
|
lib/rubyvis/layout/hierarchy.rb
|
49
51
|
lib/rubyvis/layout/network.rb
|
50
52
|
lib/rubyvis/layout/partition.rb
|
data/examples/area.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# = Area Charts
|
2
2
|
# This simple area chart is constructed using an area mark, with an added line for emphasis on the top edge. Next, rules and labels are added for reference values.
|
3
3
|
# Although this example is basic, it provides a good starting point for adding more complex features. For instance, multiple series of data can be added to produce a stacked area chart.
|
4
|
-
# * Protovis version:
|
4
|
+
# * "Protovis version":http://vis.stanford.edu/protovis/ex/area.html
|
5
5
|
# * Syntax: RBP
|
6
6
|
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
7
7
|
require 'rubyvis'
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# = Area Interpolation
|
2
|
-
# This example show the 5 types of interpolation available for areas
|
2
|
+
# This example show the 5 types of interpolation available for areas:
|
3
|
+
# * linear
|
4
|
+
# * step-before
|
5
|
+
# * step-after
|
6
|
+
# * basis
|
7
|
+
# * cardinal
|
8
|
+
#
|
9
|
+
# See also "Line Interpolation":line_interpolation.html
|
3
10
|
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
4
11
|
require 'rubyvis'
|
5
12
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# = Dendogram
|
2
|
+
# A dendrogram (or cluster layout) is a node-link diagram that places leaf nodes of the tree at the same depth. In this example, the classes (orange leaf nodes) are aligned on the right edge, with the packages (blue internal nodes) to the left. As with other tree layouts, dendrograms can also be oriented radially.
|
3
|
+
# Uses Protovis API
|
4
|
+
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
5
|
+
require 'rubyvis'
|
6
|
+
|
7
|
+
|
8
|
+
def get_files(path)
|
9
|
+
h={}
|
10
|
+
Dir.glob("#{path}/*").each {|e|
|
11
|
+
next if File.expand_path(e)=~/pkg|web|vendor|doc|~/
|
12
|
+
pa=File.expand_path(e)
|
13
|
+
if File.stat(pa).directory?
|
14
|
+
h[File.basename(pa)]=get_files(pa)
|
15
|
+
else
|
16
|
+
h[File.basename(pa)]=File.stat(pa).size
|
17
|
+
end
|
18
|
+
}
|
19
|
+
h
|
20
|
+
end
|
21
|
+
|
22
|
+
files=get_files(File.dirname(__FILE__)+"/../")
|
23
|
+
|
24
|
+
|
25
|
+
vis = Rubyvis::Panel.new do
|
26
|
+
width 200
|
27
|
+
height 1500
|
28
|
+
left 40
|
29
|
+
right 160
|
30
|
+
top 10
|
31
|
+
bottom 10
|
32
|
+
layout_cluster do
|
33
|
+
nodes pv.dom(files).root("rubyvis").sort(lambda {|a,b| a.node_name<=>b.node_name}).nodes
|
34
|
+
group 1
|
35
|
+
orient "left"
|
36
|
+
|
37
|
+
link.line do
|
38
|
+
stroke_style "#ccc"
|
39
|
+
line_width 1
|
40
|
+
antialias false
|
41
|
+
end
|
42
|
+
|
43
|
+
node.dot do
|
44
|
+
fill_style {|n| n.first_child ? "#aec7e8" : "#ff7f0e"}
|
45
|
+
end
|
46
|
+
|
47
|
+
node_label.label
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
vis.render
|
52
|
+
puts vis.to_svg
|
@@ -1,5 +1,14 @@
|
|
1
1
|
# = Line Interpolation
|
2
|
-
# This example show the 7 types of interpolation available for lines
|
2
|
+
# This example show the 7 types of interpolation available for lines:
|
3
|
+
# * linear
|
4
|
+
# * step-before
|
5
|
+
# * step-after
|
6
|
+
# * polar
|
7
|
+
# * polar-reverse
|
8
|
+
# * basis
|
9
|
+
# * cardinal
|
10
|
+
#
|
11
|
+
# See also "Area Interpolation":area_interpolation.html
|
3
12
|
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
4
13
|
require 'rubyvis'
|
5
14
|
|
data/examples/stacked_charts.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# = Stacked Area
|
2
|
+
# This example uses the Stack layout to stack areas one over another.
|
1
3
|
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
2
4
|
require 'rubyvis'
|
3
5
|
|
4
6
|
data = pv.range(4).map {|i|
|
5
|
-
pv.range(0, 10, 1).map {|x|
|
7
|
+
pv.range(0, 10, 0.1).map {|x|
|
6
8
|
OpenStruct.new({:x=> x, :y=> Math.sin(x) + rand() * 0.5 + 2})
|
7
9
|
}
|
8
10
|
}
|
data/examples/sunburst.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# = Sunbursts
|
2
2
|
# A sunburst is an adjacency diagram: a space-filling variant of the node-link diagram. Rather than drawing a link between parent and child in the hierarchy, nodes are drawn as solid areas (either wedges or bars), and their placement relative to adjacent nodes reveals their position in the hierarchy. Because the nodes are now space-filling, we can use an angle encoding for the size of software files. This reveals an additional dimension that would be difficult to show in a node-link diagram.
|
3
|
-
#
|
3
|
+
# This example show files and directory inside rubyvis lib directory and uses RBP API
|
4
4
|
|
5
5
|
$:.unshift(File.dirname(__FILE__)+"/../lib")
|
6
6
|
require 'rubyvis'
|
@@ -19,13 +19,15 @@ def get_files(path)
|
|
19
19
|
h
|
20
20
|
end
|
21
21
|
|
22
|
-
files=get_files(File.dirname(__FILE__)+"/../")
|
22
|
+
files=get_files(File.dirname(__FILE__)+"/../lib/rubyvis/")
|
23
|
+
|
24
|
+
#load(File.dirname(__FILE__)+"/treemap/treemap_data.rb")
|
25
|
+
|
23
26
|
colors=Rubyvis::Colors.category19()
|
24
27
|
|
25
28
|
vis = Rubyvis::Panel.new do
|
26
29
|
width 900
|
27
30
|
height 900
|
28
|
-
bottom -80
|
29
31
|
layout_partition_fill do
|
30
32
|
nodes Rubyvis.dom(files).root("rubyvis").nodes
|
31
33
|
size {|d| d.node_value}
|
@@ -39,7 +41,7 @@ vis = Rubyvis::Panel.new do
|
|
39
41
|
end
|
40
42
|
|
41
43
|
node_label.label do
|
42
|
-
visible {|d| d.angle * d.outer_radius >=
|
44
|
+
visible {|d| d.angle * d.outer_radius >= 10}
|
43
45
|
end
|
44
46
|
|
45
47
|
end
|
data/lib/rubyvis.rb
CHANGED
@@ -29,7 +29,7 @@ require 'rubyvis/mark/shorcut_methods'
|
|
29
29
|
module Rubyvis
|
30
30
|
@document=nil
|
31
31
|
# Rubyvis version
|
32
|
-
VERSION = '0.3.
|
32
|
+
VERSION = '0.3.2'
|
33
33
|
# Protovis API on which current Rubyvis is based
|
34
34
|
PROTOVIS_API_VERSION='3.3'
|
35
35
|
# You actually can do it! http://snipplr.com/view/2137/uses-for-infinity-in-ruby/
|
data/lib/rubyvis/dom.rb
CHANGED
@@ -78,7 +78,7 @@ module Rubyvis
|
|
78
78
|
|
79
79
|
# The node value. When generated from a map, node value corresponds to
|
80
80
|
# the leaf value for leaf nodes, and is undefined for internal nodes.
|
81
|
-
|
81
|
+
attr_accessor :node_value
|
82
82
|
|
83
83
|
# The array of child nodes. This array is empty for leaf nodes. An easy way to
|
84
84
|
# check if child nodes exist is to query <tt>firstChild</tt>.
|
data/lib/rubyvis/internals.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rubyvis
|
2
2
|
# :section: /pv-internals.js
|
3
3
|
@@id=0
|
4
|
-
#
|
4
|
+
# Returns a locally-unique positive id.
|
5
5
|
def self.id
|
6
6
|
@@id+=1
|
7
7
|
end
|
8
|
-
# Return a
|
8
|
+
# Return a proc wrapping specific constant
|
9
9
|
def self.functor(f)
|
10
10
|
(f.is_a? Proc) ? f : lambda {f}
|
11
11
|
end
|
@@ -30,7 +30,14 @@ module Rubyvis
|
|
30
30
|
array.dup
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
#
|
34
|
+
# Concatenates the specified array with itself <i>n</i> times. For example,
|
35
|
+
# +repeat([1, 2])+ returns [1, 2, 1, 2].
|
36
|
+
#
|
37
|
+
# * @param {array} a an array.
|
38
|
+
# * @param {number} [n] the number of times to repeat; defaults to two.
|
39
|
+
# * @returns {array} an array that repeats the specified array.
|
40
|
+
#
|
34
41
|
def self.repeat(array, n=2)
|
35
42
|
array*n
|
36
43
|
end
|
@@ -150,14 +157,15 @@ module Rubyvis
|
|
150
157
|
return step ? ((rand() * (stop - start).quo(step)).floor * step + start) : (rand() * (stop - start) + start);
|
151
158
|
end
|
152
159
|
|
153
|
-
def self.sum(array,f=nil)
|
160
|
+
def self.sum(array, f=nil)
|
154
161
|
if f.nil?
|
155
|
-
array.inject(0) {|ac,v| ac+v}
|
162
|
+
array.inject(0) {|ac, v| ac+v}
|
156
163
|
else
|
157
164
|
i=0
|
158
165
|
array.inject(0) {|ac,v|
|
159
|
-
o=o_index(i)
|
160
|
-
|
166
|
+
o=o_index(i)
|
167
|
+
i+=1
|
168
|
+
ac+f.js_call(o, v)
|
161
169
|
}
|
162
170
|
end
|
163
171
|
end
|
data/lib/rubyvis/layout.rb
CHANGED
@@ -0,0 +1,203 @@
|
|
1
|
+
module Rubyvis
|
2
|
+
class Layout
|
3
|
+
# Alias for Rubyvis::Layout::Cluster
|
4
|
+
def self.Cluster
|
5
|
+
Rubyvis::Layout::Cluster
|
6
|
+
end
|
7
|
+
|
8
|
+
# Implements a hierarchical layout using the cluster (or dendrogram)
|
9
|
+
# algorithm. This layout provides both node-link and space-filling
|
10
|
+
# implementations of cluster diagrams. In many ways it is similar to
|
11
|
+
# {@link pv.Layout.Partition}, except that leaf nodes are positioned at maximum
|
12
|
+
# depth, and the depth of internal nodes is based on their distance from their
|
13
|
+
# deepest descendant, rather than their distance from the root.
|
14
|
+
#
|
15
|
+
# <p>The cluster layout supports a "group" property, which if true causes
|
16
|
+
# siblings to be positioned closer together than unrelated nodes at the same
|
17
|
+
# depth. Unlike the partition layout, this layout does not support dynamic
|
18
|
+
# sizing for leaf nodes; all leaf nodes are the same size.
|
19
|
+
#
|
20
|
+
# <p>For more details on how to use this layout, see
|
21
|
+
# {@link pv.Layout.Hierarchy}.
|
22
|
+
#
|
23
|
+
# @see pv.Layout.Cluster.Fill
|
24
|
+
# @extends pv.Layout.Hierarchy
|
25
|
+
class Cluster < Hierarchy
|
26
|
+
include NodeLink
|
27
|
+
attr_accessor :interpolate
|
28
|
+
@properties=Hierarchy.properties.dup
|
29
|
+
# Constructs a new, empty cluster layout. Layouts are not typically
|
30
|
+
# constructed directly; instead, they are added to an existing panel via
|
31
|
+
# {@link pv.Mark#add}.
|
32
|
+
attr_accessor :interpolate
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
super
|
36
|
+
@interpolate=nil
|
37
|
+
that=self
|
38
|
+
## @private Cache layout state to optimize properties. #/
|
39
|
+
@link.interpolate {that.interpolate}
|
40
|
+
end
|
41
|
+
##
|
42
|
+
# :attr: group
|
43
|
+
# The group parameter; defaults to 0, disabling grouping of siblings. If this
|
44
|
+
# parameter is set to a positive number (or true, which is equivalent to 1),
|
45
|
+
# then additional space will be allotted between sibling groups. In other
|
46
|
+
# words, siblings (nodes that share the same parent) will be positioned more
|
47
|
+
# closely than nodes at the same depth that do not share a parent.
|
48
|
+
#
|
49
|
+
# @type number
|
50
|
+
|
51
|
+
##
|
52
|
+
# :attr:orient
|
53
|
+
#
|
54
|
+
# The orientation. The default orientation is "top", which means that the root
|
55
|
+
# node is placed on the top edge, leaf nodes appear on the bottom edge, and
|
56
|
+
# internal nodes are in-between. The following orientations are supported:<ul>
|
57
|
+
#
|
58
|
+
# <li>left - left-to-right.
|
59
|
+
# <li>right - right-to-left.
|
60
|
+
# <li>top - top-to-bottom.
|
61
|
+
# <li>bottom - bottom-to-top.
|
62
|
+
# <li>radial - radially, with the root at the center.</ul>
|
63
|
+
#
|
64
|
+
# @type string
|
65
|
+
|
66
|
+
##
|
67
|
+
# :attr: inner_radius
|
68
|
+
#
|
69
|
+
# The inner radius; defaults to 0. This property applies only to radial
|
70
|
+
# orientations, and can be used to compress the layout radially. Note that for
|
71
|
+
# the node-link implementation, the root node is always at the center,
|
72
|
+
# regardless of the value of this property; this property only affects internal
|
73
|
+
# and leaf nodes. For the space-filling implementation, a non-zero value of
|
74
|
+
# this property will result in the root node represented as a ring rather than
|
75
|
+
# a circle.
|
76
|
+
#
|
77
|
+
# @type number
|
78
|
+
|
79
|
+
##
|
80
|
+
# :attr: outer_radius
|
81
|
+
# The outer radius; defaults to fill the containing panel, based on the height
|
82
|
+
# and width of the layout. If the layout has no height and width specified, it
|
83
|
+
# will extend to fill the enclosing panel.
|
84
|
+
#
|
85
|
+
# @type number
|
86
|
+
|
87
|
+
attr_accessor_dsl :group, :orient, :inner_radius, :outer_radius
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
# Defaults for cluster layouts. The default group parameter is 0 and the
|
92
|
+
# default orientation is "top".
|
93
|
+
#
|
94
|
+
# @type pv.Layout.Cluster
|
95
|
+
def self.defaults
|
96
|
+
Cluster.new.mark_extend(Hierarchy.defaults).
|
97
|
+
group(0).
|
98
|
+
orient("top")
|
99
|
+
end
|
100
|
+
def build_implied(s)
|
101
|
+
cluster_build_implied(s)
|
102
|
+
end
|
103
|
+
def cluster_build_implied(s)
|
104
|
+
@interpolate=case s.orient
|
105
|
+
when /^(top|bottom)$/
|
106
|
+
'step-before'
|
107
|
+
when /^(left|right)$/
|
108
|
+
'step-after'
|
109
|
+
else
|
110
|
+
'linear'
|
111
|
+
end
|
112
|
+
return nil if hierarchy_build_implied(s)
|
113
|
+
root = s.nodes[0]
|
114
|
+
group = s.group
|
115
|
+
breadth =nil
|
116
|
+
depth = nil
|
117
|
+
leaf_count = 0
|
118
|
+
leaf_index = 0.5 - group / 2.0
|
119
|
+
|
120
|
+
# Count the leaf nodes and compute the depth of descendants. #/
|
121
|
+
par = nil
|
122
|
+
root.visit_after {|n,i|
|
123
|
+
#puts "#{n.node_value} #{i}"
|
124
|
+
if (n.first_child)
|
125
|
+
n.depth = 1 + Rubyvis.max(n.child_nodes, lambda {|nn| nn.depth })
|
126
|
+
else
|
127
|
+
if (group!=0 and (par != n.parent_node))
|
128
|
+
par = n.parent_node
|
129
|
+
leaf_count += group
|
130
|
+
end
|
131
|
+
leaf_count+=1
|
132
|
+
n.depth = 0
|
133
|
+
end
|
134
|
+
}
|
135
|
+
breadth = 1.0 / leaf_count
|
136
|
+
depth = 1.0 / root.depth
|
137
|
+
|
138
|
+
# Compute the unit breadth and depth of each node. #/
|
139
|
+
par = nil
|
140
|
+
root.visit_after {|n,i|
|
141
|
+
if (n.first_child)
|
142
|
+
n.breadth = Rubyvis.mean(n.child_nodes, lambda {|nn| nn.breadth })
|
143
|
+
else
|
144
|
+
if (group!=0 and (par != n.parent_node))
|
145
|
+
par = n.parent_node
|
146
|
+
leaf_index += group
|
147
|
+
end
|
148
|
+
n.breadth = breadth * leaf_index
|
149
|
+
leaf_index+=1
|
150
|
+
end
|
151
|
+
n.depth = 1 - n.depth * depth
|
152
|
+
}
|
153
|
+
|
154
|
+
# Compute breadth and depth ranges for space-filling layouts. #/
|
155
|
+
root.visit_after {|n,i|
|
156
|
+
n.min_breadth = n.first_child ? n.first_child.min_breadth : (n.breadth - breadth / 2.0)
|
157
|
+
n.max_breadth = n.first_child ? n.last_child.max_breadth : (n.breadth + breadth / 2.0)
|
158
|
+
}
|
159
|
+
root.visit_before {|n,i|
|
160
|
+
n.min_depth = n.parent_node ? n.parent_node.max_depth : 0
|
161
|
+
n.max_depth = n.parent_node ? (n.depth + root.depth) : (n.min_depth + 2 * root.depth)
|
162
|
+
}
|
163
|
+
root.min_depth = -depth
|
164
|
+
node_link_build_implied(s)
|
165
|
+
false
|
166
|
+
end
|
167
|
+
# Constructs a new, empty space-filling cluster layout. Layouts are not
|
168
|
+
# typically constructed directly; instead, they are added to an existing panel
|
169
|
+
# via {@link pv.Mark#add}.
|
170
|
+
#
|
171
|
+
# @class A variant of cluster layout that is space-filling. The meaning of the
|
172
|
+
# exported mark prototypes changes slightly in the space-filling
|
173
|
+
# implementation:<ul>
|
174
|
+
#
|
175
|
+
# <li><tt>node</tt> - for rendering nodes; typically a {@link pv.Bar} for
|
176
|
+
# non-radial orientations, and a {@link pv.Wedge} for radial orientations.
|
177
|
+
#
|
178
|
+
# <p><li><tt>link</tt> - unsupported; undefined. Links are encoded implicitly
|
179
|
+
# in the arrangement of the space-filling nodes.
|
180
|
+
#
|
181
|
+
# <p><li><tt>label</tt> - for rendering node labels; typically a
|
182
|
+
# {@link pv.Label}.
|
183
|
+
#
|
184
|
+
# </ul>For more details on how to use this layout, see
|
185
|
+
# {@link pv.Layout.Cluster}.
|
186
|
+
#
|
187
|
+
# @extends pv.Layout.Cluster
|
188
|
+
class Fill < Cluster
|
189
|
+
include Hierarchy::Fill
|
190
|
+
@properties=Cluster.properties.dup
|
191
|
+
def initialize
|
192
|
+
super
|
193
|
+
fill_constructor
|
194
|
+
end
|
195
|
+
def build_implied(s)
|
196
|
+
return nil if cluster_build_implied(s)
|
197
|
+
fill_build_implied(s)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -50,18 +50,13 @@ module Rubyvis
|
|
50
50
|
def links
|
51
51
|
l=self.nodes().find_all {|n| n.parent_node}
|
52
52
|
l.map {|n|
|
53
|
-
|
53
|
+
|
54
|
+
Network::Link.new({
|
54
55
|
:source_node=>n,
|
55
56
|
:target_node=>n.parent_node,
|
56
57
|
:link_value=>1
|
57
58
|
})}
|
58
59
|
end
|
59
|
-
#def node_link
|
60
|
-
# NodeLink.new(self)
|
61
|
-
#end
|
62
|
-
#def fill
|
63
|
-
# Fill.new(self)
|
64
|
-
#end
|
65
60
|
end
|
66
61
|
|
67
62
|
module NodeLink
|
@@ -69,11 +64,15 @@ module Rubyvis
|
|
69
64
|
def node_link_build_implied(s)
|
70
65
|
nodes = s.nodes
|
71
66
|
@_orient= s.orient
|
72
|
-
@_orient
|
73
|
-
|
74
|
-
|
67
|
+
horizontal= case @_orient
|
68
|
+
when /^(top|bottom)$/
|
69
|
+
true
|
70
|
+
else
|
71
|
+
false
|
72
|
+
end
|
75
73
|
@_w = s.width
|
76
74
|
@_h = s.height
|
75
|
+
|
77
76
|
# /* Compute default inner and outer radius. */
|
78
77
|
if (@_orient == "radial")
|
79
78
|
@_ir = s.inner_radius
|
@@ -123,6 +122,7 @@ module Rubyvis
|
|
123
122
|
@_h / 2.0 + radius(n) * Math.sin(n.mid_angle)
|
124
123
|
end # end case
|
125
124
|
end # end method
|
125
|
+
private :node_link_y, :node_link_x, :mid_angle, :radius
|
126
126
|
end # end class
|
127
127
|
|
128
128
|
module Fill
|
@@ -153,7 +153,7 @@ module Rubyvis
|
|
153
153
|
@_w = s.width
|
154
154
|
@_h = s.height
|
155
155
|
@_depth = -nodes[0].min_depth
|
156
|
-
if
|
156
|
+
if @_orient == "radial"
|
157
157
|
@_ir = s.inner_radius
|
158
158
|
@_or = s.outer_radius
|
159
159
|
@_ir||=0
|
@@ -163,7 +163,7 @@ module Rubyvis
|
|
163
163
|
nodes.each_with_index {|n,i|
|
164
164
|
n.x = fill_x(n)
|
165
165
|
n.y = fill_y(n)
|
166
|
-
if
|
166
|
+
if @_orient == "radial"
|
167
167
|
n.inner_radius = inner_radius(n);
|
168
168
|
n.outer_radius = outer_radius(n);
|
169
169
|
n.start_angle = start_angle(n);
|
@@ -179,7 +179,7 @@ module Rubyvis
|
|
179
179
|
end
|
180
180
|
|
181
181
|
def fill_scale(d, depth)
|
182
|
-
(d+depth) / (1
|
182
|
+
(d + depth) / (1 + depth).to_f
|
183
183
|
end
|
184
184
|
def fill_x(n)
|
185
185
|
case @_orient
|
@@ -209,6 +209,7 @@ module Rubyvis
|
|
209
209
|
@_h / 2.0
|
210
210
|
end # end case
|
211
211
|
end # end method
|
212
|
+
|
212
213
|
def dx(n)
|
213
214
|
if @_orient=='left' or @_orient=='right'
|
214
215
|
(n.max_depth - n.min_depth) / (1.0 + @_depth) * @_w
|
@@ -218,6 +219,7 @@ module Rubyvis
|
|
218
219
|
n.parent_node ? (n.inner_radius + n.outer_radius) * Math.cos(n.mid_angle) : 0
|
219
220
|
end
|
220
221
|
end
|
222
|
+
|
221
223
|
def dy(n)
|
222
224
|
if @_orient=='left' or @_orient=='right'
|
223
225
|
(n.max_breadth - n.min_breadth) * @_h
|
@@ -227,12 +229,15 @@ module Rubyvis
|
|
227
229
|
n.parent_node ? (n.inner_radius + n.outer_radius) * Math.sin(n.mid_angle) : 0
|
228
230
|
end
|
229
231
|
end
|
232
|
+
|
230
233
|
def inner_radius(n)
|
231
234
|
[0, fill_scale(n.min_depth, @_depth/2.0)].max * (@_or - @_ir) + @_ir
|
232
235
|
end
|
236
|
+
|
233
237
|
def outer_radius(n)
|
234
238
|
fill_scale(n.max_depth, @_depth / 2.0) * (@_or - @_ir) + @_ir
|
235
239
|
end
|
240
|
+
|
236
241
|
def start_angle(n)
|
237
242
|
(n.parent_node ? n.min_breadth - 0.25 : 0) * 2 * Math::PI
|
238
243
|
end
|
@@ -12,23 +12,21 @@ module Rubyvis
|
|
12
12
|
# includes hierarchical structures; a tree is represented using links from
|
13
13
|
# child to parent.
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# Network layouts require the graph data structure to be defined using two
|
16
16
|
# properties:<ul>
|
17
17
|
#
|
18
|
-
# <li><tt>nodes</tt> - an array of objects representing nodes. Objects in this
|
19
|
-
# array must conform to the {@link pv.Layout.Network.Node} interface; which is
|
18
|
+
# <li><tt>nodes</tt> - an array of objects representing nodes. Objects in this array must conform to the {@link pv.Layout.Network.Node} interface; which is
|
20
19
|
# to say, be careful to avoid naming collisions with automatic attributes such
|
21
|
-
# as <tt>index</tt> and <tt>
|
20
|
+
# as <tt>index</tt> and <tt>link_degree</tt>.
|
21
|
+
# If the nodes property is defined
|
22
22
|
# as an array of primitives, such as numbers or strings, these primitives are
|
23
|
-
# automatically wrapped in an object; the resulting object's <tt>
|
23
|
+
# automatically wrapped in an object; the resulting object's <tt>node_value</tt>
|
24
24
|
# attribute points to the original primitive value.
|
25
25
|
#
|
26
26
|
# <p><li><tt>links</tt> - an array of objects representing links. Objects in
|
27
|
-
# this array must conform to the {@link pv.Layout.Network.Link} interface; at a
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# if the links property is defined after the nodes property, the links can be
|
31
|
-
# defined in terms of <tt>this.nodes()</tt>.
|
27
|
+
# this array must conform to the {@link pv.Layout.Network.Link} interface; at a minimum, either <tt>source</tt> and <tt>target</tt> indexes or
|
28
|
+
# <tt>source_node</tt> and <tt>target_node</tt> references must be set. Note that
|
29
|
+
# if the links property is defined after the nodes property, the links can be defined in terms of <tt>this.nodes()</tt>.
|
32
30
|
#
|
33
31
|
# </ul>
|
34
32
|
#
|
@@ -118,9 +116,9 @@ module Rubyvis
|
|
118
116
|
that=self
|
119
117
|
l=Mark.new().
|
120
118
|
mark_extend(@node).
|
121
|
-
data(lambda {|
|
119
|
+
data(lambda {|d| [d.source_node, d.target_node] }).
|
122
120
|
fill_style(nil).
|
123
|
-
line_width(lambda {|d,_p|
|
121
|
+
line_width(lambda {|d,_p| _p.link_value * 1.5 }).
|
124
122
|
stroke_style("rgba(0,0,0,.2)")
|
125
123
|
l.extend LinkAdd
|
126
124
|
l.that=self
|
@@ -206,6 +204,7 @@ module Rubyvis
|
|
206
204
|
layout_build_implied(s)
|
207
205
|
return true if (!s._id.nil? and s._id >= self._id)
|
208
206
|
s._id= self._id
|
207
|
+
|
209
208
|
s.nodes.each do |d|
|
210
209
|
d.link_degree=0
|
211
210
|
end
|
@@ -224,6 +223,99 @@ module Rubyvis
|
|
224
223
|
end
|
225
224
|
false
|
226
225
|
end
|
226
|
+
|
227
|
+
# Represents a node in a network layout. There is no explicit
|
228
|
+
# constructor; this class merely serves to document the attributes that are
|
229
|
+
# used on nodes in network layouts. (Note that hierarchical nodes place
|
230
|
+
# additional requirements on node representation, vis Rubyvis::Dom::Node.)
|
231
|
+
#
|
232
|
+
class Node
|
233
|
+
# The node index, zero-based. This attribute is populated automatically based
|
234
|
+
# on the index in the array returned by the <tt>nodes</tt> property.
|
235
|
+
#
|
236
|
+
# @type number
|
237
|
+
#/
|
238
|
+
attr_accessor :index
|
239
|
+
|
240
|
+
# The link degree; the sum of link values for all incoming and outgoing links.
|
241
|
+
# This attribute is populated automatically.
|
242
|
+
#
|
243
|
+
# @type number
|
244
|
+
attr_accessor :link_degree
|
245
|
+
|
246
|
+
# The node name; optional. If present, this attribute will be used to provide
|
247
|
+
# the text for node labels. If not present, the label text will fallback to the
|
248
|
+
# <tt>nodeValue</tt> attribute.
|
249
|
+
#
|
250
|
+
# @type string
|
251
|
+
attr_accessor :node_name
|
252
|
+
|
253
|
+
# The node value; optional. If present, and no <tt>nodeName</tt> attribute is
|
254
|
+
# present, the node value will be used as the label text. This attribute is
|
255
|
+
# also automatically populated if the nodes are specified as an array of
|
256
|
+
# primitives, such as strings or numbers.
|
257
|
+
#
|
258
|
+
# @type object
|
259
|
+
attr_accessor :node_value
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
# Represents a link in a network layout. There is no explicit
|
264
|
+
# constructor; this class merely serves to document the attributes that are
|
265
|
+
# used on links in network layouts. For hierarchical layouts, this class is
|
266
|
+
# used to represent the parent-child links.
|
267
|
+
#
|
268
|
+
# @see pv.Layout.Network
|
269
|
+
# @name pv.Layout.Network.Link
|
270
|
+
class Link
|
271
|
+
def initialize(opts)
|
272
|
+
@source_node=opts.delete :source_node
|
273
|
+
@target_node=opts.delete :target_node
|
274
|
+
@link_value=opts.delete :link_value
|
275
|
+
end
|
276
|
+
# The link value, or weight; optional. If not specified (or not a number), the
|
277
|
+
# default value of 1 is used.
|
278
|
+
#
|
279
|
+
# @type number
|
280
|
+
# @name pv.Layout.Network.Link.prototype.linkValue
|
281
|
+
#/
|
282
|
+
attr_accessor :link_value
|
283
|
+
|
284
|
+
# The link's source node. If not set, this value will be derived from the
|
285
|
+
# <tt>source</tt> attribute index.
|
286
|
+
#
|
287
|
+
# @type pv.Layout.Network.Node
|
288
|
+
# @name pv.Layout.Network.Link.prototype.sourceNode
|
289
|
+
attr_accessor :source_node
|
290
|
+
# The link's target node. If not set, this value will be derived from the
|
291
|
+
# <tt>target</tt> attribute index.
|
292
|
+
#
|
293
|
+
# @type pv.Layout.Network.Node
|
294
|
+
# @name pv.Layout.Network.Link.prototype.targetNode
|
295
|
+
attr_accessor :target_node
|
296
|
+
# Alias for <tt>sourceNode</tt>, as expressed by the index of the source node.
|
297
|
+
# This attribute is not populated automatically, but may be used as a more
|
298
|
+
# convenient identification of the link's source, for example in a static JSON
|
299
|
+
# representation.
|
300
|
+
#
|
301
|
+
# @type number
|
302
|
+
# @name pv.Layout.Network.Link.prototype.source
|
303
|
+
attr_accessor :source
|
304
|
+
# Alias for <tt>targetNode</tt>, as expressed by the index of the target node.
|
305
|
+
# This attribute is not populated automatically, but may be used as a more
|
306
|
+
# convenient identification of the link's target, for example in a static JSON
|
307
|
+
# representation.
|
308
|
+
#
|
309
|
+
# @type number
|
310
|
+
# @name pv.Layout.Network.Link.prototype.target
|
311
|
+
attr_accessor :target
|
312
|
+
# Alias for <tt>linkValue</tt>. This attribute is not populated automatically,
|
313
|
+
# but may be used instead of the <tt>linkValue</tt> attribute when specifying
|
314
|
+
# links.
|
315
|
+
#
|
316
|
+
# @type number
|
317
|
+
attr_accessor :value
|
318
|
+
end
|
227
319
|
end
|
228
320
|
end
|
229
321
|
end
|
@@ -198,5 +198,19 @@ class Rubyvis::Mark
|
|
198
198
|
# See Mark for examples of use
|
199
199
|
mark_method :layout_treemap, Rubyvis::Layout::Treemap
|
200
200
|
|
201
|
+
##
|
202
|
+
# :method: layout_cluster(opts,&block)
|
203
|
+
#
|
204
|
+
# Adds a Layout::Cluster to current mark.
|
205
|
+
#
|
206
|
+
# If a block is provided, the context will be defined differently if
|
207
|
+
# parameter is provided
|
208
|
+
# * Without parameter: block executed inside context of new mark
|
209
|
+
# * With paramenter: block executed inside context of current mark.
|
210
|
+
# Paramenter references new mark
|
211
|
+
#
|
212
|
+
# See Mark for examples of use
|
213
|
+
mark_method :layout_cluster, Rubyvis::Layout::Cluster
|
214
|
+
|
201
215
|
|
202
216
|
end
|
data/lib/rubyvis/sceneelement.rb
CHANGED
@@ -8,7 +8,7 @@ module Rubyvis
|
|
8
8
|
end
|
9
9
|
include Enumerable
|
10
10
|
attr_accessor :visible
|
11
|
-
attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image, :_id, :nodes, :round, :links, :padding_left, :padding_right, :padding_top, :padding_bottom, :mode
|
11
|
+
attr_accessor :mark, :type, :child_index, :parent, :parent_index, :target, :defs, :data, :antialias, :line_width, :fill_style, :overflow, :width, :height, :top, :bottom, :left, :right, :title, :reverse, :stroke_style, :transform, :canvas, :_g, :events, :cursor, :children, :id, :segmented, :interpolate, :tension, :name, :text_baseline, :text_align, :text, :font, :text_angle, :text_style, :text_margin, :text_decoration, :text_shadow, :line_join, :eccentricity, :shape_size, :shape, :shape_angle, :shape_radius, :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :layers, :orient, :offset, :order,:url, :image_width, :image_height, :image, :_id, :nodes, :round, :links, :padding_left, :padding_right, :padding_top, :padding_bottom, :mode, :group
|
12
12
|
|
13
13
|
def []=(v,i)
|
14
14
|
if v.is_a? Numeric
|
data/web/build_site.rb
CHANGED
@@ -6,6 +6,7 @@ require 'coderay'
|
|
6
6
|
require 'haml'
|
7
7
|
require 'ostruct'
|
8
8
|
require 'rubyvis'
|
9
|
+
require 'RedCloth'
|
9
10
|
|
10
11
|
# First, create the examples
|
11
12
|
|
@@ -64,7 +65,7 @@ files.each do |f|
|
|
64
65
|
# Create an html file with svg included inside
|
65
66
|
page.source=CodeRay.scan(source_a.join(), :ruby).div
|
66
67
|
page.title=title
|
67
|
-
page.text=text
|
68
|
+
page.text=RedCloth.new(text.join("\n")).to_html
|
68
69
|
page.svg_file=base+".svg"
|
69
70
|
# Read svg size
|
70
71
|
width=350
|
data/web/examples.haml
CHANGED
data/web/index.haml
CHANGED
@@ -69,8 +69,8 @@
|
|
69
69
|
%div
|
70
70
|
%h3 Image
|
71
71
|
/[if IE]
|
72
|
-
%embed{:src=>"examples/
|
73
|
-
%object{:data=>"examples/
|
72
|
+
%embed{:src=>"examples/first_protovis_api.svg" ,:width=>"150", :height=>"150"}
|
73
|
+
%object{:data=>"examples/first_protovis_api.svg", :type=>"image/svg+xml", :width=>150,:height=>150}
|
74
74
|
.examples_div
|
75
75
|
%h2 Examples
|
76
76
|
%p
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyvis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Claudio Bustos
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
rpP0jjs0
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2010-11-
|
39
|
+
date: 2010-11-23 00:00:00 -03:00
|
40
40
|
default_executable:
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- examples/crimea/crimea_data.rb
|
158
158
|
- examples/crimea/crimea_grouped_bar.rb
|
159
159
|
- examples/crimea/crimea_line.rb
|
160
|
+
- examples/dendogram.rb
|
160
161
|
- examples/dot.rb
|
161
162
|
- examples/first_protovis_api.rb
|
162
163
|
- examples/first_rbp_api.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- lib/rubyvis/internals.rb
|
188
189
|
- lib/rubyvis/javascript_behaviour.rb
|
189
190
|
- lib/rubyvis/layout.rb
|
191
|
+
- lib/rubyvis/layout/cluster.rb
|
190
192
|
- lib/rubyvis/layout/hierarchy.rb
|
191
193
|
- lib/rubyvis/layout/network.rb
|
192
194
|
- lib/rubyvis/layout/partition.rb
|
metadata.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ޱ1�f[���J������P�_��(�&���-��?~Ո���Ӂc�V��
|
1
|
+
� x>+�L��^�#{R�baA) $��gI����+L��[�sӾ���_)���i�_�OD�w�C�E$P �L�
|
2
|
+
�`ސ��ۿ!��BEl��lH�Bo>��6Q��ƪ��qx��4ʼn���Q�W
|