social_cheesecake 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +111 -0
  3. data/app/assets/javascripts/kinetic.js +448 -407
  4. data/app/assets/javascripts/social_cheesecake.js +1 -2
  5. data/app/assets/javascripts/socialcheesecake/_header.js +28 -0
  6. data/app/assets/javascripts/socialcheesecake/actor.js +104 -41
  7. data/app/assets/javascripts/socialcheesecake/cheesecake.js +26 -31
  8. data/app/assets/javascripts/socialcheesecake/grid.js +53 -12
  9. data/app/assets/javascripts/socialcheesecake/sector.js +108 -93
  10. data/app/assets/javascripts/socialcheesecake/text.js +39 -36
  11. data/lib/generators/social_cheesecake/install_generator.rb +10 -0
  12. data/lib/social_cheesecake/version.rb +1 -1
  13. data/social_cheesecake.gemspec +1 -0
  14. data/test/dummy/.gitignore +15 -0
  15. data/test/dummy/Gemfile +34 -0
  16. data/test/dummy/README +261 -0
  17. data/test/dummy/Rakefile +7 -0
  18. data/test/dummy/app/assets/images/beatriz.png +0 -0
  19. data/test/dummy/app/assets/images/rails.png +0 -0
  20. data/test/dummy/app/assets/images/youngAlberto.png +0 -0
  21. data/test/dummy/app/assets/javascripts/application.js +10 -0
  22. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  23. data/test/dummy/app/controllers/application_controller.rb +3 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/mailers/.gitkeep +0 -0
  26. data/test/dummy/app/models/.gitkeep +0 -0
  27. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/test/dummy/config/application.rb +48 -0
  29. data/test/dummy/config/boot.rb +6 -0
  30. data/test/dummy/config/database.yml +25 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +30 -0
  33. data/test/dummy/config/environments/production.rb +60 -0
  34. data/test/dummy/config/environments/test.rb +39 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +10 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +5 -0
  42. data/test/dummy/config/routes.rb +58 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/db/seeds.rb +7 -0
  45. data/test/dummy/doc/README_FOR_APP +2 -0
  46. data/test/dummy/lib/assets/.gitkeep +0 -0
  47. data/test/dummy/lib/tasks/.gitkeep +0 -0
  48. data/test/dummy/log/.gitkeep +0 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +26 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/public/index.html +133 -0
  54. data/test/dummy/public/robots.txt +5 -0
  55. data/test/dummy/script/rails +6 -0
  56. data/test/dummy/test/fixtures/.gitkeep +0 -0
  57. data/test/dummy/test/functional/.gitkeep +0 -0
  58. data/test/dummy/test/integration/.gitkeep +0 -0
  59. data/test/dummy/test/performance/browsing_test.rb +12 -0
  60. data/test/dummy/test/test_helper.rb +13 -0
  61. data/test/dummy/test/unit/.gitkeep +0 -0
  62. data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  63. data/test/dummy/vendor/plugins/.gitkeep +0 -0
  64. metadata +114 -29
  65. data/app/assets/javascripts/socialCheesecake.js +0 -161
