rubrowser 2.3.0 → 2.4.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/rubrowser +5 -0
- data/lib/rubrowser/renderer.rb +6 -0
- data/lib/rubrowser/version.rb +1 -1
- data/public/javascript/application.js +33 -1
- data/public/javascript/toolbox.js +12 -0
- data/readme.md +2 -0
- data/views/index.erb +2 -1
- data/views/toolbox.erb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b96b57265b40b9d6be08133f053972d10052ba5f1e977a24d6c0ffb14aa0e5c
|
4
|
+
data.tar.gz: 47438b460b1f3276bc21c9f80ec3b95b34771a498c0601c8c85a4ceb5acc7912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6260b25527525ec6d2a67c8c691b681f24ba03cbff1630bfb631ded4f09ea73f129c3727d4501343b2d18f38318903f1ae99900c342b51a9cfcbd0842d676e9
|
7
|
+
data.tar.gz: 887c3e30156229cfac868468020ca48a47fc1d72358b44554341a4f19f732c92317fe5df02e6056bd765ae3c41306e3ebc19b51588915046f87b1073371e5018
|
data/Gemfile.lock
CHANGED
data/bin/rubrowser
CHANGED
@@ -7,6 +7,7 @@ require 'rubrowser/renderer'
|
|
7
7
|
|
8
8
|
options = {
|
9
9
|
toolbox: true,
|
10
|
+
layout: nil,
|
10
11
|
output: STDOUT
|
11
12
|
}
|
12
13
|
|
@@ -17,6 +18,10 @@ OptionParser.new do |opts|
|
|
17
18
|
options[:output] = output
|
18
19
|
end
|
19
20
|
|
21
|
+
opts.on('-lFILE', '--layout=FILE', 'layout file to apply on the resulting graph') do |layout|
|
22
|
+
options[:layout] = layout
|
23
|
+
end
|
24
|
+
|
20
25
|
opts.on('-T', '--no-toolbox', 'Don\'t display toolbox on the page') do
|
21
26
|
options[:toolbox] = false
|
22
27
|
end
|
data/lib/rubrowser/renderer.rb
CHANGED
@@ -23,6 +23,7 @@ module Rubrowser
|
|
23
23
|
|
24
24
|
def initialize(options)
|
25
25
|
@output = output_file(options[:output])
|
26
|
+
@layout = options[:layout]
|
26
27
|
@files = options[:files]
|
27
28
|
@toolbox = options[:toolbox]
|
28
29
|
end
|
@@ -31,6 +32,11 @@ module Rubrowser
|
|
31
32
|
path.is_a?(String) ? File.open(path, 'w') : path
|
32
33
|
end
|
33
34
|
|
35
|
+
def layout
|
36
|
+
return 'null' unless @layout
|
37
|
+
File.read(@layout)
|
38
|
+
end
|
39
|
+
|
34
40
|
def toolbox?
|
35
41
|
@toolbox
|
36
42
|
end
|
data/lib/rubrowser/version.rb
CHANGED
@@ -133,6 +133,35 @@ function transform(d) {
|
|
133
133
|
return "translate(" + d.x + "," + d.y + ")";
|
134
134
|
}
|
135
135
|
|
136
|
+
var state = {
|
137
|
+
get: function(){
|
138
|
+
var positions = [];
|
139
|
+
rubrowser.definitions.forEach(function(elem){
|
140
|
+
if( elem.fx !== undefined && elem.fy !== undefined) {
|
141
|
+
positions.push({
|
142
|
+
id: elem.id,
|
143
|
+
x: elem.fx,
|
144
|
+
y: elem.fy
|
145
|
+
});
|
146
|
+
}
|
147
|
+
});
|
148
|
+
return positions;
|
149
|
+
},
|
150
|
+
|
151
|
+
set: function(layout){
|
152
|
+
if ( !layout ) { return; }
|
153
|
+
layout.forEach(function(pos) {
|
154
|
+
var definition = node.filter(function(e) { return e.id == pos.id; })
|
155
|
+
definition.classed("fixed", true);
|
156
|
+
|
157
|
+
var datum = definition.data()[0]
|
158
|
+
if( datum ) {
|
159
|
+
datum.fx = pos.x
|
160
|
+
datum.fy = pos.y
|
161
|
+
}
|
162
|
+
});
|
163
|
+
}
|
164
|
+
}
|
136
165
|
|
137
166
|
node.on('mouseover', function(d) {
|
138
167
|
var relatives = [];
|
@@ -161,5 +190,8 @@ window.rubrowser = {
|
|
161
190
|
relations: relations,
|
162
191
|
simulation: simulation,
|
163
192
|
node: node,
|
164
|
-
link: link
|
193
|
+
link: link,
|
194
|
+
state: state
|
165
195
|
};
|
196
|
+
|
197
|
+
rubrowser.state.set(layout);
|
@@ -139,3 +139,15 @@ $(document).on('change', "#hide_namespaces", function(){
|
|
139
139
|
$(document).on('click', "#pause_simulation", function(){
|
140
140
|
rubrowser.simulation.stop();
|
141
141
|
});
|
142
|
+
|
143
|
+
$(document).on('click', "#download_layout", function(){
|
144
|
+
var json = JSON.stringify(rubrowser.state.get());
|
145
|
+
var element = document.createElement('a');
|
146
|
+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(json));
|
147
|
+
element.setAttribute('download', 'layout.json');
|
148
|
+
|
149
|
+
element.style.display = 'none';
|
150
|
+
document.body.appendChild(element);
|
151
|
+
element.click();
|
152
|
+
document.body.removeChild(element);
|
153
|
+
});
|
data/readme.md
CHANGED
@@ -53,6 +53,7 @@ gem install rubrowser
|
|
53
53
|
```
|
54
54
|
Usage: rubrowser [options] [file] ...
|
55
55
|
-o, --output=FILE output file page, if not specified output will be written to stdout
|
56
|
+
-l, --layout=FILE layout file to apply on the resulting graph
|
56
57
|
-T, --no-toolbox Don't display toolbox on the page
|
57
58
|
-v, --version Print Rubrowser version
|
58
59
|
-h, --help Prints this help
|
@@ -84,6 +85,7 @@ rubrowser > output.html
|
|
84
85
|
* Module/class circle size on the graph will be relative to module number of
|
85
86
|
lines in your code
|
86
87
|
* cyclical dependencies are marked in red
|
88
|
+
* after you move nodes around, you can download the layout as a file, then provide it when generating the graph file again with `-l file.json` it will embed the layout in the file and the graph will have the same layout by default.
|
87
89
|
|
88
90
|
## Why?
|
89
91
|
|
data/views/index.erb
CHANGED
@@ -17,7 +17,8 @@
|
|
17
17
|
<script src='https://unpkg.com/lodash@4.17.4/lodash.min.js' type='text/javascript'></script>
|
18
18
|
<script src='https://unpkg.com/d3@4.13.0/build/d3.min.js' type='text/javascript'></script>
|
19
19
|
<script type='text/javascript'>
|
20
|
-
var data = <%= data
|
20
|
+
var data = <%= data %>;
|
21
|
+
var layout = <%= layout %>;
|
21
22
|
</script>
|
22
23
|
<script type='text/javascript'><%= file('javascript/application.js') %></script>
|
23
24
|
|
data/views/toolbox.erb
CHANGED
@@ -42,7 +42,8 @@
|
|
42
42
|
<div class="card mt-2">
|
43
43
|
<div class="card-header">Display</div>
|
44
44
|
<div class="card-body">
|
45
|
-
<
|
45
|
+
<button type="button" id="download_layout" class="btn btn-secondary btn-block">Download layout</button>
|
46
|
+
<button type="button" id="pause_simulation" class="btn btn-secondary btn-block">Pause animation</button>
|
46
47
|
</div>
|
47
48
|
<div class="card-body">
|
48
49
|
<label class="form-label">Force Collide</label>
|