social_cheesecake 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,27 +5,30 @@ var socialCheesecake = socialCheesecake || {};
5
5
  center : { x : 0, y : 0 },
6
6
  rIn : 0,
7
7
  rOut : 300,
8
- delta : Math.PI / 2,
8
+ delta : Math.PI /2 ,
9
9
  phi : 0,
10
10
  label : "",
11
- color : "#eeffee",
12
- mouseover : { color : "#aaffaa" },
13
- mouseout : { color : "#eeffee" },
14
- mouseup : { color : "#77ff77" },
15
- mousedown : { color : "#aaffaa" },
11
+ color : socialCheesecake.Cheesecake.getSectorFillColor(),
12
+ textAndStrokeColor : socialCheesecake.Cheesecake.getSectorTextAndStrokeColor(),
13
+ mouseover : { color : socialCheesecake.Cheesecake.getSectorHoverColor() },
14
+ mouseout : { color : socialCheesecake.Cheesecake.getSectorFillColor() },
15
+ mouseup : { color : socialCheesecake.Cheesecake.getSectorFillColor() },
16
+ mousedown : { color : socialCheesecake.Cheesecake.getSectorFocusColor() },
16
17
  auxiliar : false
17
18
  }
18
19
  for(var property in defaultSettings) {
19
- if(!(property in settings)) {
20
+ if(!(property in settings) || (settings[property]===undefined)) {
20
21
  settings[property] = defaultSettings[property];
21
22
  }
22
23
  }
23
- if(settings.phi < 0 || settings.phi > 2 * Math.PI) {
24
- throw "Phi must be greater or equal to 0 and less than 2*pi";
24
+ settings.phi %= 2*Math.PI;
25
+ while(settings.phi <0){
26
+ settings.phi += 2*Math.PI;
25
27
  }
26
28
  if(settings.delta <= 0 || settings.delta > 2 * Math.PI) {
27
29
  throw "Delta must be greater than 0 and less than 2*pi";
28
30
  }
31
+ if(settings.id) this.id = settings.id;
29
32
  this.x = settings.center.x;
30
33
  this.y = settings.center.y;
31
34
  this.rOut = settings.rOut;
@@ -34,11 +37,13 @@ var socialCheesecake = socialCheesecake || {};
34
37
  this.delta = settings.delta;
35
38
  this.label = settings.label;
36
39
  this.color = settings.color;
40
+ this.textAndStrokeColor = settings.textAndStrokeColor;
37
41
  this.mouseover = settings.mouseover;
38
42
  this.mouseup = settings.mouseup;
39
43
  this.mouseout = settings.mouseout;
40
44
  this.mousedown = settings.mousedown;
41
45
  this.subsectors = [];
46
+ this.extraSubsectors = [];
42
47
  this.actors = [];
43
48
  if(settings.parent != null) this.parent = settings.parent;
44
49
  if(settings.simulate != null) this.simulate = settings.simulate;
@@ -49,7 +54,8 @@ var socialCheesecake = socialCheesecake || {};
49
54
  var separation = (this.rOut - this.rIn) / settings.subsectors.length;
50
55
  for(var i in settings.subsectors) {
51
56
  var rOutSubsector = rInSubsector + separation;
52
- var layer = new socialCheesecake.Subsector({
57
+ var subsector = new socialCheesecake.Subsector({
58
+ id : settings.subsectors[i].id,
53
59
  label : settings.subsectors[i].name,
54
60
  parent : this,
55
61
  x : this.x,
@@ -59,11 +65,11 @@ var socialCheesecake = socialCheesecake || {};
59
65
  rIn : rInSubsector,
60
66
  rOut : rOutSubsector,
61
67
  actors : settings.subsectors[i].actors,
62
- mouseover : { color : "#aaffaa",
68
+ mouseover : { color : socialCheesecake.Cheesecake.getSectorHoverColor(),
63
69
  callback : function(subsector) {
64
70
  /* FIX FOR EXECUTING MOUSEOUT BEFORE MOUSEOVER */
65
71
  for(var i in subsector.parent.subsectors){
66
- subsector.parent.subsectors[i].getRegion().addEventListener("mouseout", undefined);
72
+ subsector.parent.subsectors[i].getRegion().removeEventListener("mouseout");
67
73
  if(subsector.parent.subsectors[i]!= subsector){
68
74
  subsector.parent.subsectors[i].changeColor(subsector.parent.subsectors[i].mouseout.color);
69
75
  }
@@ -71,22 +77,30 @@ var socialCheesecake = socialCheesecake || {};
71
77
  subsector.getRegion().addEventListener("mouseout", function() {
72
78
  subsector.eventHandler('mouseout');
73
79
  });
74
-
80
+ /* END of FIX */
75
81
  document.body.style.cursor = "pointer";
76
- subsector.parent.parent.grid.hideAll();
77
- subsector.parent.parent.grid.fadeIn(subsector.actors, 300, true);
82
+ subsector.getCheesecake().grid.hideAll();
83
+ subsector.getCheesecake().grid.fadeIn(subsector.actors, 300, true);
84
+ subsector.getCheesecake().setHighlightedSector(subsector);
78
85
  }
79
86
  },
80
87
  mouseout :{
81
- color : "#eeffee",
88
+ color : socialCheesecake.Cheesecake.getSectorFillColor(),
82
89
  callback : function(subsector) {
83
90
  document.body.style.cursor = "default";
84
- subsector.parent.parent.grid.fadeIn(subsector.parent.actors, 300, true);
91
+ subsector.getCheesecake().grid.fadeIn(subsector.parent.actors, 300, true);
92
+ subsector.getCheesecake().setHighlightedSector(subsector.parent);
85
93
  }
86
- }
94
+ },
95
+ mousedown : {
96
+ callback : function(subsector) {
97
+ var selectedActors = subsector.getCheesecake().grid.getSelectedActors();
98
+ subsector.changeMembership(selectedActors);
99
+ }
100
+ }
87
101
  });
88
102
  rInSubsector = rOutSubsector;
89
- this.subsectors.push(layer);
103
+ this.subsectors.push(subsector);
90
104
  }
91
105
  }
92
106
  this.originalAttr = {
@@ -97,6 +111,7 @@ var socialCheesecake = socialCheesecake || {};
97
111
  rIn : this.rIn,
98
112
  rOut : this.rOut,
99
113
  color : this.color,
114
+ textAndStrokeColor : this.textAndStrokeColor,
100
115
  label : this.label,
101
116
  mouseover : this.mouseover,
102
117
  mouseout : this.mouseout,
@@ -117,18 +132,10 @@ var socialCheesecake = socialCheesecake || {};
117
132
  var rIn = this.rIn;
118
133
  var rOut = this.rOut;
119
134
  var color = this.color;
135
+ var textAndStrokeColor = this.textAndStrokeColor;
120
136
  var label = this.label;
121
137
  var actors = this.actors;
122
- if(options != null) {
123
- if(options.x != null) x = options.x;
124
- if(options.y != null) y = options.y;
125
- if(options.phi != null) phi = options.phi;
126
- if(options.delta != null) delta = options.delta;
127
- if(options.rIn != null) rIn = options.rIn;
128
- if(options.rOut != null) rOut = options.rOut;
129
- if(options.color != null) color = options.color;
130
- if(options.label != null) label = options.label;
131
- }
138
+
132
139
  context.restore();
133
140
  context.save();
134
141
  context.beginPath();
@@ -138,11 +145,19 @@ var socialCheesecake = socialCheesecake || {};
138
145
  context.closePath();
139
146
  context.fillStyle = color;
140
147
  context.fill();
141
- context.lineWidth = 4;
148
+ context.lineWidth = 2;
149
+ context.strokeStyle = textAndStrokeColor;
142
150
  context.stroke();
143
- socialCheesecake.text.writeCurvedText(label, context, x, y, 0.75*rOut, phi, delta);
151
+ if((this.auxiliar)&&(label=="+")){
152
+ socialCheesecake.text.addPlusCharacter(context, x, y, 0.5*(rOut-rIn) + rIn,
153
+ phi, delta, textAndStrokeColor);
154
+ }else{
155
+ socialCheesecake.text.writeCurvedText(label, context, x, y, 0.7*(rOut-rIn) + rIn,
156
+ phi, delta, textAndStrokeColor);
157
+ }
144
158
  if(!this.auxiliar)
145
- socialCheesecake.text.writeCurvedText("(" + actors.length + ")", context, x, y, 0.6*rOut, phi, delta);
159
+ socialCheesecake.text.writeCurvedText("(" + actors.length + ")", context, x, y,
160
+ 0.55*(rOut-rIn) + rIn, phi, delta, textAndStrokeColor);
146
161
  }
147
162
 
148
163
  socialCheesecake.Sector.prototype.getRegion = function() {
@@ -194,27 +209,111 @@ var socialCheesecake = socialCheesecake || {};
194
209
  var rIn = this.rIn;
195
210
  var sector = (this.simulate != null) ? cheesecake.sectors[this.simulate] : this;
196
211
  var subsectors = sector.subsectors;
212
+ var parts = subsectors.length * 2 + 1;
197
213
 
198
214
  //Draw sector's subsectors over it
199
215
  var subsectorRIn = rIn;
200
- var separation = 0;
201
- if(subsectors.length > 0)
202
- separation = (rOut + rIn) / subsectors.length;
203
- for(var i in subsectors) {
216
+ var extraWidth = (rOut - rIn) * 0.06;
217
+ var sectorWidth = (rOut - rIn - (parts - subsectors.length) * extraWidth) / subsectors.length;
218
+ var extraSettings = {
219
+ x : cheesecake.center.x,
220
+ y : cheesecake.center.y,
221
+ delta : delta,
222
+ phi : phi,
223
+ label : "+",
224
+ parent : this,
225
+ auxiliar : true,
226
+ color : socialCheesecake.Cheesecake.getExtraSectorFillColor(),
227
+ mouseover : {
228
+ color : socialCheesecake.Cheesecake.getExtraSectorHoverColor(),
229
+ callback : function (sector){
230
+ sector.resizeWidth({
231
+ width : extraWidth*1.5,
232
+ anchor : "m",
233
+ step : 1
234
+ });
235
+ }
236
+ },
237
+ mouseout : {
238
+ color : socialCheesecake.Cheesecake.getExtraSectorFillColor(),
239
+ callback : function(sector){
240
+ sector.resizeWidth({
241
+ width : extraWidth,
242
+ anchor : "m",
243
+ step : 1,
244
+ priority : true
245
+ })
246
+ }
247
+ }
248
+ }
249
+ //Add sector's subsectors
250
+ for(var i in subsectors){
251
+ rIn += extraWidth;
204
252
  subsectors[i].rIn = rIn;
205
- subsectors[i].rOut = rIn + separation;
253
+ subsectors[i].rOut = rIn + sectorWidth;
206
254
  subsectors[i].phi = phi;
207
255
  subsectors[i].delta = delta;
208
256
  cheesecake.stage.add(subsectors[i].getRegion());
209
- rIn += separation;
257
+ rIn += sectorWidth;
258
+ }
259
+ //Add extra subsectors
260
+ rIn = 0;
261
+ for(var i = 0; i< parts- subsectors.length; i++){
262
+ if(i == 0){
263
+ var extraSettingsFirst = {
264
+ x : cheesecake.center.x,
265
+ y : cheesecake.center.y,
266
+ rIn : rIn,
267
+ rOut : rIn +extraWidth,
268
+ delta : delta,
269
+ phi : phi,
270
+ label : "+",
271
+ parent : this,
272
+ auxiliar : true,
273
+ color : socialCheesecake.Cheesecake.getExtraSectorFillColor(),
274
+ mouseover : {
275
+ color : socialCheesecake.Cheesecake.getExtraSectorHoverColor(),
276
+ callback : function (sector){
277
+ sector.resizeWidth({
278
+ width : extraWidth*1.5,
279
+ anchor : "rin",
280
+ step : 1
281
+ });
282
+ }
283
+ },
284
+ mouseout : {
285
+ color : socialCheesecake.Cheesecake.getExtraSectorFillColor(),
286
+ callback : function(sector){
287
+ sector.resizeWidth({
288
+ width : extraWidth,
289
+ anchor : "rin",
290
+ step : 1,
291
+ priority : true
292
+ })
293
+ }
294
+ }
295
+ }
296
+ var extraSector = new socialCheesecake.Subsector(extraSettingsFirst);
297
+ }else{
298
+ extraSettings["rIn"]= rIn;
299
+ extraSettings["rOut"]= rIn + extraWidth;
300
+ var extraSector = new socialCheesecake.Subsector(extraSettings);
301
+ }
302
+ cheesecake.stage.add(extraSector.getRegion());
303
+ this.extraSubsectors.push(extraSector);
304
+ rIn += extraWidth + sectorWidth;
210
305
  }
211
306
  }
212
307
 
213
308
  socialCheesecake.Sector.prototype.putTogether = function() {
214
309
  var cheesecake = this.getCheesecake();
215
- var sector; (this.simulate != null) ? sector = cheesecake.sectors[this.simulate] : sector = this;
310
+ var sector = (this.simulate != null) ? cheesecake.sectors[this.simulate] : this;
216
311
  var subsectors = sector.subsectors;
312
+ var extraSubsectors = this.extraSubsectors;
217
313
  //Clear subsectors from stage
314
+ for(var i = extraSubsectors.length ; i>0 ; i--){
315
+ cheesecake.stage.remove((extraSubsectors.pop()).getRegion());
316
+ }
218
317
  for(var i in subsectors) {
219
318
  cheesecake.stage.remove(subsectors[i].getRegion());
220
319
  }
@@ -233,17 +332,14 @@ var socialCheesecake = socialCheesecake || {};
233
332
  }
234
333
 
235
334
  /**
236
- *
237
- * Options:
238
- * delta - new delta to achieve
239
- * context - sector context to work with
240
- * step - sets the animation speed
241
- * anchor - "beginning" , "b", "B"
242
- * "middle", "m", "M"
243
- * "end", "e", "E"
244
- *
245
- **/
246
- socialCheesecake.Sector.prototype.resize = function(options) {
335
+ * Options:
336
+ * delta - new delta to achieve (default: Math.PI/2)
337
+ * step - sets the animation speed (default: 0.05)
338
+ * anchor - "beginning" , "b", "B"
339
+ * "middle", "m", "M"
340
+ * "end", "e", "E"
341
+ */
342
+ socialCheesecake.Sector.prototype.resizeDelta = function(options) {
247
343
  if(!options)
248
344
  throw "No arguments passed to the function";
249
345
  var sector = this;
@@ -254,10 +350,15 @@ var socialCheesecake = socialCheesecake || {};
254
350
  var step = 0.05;
255
351
  var goalDelta = Math.PI / 2;
256
352
  var anchor = 1;
353
+
257
354
  if(options.step) step = options.step;
258
355
  if(options.delta) {
259
356
  goalDelta = options.delta;
260
357
  }
358
+ console.log("resizing delta of sector "+ sector.label);
359
+ console.log("current delta "+ currentDelta);
360
+ console.log("delta to achieve "+ goalDelta);
361
+
261
362
  if(options.anchor) {
262
363
  if((options.anchor.toLowerCase() == "b") || (options.anchor == "beginning"))
263
364
  anchor = 0;
@@ -266,7 +367,7 @@ var socialCheesecake = socialCheesecake || {};
266
367
  if((options.anchor.toLowerCase() == "e") || (options.anchor == "end"))
267
368
  anchor = 1;
268
369
  }
269
-
370
+ //Calculate new parameters
270
371
  if(currentDelta > goalDelta) {
271
372
  if(currentDelta - goalDelta < step) step = currentDelta - goalDelta;
272
373
  currentDelta -= step;
@@ -278,24 +379,108 @@ var socialCheesecake = socialCheesecake || {};
278
379
  }
279
380
  sector.delta = currentDelta;
280
381
  sector.phi = currentPhi;
281
-
382
+
383
+ //Redraw
282
384
  context.restore();
283
385
  context.save();
284
386
  stage.draw();
387
+ //Repeat if necessary
285
388
  if(currentDelta != goalDelta) {
286
389
  requestAnimFrame(function() {
287
- sector.resize(options);
390
+ sector.resizeDelta(options);
288
391
  });
289
392
  } else if(options.callback) {
290
393
  options.callback();
291
394
  }
292
395
  }
293
-
396
+
397
+ /**
398
+ * Options:
399
+ * width - new width to achieve
400
+ * step - sets the animation speed
401
+ * anchor - "rIn" , "rin", "in", "I", "i"
402
+ * "middle", "m", "M"
403
+ * "rOut", "rout", "out", "O", "o"
404
+ * priority - true to terminate other resizeWidth methods running
405
+ */
406
+ socialCheesecake.Sector.prototype.resizeWidth = function(options) {
407
+ var sector = this;
408
+ var context = sector.getRegion().layer.getContext();
409
+ var stage = sector.getCheesecake().stage;
410
+ var currentRIn = this.rIn;
411
+ var currentROut = this.rOut;
412
+ var currentWidth = (currentROut - currentRIn);
413
+ var step = 0.05;
414
+ var goalWidth = currentWidth;
415
+ var anchor = 1;
416
+ var grow = 0;
417
+ var error = false;
418
+ var goOn = true;
419
+ if(options.step) step = options.step;
420
+ if(options.width) goalWidth = options.width;
421
+ if(goalWidth < 0) throw "Width must be greater than or equal to zero";
422
+ if(options.anchor) {
423
+ if((options.anchor.toLowerCase() == "i") || (options.anchor == "in")
424
+ || (options.anchor.toLowerCase() == "rin")){
425
+ anchor = 1;
426
+ }
427
+ if((options.anchor.toLowerCase() == "m") || (options.anchor == "middle")){
428
+ anchor = 0.5;
429
+ }
430
+ if((options.anchor.toLowerCase() == "o") || (options.anchor == "out")
431
+ || (options.anchor.toLowerCase() == "rout")){
432
+ anchor = 0;
433
+ }
434
+ }
435
+ //Calculate new parameters
436
+ if(currentWidth > goalWidth) {
437
+ //Make more little
438
+ if(currentWidth - goalWidth < step) step = currentWidth - goalWidth;
439
+ grow = -1;
440
+ } else if(currentWidth < goalWidth) {
441
+ //Make bigger
442
+ if(goalWidth - currentWidth < step) step = goalWidth - currentWidth;
443
+ grow = 1;
444
+ }
445
+ if(options.priority) sector.grow =grow;
446
+ if((sector.grow!=null)&&(grow != sector.grow)){
447
+ goOn =false;
448
+ }else{
449
+ goOn = true;
450
+ sector.grow = grow;
451
+ }
452
+ currentROut = currentROut + (grow * anchor * step);
453
+ currentRIn = currentRIn - (grow * (1 - anchor) * step);
454
+ currentWidth = currentROut - currentRIn;
455
+ if(currentRIn <0 || currentROut <0){
456
+ console.log("WARNING!! Width cannot change anymore. It has reached it maximum/ minimum level.");
457
+ error =true;
458
+ }else{
459
+ sector.rOut = currentROut;
460
+ sector.rIn = currentRIn;
461
+ //Redraw
462
+ context.restore();
463
+ context.save();
464
+ stage.draw();
465
+ }
466
+ //Repeat if necessary
467
+ if ((goOn) &&(!error && Math.round(currentWidth *1000) != Math.round(goalWidth *1000))) {
468
+ requestAnimFrame(function() {
469
+ sector.resizeWidth(options);
470
+ });
471
+ } else{
472
+ sector.grow= undefined;
473
+ if(options.callback) {
474
+ options.callback();
475
+ }
476
+ }
477
+ }
478
+
294
479
  socialCheesecake.Sector.prototype.focus = function() {
295
480
  var sector = this;
296
481
  var context = sector.getRegion().layer.getContext();
297
482
  var stage = sector.getCheesecake().stage;
298
- sector.rOut *= 1.05;
483
+ sector.rOut = sector.originalAttr.rOut * 1.05;
299
484
  context.restore();
300
485
  context.save();
301
486
  stage.draw();
@@ -344,7 +529,9 @@ var socialCheesecake = socialCheesecake || {};
344
529
  } else if(phiDestination < currentPhi) {
345
530
  grow = -1;
346
531
  }
347
- if(Math.round(((2 * Math.PI) - Math.abs(phiDestination - currentPhi) ) * 1000) / 1000 >= Math.round(Math.abs(phiDestination - currentPhi) * 1000) / 1000) {
532
+ if(Math.round(((2 * Math.PI) - Math.abs(phiDestination - currentPhi) ) * 1000) / 1000
533
+ >= Math.round(Math.abs(phiDestination - currentPhi) * 1000) / 1000) {
534
+
348
535
  if(Math.abs(phiDestination - currentPhi) < step)
349
536
  step = Math.abs(phiDestination - currentPhi);
350
537
  currentPhi += (grow * step);
@@ -383,14 +570,14 @@ var socialCheesecake = socialCheesecake || {};
383
570
  }
384
571
  }
385
572
 
386
- socialCheesecake.Sector.prototype.addActor = function(actor_info , subsector){
573
+ socialCheesecake.Sector.prototype.addActor = function(actorInfo , subsector){
387
574
  var actors = this.actors;
388
575
  var actor;
389
576
 
390
577
  //Check if the actor is already in the array
391
578
  var actorAlreadyDeclared = false;
392
579
  for (var i in actors){
393
- if (actors[i].id == actor_info.id){
580
+ if (actors[i].id == actorInfo.id){
394
581
  actorAlreadyDeclared = true;
395
582
  actor = actors[i];
396
583
  //Check if the subsector has already been declared a parent of the actor
@@ -404,17 +591,43 @@ var socialCheesecake = socialCheesecake || {};
404
591
  // If the actor was not in the array, ask the parent or the grid for it
405
592
  if(!actorAlreadyDeclared){
406
593
  if (this == subsector){
407
- actor = this.parent.addActor(actor_info, subsector);
594
+ actor = this.parent.addActor(actorInfo, subsector);
408
595
  }else{
409
- actor = this.parent.grid.addActor(actor_info, subsector);
596
+ actor = this.parent.grid.addActor(actorInfo, subsector);
410
597
  }
411
598
  actors.push(actor);
412
599
  }
413
600
  return actor;
414
601
  }
415
602
 
603
+ socialCheesecake.Sector.prototype.removeActor = function (actor){
604
+ var actors = this.actors;
605
+ var actorParents;
606
+ var actorPresentInSector = false;
607
+
608
+ for(var actorIndex in actors){
609
+ if(actors[actorIndex].id == actor.id){
610
+ actorParents = actor.parents;
611
+ //Find out if there is a subsector in this sector with this actor
612
+ for (var parent in actorParents){
613
+ for (var subsector in this.subsectors){
614
+ if(actorParents[parent] === this.subsectors[subsector]){
615
+ actorPresentInSector = true;
616
+ break;
617
+ }
618
+ }
619
+ }
620
+ //If there isn't, remove the actor from the array and tell the Grid
621
+ if(!actorPresentInSector){
622
+ actors.splice(actorIndex,1);
623
+ }
624
+ }
625
+ }
626
+ }
627
+
416
628
  /*SUBSECTOR*/
417
629
  socialCheesecake.Subsector = function(settings) {
630
+ this.id = settings.id;
418
631
  if(settings.parent != null) this.parent = settings.parent;
419
632
  this.label = "";
420
633
  if(settings.label != null) this.label = settings.label;
@@ -425,6 +638,9 @@ var socialCheesecake = socialCheesecake || {};
425
638
  this.phi = settings.phi;
426
639
  this.delta = settings.delta;
427
640
  this.actors = [];
641
+ this.auxiliar = (settings.auxiliar) ? settings.auxiliar : false;
642
+ if(settings.color) this.color = settings.color;
643
+ if(settings.textAndStrokeColor) this.textAndStrokeColor = settings.textAndStrokeColor;
428
644
  if(settings.mousedown != null) this.mousedown = settings.mousedown;
429
645
  if(settings.mouseup != null) this.mouseup = settings.mouseup;
430
646
  if(settings.mouseover != null) this.mouseover = settings.mouseover;
@@ -432,9 +648,10 @@ var socialCheesecake = socialCheesecake || {};
432
648
 
433
649
  var grid = this.getCheesecake().grid;
434
650
  if (settings.actors){
435
- for( var actor in settings.actors){
651
+ for(var actor in settings.actors){
436
652
  var actor_info = {
437
- id : settings.actors[actor][0]
653
+ id : settings.actors[actor][0],
654
+ name : settings.actors[actor][1]
438
655
  }
439
656
  this.addActor(actor_info ,this);
440
657
  }
@@ -442,6 +659,7 @@ var socialCheesecake = socialCheesecake || {};
442
659
  }
443
660
 
444
661
  socialCheesecake.Subsector.prototype = new socialCheesecake.Sector({
662
+ id : this.id,
445
663
  parent : this.parent,
446
664
  center : { x : this.x, y : this.y },
447
665
  label : this.label,
@@ -449,6 +667,9 @@ var socialCheesecake = socialCheesecake || {};
449
667
  rOut : this.rOut,
450
668
  phi : this.phi,
451
669
  delta : this.delta,
670
+ auxiliar : this.auxiliar,
671
+ color : this.color,
672
+ textAndStrokeColor : this.textAndStrokeColor,
452
673
 
453
674
  mouseover : this.mouseover,
454
675
  mouseout : this.mouseout,
@@ -460,4 +681,47 @@ var socialCheesecake = socialCheesecake || {};
460
681
  var subsector = this;
461
682
  return subsector.parent.parent;
462
683
  }
684
+
685
+ socialCheesecake.Subsector.prototype.removeActor = function(actor){
686
+ var actors = this.actors;
687
+ var actorParents;
688
+ for(var actorIndex in actors){
689
+ if(actors[actorIndex].id == actor.id){
690
+ actorParents = actor.parents;
691
+ //Remove subsector from actors parents array
692
+ for( var parent in actorParents){
693
+ if (actorParents[parent] === this){
694
+ actorParents.splice(parent,1);
695
+ }
696
+ }
697
+ //Remove from actors array and tell the sector parent
698
+ actors.splice(actorIndex,1);
699
+ this.parent.removeActor(actor);
700
+ }
701
+ }
702
+ }
703
+
704
+ socialCheesecake.Subsector.prototype.changeMembership = function(actors){
705
+ var actualActors = this.actors;
706
+ var actorInfo;
707
+ var isMember = false;
708
+
709
+ for(var i in actors){
710
+ for ( var j in actualActors){
711
+ if (actualActors[j].id == actors[i].id){
712
+ isMember = true;
713
+ this.removeActor(actors[i]);
714
+ break;
715
+ }
716
+ }
717
+ if(!isMember){
718
+ actorInfo = { id : actors[i].id};
719
+ this.addActor(actorInfo, this);
720
+ }
721
+ this.getCheesecake().updateActorMembership(actors[i].id);
722
+ isMember = false;
723
+ }
724
+ this.getCheesecake().calculatePortions();
725
+ }
726
+
463
727
  })();
@@ -1,11 +1,34 @@
1
1
  var socialCheesecake = socialCheesecake || {}; (function() {
2
2
  socialCheesecake.text = {
3
- writeCurvedText : function(text, context, x, y, r, phi, delta) {
3
+ addPlusCharacter : function(context, x, y, r, phi, delta, color) {
4
4
  context.font = "bold 14px sans-serif";
5
- context.fillStyle = '#000';
5
+ context.fillStyle = color || "#000";
6
+ context.textAlign = "center";
7
+ context.textBaseline = "middle";
8
+ text = "+";
9
+ context.translate(x, y);
10
+ context.rotate(- delta / 2 - phi - Math.PI / 2);
11
+ context.fillText(text[0], 0, r);
12
+ context.restore();
13
+ context.save();
14
+ },
15
+ writeCurvedText : function(text, context, x, y, r, phi, delta, color) {
16
+ context.font = "bold 14px sans-serif";
17
+ context.fillStyle = color || "#000";
6
18
  context.textBaseline = "middle";
7
19
  var medium_alpha = Math.tan(context.measureText(text).width / (text.length * r));
20
+ var old_text = null;
21
+ var original_text = text;
8
22
  while(medium_alpha * (text.length + 4) > delta) {
23
+ if(old_text==text){
24
+ console.log("WARNING: Infinite loop detected and stopped. Text '" + original_text + "' failed to be " +
25
+ "correctly truncated. Proccesed serveral times as '" + text + "' and will be returned as '" +
26
+ words[0].substring(0, delta/medium_alpha - 7) + "'. Space too small to even be able to truncate.")
27
+ text = words[0].substring(0, delta/medium_alpha - 7);
28
+ break;
29
+ }else{
30
+ old_text = text;
31
+ }
9
32
  words = text.split(" ");
10
33
  if(words.length > 1){
11
34
  words.splice(words.length - 1, 1);
@@ -1,3 +1,3 @@
1
1
  module SocialCheesecake
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end