|
222 | 222 | * |
223 | 223 | * Update the current map |
224 | 224 | * Refresh attributes and tooltips for areas and plots |
225 | | - * @param updatedOptions options to update for plots and areas |
226 | | - * @param newPlots new plots to add to the map |
227 | | - * @param deletedPlots plots to delete from the map (array, or "all" to remove all plots) |
228 | 225 | * @param opt option for the refresh : |
229 | | - * opt.animDuration animation duration in ms (default = 0) |
230 | | - * opt.resetAreas true to reset previous areas options |
231 | | - * opt.resetPlots true to reset previous plots options |
232 | | - * opt.resetLinks true to reset previous links options |
233 | | - * opt.afterUpdate Hook that allows to add custom processing on the map |
| 226 | + * opt.mapOptions: options to update for plots and areas |
| 227 | + * opt.replaceOptions: whether mapsOptions should entirely replace current map options, or just extend it |
| 228 | + * opt.opt.newPlots new plots to add to the map |
234 | 229 | * opt.newLinks new links to add to the map |
235 | | - * opt.deletedLinks links to remove from the map (array, or "all" to remove all links) |
| 230 | + * opt.deletePlotKeys plots to delete from the map (array, or "all" to remove all plots) |
| 231 | + * opt.deleteLinkKeys links to remove from the map (array, or "all" to remove all links) |
236 | 232 | * opt.setLegendElemsState the state of legend elements to be set : show (default) or hide |
| 233 | + * opt.animDuration animation duration in ms (default = 0) |
| 234 | + * opt.afterUpdate Hook that allows to add custom processing on the map |
237 | 235 | */ |
238 | | - $self.on("update", function(e, updatedOptions, newPlots, deletedPlots, opt) { |
| 236 | + $self.on("update", function(e, opt) { |
239 | 237 | var i = 0 |
240 | | - , animDuration = 0 |
| 238 | + , animDuration = (opt.animDuration) ? (opt.animDuration) : 0 |
241 | 239 | , elemOptions = {} |
242 | 240 | // This function remove an element using animation (or not, depending on animDuration) |
243 | | - // Used for deletedPlots and deletedLinks |
| 241 | + // Used for deletePlotKeys and deleteLinkKeys |
244 | 242 | , fnRemoveElement = function(elem) { |
245 | 243 | // Unset all event handlers |
246 | 244 | Mapael.unsetHover(elem.mapElem, elem.textElem); |
|
272 | 270 | } |
273 | 271 | }; |
274 | 272 |
|
275 | | - if (typeof opt != "undefined") { |
276 | | - if (opt.resetAreas) options.areas = {}; |
277 | | - if (opt.resetPlots) options.plots = {}; |
278 | | - if (opt.resetLinks) options.links = {}; |
279 | | - if (opt.animDuration) animDuration = opt.animDuration; |
| 273 | + if (opt.mapOptions) { |
| 274 | + if (opt.replaceOptions === true) options = opt.mapOptions; |
| 275 | + else $.extend(true, options, opt.mapOptions); |
280 | 276 | } |
281 | 277 |
|
282 | | - $.extend(true, options, updatedOptions); |
283 | | - |
284 | | - // Delete plots by name if deletedPlots is array |
285 | | - if (typeof deletedPlots == "object") { |
286 | | - for (;i < deletedPlots.length; i++) { |
287 | | - if (typeof plots[deletedPlots[i]] != "undefined") { |
288 | | - fnRemoveElement(plots[deletedPlots[i]]); |
289 | | - delete plots[deletedPlots[i]]; |
| 278 | + // Delete plots by name if deletePlotKeys is array |
| 279 | + if (typeof opt.deletePlotKeys === "object") { |
| 280 | + for (;i < opt.deletePlotKeys.length; i++) { |
| 281 | + if (typeof plots[opt.deletePlotKeys[i]] != "undefined") { |
| 282 | + fnRemoveElement(plots[opt.deletePlotKeys[i]]); |
| 283 | + delete plots[opt.deletePlotKeys[i]]; |
290 | 284 | } |
291 | 285 | } |
292 | | - // Delete ALL plots if deletedPlots is set to "all" |
293 | | - } else if (deletedPlots === "all") { |
| 286 | + // Delete ALL plots if deletePlotKeys is set to "all" |
| 287 | + } else if (opt.deletePlotKeys === "all") { |
294 | 288 | $.each(plots, function(id, elem) { |
295 | 289 | fnRemoveElement(elem); |
296 | 290 | }); |
297 | 291 | // Empty plots object |
298 | 292 | plots = {}; |
299 | 293 | } |
300 | 294 |
|
301 | | - // Delete links by name if deletedLinks is array |
302 | | - if (typeof opt != "undefined" && typeof opt.deletedLinks == "object") { |
303 | | - for (i = 0;i < opt.deletedLinks.length; i++) { |
304 | | - if (typeof links[opt.deletedLinks[i]] != "undefined") { |
305 | | - fnRemoveElement(links[opt.deletedLinks[i]]); |
306 | | - delete links[opt.deletedLinks[i]]; |
| 295 | + // Delete links by name if deleteLinkKeys is array |
| 296 | + if (typeof opt.deleteLinkKeys === "object") { |
| 297 | + for (i = 0;i < opt.deleteLinkKeys.length; i++) { |
| 298 | + if (typeof links[opt.deleteLinkKeys[i]] != "undefined") { |
| 299 | + fnRemoveElement(links[opt.deleteLinkKeys[i]]); |
| 300 | + delete links[opt.deleteLinkKeys[i]]; |
307 | 301 | } |
308 | 302 | } |
309 | | - // Delete ALL links if deletedLinks is set to "all" |
310 | | - } else if (typeof opt != "undefined" && opt.deletedLinks === "all") { |
| 303 | + // Delete ALL links if deleteLinkKeys is set to "all" |
| 304 | + } else if (typeof opt != "undefined" && opt.deleteLinkKeys === "all") { |
311 | 305 | $.each(links, function(id, elem) { |
312 | 306 | fnRemoveElement(elem); |
313 | 307 | }); |
|
316 | 310 | } |
317 | 311 |
|
318 | 312 | // New plots |
319 | | - if (typeof newPlots == "object") { |
320 | | - $.each(newPlots, function(id) { |
| 313 | + if (typeof opt.newPlots === "object") { |
| 314 | + $.each(opt.newPlots, function(id) { |
321 | 315 | if (typeof plots[id] == "undefined") { |
322 | | - options.plots[id] = newPlots[id]; |
| 316 | + options.plots[id] = opt.newPlots[id]; |
323 | 317 | plots[id] = Mapael.drawPlot(id, options, mapConf, paper, $tooltip); |
324 | 318 | if (animDuration > 0) { |
325 | 319 | fnShowElement(plots[id]); |
|
329 | 323 | } |
330 | 324 |
|
331 | 325 | // New links |
332 | | - if (typeof opt != "undefined" && typeof opt.newLinks == "object") { |
| 326 | + if (typeof opt.newLinks === "object") { |
333 | 327 | var newLinks = Mapael.drawLinksCollection(paper, options, opt.newLinks, mapConf.getCoords, $tooltip); |
334 | 328 | $.extend(links, newLinks); |
335 | 329 | $.extend(options.links, opt.newLinks); |
|
387 | 381 | }); |
388 | 382 |
|
389 | 383 | // Update legends |
390 | | - if (typeof updatedOptions != "undefined" && typeof updatedOptions.legend === "object") { |
| 384 | + if (typeof opt.mapOptions.legend === "object") { |
391 | 385 | Mapael.createLegends($self, options, "area", areas, 1); |
392 | 386 | if (options.map.width) { |
393 | 387 | Mapael.createLegends($self, options, "plot", plots, (options.map.width / mapConf.width)); |
|
400 | 394 | // Toggle (i.e. click) only if: |
401 | 395 | // - slice legend is shown AND we want to hide |
402 | 396 | // - slice legend is hidden AND we want to show |
403 | | - if (typeof opt != "undefined" && typeof opt.setLegendElemsState === "object") { |
| 397 | + if (typeof opt.setLegendElemsState === "object") { |
404 | 398 | // setLegendElemsState is an object listing the legend we want to hide/show |
405 | 399 | $.each(opt.setLegendElemsState, function (legendCSSClass, action) { |
406 | 400 | // Search for the legend |
|
419 | 413 | } else { |
420 | 414 | // setLegendElemsState is a string, or is undefined |
421 | 415 | // Default : "show" |
422 | | - var action = (typeof opt != "undefined" && opt.setLegendElemsState === "hide") ? "hide" : "show"; |
| 416 | + var action = (opt.setLegendElemsState === "hide") ? "hide" : "show"; |
423 | 417 |
|
424 | 418 | $("[data-type='elem']", $self).each(function(id, elem) { |
425 | 419 | if (($(elem).attr('data-hidden') === "0" && action === "hide") || |
|
430 | 424 | }); |
431 | 425 | } |
432 | 426 |
|
433 | | - if (typeof opt != "undefined" && opt.afterUpdate) |
434 | | - opt.afterUpdate($self, paper, areas, plots, options); |
| 427 | + if (opt.afterUpdate) opt.afterUpdate($self, paper, areas, plots, options); |
| 428 | + |
435 | 429 | }); |
436 | 430 |
|
437 | 431 | // Handle resizing of the map |
|
0 commit comments