|
842 | 842 | , paper = {}
|
843 | 843 | , width = 0
|
844 | 844 | , height = 0
|
845 |
| - , title = {} |
| 845 | + , title = null |
846 | 846 | , elem = {}
|
847 | 847 | , elemBBox = {}
|
848 | 848 | , label = {}
|
|
861 | 861 | height = width = 0;
|
862 | 862 |
|
863 | 863 | // Set the title of the legend
|
864 |
| - if(legendOptions.title) { |
| 864 | + if(legendOptions.title && legendOptions.title !== "") { |
865 | 865 | title = paper.text(legendOptions.marginLeftTitle, 0, legendOptions.title).attr(legendOptions.titleAttrs);
|
866 | 866 | title.attr({y : 0.5 * title.getBBox().height});
|
867 | 867 |
|
|
871 | 871 |
|
872 | 872 | // Calculate attrs (and width, height and r (radius)) for legend elements, and yCenter for horizontal legends
|
873 | 873 | for(i = 0, length = legendOptions.slices.length; i < length; ++i) {
|
| 874 | + var current_yCenter = 0; |
| 875 | + |
874 | 876 | if (typeof legendOptions.slices[i].legendSpecificAttrs == "undefined")
|
875 | 877 | legendOptions.slices[i].legendSpecificAttrs = {};
|
876 | 878 |
|
|
901 | 903 | sliceAttrs[i].r = legendOptions.slices[i].size / 2;
|
902 | 904 | }
|
903 | 905 |
|
| 906 | + // Compute yCenter for this legend slice |
| 907 | + current_yCenter = legendOptions.marginBottomTitle; |
| 908 | + // Add title height if it exists |
| 909 | + if (title) { |
| 910 | + current_yCenter += title.getBBox().height; |
| 911 | + } |
904 | 912 | if(legendType == "plot" && (typeof legendOptions.slices[i].type == "undefined" || legendOptions.slices[i].type == "circle")) {
|
905 |
| - yCenter = Math.max(yCenter, legendOptions.marginBottomTitle + title.getBBox().height + scale * sliceAttrs[i].r); |
| 913 | + current_yCenter += scale * sliceAttrs[i].r; |
906 | 914 | } else {
|
907 |
| - yCenter = Math.max(yCenter, legendOptions.marginBottomTitle + title.getBBox().height + scale * sliceAttrs[i].height/2); |
| 915 | + current_yCenter += scale * sliceAttrs[i].height/2; |
908 | 916 | }
|
| 917 | + // Update yCenter if current larger |
| 918 | + yCenter = Math.max(yCenter, current_yCenter); |
909 | 919 | }
|
910 | 920 |
|
911 | 921 | if (legendOptions.mode == "horizontal") {
|
|
983 | 993 |
|
984 | 994 | // Update the width and height for the paper
|
985 | 995 | if (legendOptions.mode == "horizontal") {
|
| 996 | + var current_height = legendOptions.marginBottom + elemBBox.height; |
986 | 997 | width += legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel + label.getBBox().width;
|
987 |
| - if(legendOptions.slices[i].type == "image" || legendType == "area") { |
988 |
| - height = Math.max(height, legendOptions.marginBottom + title.getBBox().height + elemBBox.height); |
989 |
| - } else { |
990 |
| - height = Math.max(height, legendOptions.marginBottomTitle + legendOptions.marginBottom + title.getBBox().height + elemBBox.height); |
| 998 | + if(legendOptions.slices[i].type != "image" && legendType != "area") { |
| 999 | + current_height += legendOptions.marginBottomTitle; |
| 1000 | + } |
| 1001 | + // Add title height if it exists |
| 1002 | + if (title) { |
| 1003 | + current_height += title.getBBox().height; |
991 | 1004 | }
|
| 1005 | + height = Math.max(height, current_height); |
992 | 1006 | } else {
|
993 | 1007 | width = Math.max(width, legendOptions.marginLeft + elemBBox.width + legendOptions.marginLeftLabel + label.getBBox().width);
|
994 | 1008 | height += legendOptions.marginBottom + elemBBox.height;
|
|
0 commit comments