caravaggio 0.0.12

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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/images/david_and_goliath.jpg +0 -0
  5. data/app/assets/javascripts/caravaggio/application.js +14 -0
  6. data/app/assets/javascripts/caravaggio/caravaggio.js +265 -0
  7. data/app/assets/stylesheets/caravaggio/application.css +15 -0
  8. data/app/assets/stylesheets/caravaggio/caravaggio.css +90 -0
  9. data/app/controllers/caravaggio/application_controller.rb +5 -0
  10. data/app/controllers/caravaggio/c.txt +2 -0
  11. data/app/controllers/caravaggio/canvas_controller.rb +14 -0
  12. data/app/helpers/caravaggio/application_helper.rb +4 -0
  13. data/app/views/caravaggio/canvas/_association.html.erb +13 -0
  14. data/app/views/caravaggio/canvas/_figure.html.erb +24 -0
  15. data/app/views/caravaggio/canvas/index.html.erb +54 -0
  16. data/app/views/layouts/caravaggio/application.html.erb +14 -0
  17. data/app/views/untitled.txt +0 -0
  18. data/config/initializers/assets.rb +4 -0
  19. data/config/routes.rb +3 -0
  20. data/lib/caravaggio/canvas.rb +35 -0
  21. data/lib/caravaggio/engine.rb +5 -0
  22. data/lib/caravaggio/figure.rb +104 -0
  23. data/lib/caravaggio/version.rb +3 -0
  24. data/lib/caravaggio.rb +38 -0
  25. data/lib/tasks/caravaggio_tasks.rake +4 -0
  26. data/test/caravaggio_test.rb +7 -0
  27. data/test/dummy/README.rdoc +28 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/app/assets/javascripts/application.js +13 -0
  30. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  31. data/test/dummy/app/controllers/application_controller.rb +5 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/bin/bundle +3 -0
  35. data/test/dummy/bin/rails +4 -0
  36. data/test/dummy/bin/rake +4 -0
  37. data/test/dummy/bin/setup +29 -0
  38. data/test/dummy/config/application.rb +26 -0
  39. data/test/dummy/config/boot.rb +5 -0
  40. data/test/dummy/config/database.yml +25 -0
  41. data/test/dummy/config/environment.rb +5 -0
  42. data/test/dummy/config/environments/development.rb +41 -0
  43. data/test/dummy/config/environments/production.rb +79 -0
  44. data/test/dummy/config/environments/test.rb +42 -0
  45. data/test/dummy/config/initializers/assets.rb +11 -0
  46. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  47. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  48. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  49. data/test/dummy/config/initializers/inflections.rb +16 -0
  50. data/test/dummy/config/initializers/mime_types.rb +4 -0
  51. data/test/dummy/config/initializers/session_store.rb +3 -0
  52. data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +4 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/config.ru +4 -0
  58. data/test/dummy/public/404.html +67 -0
  59. data/test/dummy/public/422.html +67 -0
  60. data/test/dummy/public/500.html +66 -0
  61. data/test/dummy/public/favicon.ico +0 -0
  62. data/test/integration/navigation_test.rb +8 -0
  63. data/test/test_helper.rb +21 -0
  64. data/vendor/assets/javascripts/caravaggio_d3/API.md +1434 -0
  65. data/vendor/assets/javascripts/caravaggio_d3/CHANGES.md +1643 -0
  66. data/vendor/assets/javascripts/caravaggio_d3/LICENSE +27 -0
  67. data/vendor/assets/javascripts/caravaggio_d3/README.caravaggio.txt +1 -0
  68. data/vendor/assets/javascripts/caravaggio_d3/README.md +57 -0
  69. data/vendor/assets/javascripts/caravaggio_d3/caravaggio_d3.js +19651 -0
  70. data/vendor/assets/javascripts/caravaggio_d3/caravaggio_d3.min.js +2 -0
  71. metadata +151 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c0d90d2672df3cc81691479e1e52a1e7f1deb48
