|
1007 | 1007 | (self.options.areas[id] ? self.options.areas[id] : {}),
|
1008 | 1008 | self.options.legend.area
|
1009 | 1009 | );
|
1010 |
| - |
1011 | 1010 | self.updateElem(elemOptions, self.areas[id], animDuration);
|
1012 | 1011 | }
|
1013 | 1012 | });
|
|
1217 | 1216 | return elem;
|
1218 | 1217 | },
|
1219 | 1218 |
|
| 1219 | + /* |
| 1220 | + * Check wether newAttrs object bring modifications to originalAttrs object |
| 1221 | + */ |
| 1222 | + isAttrsChanged: function(originalAttrs, newAttrs) { |
| 1223 | + for (var key in newAttrs) { |
| 1224 | + if (typeof originalAttrs[key] === 'undefined' || newAttrs[key] !== originalAttrs[key]) { |
| 1225 | + return true; |
| 1226 | + } |
| 1227 | + } |
| 1228 | + return false; |
| 1229 | + }, |
| 1230 | + |
1220 | 1231 | /*
|
1221 | 1232 | * Update the element "elem" on the map with the new elemOptions options
|
1222 | 1233 | */
|
1223 | 1234 | updateElem: function (elemOptions, elem, animDuration) {
|
| 1235 | + |
1224 | 1236 | var self = this;
|
1225 |
| - var bbox = elem.mapElem.getBBox(); |
| 1237 | + |
| 1238 | + var bbox; |
1226 | 1239 | var textPosition;
|
1227 | 1240 | var plotOffsetX;
|
1228 | 1241 | var plotOffsetY;
|
|
1235 | 1248 | if (elemOptions.text !== undefined && elemOptions.text.content !== undefined && elemOptions.text.content != elem.textElem.attrs.text)
|
1236 | 1249 | elem.textElem.attr({text: elemOptions.text.content});
|
1237 | 1250 |
|
| 1251 | + bbox = elem.mapElem.getBBox(); |
| 1252 | + |
1238 | 1253 | if (elemOptions.size || (elemOptions.width && elemOptions.height)) {
|
1239 | 1254 | if (elemOptions.type == "image" || elemOptions.type == "svg") {
|
1240 | 1255 | plotOffsetX = (elemOptions.width - bbox.width) / 2;
|
|
1271 | 1286 |
|
1272 | 1287 | // Update elements attrs and attrsHover
|
1273 | 1288 | self.setHoverOptions(elem.mapElem, elemOptions.attrs, elemOptions.attrsHover);
|
1274 |
| - if (animDuration > 0) |
1275 |
| - elem.mapElem.animate(elemOptions.attrs, animDuration); |
1276 |
| - else |
1277 |
| - elem.mapElem.attr(elemOptions.attrs); |
| 1289 | + |
| 1290 | + if (self.isAttrsChanged(elem.mapElem.attrs, elemOptions.attrs)) { |
| 1291 | + if (animDuration > 0) |
| 1292 | + elem.mapElem.animate(elemOptions.attrs, animDuration); |
| 1293 | + else |
| 1294 | + elem.mapElem.attr(elemOptions.attrs); |
| 1295 | + } |
1278 | 1296 |
|
1279 | 1297 | // Update dimensions of SVG plots
|
1280 | 1298 | if (elemOptions.type == "svg") {
|
| 1299 | + |
| 1300 | + if (bbox === undefined) { |
| 1301 | + bbox = elem.mapElem.getBBox(); |
| 1302 | + } |
1281 | 1303 | elem.mapElem.transform("m" + (elemOptions.width / elem.mapElem.originalWidth) + ",0,0," + (elemOptions.height / elem.mapElem.originalHeight) + "," + bbox.x + "," + bbox.y);
|
1282 | 1304 | }
|
1283 | 1305 |
|
|
1395 | 1417 |
|
1396 | 1418 | var updateTooltipPosition = function (x, y) {
|
1397 | 1419 |
|
1398 |
| - var offsetLeft = 10; |
1399 |
| - var offsetTop = 20; |
| 1420 | + var offsetLeft = 10; |
| 1421 | + var offsetTop = 20; |
1400 | 1422 |
|
1401 | 1423 | if (typeof elem.tooltip.offset === "object") {
|
1402 | 1424 | if (typeof elem.tooltip.offset.left !== "undefined") {
|
|
0 commit comments