rubrowser 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66b465f4952d44dbd2141eb12066017e16a65a2d
4
- data.tar.gz: da121cdfe98febb25db3bc057e55d4c9a200179a
3
+ metadata.gz: 3d1e814cf21c8e6a89504e7087deeded72c8d4a3
4
+ data.tar.gz: b77604a0c9f9417bc3fa61021f3c313ee41fa8c4
5
5
  SHA512:
6
- metadata.gz: ca739a897ac010919307c214e7b5c7d824f04003f7f228b5d13137ce4b2091cb24d667b9b0c2ce39a66ffee4781d4302fe8b48c1bb6be8515a195e26777b8640
7
- data.tar.gz: 7f70f2724171b73abb3d82391da021015b1d6f235868046a204e33e50036f947dc31cb93ae28404a6d4804813cc5a6277a0a7088354fca85abfdb18b4787fd2c
6
+ metadata.gz: da0b7cdfc663e971e3cfc393e319fd60d3bdeab3991411d4d6a75ec386d05749495385be38bd245ca84ba6a443faac12b08cbed7e1d330301efd2fafc0773858
7
+ data.tar.gz: 0e2e9037a14236096589596408fedfe50fb2500d2a8e8cce8241056fbc257cb40abf041da00a3babf11ef23fdfd0095793b0a3b0d8c5ac492ba472d69e97a49c
data/lib/rubrowser.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rubrowser
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
@@ -25,7 +25,7 @@ circle {
25
25
  stroke-width: 1.5px;
26
26
  }
27
27
 