4
+ data.tar.gz: f1d87ce1735d6344c04b587cdc07694160e525c5
5
+ SHA512:
6
+ metadata.gz: ecabd7b1cb1e8b0ce714189c935f76a5fc39427977cdfeb1e6c8f971f4e5ec5995b8564361c9f454f007f711daae95b835afda6f67edd486b1b4e8630a6a6268
7
+ data.tar.gz: e15e0217418f1089ad832348c7a5c61874292df4153c65b65145c85d03a239bf8053a0186ef24bda103dd7e35df4342a92893f31f46d98761d0b20698fe59db7
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 jdzik
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Caravaggio'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_directory .
14
+ //= require caravaggio_d3/caravaggio_d3.min
@@ -0,0 +1,265 @@
1
+ function initializeCaravaggio() {
2
+ setAllModelChecked(false);
3
+ connectAssociations();
4
+ displayModels();
5
+ }
6
+
7
+
8
+ function displayModels() {
9
+ // clear out the playing field
10
+ clearModelLocations();
11
+ d3.select("svg").remove();
12
+ var svg = d3.select('#canvas').append("svg").attr("width", 1000).attr("height", 1000)
13
+
14
+ var defs = svg.append('svg:defs');
15
+
16
+ createMarker(defs, "belongs_to", "red");
17
+ createMarker(defs, "has_one", "blue");
18
+ createMarker(defs, "has_many", "green");
19
+ createMarker(defs, "has_and_belongs_to_many", "orange");
20
+
21
+ // apply forces
22
+ var linkForce = d3.forceLink();
23
+ var selectedModels = displayedModels();
24
+ var targetModels = expandModels(selectedModels);
25
+ var associationLinks = displayedAssociations(selectedModels, targetModels);
26
+ var collisionRadius = 200 / associationLinks.length;
27
+ if(collisionRadius < 8)
28
+ collisionRadius = 8;
29
+
30
+ var simulation = d3.forceSimulation()
31
+ .force("charge", d3.forceManyBody().strength(-40))
32
+ .force("center", d3.forceCenter().x(500).y(500))
33
+ .force('collision', d3.forceCollide().radius(collisionRadius))
34
+ .force("centerSelected", isolate(d3.forceCenter().x(500).y(500), function(d) { return d.checked }))
35
+ .force("link", linkForce)
36
+ .nodes(targetModels)
37
+ .on("tick", updateNetwork);
38
+
39
+ // add lines for all associations
40
+ svg.selectAll("line.association")
41
+ .data(associationLinks, d => `${d.source}-${d.target}`)
42
+ .enter()
43
+ .append("line")
44
+ .attr("class", d => "association " + d.association_type)
45
+ .attr("marker-end", d => "url(#" + d.association_type + "-arrowhead)")
46
+ .attr("onclick", d => "exhibitAssociation(" + d.index + ")");
47
+
48
+ // add labelled circles for all models
49
+ var modelDisplay = svg
50
+ .selectAll("g.model")
51
+ .data(targetModels, d => d.id)
52
+ .enter()
53
+ .append("g")
54
+ .attr("class", "model");
55
+ modelDisplay.append("circle")
56
+ .attr("r", d => d.checked ? 8 : 5)
57
+ .attr("onclick", d => "clickCircle('" + d.id + "')")
58
+ .style("fill", d => d.checked ? "red" : "blue");
59
+ modelDisplay.append("text")
60
+ .style("text-anchor", "middle")
61
+ .attr("y", 15)
62
+ .text(d => d["short_name"])
63
+ }
64
+
65
+ function createMarker(defs, name, color) {
66
+ return defs.append("marker")
67
+ .attr('id', name + '-arrowhead')
68
+ .attr('markerHeight', 15)
69
+ .attr('markerWidth', 15)
70
+ .attr('orient', 'auto-start-reverse')
71
+ .attr('refX', 15)
72
+ .attr('refY',8)
73
+ .attr('viewBox', '0 0 15 15')
74
+ .append('svg:path')
75
+ .attr('d', 'M 0 0 L 15 8 L 0 15 z')
76
+ .attr('class', function(d,i) { i.association_type})
77
+ .attr("fill", color);
78
+ }
79
+
80
+ function isolate(force, filter) {
81
+ var initialize = force.initialize;
82
+ force.initialize = function() { initialize.call(force, models.filter(filter)); };
83
+ return force;
84
+ }
85
+
86
+ function clickCircle(modelId) {
87
+ model = findModel(modelId);
88
+ model.checked = !model.checked;
89
+ d3.select("input#" + model.friendly_name).property('checked', model.checked);
90
+ if(model.checked) {
91
+ exhibitFigure(model);
92
+ }
93
+ displayModels();
94
+ }
95
+
96
+
97
+ function updateNetwork() {
98
+ d3.selectAll("line.association")
99
+ .attr("x1", d => d.sourceModel.x)
100
+ .attr("x2", d => d.targetModel.x)
101
+ .attr("y1", d => d.sourceModel.y)
102
+ .attr("y2", d => d.targetModel.y)
103
+ d3.selectAll("g.model")
104
+ .attr("transform", d => `translate(${d.x},${d.y})`);
105
+ }
106
+
107
+ function connectAssociations() {
108
+ associations.forEach(association => {
109
+ association.sourceModel = findModel(association["source"]);
110
+ association.targetModel = findModel(association["target"]);
111
+ });
112
+
113
+ associations = associations.filter(association => !((typeof(association.sourceModel) === 'undefined') || (typeof(association.targetModel) === 'undefined')))
114
+ }
115
+
116
+ function displayedAssociations(models, associatedModels) {
117
+ var modelIds = models.map(model => model.id);
118
+ var associatedModelIds = associatedModels.map(model => model.id);
119
+
120
+ selectedAssociations = [];
121
+
122
+ if(displayLinksFrom()) {
123
+ selectedAssociations = selectedAssociations.concat(linkedAssociations(modelIds, associatedModelIds));
124
+ }
125
+ if(displayLinksTo()) {
126
+ selectedAssociations = selectedAssociations.concat(linkedAssociations(associatedModelIds, modelIds));
127
+ }
128
+ return selectedAssociations;
129
+ }
130
+
131
+ function linkedAssociations(fromIds, toIds) {
132
+ var results = associations.filter(association => associationMatches(association, fromIds, toIds))
133
+
134
+ results = results.sort((a1, a2) => {
135
+ if(a1.association_type > a2.association_type) {
136
+ return -1;
137
+ } else if (a2.association_type > a1.association_type) {
138
+ return 1;
139
+ } else {
140
+ return 0;
141
+ }
142
+ });
143
+
144
+ return results;
145
+ }
146
+
147
+ function debugResults(label, results) {
148
+ console.log("RESULTS: " + label);
149
+ for(var i = 0; i < results.length; ++i) {
150
+ console.log(" " + results[i].association_type + " " + results[i].source + " -> " + results[i].target);
151
+ }
152
+ }
153
+
154
+ function associationMatches(association, fromIds, toIds) {
155
+ return (!fromIds || fromIds.includes(association.source)) && (!toIds || toIds.includes(association.target));
156
+ }
157
+
158
+ // For the list of models to display, find all models plus models they have associations to
159
+ function displayedModels() {
160
+ return models.filter(model => model.checked);
161
+ }
162
+
163
+ function exhibitFigure(model) {
164
+ hideExhibits();
165
+ d3.select("#figure-" + model.friendly_name).classed("hidden", false);
166
+ document.getElementById("exhibit").scrollTop = 0;
167
+ }
168
+
169
+ function exhibitAssociation(associationIndex) {
170
+ hideExhibits();
171
+ d3.select("#association-" + associationIndex).classed("hidden", false);
172
+ document.getElementById("exhibit").scrollTop = 0;
173
+ }
174
+
175
+ function hideExhibits() {
176
+ d3.selectAll("div.detailed-content").classed("hidden", true);
177
+ }
178
+
179
+ function expandModels(coreModels) {
180
+ expandedModels = [...coreModels];
181
+
182
+ if(!displayCheckedOnly()) {
183
+ var coreModelIds = coreModels.map(model => model.id)
184
+ var addedSet = new Set();
185
+
186
+ if(displayLinksFrom()) {
187
+ var associations = linkedAssociations(coreModelIds, null);
188
+ for(var i = 0; i < associations.length; ++i) {
189
+ addedSet.add(associations[i].target);
190
+ }
191
+ }
192
+
193
+ if(displayLinksTo()) {
194
+ var associations = linkedAssociations(null, coreModelIds);
195
+ for(var i = 0; i < associations.length; ++i) {
196
+ addedSet.add(associations[i].source);
197
+ }
198
+ }
199
+
200
+ addedSet.forEach(addition => {
201
+ if(!coreModelIds.includes(addition)) {
202
+ var newModel = findModel(addition);
203
+ if(typeof(newModel) !== "undefined")
204
+ expandedModels.push(findModel(addition));
205
+ }
206
+ });
207
+ }
208
+
209
+ return expandedModels;
210
+ }
211
+
212
+ function displayLinksTo() {
213
+ return document.getElementById("links_to").checked;
214
+ }
215
+
216
+ function displayLinksFrom() {
217
+ return document.getElementById("links_from").checked;
218
+ }
219
+
220
+ function displayCheckedOnly() {
221
+ return document.getElementById("only_checked").checked;
222
+ }
223
+
224
+ function setAllModels(cb) {
225
+ checked = cb.checked;
226
+ checkboxes = document.getElementsByClassName("model-checkbox");
227
+ for(var i = 0; i < checkboxes.length; ++i) {
228
+ checkboxes[i].checked = checked;
229
+ }
230
+ setAllModelChecked(checked);
231
+
232
+ displayModels();
233
+ }
234
+
235
+ function setModel(cb) {
236
+ if(!(typeof(model = findModel(cb.dataset.className)) === 'undefined')) {
237
+ model.checked = cb.checked;
238
+ if(model.checked) {
239
+ exhibitFigure(model);
240
+ }
241
+ }
242
+
243
+ displayModels();
244
+ }
245
+
246
+ function findModel(id) {
247
+ return models.find(model => model["id"] === id);
248
+ }
249
+
250
+ function setAllModelChecked(checked) {
251
+ for(i = 0; i < models.length; ++i) {
252
+ models[i].checked = checked;
253
+ }
254
+ }
255
+
256
+ // move all model to a random point near the center.
257
+ // It can't be in the center, because putting them all exactly in the center has
258
+ // unfortunate side-effects if there are too many.
259
+ function clearModelLocations() {
260
+ for(i = 0; i < models.length; ++i) {
261
+ models[i].x = 400 + Math.random() * 200;
262
+ models[i].y = 500 + Math.random() * 200;
263
+ }
264
+ }
265
+
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,90 @@
1
+ html {
2
+ height: 100%;
3
+ }
4
+ body {
5
+ height: 100%;
6
+ margin: 0;
7
+ background-repeat: no-repeat;
8
+ background-attachment: fixed;
9
+ background-image: linear-gradient(#93a9fc, #ccc);
10
+ }
11
+
12
+ .color-key {
13
+ background: #fff;
14
+ border: 3px solid #414652;
15
+ }
16
+ svg {
17
+ background: #fff;
18
+ }
19
+
20
+ h1 {
21
+ text-align: center;
22
+ padding: 10px 0px;
23
+ }
24
+
25
+ h2, h3 {
26
+ text-align: center;
27
+ }
28
+
29
+ div.sidebar {
30
+ float: left;
31
+ padding: 0px 3px;
32
+ height: 85vh;
33
+ min-height: 85vh;
34
+ overflow-y: scroll;
35
+ }
36
+
37
+ div.left-sidebar {
38
+ width: 15%;
39
+ }
40
+
41
+ div.right-sidebar {
42
+ width: 18%;
43
+ }
44
+
45
+ ul {
46
+ list-style-type: none;
47
+ padding-left: 5px;
48
+ }
49
+
50
+ li {
51
+ margin-left: 2em;
52
+ text-indent: -2em;
53
+ }
54
+
55
+ div#canvas {
56
+ border: 5px solid #414652;
57
+ max-width: 65%;
58
+ float: left;
59
+ height: 85vh;
60
+ min-height: 85vh;
61
+ overflow: scroll;
62
+ }
63
+
64
+ .belongs_to {
65
+ stroke: red;
66
+ color: red;
67
+ fill: red;
68
+ }
69
+
70
+ .has_many {
71
+ stroke: green;
72
+ color: green;
73
+ fill: green;
74
+ }
75
+
76
+ .has_one {
77
+ stroke: blue;
78
+ color: blue;
79
+ fill: blue;
80
+ }
81
+
82
+ .has_and_belongs_to_many {
83
+ stroke: orange;
84
+ color: orange;
85
+ fill: orange;
86
+ }
87
+
88
+ .hidden {
89
+ display: none;
90
+ }