visualize_inheritance 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +7 -0
- data/lib/visualize_inheritance/create_graph.sh +45 -0
- data/lib/visualize_inheritance/create_nodes.rb +45 -0
- data/lib/visualize_inheritance/index.html +187 -0
- data/lib/visualize_inheritance/version.rb +3 -0
- data/lib/visualize_inheritance.rb +5 -0
- data/visualize_inheritance.gemspec +23 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c3402ddcc1259e4f445f60a758c5dfb1810c62e
|
4
|
+
data.tar.gz: 450e4b7740765f5e71f128aa68446bf0587166f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f15eb0f6f944f4c858283356e5d50ededb25cc5bea2898aa63f4731fa945e9745c86499d4de35a23dce8a166d1a820accc2ce0bb1db1674ff527eddb53fc3fe
|
7
|
+
data.tar.gz: ab43bab19cf1bb28ac6612db98eaf998ec1ce94974547330e6a8e2653fbaae8ed8169998727fa59a3ccc8e48af9f0848976c31962761c379fbb95dbfe55c0e5b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Cyrus Vandrevala
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
# VisualizeInheritance
|
3
|
+
|
4
|
+
TODO: Write a gem description
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'visualize_inheritance'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install visualize_inheritance
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/[my-github-username]/visualize_inheritance/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
31
|
+
|
32
|
+
|
33
|
+
Visualizing Inheritance Structure in Ruby
|
34
|
+
=========================================
|
35
|
+
|
36
|
+
This code uses a simple Bash script combined with a force directed graph in D3 to visualize the inheritance structure of a Ruby project.
|
37
|
+
|
38
|
+
Put this in the main folder of the project. Upon running the bash script create_graph.sh, it will scan the lib folder for all classes, and then create a force directed graph in a browser window using D3.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
rm -f raw_files.txt trimmed_files.txt
|
4
|
+
rm -f raw_classes.txt spaced_classes.txt
|
5
|
+
rm -f reordered_classes.txt force.csv
|
6
|
+
|
7
|
+
grep --recursive '../' --include \*.rb --regexp 'class ' \
|
8
|
+
> raw_files.txt
|
9
|
+
|
10
|
+
tr -d ' \t\r\f' < raw_files.txt > trimmed_files.txt
|
11
|
+
|
12
|
+
grep --extended-regexp --only-matching "(class\S+)" \
|
13
|
+
< trimmed_files.txt | cut -c 6- > raw_classes.txt
|
14
|
+
|
15
|
+
sed 's/</ < /g' raw_classes.txt >> spaced_classes.txt
|
16
|
+
|
17
|
+
awk '{ for (i=NF; i>=1; i--) printf (i!=1) ? $i OFS : $i "\n" }' \
|
18
|
+
spaced_classes.txt >> reordered_classes.txt
|
19
|
+
|
20
|
+
echo 'source,target' > force.csv
|
21
|
+
exec < reordered_classes.txt
|
22
|
+
while read LINE; do
|
23
|
+
if [[ $LINE == *\<* ]]; then
|
24
|
+
Y=0
|
25
|
+
for WORD in $LINE; do
|
26
|
+
if [ $Y == 0 ]
|
27
|
+
then
|
28
|
+
PARENT=$WORD
|
29
|
+
elif [ $Y == 2 ]
|
30
|
+
then
|
31
|
+
CHILD=$WORD
|
32
|
+
fi
|
33
|
+
Y=$((Y+1))
|
34
|
+
done
|
35
|
+
echo "$PARENT,$CHILD" >> force.csv
|
36
|
+
echo "Ruby,$PARENT" >> force.csv
|
37
|
+
else
|
38
|
+
echo "Ruby,$LINE" >> force.csv
|
39
|
+
fi
|
40
|
+
done
|
41
|
+
|
42
|
+
open index.html
|
43
|
+
#rm -f raw_files.txt trimmed_files.txt
|
44
|
+
#rm -f raw_classes.txt spaced_classes.txt
|
45
|
+
#rm -f reordered_classes.txt
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/bin/ruby
|
2
|
+
|
3
|
+
rm -f raw_files.txt trimmed_files.txt
|
4
|
+
rm -f raw_classes.txt spaced_classes.txt
|
5
|
+
rm -f reordered_classes.txt force.csv
|
6
|
+
|
7
|
+
grep --recursive '../' --include \*.rb --regexp 'class ' \
|
8
|
+
> raw_files.txt
|
9
|
+
|
10
|
+
tr -d ' \t\r\f' < raw_files.txt > trimmed_files.txt
|
11
|
+
|
12
|
+
grep --extended-regexp --only-matching "(class\S+)" \
|
13
|
+
< trimmed_files.txt | cut -c 6- > raw_classes.txt
|
14
|
+
|
15
|
+
sed 's/</ < /g' raw_classes.txt >> spaced_classes.txt
|
16
|
+
|
17
|
+
awk '{ for (i=NF; i>=1; i--) printf (i!=1) ? $i OFS : $i "\n" }' \
|
18
|
+
spaced_classes.txt >> reordered_classes.txt
|
19
|
+
|
20
|
+
echo 'source,target' > force.csv
|
21
|
+
exec < reordered_classes.txt
|
22
|
+
while read LINE; do
|
23
|
+
if [[ $LINE == *\<* ]]; then
|
24
|
+
Y=0
|
25
|
+
for WORD in $LINE; do
|
26
|
+
if [ $Y == 0 ]
|
27
|
+
then
|
28
|
+
PARENT=$WORD
|
29
|
+
elif [ $Y == 2 ]
|
30
|
+
then
|
31
|
+
CHILD=$WORD
|
32
|
+
fi
|
33
|
+
Y=$((Y+1))
|
34
|
+
done
|
35
|
+
echo "$PARENT,$CHILD" >> force.csv
|
36
|
+
echo "Ruby,$PARENT" >> force.csv
|
37
|
+
else
|
38
|
+
echo "Ruby,$LINE" >> force.csv
|
39
|
+
fi
|
40
|
+
done
|
41
|
+
|
42
|
+
open index.html
|
43
|
+
#rm -f raw_files.txt trimmed_files.txt
|
44
|
+
#rm -f raw_classes.txt spaced_classes.txt
|
45
|
+
#rm -f reordered_classes.txt
|
@@ -0,0 +1,187 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<meta charset="utf-8">
|
3
|
+
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
|
4
|
+
<style>
|
5
|
+
|
6
|
+
path.link {
|
7
|
+
fill: none;
|
8
|
+
stroke: #666;
|
9
|
+
stroke-width: 1.5px;
|
10
|
+
}
|
11
|
+
|
12
|
+
path.link.twofive {
|
13
|
+
opacity: 0.25;
|
14
|
+
}
|
15
|
+
|
16
|
+
path.link.fivezero {
|
17
|
+
opacity: 0.50;
|
18
|
+
}
|
19
|
+
|
20
|
+
path.link.sevenfive {
|
21
|
+
opacity: 0.75;
|
22
|
+
}
|
23
|
+
|
24
|
+
path.link.onezerozero {
|
25
|
+
opacity: 1.0;
|
26
|
+
}
|
27
|
+
|
28
|
+
circle {
|
29
|
+
fill: #ccc;
|
30
|
+
stroke: #fff;
|
31
|
+
stroke-width: 1.5px;
|
32
|
+
}
|
33
|
+
|
34
|
+
text {
|
35
|
+
fill: #000;
|
36
|
+
font: 10px sans-serif;
|
37
|
+
pointer-events: none;
|
38
|
+
}
|
39
|
+
|
40
|
+
</style>
|
41
|
+
<body>
|
42
|
+
<script>
|
43
|
+
|
44
|
+
// get the data
|
45
|
+
d3.csv("force.csv", function(error, links) {
|
46
|
+
|
47
|
+
var nodes = {};
|
48
|
+
|
49
|
+
// Compute the distinct nodes from the links.
|
50
|
+
links.forEach(function(link) {
|
51
|
+
link.source = nodes[link.source] ||
|
52
|
+
(nodes[link.source] = {name: link.source});
|
53
|
+
link.target = nodes[link.target] ||
|
54
|
+
(nodes[link.target] = {name: link.target});
|
55
|
+
link.value = +link.value;
|
56
|
+
});
|
57
|
+
|
58
|
+
var width = 960,
|
59
|
+
height = 500;
|
60
|
+
|
61
|
+
var force = d3.layout.force()
|
62
|
+
.nodes(d3.values(nodes))
|
63
|
+
.links(links)
|
64
|
+
.size([width, height])
|
65
|
+
.linkDistance(100) //This used to be 60
|
66
|
+
.charge(-1000) //This used to be -300
|
67
|
+
.on("tick", tick)
|
68
|
+
.start();
|
69
|
+
|
70
|
+
// Set the range
|
71
|
+
var v = d3.scale.linear().range([0, 100]);
|
72
|
+
|
73
|
+
// Scale the range of the data
|
74
|
+
v.domain([0, d3.max(links, function(d) { return d.value; })]);
|
75
|
+
|
76
|
+
// asign a type per value to encode opacity
|
77
|
+
links.forEach(function(link) {
|
78
|
+
if (v(link.value) <= 25) {
|
79
|
+
link.type = "twofive";
|
80
|
+
} else if (v(link.value) <= 50 && v(link.value) > 25) {
|
81
|
+
link.type = "fivezero";
|
82
|
+
} else if (v(link.value) <= 75 && v(link.value) > 50) {
|
83
|
+
link.type = "sevenfive";
|
84
|
+
} else if (v(link.value) <= 100 && v(link.value) > 75) {
|
85
|
+
link.type = "onezerozero";
|
86
|
+
}
|
87
|
+
});
|
88
|
+
|
89
|
+
var svg = d3.select("body").append("svg")
|
90
|
+
.attr("width", width)
|
91
|
+
.attr("height", height);
|
92
|
+
|
93
|
+
// build the arrow.
|
94
|
+
svg.append("svg:defs").selectAll("marker")
|
95
|
+
.data(["end"]) // Different link/path types can be defined here
|
96
|
+
.enter().append("svg:marker") // This section adds in the arrows
|
97
|
+
.attr("id", String)
|
98
|
+
.attr("viewBox", "0 -5 10 10")
|
99
|
+
.attr("refX", 15)
|
100
|
+
.attr("refY", -1.5)
|
101
|
+
.attr("markerWidth", 6)
|
102
|
+
.attr("markerHeight", 6)
|
103
|
+
.attr("orient", "auto")
|
104
|
+
.append("svg:path")
|
105
|
+
.attr("d", "M0,-5L10,0L0,5");
|
106
|
+
|
107
|
+
// add the links and the arrows
|
108
|
+
var path = svg.append("svg:g").selectAll("path")
|
109
|
+
.data(force.links())
|
110
|
+
.enter().append("svg:path")
|
111
|
+
.attr("class", function(d) { return "link " + d.type; })
|
112
|
+
.attr("marker-end", "url(#end)");
|
113
|
+
|
114
|
+
// define the nodes
|
115
|
+
var node = svg.selectAll(".node")
|
116
|
+
.data(force.nodes())
|
117
|
+
.enter().append("g")
|
118
|
+
.attr("class", "node")
|
119
|
+
.on("click", click)
|
120
|
+
.on("dblclick", dblclick)
|
121
|
+
.call(force.drag);
|
122
|
+
|
123
|
+
// add the nodes
|
124
|
+
node.append("circle")
|
125
|
+
.attr("r", 5);
|
126
|
+
|
127
|
+
// add the text
|
128
|
+
node.append("text")
|
129
|
+
.attr("x", 12)
|
130
|
+
.attr("dy", ".35em")
|
131
|
+
.text(function(d) { return d.name; });
|
132
|
+
|
133
|
+
// add the curvy lines
|
134
|
+
function tick() {
|
135
|
+
path.attr("d", function(d) {
|
136
|
+
var dx = d.target.x - d.source.x,
|
137
|
+
dy = d.target.y - d.source.y,
|
138
|
+
dr = Math.sqrt(dx * dx + dy * dy);
|
139
|
+
return "M" +
|
140
|
+
d.source.x + "," +
|
141
|
+
d.source.y + "A" +
|
142
|
+
dr + "," + dr + " 0 0,1 " +
|
143
|
+
d.target.x + "," +
|
144
|
+
d.target.y;
|
145
|
+
});
|
146
|
+
|
147
|
+
node
|
148
|
+
.attr("transform", function(d) {
|
149
|
+
return "translate(" + d.x + "," + d.y + ")"; });
|
150
|
+
}
|
151
|
+
|
152
|
+
// action to take on mouse click
|
153
|
+
function click() {
|
154
|
+
d3.select(this).select("text").transition()
|
155
|
+
.duration(750)
|
156
|
+
.attr("x", 22)
|
157
|
+
.style("fill", "steelblue")
|
158
|
+
.style("stroke", "lightsteelblue")
|
159
|
+
.style("stroke-width", ".5px")
|
160
|
+
.style("font", "20px sans-serif");
|
161
|
+
d3.select(this).select("circle").transition()
|
162
|
+
.duration(750)
|
163
|
+
.attr("r", 16)
|
164
|
+
.style("fill", "lightsteelblue");
|
165
|
+
}
|
166
|
+
|
167
|
+
// action to take on mouse double click
|
168
|
+
function dblclick() {
|
169
|
+
d3.select(this).select("circle").transition()
|
170
|
+
.duration(750)
|
171
|
+
.attr("r", 6)
|
172
|
+
.style("fill", "#ccc");
|
173
|
+
d3.select(this).select("text").transition()
|
174
|
+
.duration(750)
|
175
|
+
.attr("x", 12)
|
176
|
+
.style("stroke", "none")
|
177
|
+
.style("fill", "black")
|
178
|
+
.style("stroke", "none")
|
179
|
+
.style("font", "10px sans-serif");
|
180
|
+
}
|
181
|
+
|
182
|
+
});
|
183
|
+
|
184
|
+
</script>
|
185
|
+
</body>
|
186
|
+
</html>
|
187
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'visualize_inheritance/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "visualize_inheritance"
|
8
|
+
spec.version = VisualizeInheritance::VERSION
|
9
|
+
spec.authors = ["Cyrus Vandrevala"]
|
10
|
+
spec.email = ["cyrus.vandrevala@gmail.com"]
|
11
|
+
spec.description = %q{Create a directed graph of the relationships between classes in a Ruby program.}
|
12
|
+
spec.summary = %q{Directed graph of relations.}
|
13
|
+
spec.homepage = "http://rubygems.org/gems/visualize_inheritance"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visualize_inheritance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyrus Vandrevala
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Create a directed graph of the relationships between classes in a Ruby
|
56
|
+
program.
|
57
|
+
email:
|
58
|
+
- cyrus.vandrevala@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/visualize_inheritance.rb
|
69
|
+
- lib/visualize_inheritance/create_graph.sh
|
70
|
+
- lib/visualize_inheritance/create_nodes.rb
|
71
|
+
- lib/visualize_inheritance/index.html
|
72
|
+
- lib/visualize_inheritance/version.rb
|
73
|
+
- visualize_inheritance.gemspec
|
74
|
+
homepage: http://rubygems.org/gems/visualize_inheritance
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Directed graph of relations.
|
98
|
+
test_files: []
|