28
- .fixed {
28
+ .fixed circle {
29
29
  fill: #f00;
30
30
  }
31
31
 
@@ -6,25 +6,24 @@ var ParseGraph = function(){
6
6
  return false;
7
7
  }
8
8
 
9
-
10
9
  var width = $svg.width(),
11
10
  height = $svg.height(),
12
11
  constants = JSON.parse(svg.attr('data-constants')),
13
- occurences = JSON.parse(svg.attr('data-occurences'));
14
- var color = d3.scaleOrdinal(d3.schemeCategory20);
15
-
16
- var drag = d3.drag()
12
+ occurences = JSON.parse(svg.attr('data-occurences')),
13
+ drag = d3.drag()
17
14
  .on("start", dragstarted)
18
15
  .on("drag", dragged)
19
16
  .on("end", dragended);
20
17
 
18
+ var zoom = d3.zoom()
19
+ .on("zoom", function () {
20
+ container.attr("transform", d3.event.transform);
21
+ });
21
22
 
22
- svg.call(d3.zoom().on("zoom", function () {
23
- container.attr("transform", d3.event.transform);
24
- }));
25
-
26
- container = svg.append('g');
23
+ svg.call(zoom)
24
+ .on("dblclick.zoom", null);
27
25
 
26
+ var container = svg.append('g');
28
27
 
29
28
  var simulation = d3.forceSimulation()
30
29
  .force("link", d3.forceLink().id(function(d) { return d.id; }))
@@ -32,6 +31,13 @@ var ParseGraph = function(){
32
31
  .force("center", d3.forceCenter(width / 2, height / 2))
33
32
  .force("forceCollide", d3.forceCollide(function(){ return 80; }));
34
33
 
34
+ simulation
35
+ .nodes(constants)
36
+ .on("tick", ticked);
37
+
38
+ simulation.force("link")
39
+ .links(occurences);
40
+
35
41
  var link = container.append("g")
36
42
  .attr("class", "links")
37
43
  .selectAll("path")
@@ -40,16 +46,20 @@ var ParseGraph = function(){
40
46
  .attr("class", 'link')
41
47
  .attr("marker-end", "url(#occurence)");
42
48
 
43
- var circle = container.append("g").selectAll("circle")
49
+ var node = container.append("g")
50
+ .attr("class", "nodes")
51
+ .selectAll("g")
44
52
  .data(constants)
45
- .enter().append("circle")
46
- .attr("r", 6)
47
- .on("dblclick", dblclick)
48
- .call(drag);
53
+ .enter().append("g")
54
+ .call(drag)
55
+ .on("dblclick", dblclick);
49
56
 
50
- var text = container.append("g").selectAll("text")
51
- .data(constants)
52
- .enter().append("text")
57
+ var circle = node
58
+ .append("circle")
59
+ .attr("r", 6);
60
+
61
+ var text = node
62
+ .append("text")
53
63
  .attr("x", 8)
54
64
  .attr("y", ".31em")
55
65
  .text(function(d) { return d.id; });
@@ -67,29 +77,21 @@ var ParseGraph = function(){
67
77
  .append("path")
68
78
  .attr("d", "M0,-5L10,0L0,5");
69
79
 
70
- simulation
71
- .nodes(constants)
72
- .on("tick", ticked);
73
-
74
- simulation.force("link")
75
- .links(occurences);
76
-
77
80
  function ticked() {
78
81
  link.attr("d", linkArc);
79
- circle.attr("transform", transform);
80
- text.attr("transform", transform);
82
+ node.attr("transform", transform);
81
83
  }
82
84
 
83
85
  function linkArc(d) {
84
86
  var dx = d.target.x - d.source.x,
85
87
  dy = d.target.y - d.source.y,
86
- dr = 0; // Math.sqrt(dx * dx + dy * dy);
88
+ dr = 0;
87
89
  return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
88
90
  }
89
91
 
90
92
  function dragstarted(d) {
91
93
  if (!d3.event.active) simulation.alphaTarget(0.3).restart();
92
- d3.select(this).classed("fixed", true );
94
+ d3.select(this).classed("fixed", true);
93
95
  d.fx = d.x;
94
96
  d.fy = d.y;
95
97
  }
@@ -104,8 +106,7 @@ var ParseGraph = function(){
104
106
  }
105
107
 
106
108
  function dblclick(d) {
107
- var node = d3.select(this);
108
- node.classed("fixed", false);
109
+ d3.select(this).classed("fixed", false);
109
110
  d.fx = null;
110
111
  d.fy = null;
111
112
  }
@@ -114,6 +115,32 @@ var ParseGraph = function(){
114
115
  return "translate(" + d.x + "," + d.y + ")";
115
116
  }
116
117
 
118
+
119
+ node.on('mouseover', function(d) {
120
+ var relatives = [];
121
+ link.style('opacity', function(l) {
122
+ if (d === l.source || d === l.target){
123
+ relatives.push(l.source);
124
+ relatives.push(l.target);
125
+ return 1;
126
+ }else{
127
+ return 0.1;
128
+ }
129
+ });
130
+ node.style('opacity', function(n) {
131
+ if( n == d || relatives.indexOf(n) > -1 ){
132
+ return 1;
133
+ }else{
134
+ return 0.1;
135
+ }
136
+ });
137
+ });
138
+
139
+ node.on('mouseout', function() {
140
+ link.style('opacity', 1);
141
+ node.style('opacity', 1);
142
+ });
143
+
117
144
  return true;
118
145
 
119
146
  };
data/readme.md CHANGED
@@ -14,7 +14,7 @@ the idea is that the project opens every `.rb` file and parse it with `parser` g
14
14
  * if you reference a class that is not defined in your project it won't be in the graph, we only display the graph of classes/modules you defined
15
15
  * the server analyze your code once upon the script starts if you changed your code you'll have to restart rubrowser
16
16
  * it statically analyze the code so meta programming is out of question in here
17
- * rails associations are meta programming to forget it :smile:
17
+ * rails associations are meta programming so forget it :smile:
18
18
 
19
19
  ## Usage
20
20
 
@@ -30,6 +30,7 @@ it'll analyze the project and open port 9000, so you can access the graph from `
30
30
  * interactive graph, you can pull any node to fix it to some position
31
31
  * to release node double click on it
32
32
  * zoom and pan with mouse or touch pad
33
+ * highlight node and all related nodes, it'll make it easier for you to see what depends and dependencies of certain class
33
34
 
34
35
 
35
36
  ## Tests?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubrowser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emad Elsaid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra