Version 3.18.1
Show:

File: charts/js/PieChartLegend.js

  1. PieChartLegend = Y.Base.create("pieChartLegend", Y.PieChart, [], {
  2. /**
  3. * Redraws the chart instance.
  4. *
  5. * @method _redraw
  6. * @private
  7. */
  8. _redraw: function()
  9. {
  10. if(this._drawing)
  11. {
  12. this._callLater = true;
  13. return;
  14. }
  15. this._drawing = true;
  16. this._callLater = false;
  17. var graph = this.get("graph"),
  18. w = this.get("width"),
  19. h = this.get("height"),
  20. graphWidth,
  21. graphHeight,
  22. legend = this.get("legend"),
  23. x = 0,
  24. y = 0,
  25. legendX = 0,
  26. legendY = 0,
  27. legendWidth,
  28. legendHeight,
  29. dimension,
  30. gap,
  31. position,
  32. direction;
  33. if(graph)
  34. {
  35. if(legend)
  36. {
  37. position = legend.get("position");
  38. direction = legend.get("direction");
  39. graphWidth = graph.get("width");
  40. graphHeight = graph.get("height");
  41. legendWidth = legend.get("width");
  42. legendHeight = legend.get("height");
  43. gap = legend.get("styles").gap;
  44. if((direction === "vertical" && (graphWidth + legendWidth + gap !== w)) ||
  45. (direction === "horizontal" && (graphHeight + legendHeight + gap !== h)))
  46. {
  47. switch(legend.get("position"))
  48. {
  49. case LEFT :
  50. dimension = Math.min(w - (legendWidth + gap), h);
  51. legendHeight = h;
  52. x = legendWidth + gap;
  53. legend.set(HEIGHT, legendHeight);
  54. break;
  55. case TOP :
  56. dimension = Math.min(h - (legendHeight + gap), w);
  57. legendWidth = w;
  58. y = legendHeight + gap;
  59. legend.set(WIDTH, legendWidth);
  60. break;
  61. case RIGHT :
  62. dimension = Math.min(w - (legendWidth + gap), h);
  63. legendHeight = h;
  64. legendX = dimension + gap;
  65. legend.set(HEIGHT, legendHeight);
  66. break;
  67. case BOTTOM :
  68. dimension = Math.min(h - (legendHeight + gap), w);
  69. legendWidth = w;
  70. legendY = dimension + gap;
  71. legend.set(WIDTH, legendWidth);
  72. break;
  73. }
  74. graph.set(WIDTH, dimension);
  75. graph.set(HEIGHT, dimension);
  76. }
  77. else
  78. {
  79. switch(legend.get("position"))
  80. {
  81. case LEFT :
  82. x = legendWidth + gap;
  83. break;
  84. case TOP :
  85. y = legendHeight + gap;
  86. break;
  87. case RIGHT :
  88. legendX = graphWidth + gap;
  89. break;
  90. case BOTTOM :
  91. legendY = graphHeight + gap;
  92. break;
  93. }
  94. }
  95. }
  96. else
  97. {
  98. graph.set(_X, 0);
  99. graph.set(_Y, 0);
  100. graph.set(WIDTH, w);
  101. graph.set(HEIGHT, h);
  102. }
  103. }
  104. this._drawing = false;
  105. if(this._callLater)
  106. {
  107. this._redraw();
  108. return;
  109. }
  110. if(graph)
  111. {
  112. graph.set(_X, x);
  113. graph.set(_Y, y);
  114. }
  115. if(legend)
  116. {
  117. legend.set(_X, legendX);
  118. legend.set(_Y, legendY);
  119. }
  120. }
  121. }, {
  122. ATTRS: {
  123. /**
  124. * The legend for the chart.
  125. *
  126. * @attribute
  127. * @type Legend
  128. */
  129. legend: LEGEND
  130. }
  131. });
  132. Y.PieChart = PieChartLegend;