rails-erd-d3 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b0a5f9fb07acc079927bd991e09878cee95cef6
4
- data.tar.gz: 361a63bbfbf57bc3143f769b44c0eb8d8e34b339
3
+ metadata.gz: 609e081fe5033be3fe4e163f6f79b31ccaad2263
4
+ data.tar.gz: 5ea5c46a0e0fc60be4d19844df712d9ccd1cff32
5
5
  SHA512:
6
- metadata.gz: f22eb430be8d354d16bfdba06c0e36885f720a77b0591d5d76dda8dcb40aeef7d785e31caf53cf394b54c92f394088bcaf68bb8c8a48fbda73f048c6960130e1
7
- data.tar.gz: b69aca96376c4e3c207a4fa72f279565564c36fda64b22ee25ce95818c51d1413e86284d6890557cfd59a6e51a30645862049e58b489203479fdeab24dd85852
6
+ metadata.gz: 7734e3063d9fce108d9c84e8ef6ca71ddacfd6295c489061d398adbde5da4e022b4670d86b54cd3847db6bcaf2786e2f366646034694902845a87eb9f8316dea
7
+ data.tar.gz: a026def9fde2e298f9d275874a0a9b1aa603fee8f15c34a72a658570e6df39077d29c794397bd881743f56927fa61fb9852a14bdd0b1006cda9cd5d875c4d445
data/README.md CHANGED
@@ -21,12 +21,11 @@ And then execute for creating file erd.html:
21
21
 
22
22
  ## Todo
23
23
 
24
- - Add message after creating
25
24
  - Sort nodes by label
26
25
  - Check all associations
27
- - belongs_to
28
- - has_one
29
- - has_many
26
+ - [X] belongs_to
27
+ - [X] has_one
28
+ - [x] has_many
30
29
  - has_many :through
31
30
  - has_one :through
32
31
  - has_and_belongs_to_many
data/lib/rails_erd_d3.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require "erb"
2
3
 
3
4
  class RailsErdD3
4
5
  def self.get_rails_version
@@ -6,8 +7,6 @@ class RailsErdD3
6
7
  end
7
8
 
8
9
  def self.get_all_models
9
- version = get_rails_version
10
-
11
10
  case get_rails_version
12
11
  when 4
13
12
  klass = ActiveRecord::Base
@@ -67,37 +66,21 @@ class RailsErdD3
67
66
  private
68
67
 
69
68
  def self.get_head
70
- "<head>"\
71
- "<title>Rails-ERD-D3</title>"\
72
- "<meta charset='utf-8'>"\
73
- "<script src='https://code.jquery.com/jquery-3.1.1.min.js' integrity='sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=' crossorigin='anonymous'></script>"\
74
- "<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js'></script>"\
75
- "<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa' crossorigin='anonymous'></script>"\
76
- "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u' crossorigin='anonymous'>"\
77
- "</head>"
69
+ File.read(
70
+ File.expand_path(
71
+ "templates/head.html",
72
+ File.dirname(__FILE__)
73
+ )
74
+ )
78
75
  end
79
76
 
80
77
  def self.get_nav
81
- "<nav class='navbar navbar-default' style='background-color: #337ab7;'>"\
82
- "<div class='container'>"\
83
- "<div class='navbar-header'>"\
84
- "<div class='navbar-brand'>"\
85
- "<a href='https://github.com/RomanKrasavtsev/rails-erd-d3' target='_blank' style='color: white;'>"\
86
- "Rails-ERD-D3"\
87
- "</a>"\
88
- "</div>"\
89
- "</div>"\
90
- "<div class='collapse navbar-collapse'>"\
91
- "<ul class='nav navbar-nav navbar-right'>"\
92
- "<li>"\
93
- "<a href='https://github.com/romankrasavtsev' target='_blank' style='color: white;'>"\
94
- "&copy; 2016 Roman Krasavtsev"\
95
- "</a>"\
96
- "</li>"\
97
- "</ul>"\
98
- "</div>"\
99
- "</div>"\
100
- "</nav>"
78
+ File.read(
79
+ File.expand_path(
80
+ "templates/nav.html",
81
+ File.dirname(__FILE__)
82
+ )
83
+ )
101
84
  end
102
85
 
103
86
  def self.get_d3
@@ -209,7 +192,7 @@ class RailsErdD3
209
192
  "<h4 class='modal-title'>#{name}</h4>"\
210
193
  "</div>"\
211
194
  "<div class='modal-body'>"\
212
- "<div class='panel panel-default'>"\
195
+ "<div class='panel panel-primary'>"\
213
196
  "<div class='panel-heading'>Associations</div>"\
214
197
  "<table class='table table-hover'>"\
215
198
  "<thead>"\
