]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/chart/label/Callout.js
2 * @class Ext.chart.label.Callout
3 * @extends Ext.draw.modifier.Modifier
5 * This is a modifier to place labels and callouts by additional attributes.
7 Ext
.define("Ext.chart.label.Callout", {
8 extend
: 'Ext.draw.modifier.Modifier',
10 prepareAttributes: function (attr
) {
11 if (!attr
.hasOwnProperty('calloutOriginal')) {
12 attr
.calloutOriginal
= Ext
.Object
.chain(attr
);
15 this._previous
.prepareAttributes(attr
.calloutOriginal
);
19 setAttrs: function (attr
, changes
) {
20 var callout
= attr
.callout
,
21 origin
= attr
.calloutOriginal
,
22 bbox
= attr
.bbox
.plain
,
23 width
= (bbox
.width
|| 0) + attr
.labelOverflowPadding
,
24 height
= (bbox
.height
|| 0) + attr
.labelOverflowPadding
,
27 if ('callout' in changes
) {
28 callout
= changes
.callout
;
31 if ('callout' in changes
|| 'calloutPlaceX' in changes
|| 'calloutPlaceY' in changes
|| 'x' in changes
|| 'y' in changes
) {
32 var rotationRads
= 'rotationRads' in changes
? origin
.rotationRads
= changes
.rotationRads
: origin
.rotationRads
,
33 x
= 'x' in changes
? (origin
.x
= changes
.x
) : origin
.x
,
34 y
= 'y' in changes
? (origin
.y
= changes
.y
) : origin
.y
,
35 calloutPlaceX
= 'calloutPlaceX' in changes
? changes
.calloutPlaceX
: attr
.calloutPlaceX
,
36 calloutPlaceY
= 'calloutPlaceY' in changes
? changes
.calloutPlaceY
: attr
.calloutPlaceY
,
37 calloutVertical
= 'calloutVertical' in changes
? changes
.calloutVertical
: attr
.calloutVertical
,
40 // Normalize Rotations
41 rotationRads
%= Math
.PI
* 2;
42 if (Math
.cos(rotationRads
) < 0) {
43 rotationRads
= (rotationRads
+ Math
.PI
) % (Math
.PI
* 2);
46 if (rotationRads
> Math
.PI
) {
47 rotationRads
-= Math
.PI
* 2;
50 if (calloutVertical
) {
51 rotationRads
= rotationRads
* (1 - callout
) - Math
.PI
/ 2 * callout
;
56 rotationRads
= rotationRads
* (1 - callout
);
58 changes
.rotationRads
= rotationRads
;
62 changes
.x
= x
* (1 - callout
) + calloutPlaceX
* callout
;
63 changes
.y
= y
* (1 - callout
) + calloutPlaceY
* callout
;
66 // Placing the end of the callout line.
67 dx
= calloutPlaceX
- x
;
68 dy
= calloutPlaceY
- y
;
69 if (Math
.abs(dy
* width
) > Math
.abs(height
* dx
)) {
72 changes
.calloutEndX
= changes
.x
- (height
/ (dy
* 2) * dx
) * callout
;
73 changes
.calloutEndY
= changes
.y
- height
/ 2 * callout
;
75 changes
.calloutEndX
= changes
.x
+ (height
/ (dy
* 2) * dx
) * callout
;
76 changes
.calloutEndY
= changes
.y
+ height
/ 2 * callout
;
81 changes
.calloutEndX
= changes
.x
- width
/ 2;
82 changes
.calloutEndY
= changes
.y
- (width
/ (dx
* 2) * dy
) * callout
;
84 changes
.calloutEndX
= changes
.x
+ width
/ 2;
85 changes
.calloutEndY
= changes
.y
+ (width
/ (dx
* 2) * dy
) * callout
;
93 pushDown: function (attr
, changes
) {
94 changes
= Ext
.draw
.modifier
.Modifier
.prototype.pushDown
.call(this, attr
.calloutOriginal
, changes
);
95 return this.setAttrs(attr
, changes
);
98 popUp: function (attr
, changes
) {
99 attr
= Object
.getPrototypeOf(attr
);
100 changes
= this.setAttrs(attr
, changes
);
102 return this._next
.popUp(attr
, changes
);
104 return Ext
.apply(attr
, changes
);