@@ -1,10 +1,5 @@
1
- socialCheesecake.defineModule(
2
- 'SocialCheesecake#Sector'
3
- )
4
- .dependsOn(
5
- 'SocialCheesecake#Text'
6
- )
7
- .withCode(function() {
1
+ var socialCheesecake = socialCheesecake || {};
2
+ (function() {
8
3
  socialCheesecake.Sector = function(settings) {
9
4
  var defaultSettings = {
10
5
  center : { x : 0, y : 0 },
@@ -16,11 +11,12 @@ socialCheesecake.defineModule(
16
11
  color : "#eeffee",
17
12
  mouseover : { color : "#aaffaa" },
18
13
  mouseout : { color : "#eeffee" },
19
- mouseup : { color : "#77ff77" },
20
- mousedown : { color : "#aaffaa" }
14
+ mouseup : { color : "#77ff77" },
15
+ mousedown : { color : "#aaffaa" },
16
+ auxiliar : false
21
17
  }
22
18
  for(var property in defaultSettings) {
23
- if(!( property in settings)) {
19
+ if(!(property in settings)) {
24
20
  settings[property] = defaultSettings[property];
25
21
  }
26
22
  }
@@ -46,7 +42,8 @@ socialCheesecake.defineModule(
46
42
  this.actors = [];
47
43
  if(settings.parent != null) this.parent = settings.parent;
48
44
  if(settings.simulate != null) this.simulate = settings.simulate;
49
-
45
+ this.auxiliar = settings.auxiliar;
46
+
50
47
  if(settings.subsectors != null) {
51
48
  var rInSubsector = this.rIn;
52
49
  var separation = (this.rOut - this.rIn) / settings.subsectors.length;
@@ -61,7 +58,32 @@ socialCheesecake.defineModule(
61
58
  delta : this.delta,
62
59
  rIn : rInSubsector,
63
60
  rOut : rOutSubsector,
64
- actors : settings.subsectors[i].actors
61
+ actors : settings.subsectors[i].actors,
62
+ mouseover : { color : "#aaffaa",
63
+ callback : function(subsector) {
64
+ /* FIX FOR EXECUTING MOUSEOUT BEFORE MOUSEOVER */
65
+ for(var i in subsector.parent.subsectors){
66
+ subsector.parent.subsectors[i].getRegion().addEventListener("mouseout", undefined);
67
+ if(subsector.parent.subsectors[i]!= subsector){
68
+ subsector.parent.subsectors[i].changeColor(subsector.parent.subsectors[i].mouseout.color);
69
+ }
70
+ }
71
+ subsector.getRegion().addEventListener("mouseout", function() {
72
+ subsector.eventHandler('mouseout');
73
+ });
74
+
75
+ document.body.style.cursor = "pointer";
76
+ subsector.parent.parent.grid.hideAll();
77
+ subsector.parent.parent.grid.fadeIn(subsector.actors, 300, true);
78
+ }
79
+ },
80
+ mouseout :{
81
+ color : "#eeffee",
82
+ callback : function(subsector) {
83
+ document.body.style.cursor = "default";
84
+ subsector.parent.parent.grid.fadeIn(subsector.parent.actors, 300, true);
85
+ }
86
+ }
65
87
  });
66
88
  rInSubsector = rOutSubsector;
67
89
  this.subsectors.push(layer);
@@ -81,7 +103,8 @@ socialCheesecake.defineModule(
81
103
  mousedown : this.mousedown,
82
104
  mouseup : this.mouseup,
83
105
  simulate : this.simulate,
84
- subsectors : this.subsectors
106
+ subsectors : this.subsectors,
107
+ auxiliar : this.auxiliar
85
108
  };
86
109
  this._region = null;
87
110
  }
@@ -95,6 +118,7 @@ socialCheesecake.defineModule(
95
118
  var rOut = this.rOut;
96
119
  var color = this.color;
97
120
  var label = this.label;
121
+ var actors = this.actors;
98
122
  if(options != null) {
99
123
  if(options.x != null) x = options.x;
100
124
  if(options.y != null) y = options.y;
@@ -116,37 +140,18 @@ socialCheesecake.defineModule(
116
140
  context.fill();
117
141
  context.lineWidth = 4;
118
142
  context.stroke();
119
- socialCheesecake.text.writeCurvedText(label, context, x, y, (rOut + rIn) / 2, phi, delta);
143
+ socialCheesecake.text.writeCurvedText(label, context, x, y, 0.75*rOut, phi, delta);
144
+ if(!this.auxiliar)
145
+ socialCheesecake.text.writeCurvedText("(" + actors.length + ")", context, x, y, 0.6*rOut, phi, delta);
120
146
  }
121
147
 
122
- socialCheesecake.Sector.prototype.getRegion = function(regenerate) {
123
- if((this._region == null) || (regenerate == true)) {
148
+ socialCheesecake.Sector.prototype.getRegion = function() {
149
+ if(this._region == null) {
124
150
  var sector = this;
125
- if(sector._region != null) {
126
- /* TO-DO!!!
127
- if(sector.parent != null){
128
- var cheesecake=sector.parent;
129
- var regions= cheesecake.stage.regions;
130
- var regionIndex;
131
- for(var j in regions){
132
- if(regions[j]==sector._region){
133
- regionIndex= j;
134
- }
135
- }
136
- }
137
- var canvas=sector.getRegion().getCanvas();
138
- if((canvas!=null)&&(canvas.parentNode!=null)){
139
- canvas.parentNode.removeChild(canvas);
140
- }*/
141
- }
142
151
  sector._region = new Kinetic.Shape(function() {
143
152
  var context = this.getContext();
144
153
  sector._draw(context);
145
154
  });
146
- /*
147
- if(regionIndex!=null){
148
- regions[regionIndex]=this._region;
149
- } */
150
155
  sector._region.addEventListener('mouseover', function() {
151
156
  sector.eventHandler('mouseover');
152
157
  });
@@ -164,25 +169,30 @@ socialCheesecake.defineModule(
164
169
  }
165
170
 
166
171
  socialCheesecake.Sector.prototype.eventHandler = function(eventName) {
167
- var sector = this;
168
- if(sector[eventName] != null){
169
- if(sector[eventName].color != null) {
170
- var color = sector[eventName].color;
171
- sector.changeColor(color);
172
- }
173
- if(sector[eventName].callback != null) {
174
- sector[eventName].callback(sector);
175
- }
176
- }
172
+ var sector = this;
173
+ if(sector[eventName] != null){
174
+ if(sector[eventName].color != null) {
175
+ var color = sector[eventName].color;
176
+ sector.changeColor(color);
177
+ }
178
+ if(sector[eventName].callback != null) {
179
+ sector[eventName].callback(sector);
180
+ }
181
+ }
182
+ }
183
+
184
+ socialCheesecake.Sector.prototype.getCheesecake = function () {
185
+ var sector = this;
186
+ return sector.parent;
177
187
  }
178
188
 
179
189
  socialCheesecake.Sector.prototype.splitUp = function() {
180
- var cheesecake = this.parent;
190
+ var cheesecake = this.getCheesecake();
181
191
  var phi = this.phi;
182
192
  var delta = this.delta;
183
193
  var rOut = this.rOut;
184
194
  var rIn = this.rIn;
185
- var sector; (this.simulate != null) ? sector = cheesecake.sectors[this.simulate] : sector = this;
195
+ var sector = (this.simulate != null) ? cheesecake.sectors[this.simulate] : this;
186
196
  var subsectors = sector.subsectors;
187
197
 
188
198
  //Draw sector's subsectors over it
@@ -201,7 +211,7 @@ socialCheesecake.defineModule(
201
211
  }
202
212
 
203
213
  socialCheesecake.Sector.prototype.putTogether = function() {
204
- var cheesecake = this.parent;
214
+ var cheesecake = this.getCheesecake();
205
215
  var sector; (this.simulate != null) ? sector = cheesecake.sectors[this.simulate] : sector = this;
206
216
  var subsectors = sector.subsectors;
207
217
  //Clear subsectors from stage
@@ -212,18 +222,14 @@ socialCheesecake.defineModule(
212
222
 
213
223
  socialCheesecake.Sector.prototype.changeColor = function(color) {
214
224
  var sector = this;
215
- if (sector._region){
216
- var context = sector._region.getContext();
217
- sector.color = color;
218
- context.fillStyle = color;
219
- context.fill();
220
- context.lineWidth = 4;
221
- context.stroke();
222
- sector._region.getContext().restore();
223
- sector._region.getContext().save();
224
- socialCheesecake.text.writeCurvedText(sector.label, sector._region.getContext(),
225
- sector.x, sector.y, (sector.rOut + sector.rIn) / 2, sector.phi, sector.delta);
226
- }
225
+ if (sector.getRegion().layer){
226
+ var context = sector.getRegion().layer.getContext();
227
+ var stage = sector.getCheesecake().stage;
228
+ sector.color = color;
229
+ context.restore();
230
+ context.save();
231
+ stage.draw();
232
+ }
227
233
  }
228
234
 
229
235
  /**
@@ -240,10 +246,9 @@ socialCheesecake.defineModule(
240
246
  socialCheesecake.Sector.prototype.resize = function(options) {
241
247
  if(!options)
242
248
  throw "No arguments passed to the function";
243
- if(options.context == null)
244
- throw "context must be defined"
245
- var context = options.context;
246
249
  var sector = this;
250
+ var context = sector.getRegion().layer.getContext();
251
+ var stage = sector.getCheesecake().stage;
247
252
  var currentDelta = sector.delta;
248
253
  var currentPhi = sector.phi;
249
254
  var step = 0.05;
@@ -274,8 +279,9 @@ socialCheesecake.defineModule(
274
279
  sector.delta = currentDelta;
275
280
  sector.phi = currentPhi;
276
281
 
277
- sector.clear();
278
- sector._draw(context);
282
+ context.restore();
283
+ context.save();
284
+ stage.draw();
279
285
  if(currentDelta != goalDelta) {
280
286
  requestAnimFrame(function() {
281
287
  sector.resize(options);
@@ -287,28 +293,22 @@ socialCheesecake.defineModule(
287
293
 
288
294
  socialCheesecake.Sector.prototype.focus = function() {
289
295
  var sector = this;
290
- var context = sector._region.getContext();
296
+ var context = sector.getRegion().layer.getContext();
297
+ var stage = sector.getCheesecake().stage;
291
298
  sector.rOut *= 1.05;
292
- sector.clear();
293
- sector._draw(context);
299
+ context.restore();
300
+ context.save();
301
+ stage.draw();
294
302
  }
295
303
 
296
304
  socialCheesecake.Sector.prototype.unfocus = function() {
297
305
  var sector = this;
298
- var context = sector._region.getContext();
306
+ var context = sector.getRegion().layer.getContext();
307
+ var stage = sector.getCheesecake().stage;
299
308
  sector.rOut = sector.originalAttr.rOut;
300
- sector.clear();
301
- sector._draw(context);
302
- }
303
-
304
- socialCheesecake.Sector.prototype.clear = function() {
305
- var sector = this;
306
- var context = sector.getRegion().getContext();
307
- if(context != undefined) {
308
- context.restore();
309
- context.save();
310
- }
311
- sector.getRegion().clear();
309
+ context.restore();
310
+ context.save();
311
+ stage.draw();
312
312
  }
313
313
 
314
314
  socialCheesecake.Sector.prototype.rotateTo = function(options) {
@@ -318,10 +318,12 @@ socialCheesecake.defineModule(
318
318
  var delta = this.delta;
319
319
  var step = 0.05;
320
320
  var anchor = 0;
321
+ var stage = sector.getCheesecake().stage;
322
+ var context = sector.getRegion().layer.getContext();
321
323
  if(!options) throw "No arguments passed to the function";
322
324
  if(options.step) step = options.step;
323
- if(options.context == null) throw "context must be defined";
324
- var context = options.context;
325
+ /*if(options.context == null) throw "context must be defined";
326
+ var context = options.context;*/
325
327
  if(options.destination == null) throw "destination must be defined";
326
328
  if(options.anchor){
327
329
  if((options.anchor.toLowerCase() == "b") || (options.anchor == "beginning"))
@@ -359,11 +361,10 @@ socialCheesecake.defineModule(
359
361
  }
360
362
  sector.phi = currentPhi;
361
363
 
362
- // clear stage
363
- sector.clear();
364
-
365
- // draw stage
366
- this._draw(context);
364
+ // redraw
365
+ context.restore();
366
+ context.save();
367
+ stage.draw();
367
368
 
368
369
  // request new frame
369
370
  if(Math.abs(currentPhi - phiDestination) > 0.001) {
@@ -424,8 +425,12 @@ socialCheesecake.defineModule(
424
425
  this.phi = settings.phi;
425
426
  this.delta = settings.delta;
426
427
  this.actors = [];
428
+ if(settings.mousedown != null) this.mousedown = settings.mousedown;
429
+ if(settings.mouseup != null) this.mouseup = settings.mouseup;
430
+ if(settings.mouseover != null) this.mouseover = settings.mouseover;
431
+ if(settings.mouseout != null) this.mouseout = settings.mouseout;
427
432
 
428
- var grid = this.parent.parent.grid;
433
+ var grid = this.getCheesecake().grid;
429
434
  if (settings.actors){
430
435
  for( var actor in settings.actors){
431
436
  var actor_info = {
@@ -443,6 +448,16 @@ socialCheesecake.defineModule(
443
448
  rIn : this.rIn,
444
449
  rOut : this.rOut,
445
450
  phi : this.phi,
446
- delta : this.delta
451
+ delta : this.delta,
452
+
453
+ mouseover : this.mouseover,
454
+ mouseout : this.mouseout,
455
+ mouseup : this.mouseup,
456
+ mousedown : this.mousedown
447
457
  });
448
- });
458
+
459
+ socialCheesecake.Subsector.prototype.getCheesecake = function () {
460
+ var subsector = this;
461
+ return subsector.parent.parent;
462
+ }
463
+ })();
@@ -1,36 +1,39 @@
1
- socialCheesecake.defineModule(
2
- 'SocialCheesecake#Text'
3
- ).dependsOn(
4
-
5
- ).withCode(function() {
6
- socialCheesecake.text = {
7
- writeCurvedText : function(text, context, x, y, r, phi, delta) {
8
- context.font = "bold 14px sans-serif";
9
- context.fillStyle = '#000';
10
- context.textBaseline = "middle";
11
- var medium_alpha = Math.tan(context.measureText(text).width / (text.length * r));
12
- if(medium_alpha * text.length <= delta) {
13
- context.translate(x, y);
14
- var orientation = 0;
15
- if((phi + delta / 2 >= Math.PI ) && (phi + delta / 2 < Math.PI * 2)) {
16
- orientation = -1;
17
- context.rotate(-(delta - (medium_alpha * text.length)) / 2 - phi - Math.PI / 2);
18
- } else {
19
- orientation = 1;
20
- context.rotate((delta - (medium_alpha * text.length)) / 2 + Math.PI / 2 - delta - phi);
21
- }
22
- for(var i = 0; i < text.length; i++) {
23
- context.fillText(text[i], 0, -(orientation * r));
24
- var alpha = Math.tan(context.measureText(text[i]).width / r);
25
- context.rotate(orientation * alpha);
26
- }
27
- return true;
28
- } else {
29
- return false;
30
- }
31
- },
32
- writeCenterText : function(text, context, centerX, centerY) {
33
- context.fillText(text, centerX - context.measureText(text).width / 2, centerY);
34
- }
35
- }
36
- });
1
+ var socialCheesecake = socialCheesecake || {}; (function() {
2
+ socialCheesecake.text = {
3
+ writeCurvedText : function(text, context, x, y, r, phi, delta) {
4
+ context.font = "bold 14px sans-serif";
5
+ context.fillStyle = '#000';
6
+ context.textBaseline = "middle";
7
+ var medium_alpha = Math.tan(context.measureText(text).width / (text.length * r));
8
+ while(medium_alpha * (text.length + 4) > delta) {
9
+ words = text.split(" ");
10
+ if(words.length > 1){
11
+ words.splice(words.length - 1, 1);
12
+ text = words.join(" ") + "...";
13
+ }else{
14
+ text = words[0].substring(0, delta/medium_alpha - 7) + "...";
15
+ }
16
+ medium_alpha = Math.tan(context.measureText(text).width / (text.length * r));
17
+ }
18
+ context.translate(x, y);
19
+ var orientation = 0;
20
+ if((phi + delta / 2 >= Math.PI ) && (phi + delta / 2 < Math.PI * 2)) {
21
+ orientation = -1;
22
+ context.rotate(-(delta - (medium_alpha * text.length)) / 2 - phi - Math.PI / 2);
23
+ } else {
24
+ orientation = 1;
25
+ context.rotate((delta - (medium_alpha * text.length)) / 2 + Math.PI / 2 - delta - phi);
26
+ }
27
+ for(var i = 0; i < text.length; i++) {
28
+ context.fillText(text[i], 0, -(orientation * r));
29
+ var alpha = Math.tan(context.measureText(text[i]).width / r);
30
+ context.rotate(orientation * alpha);
31
+ }
32
+ context.restore();
33
+ context.save();
34
+ },
35
+ writeCenterText : function(text, context, centerX, centerY) {
36
+ context.fillText(text, centerX - context.measureText(text).width / 2, centerY);
37
+ }
38
+ }
39
+ })();
@@ -0,0 +1,10 @@
1
+ class SocialCheesecake::InstallGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ def require_javascripts
6
+ inject_into_file 'app/assets/javascripts/application.js',
7
+ "//= require social_cheesecake\n",
8
+ :before => '//= require_tree .'
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialCheesecake
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  # specify any dependencies here; for example:
23
23
  # s.add_development_dependency "rspec"
24
24
  # s.add_runtime_dependency "rest-client"
25
+ s.add_runtime_dependency('railties', '>= 3.1.3')
25
26
  end
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
@@ -0,0 +1,34 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.1.3'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3'
9
+
10
+ gem 'json'
11
+
12
+ # Gems used only for assets and not required
13
+ # in production environments by default.
14
+ group :assets do
15
+ gem 'sass-rails', '~> 3.1.5'
16
+ gem 'coffee-rails', '~> 3.1.1'
17
+ gem 'uglifier', '>= 1.0.3'
18
+ end
19
+
20
+ gem 'jquery-rails'
21
+ gem 'social_cheesecake', :path => '../../'
22
+
23
+ # To use ActiveModel has_secure_password
24
+ # gem 'bcrypt-ruby', '~> 3.0.0'
25
+
26
+ # Use unicorn as the web server
27
+ # gem 'unicorn'
28
+
29
+ # Deploy with Capistrano
30
+ # gem 'capistrano'
31
+
32
+ # To use debugger
33
+ # gem 'ruby-debug'
34
+