@@ -0,0 +1,93 @@
1
+ <script>
2
+ var data = <%= get_data %>;
3
+
4
+ var width = window.innerWidth
5
+ || document.documentElement.clientWidth
6
+ || document.body.clientWidth;
7
+ var height = window.innerHeight
8
+ || document.documentElement.clientHeight
9
+ || document.body.clientHeight;
10
+
11
+ var colorScale = d3.scaleOrdinal(d3.schemeCategory20);
12
+
13
+ var svg = d3.select('#erd').append('svg')
14
+ .attr('height', height)
15
+ .attr('width', width)
16
+ .style('background', 'white');
17
+
18
+ var simulation = d3.forceSimulation()
19
+ .force('link', d3.forceLink().id(function(d) { return d.index }))
20
+ .force('collide',d3.forceCollide( function(d){return d.r + 20 }).iterations(30) )
21
+ .force('charge', d3.forceManyBody())
22
+ .force('center', d3.forceCenter(width / 2, height / 2))
23
+ .force('y', d3.forceY(0))
24
+ .force('x', d3.forceX(0));
25
+
26
+ var link = svg.append('g')
27
+ .classed('links', true)
28
+ .selectAll('line')
29
+ .data(data.links)
30
+ .enter()
31
+ .append('line')
32
+ .attr('stroke', 'black');
33
+
34
+ var node = svg.selectAll('.node')
35
+ .data(data.nodes)
36
+ .enter()
37
+ .append('g')
38
+ .classed('node', true)
39
+ .style('cursor', 'pointer')
40
+ .attr('data-toggle', 'modal')
41
+ .attr('data-target', function(d, i){ return '#' + data.nodes[i].label })
42
+ .call(d3.drag()
43
+ .on('start', dragstarted)
44
+ .on('drag', dragged)
45
+ .on('end', dragended));
46
+
47
+ node.append('circle')
48
+ .classed('circle', true)
49
+ .attr('r', function(d){ return d.r })
50
+ .attr('fill', function(d, i){ return colorScale(i) });
51
+
52
+ node.append('text')
53
+ .classed('text', true)
54
+ .text(function(d) {
55
+ return d.label;
56
+ });
57
+
58
+ var ticked = function() {
59
+ link
60
+ .attr('x1', function(d) { return d.source.x; })
61
+ .attr('y1', function(d) { return d.source.y; })
62
+ .attr('x2', function(d) { return d.target.x; })
63
+ .attr('y2', function(d) { return d.target.y; });
64
+
65
+ node
66
+ .attr('transform', function(d) {
67
+ return 'translate(' + [d.x, d.y] + ')';
68
+ });
69
+ }
70
+
71
+ simulation.nodes(data.nodes)
72
+ .on('tick', ticked);
73
+
74
+ simulation.force('link')
75
+ .links(data.links);
76
+
77
+ function dragstarted(d) {
78
+ if (!d3.event.active) simulation.alphaTarget(0.3).restart();
79
+ d.fx = d.x;
80
+ d.fy = d.y;
81
+ }
82
+
83
+ function dragged(d) {
84
+ d.fx = d3.event.x;
85
+ d.fy = d3.event.y;
86
+ }
87
+
88
+ function dragended(d) {
89
+ if (!d3.event.active) simulation.alphaTarget(0);
90
+ d.fx = null;
91
+ d.fy = null;
92
+ }
93
+ </script>
@@ -0,0 +1,8 @@
1
+ <head>
2
+ <title>Rails-ERD-D3</title>
3
+ <meta charset="utf-8">
4
+ <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js"></script>
6
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
7
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
8
+ </head>
@@ -0,0 +1,40 @@
1
+ <div class="modal fade" id="<%= name %>" tabindex="-1" role="dialog">
2
+ <div class="modal-dialog" role="document">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
6
+ <h4 class="modal-title">
7
+ <%= name %>
8
+ </h4>
9
+ </div>
10
+ <div class="modal-body">
11
+ <div class="panel panel-primary">
12
+ <div class="panel-heading">Associations</div>
13
+ <table class="table table-hover">
14
+ <thead>
15
+ <tr>
16
+ <th>#</th>
17
+ <th>name</th>
18
+ <th>macro</th>
19
+ <th>foreign_key</th>
20
+ </tr>
21
+ </thead>
22
+ <tbody>
23
+ <% model.reflections.each_with_index do |r, index| %>
24
+ <tr>
25
+ <th><%= index + 1 %></th>
26
+ <td><%= r[0].capitalize %></td>
27
+ <td><%= model.reflections[r[0]].macro %></td>
28
+ <td><%= model.reflections[r[0]].foreign_key %></td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+ </div>
34
+ </div>
35
+ <div class="modal-footer">
36
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ </div>
@@ -0,0 +1,20 @@
1
+ <nav class="navbar navbar-default" style="background-color: #337ab7;">
2
+ <div class="container">
3
+ <div class="navbar-header">
4
+ <div class="navbar-brand">
5
+ <a href="https://github.com/RomanKrasavtsev/rails-erd-d3" target="_blank" style="color: #ffffff;">
6
+ Rails-ERD-D3
7
+ </a>
8
+ </div>
9
+ </div>
10
+ <div class="collapse navbar-collapse">
11
+ <ul class="nav navbar-nav navbar-right">
12
+ <li>
13
+ <a href="https://github.com/romankrasavtsev" target="_blank" style="color: #ffffff;">
14
+ &copy; 2016 Roman Krasavtsev
15
+ </a>
16
+ </li>
17
+ </ul>
18
+ </div>
19
+ </div>
20
+ </nav>
data/rails-erd-d3.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "rails-erd-d3"
7
7
  spec.authors = ["Roman Krasavtsev"]
8
8
  spec.email = ["mr.krasavtsev@gmail.com"]
9
- spec.version = "0.0.16"
9
+ spec.version = "0.0.17"
10
10
  spec.summary = "Entity–relationship diagram with D3.js for Rails application"
11
11
  spec.description = "This gem creates entity–relationship diagram with D3.js for your Rails application"
12
12
  spec.homepage = "https://github.com/RomanKrasavtsev/rails-erd-d3"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-erd-d3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Krasavtsev
@@ -71,6 +71,10 @@ files:
71
71
  - bin/erd
72
72
  - lib/rails-erd-d3.rb
73
73
  - lib/rails_erd_d3.rb
74
+ - lib/templates/d3.html.erb
75
+ - lib/templates/head.html
76
+ - lib/templates/modals.html.erb
77
+ - lib/templates/nav.html
74
78
  - rails-erd-d3.gemspec
75
79
  homepage: https://github.com/RomanKrasavtsev/rails-erd-d3
76
80
  licenses: