]> git.proxmox.com Git - extjs.git/blame - extjs/packages/charts/src/chart/MarkerHolder.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / charts / src / chart / MarkerHolder.js
CommitLineData
6527f429
DM
1/**\r
2 * Mixin that provides the functionality to place markers.\r
3 */\r
4Ext.define('Ext.chart.MarkerHolder', {\r
5 extend: 'Ext.Mixin',\r
6\r
7 mixinConfig: {\r
8 id: 'markerHolder',\r
9 after: {\r
10 constructor: 'constructor',\r
11 preRender: 'preRender'\r
12 },\r
13 before: {\r
14 destroy: 'destroy'\r
15 }\r
16 },\r
17\r
18 isMarkerHolder: true,\r
19\r
20 // The combined transformation applied to the sprite by its parents.\r
21 // Does not include the transformation matrix of the sprite itself.\r
22 surfaceMatrix: null,\r
23 // The inverse of the above transformation to go back to the original state.\r
24 inverseSurfaceMatrix: null,\r
25\r
26 deprecated: {\r
27 6: {\r
28 methods: {\r
29 /**\r
30 * Returns the markers bound to the given name.\r
31 * @param {String} name The name of the marker (e.g., "items", "labels", etc.).\r
32 * @return {Ext.chart.Markers[]}\r
33 * @method getBoundMarker\r
34 * @deprecated 6.0 Use {@link #getMarker} instead.\r
35 */\r
36 getBoundMarker: {\r
37 message: "Please use the 'getMarker' method instead.",\r
38 fn: function (name) {\r
39 var marker = this.boundMarkers[name];\r
40 return marker ? [marker] : marker;\r
41 }\r
42 }\r
43 }\r
44 }\r
45 },\r
46\r
47 constructor: function () {\r
48 this.boundMarkers = {};\r
49 this.cleanRedraw = false;\r
50 },\r
51\r
52 /**\r
53 * Registers the given marker with the marker holder under the specified name.\r
54 * @param {String} name The name of the marker (e.g., "items", "labels", etc.).\r
55 * @param {Ext.chart.Markers} marker\r
56 */\r
57 bindMarker: function (name, marker) {\r
58 var me = this,\r
59 markers = me.boundMarkers;\r
60\r
61 if (marker && marker.isMarkers) {\r
62 //<debug>\r
63 if (markers[name] && markers[name] === marker) {\r
64 Ext.log.warn(me.getId(), " (MarkerHolder): the Markers instance '", marker.getId(), "' is already bound under the name '", name, "'.");\r
65 }\r
66 //</debug>\r
67 me.releaseMarker(name);\r
68 markers[name] = marker;\r
69 marker.on('destroy', me.onMarkerDestroy, me);\r
70 }\r
71 },\r
72\r
73 onMarkerDestroy: function (marker) {\r
74 this.releaseMarker(marker);\r
75 },\r
76\r
77 /**\r
78 * Unregisters the given marker or a marker with the given name.\r
79 * Providing a name of the marker is more efficient as it avoids lookup.\r
80 * @param marker {String/Ext.chart.Markers}\r
81 * @return {Ext.chart.Markers} Released marker or null.\r
82 */\r
83 releaseMarker: function (marker) {\r
84 var markers = this.boundMarkers,\r
85 name;\r
86\r
87 if (marker && marker.isMarkers) {\r
88 for (name in markers) {\r
89 if (markers[name] === marker) {\r
90 delete markers[name];\r
91 break;\r
92 }\r
93 }\r
94 } else {\r
95 name = marker;\r
96 marker = markers[name];\r
97 delete markers[name];\r
98 }\r
99\r
100 return marker || null;\r
101 },\r
102\r
103 /**\r
104 * Returns the marker bound to the given name (or null). See {@link #bindMarker}.\r
105 * @param {String} name The name of the marker (e.g., "items", "labels", etc.).\r
106 * @return {Ext.chart.Markers}\r
107 */\r
108 getMarker: function (name) {\r
109 return this.boundMarkers[name] || null;\r
110 },\r
111\r
112 preRender: function () {\r
113 var me = this,\r
114 id = me.getId(),\r
115 boundMarkers = me.boundMarkers,\r
116 parent = me.getParent(),\r
117 name, marker,\r
118 matrix;\r
119\r
120 if (me.surfaceMatrix) {\r
121 matrix = me.surfaceMatrix.set(1, 0, 0, 1, 0, 0);\r
122 } else {\r
123 matrix = me.surfaceMatrix = new Ext.draw.Matrix();\r
124 }\r
125\r
126 me.cleanRedraw = !me.attr.dirty;\r
127 if (!me.cleanRedraw) {\r
128 for (name in boundMarkers) {\r
129 marker = boundMarkers[name];\r
130 if (marker) {\r
131 marker.clear(id);\r
132 }\r
133 }\r
134 }\r
135\r
136 // Parent can be either a sprite (like a composite or instancing)\r
137 // or a surface. First, climb up and apply transformations of the\r
138 // parent sprites.\r
139 while (parent && parent.attr && parent.attr.matrix) {\r
140 matrix.prependMatrix(parent.attr.matrix);\r
141 parent = parent.getParent();\r
142 }\r
143 // Finally, apply the transformation used by the surface.\r
144 matrix.prependMatrix(parent.matrix);\r
145 me.surfaceMatrix = matrix;\r
146 me.inverseSurfaceMatrix = matrix.inverse(me.inverseSurfaceMatrix);\r
147 },\r
148\r
149 putMarker: function (name, attr, index, bypassNormalization, keepRevision) {\r
150 var marker = this.boundMarkers[name],\r
151 id = this.getId();\r
152\r
153 if (marker) {\r
154 marker.putMarkerFor(id, attr, index, bypassNormalization, keepRevision);\r
155 }\r
156 },\r
157\r
158 getMarkerBBox: function (name, index, isWithoutTransform) {\r
159 var marker = this.boundMarkers[name],\r
160 id = this.getId();\r
161\r
162 if (marker) {\r
163 return marker.getMarkerBBoxFor(id, index, isWithoutTransform);\r
164 }\r
165 },\r
166\r
167 destroy: function () {\r
168 var boundMarkers = this.boundMarkers,\r
169 name, marker;\r
170\r
171 for (name in boundMarkers) {\r
172 marker = boundMarkers[name];\r
173 marker.destroy();\r
174 }\r
175 }\r
176\r
177});\r