|
72 | 72 | $.fn.mapael.initElem(paper, plots[id], elemOptions, $tooltip); |
73 | 73 | } |
74 | 74 |
|
75 | | - // Create the legends for areas and plots |
76 | | - if (options.legend.area.slices && options.legend.area.display) |
77 | | - areaLegend = $.fn.mapael.createLegend($(this), options, 'area', areas); |
78 | | - |
79 | | - if (options.legend.plot.slices && options.legend.plot.display) |
80 | | - plotLegend = $.fn.mapael.createLegend($(this), options, 'plot', plots); |
81 | | - |
82 | 75 | // Enable zoom |
83 | 76 | if (options.map.zoom.enabled) |
84 | 77 | $.fn.mapael.initZoom($container, paper, mapConf.width, mapConf.height, options.map.zoom); |
|
184 | 177 | // Handle resizing of the map |
185 | 178 | if (options.map.width) { |
186 | 179 | paper.setSize(options.map.width, mapConf.height * (options.map.width / mapConf.width)); |
| 180 | + |
| 181 | + // Create the legends for areas and plots taking into account the scale of the map |
| 182 | + if (options.legend.area.slices && options.legend.area.display) |
| 183 | + areaLegend = $.fn.mapael.createLegend($(this), options, 'area', areas, 1); |
| 184 | + if (options.legend.plot.slices && options.legend.plot.display) |
| 185 | + plotLegend = $.fn.mapael.createLegend($(this), options, 'plot', plots, (options.map.width / mapConf.width)); |
187 | 186 | } else { |
188 | 187 | $(window).on('resize', function(){ |
189 | 188 | clearTimeout(resizeTO); |
190 | 189 | resizeTO = setTimeout(function(){$container.trigger('resizeEnd');}, 150); |
191 | 190 | }); |
192 | | - $(document).on('ready', function(){$container.trigger('resizeEnd');}); |
193 | 191 | $container.on('resizeEnd', function(e) { |
194 | 192 | var containerWidth = $container.width(); |
195 | 193 | if (paper.width != containerWidth) { |
196 | 194 | paper.setSize(containerWidth, mapConf.height * (containerWidth / mapConf.width)); |
197 | 195 | } |
198 | 196 | }); |
| 197 | + (function(self, $container, options, areas, plots) { |
| 198 | + $(document).on('ready', function(){ |
| 199 | + $container.trigger('resizeEnd'); |
| 200 | + |
| 201 | + // Create the legends for areas and plots taking into account the scale of the map |
| 202 | + if (options.legend.area.slices && options.legend.area.display) |
| 203 | + areaLegend = $.fn.mapael.createLegend($(self), options, 'area', areas, 1); |
| 204 | + if (options.legend.plot.slices && options.legend.plot.display) |
| 205 | + plotLegend = $.fn.mapael.createLegend($(self), options, 'plot', plots, ($container.width() / mapConf.width)); |
| 206 | + }); |
| 207 | + })(this, $container, options, areas, plots); |
| 208 | + |
199 | 209 | $container.trigger('resizeEnd'); |
200 | 210 | } |
201 | 211 |
|
|
374 | 384 | * @param options map options |
375 | 385 | * @param legendType the type of the legend : 'area' or 'plot' |
376 | 386 | */ |
377 | | - $.fn.mapael.createLegend = function ($container, options, legendType, elems) { |
| 387 | + $.fn.mapael.createLegend = function ($container, options, legendType, elems, scale) { |
378 | 388 | var legendOptions = options.legend[legendType] |
379 | 389 | , $legend = (legendType == 'plot') ? $('.' + options.legend.plot.cssClass, $container).empty() : $('.' + options.legend.area.cssClass, $container).empty() |
380 | 390 | , paper = new Raphael($legend.get(0)) |
|
413 | 423 | elem = paper.rect( |
414 | 424 | legendOptions.marginLeft |
415 | 425 | , height |
416 | | - , legendOptions.slices[i].size |
417 | | - , legendOptions.slices[i].size |
| 426 | + , scale * (legendOptions.slices[i].size) |
| 427 | + , scale * (legendOptions.slices[i].size) |
418 | 428 | ).attr(legendOptions.slices[i].attrs); |
419 | 429 | } else { |
420 | 430 | elem = paper.circle( |
421 | | - legendOptions.marginLeft + legendOptions.slices[i].size / 2 |
422 | | - , height + legendOptions.slices[i].size / 2 |
423 | | - , legendOptions.slices[i].size / 2 |
| 431 | + legendOptions.marginLeft + scale * (legendOptions.slices[i].size / 2) |
| 432 | + , height + scale * (legendOptions.slices[i].size / 2) |
| 433 | + , scale * (legendOptions.slices[i].size / 2) |
424 | 434 | ).attr(legendOptions.slices[i].attrs); |
425 | 435 | } |
426 | 436 |
|
427 | 437 | label = paper.text( |
428 | | - legendOptions.marginLeft + legendOptions.slices[i].size + legendOptions.marginLeftLabel |
429 | | - , height + legendOptions.slices[i].size / 2 |
| 438 | + legendOptions.marginLeft + scale * legendOptions.slices[i].size + legendOptions.marginLeftLabel |
| 439 | + , height + scale * (legendOptions.slices[i].size / 2) |
430 | 440 | , legendOptions.slices[i].label |
431 | 441 | ).attr(legendOptions.labelAttrs); |
432 | 442 |
|
433 | | - height += legendOptions.marginBottom + legendOptions.slices[i].size; |
434 | | - width = Math.max(width, legendOptions.marginLeft + legendOptions.slices[i].size + legendOptions.marginLeftLabel + label.getBBox().width); |
| 443 | + height += legendOptions.marginBottom + scale * legendOptions.slices[i].size; |
| 444 | + width = Math.max(width, legendOptions.marginLeft + scale * legendOptions.slices[i].size + legendOptions.marginLeftLabel + label.getBBox().width); |
435 | 445 |
|
436 | 446 | if (legendOptions.hideElemsOnClick.enabled) { |
437 | 447 | // Hide/show elements when user clicks on a legend element |
|
0 commit comments