API Docs for: 3.8.0
Show:

File: charts/js/CartesianChartLegend.js

  1. /**
  2.  * Adds legend functionality to charts.
  3.  *
  4.  * @module charts
  5.  * @submodule charts-legend
  6.  */
  7. var DOCUMENT = Y.config.doc,
  8. TOP = "top",
  9. RIGHT = "right",
  10. BOTTOM = "bottom",
  11. LEFT = "left",
  12. EXTERNAL = "external",
  13. HORIZONTAL = "horizontal",
  14. VERTICAL = "vertical",
  15. WIDTH = "width",
  16. HEIGHT = "height",
  17. POSITION = "position",
  18. _X = "x",
  19. _Y = "y",
  20. PX = "px",
  21. LEGEND = {
  22.     setter: function(val)
  23.     {
  24.         var legend = this.get("legend");
  25.         if(legend)
  26.         {
  27.             legend.destroy(true);
  28.         }
  29.         if(val instanceof Y.ChartLegend)
  30.         {
  31.             legend = val;
  32.             legend.set("chart", this);
  33.         }
  34.         else
  35.         {
  36.             val.chart = this;
  37.             if(!val.hasOwnProperty("render"))
  38.             {
  39.                 val.render = this.get("contentBox");
  40.                 val.includeInChartLayout = true;
  41.             }
  42.             legend = new Y.ChartLegend(val);
  43.         }
  44.         return legend;
  45.     }
  46. },

  47. /**
  48.  * Contains methods for displaying items horizontally in a legend.
  49.  *
  50.  * @module charts
  51.  * @submodule charts-legend
  52.  * @class HorizontalLegendLayout
  53.  */
  54. HorizontalLegendLayout = {
  55.     /**
  56.      * Displays items horizontally in a legend.
  57.      *
  58.      * @method _positionLegendItems
  59.      * @param {Array} items Array of items to display in the legend.
  60.      * @param {Number} maxWidth The width of the largest item in the legend.
  61.      * @param {Number} maxHeight The height of the largest item in the legend.
  62.      * @param {Number} totalWidth The total width of all items in a legend.
  63.      * @param {Number} totalHeight The total height of all items in a legend.
  64.      * @param {Number} padding The left, top, right and bottom padding properties for the legend.
  65.      * @param {Number} horizontalGap The horizontal distance between items in a legend.
  66.      * @param {Number} verticalGap The vertical distance between items in a legend.
  67.      * @param {String} hAlign The horizontal alignment of the legend.
  68.      * @param {String} vAlign The vertical alignment of the legend.
  69.      * @protected
  70.      */
  71.     _positionLegendItems: function(items, maxWidth, maxHeight, totalWidth, totalHeight, padding, horizontalGap, verticalGap, hAlign, vAlign)
  72.     {
  73.         var i = 0,
  74.             rowIterator = 0,
  75.             item,
  76.             node,
  77.             itemWidth,
  78.             itemHeight,
  79.             len,
  80.             width = this.get("width"),
  81.             rows,
  82.             rowsLen,
  83.             row,
  84.             totalWidthArray,
  85.             legendWidth,
  86.             topHeight = padding.top - verticalGap,
  87.             limit = width - (padding.left + padding.right),
  88.             left,
  89.             top,
  90.             right,
  91.             bottom;
  92.         HorizontalLegendLayout._setRowArrays(items, limit, horizontalGap);
  93.         rows = HorizontalLegendLayout.rowArray;
  94.         totalWidthArray = HorizontalLegendLayout.totalWidthArray;
  95.         rowsLen = rows.length;
  96.         for(; rowIterator < rowsLen; ++ rowIterator)
  97.         {
  98.             topHeight += verticalGap;
  99.             row = rows[rowIterator];
  100.             len = row.length;
  101.             legendWidth =  HorizontalLegendLayout.getStartPoint(width, totalWidthArray[rowIterator], hAlign, padding);
  102.             for(i = 0; i < len; ++i)
  103.             {
  104.                 item = row[i];
  105.                 node = item.node;
  106.                 itemWidth = item.width;
  107.                 itemHeight = item.height;
  108.                 item.x = legendWidth;
  109.                 item.y = 0;
  110.                 left = !isNaN(left) ? Math.min(left, legendWidth) : legendWidth;
  111.                 top = !isNaN(top) ? Math.min(top, topHeight) : topHeight;
  112.                 right = !isNaN(right) ? Math.max(legendWidth + itemWidth, right) : legendWidth + itemWidth;
  113.                 bottom = !isNaN(bottom) ? Math.max(topHeight + itemHeight, bottom) : topHeight + itemHeight;
  114.                 node.setStyle("left", legendWidth + PX);
  115.                 node.setStyle("top", topHeight + PX);
  116.                 legendWidth += itemWidth + horizontalGap;
  117.             }
  118.             topHeight += item.height;
  119.         }
  120.         this._contentRect = {
  121.             left: left,
  122.             top: top,
  123.             right: right,
  124.             bottom: bottom
  125.         };
  126.         if(this.get("includeInChartLayout"))
  127.         {
  128.             this.set("height", topHeight + padding.bottom);
  129.         }
  130.     },

  131.     /**
  132.      * Creates row and total width arrays used for displaying multiple rows of
  133.      * legend items based on the items, available width and horizontalGap for the legend.
  134.      *
  135.      * @method _setRowArrays
  136.      * @param {Array} items Array of legend items to display in a legend.
  137.      * @param {Number} limit Total available width for displaying items in a legend.
  138.      * @param {Number} horizontalGap Horizontal distance between items in a legend.
  139.      * @protected
  140.      */
  141.     _setRowArrays: function(items, limit, horizontalGap)
  142.     {
  143.         var item = items[0],
  144.             rowArray = [[item]],
  145.             i = 1,
  146.             rowIterator = 0,
  147.             len = items.length,
  148.             totalWidth = item.width,
  149.             itemWidth,
  150.             totalWidthArray = [[totalWidth]];
  151.         for(; i < len; ++i)
  152.         {
  153.             item = items[i];
  154.             itemWidth = item.width;
  155.             if((totalWidth + horizontalGap + itemWidth) <= limit)
  156.             {
  157.                 totalWidth += horizontalGap + itemWidth;
  158.                 rowArray[rowIterator].push(item);
  159.             }
  160.             else
  161.             {
  162.                 totalWidth = horizontalGap + itemWidth;
  163.                 if(rowArray[rowIterator])
  164.                 {
  165.                     rowIterator += 1;
  166.                 }
  167.                 rowArray[rowIterator] = [item];
  168.             }
  169.             totalWidthArray[rowIterator] = totalWidth;
  170.         }
  171.         HorizontalLegendLayout.rowArray = rowArray;
  172.         HorizontalLegendLayout.totalWidthArray = totalWidthArray;
  173.     },

  174.     /**
  175.      * Returns the starting x-coordinate for a row of legend items.
  176.      *
  177.      * @method getStartPoint
  178.      * @param {Number} w Width of the legend.
  179.      * @param {Number} totalWidth Total width of all labels in the row.
  180.      * @param {String} align Horizontal alignment of items for the legend.
  181.      * @param {Object} padding Object contain left, top, right and bottom padding properties.
  182.      * @return Number
  183.      * @protected
  184.      */
  185.     getStartPoint: function(w, totalWidth, align, padding)
  186.     {
  187.         var startPoint;
  188.         switch(align)
  189.         {
  190.             case LEFT :
  191.                 startPoint = padding.left;
  192.             break;
  193.             case "center" :
  194.                 startPoint = (w - totalWidth) * 0.5;
  195.             break;
  196.             case RIGHT :
  197.                 startPoint = w - totalWidth - padding.right;
  198.             break;
  199.         }
  200.         return startPoint;
  201.     }
  202. },

  203. /**
  204.  * Contains methods for displaying items vertically in a legend.
  205.  *
  206.  * @module charts
  207.  * @submodule charts-legend
  208.  * @class VerticalLegendLayout
  209.  */
  210. VerticalLegendLayout = {
  211.     /**
  212.      * Displays items vertically in a legend.
  213.      *
  214.      * @method _positionLegendItems
  215.      * @param {Array} items Array of items to display in the legend.
  216.      * @param {Number} maxWidth The width of the largest item in the legend.
  217.      * @param {Number} maxHeight The height of the largest item in the legend.
  218.      * @param {Number} totalWidth The total width of all items in a legend.
  219.      * @param {Number} totalHeight The total height of all items in a legend.
  220.      * @param {Number} padding The left, top, right and bottom padding properties for the legend.
  221.      * @param {Number} horizontalGap The horizontal distance between items in a legend.
  222.      * @param {Number} verticalGap The vertical distance between items in a legend.
  223.      * @param {String} hAlign The horizontal alignment of the legend.
  224.      * @param {String} vAlign The vertical alignment of the legend.
  225.      * @protected
  226.      */
  227.     _positionLegendItems: function(items, maxWidth, maxHeight, totalWidth, totalHeight, padding, horizontalGap, verticalGap, hAlign, vAlign)
  228.     {
  229.         var i = 0,
  230.             columnIterator = 0,
  231.             item,
  232.             node,
  233.             itemHeight,
  234.             itemWidth,
  235.             len,
  236.             height = this.get("height"),
  237.             columns,
  238.             columnsLen,
  239.             column,
  240.             totalHeightArray,
  241.             legendHeight,
  242.             leftWidth = padding.left - horizontalGap,
  243.             legendWidth,
  244.             limit = height - (padding.top + padding.bottom),
  245.             left,
  246.             top,
  247.             right,
  248.             bottom;
  249.         VerticalLegendLayout._setColumnArrays(items, limit, verticalGap);
  250.         columns = VerticalLegendLayout.columnArray;
  251.         totalHeightArray = VerticalLegendLayout.totalHeightArray;
  252.         columnsLen = columns.length;
  253.         for(; columnIterator < columnsLen; ++ columnIterator)
  254.         {
  255.             leftWidth += horizontalGap;
  256.             column = columns[columnIterator];
  257.             len = column.length;
  258.             legendHeight =  VerticalLegendLayout.getStartPoint(height, totalHeightArray[columnIterator], vAlign, padding);
  259.             legendWidth = 0;
  260.             for(i = 0; i < len; ++i)
  261.             {
  262.                 item = column[i];
  263.                 node = item.node;
  264.                 itemHeight = item.height;
  265.                 itemWidth = item.width;
  266.                 item.y = legendHeight;
  267.                 item.x = leftWidth;
  268.                 left = !isNaN(left) ? Math.min(left, leftWidth) : leftWidth;
  269.                 top = !isNaN(top) ? Math.min(top, legendHeight) : legendHeight;
  270.                 right = !isNaN(right) ? Math.max(leftWidth + itemWidth, right) : leftWidth + itemWidth;
  271.                 bottom = !isNaN(bottom) ? Math.max(legendHeight + itemHeight, bottom) : legendHeight + itemHeight;
  272.                 node.setStyle("left", leftWidth + PX);
  273.                 node.setStyle("top", legendHeight + PX);
  274.                 legendHeight += itemHeight + verticalGap;
  275.                 legendWidth = Math.max(legendWidth, item.width);
  276.             }
  277.             leftWidth += legendWidth;
  278.         }
  279.         this._contentRect = {
  280.             left: left,
  281.             top: top,
  282.             right: right,
  283.             bottom: bottom
  284.         };
  285.         if(this.get("includeInChartLayout"))
  286.         {
  287.             this.set("width", leftWidth + padding.right);
  288.         }
  289.     },

  290.     /**
  291.      * Creates column and total height arrays used for displaying multiple columns of
  292.      * legend items based on the items, available height and verticalGap for the legend.
  293.      *
  294.      * @method _setColumnArrays
  295.      * @param {Array} items Array of legend items to display in a legend.
  296.      * @param {Number} limit Total available height for displaying items in a legend.
  297.      * @param {Number} verticalGap Vertical distance between items in a legend.
  298.      * @protected
  299.      */
  300.     _setColumnArrays: function(items, limit, verticalGap)
  301.     {
  302.         var item = items[0],
  303.             columnArray = [[item]],
  304.             i = 1,
  305.             columnIterator = 0,
  306.             len = items.length,
  307.             totalHeight = item.height,
  308.             itemHeight,
  309.             totalHeightArray = [[totalHeight]];
  310.         for(; i < len; ++i)
  311.         {
  312.             item = items[i];
  313.             itemHeight = item.height;
  314.             if((totalHeight + verticalGap + itemHeight) <= limit)
  315.             {
  316.                 totalHeight += verticalGap + itemHeight;
  317.                 columnArray[columnIterator].push(item);
  318.             }
  319.             else
  320.             {
  321.                 totalHeight = verticalGap + itemHeight;
  322.                 if(columnArray[columnIterator])
  323.                 {
  324.                     columnIterator += 1;
  325.                 }
  326.                 columnArray[columnIterator] = [item];
  327.             }
  328.             totalHeightArray[columnIterator] = totalHeight;
  329.         }
  330.         VerticalLegendLayout.columnArray = columnArray;
  331.         VerticalLegendLayout.totalHeightArray = totalHeightArray;
  332.     },

  333.     /**
  334.      * Returns the starting y-coordinate for a column of legend items.
  335.      *
  336.      * @method getStartPoint
  337.      * @param {Number} h Height of the legend.
  338.      * @param {Number} totalHeight Total height of all labels in the column.
  339.      * @param {String} align Vertical alignment of items for the legend.
  340.      * @param {Object} padding Object contain left, top, right and bottom padding properties.
  341.      * @return Number
  342.      * @protected
  343.      */
  344.     getStartPoint: function(h, totalHeight, align, padding)
  345.     {
  346.         var startPoint;
  347.         switch(align)
  348.         {
  349.             case TOP :
  350.                 startPoint = padding.top;
  351.             break;
  352.             case "middle" :
  353.                 startPoint = (h - totalHeight) * 0.5;
  354.             break;
  355.             case BOTTOM :
  356.                 startPoint = h - totalHeight - padding.bottom;
  357.             break;
  358.         }
  359.         return startPoint;
  360.     }
  361. },

  362. CartesianChartLegend = Y.Base.create("cartesianChartLegend", Y.CartesianChart, [], {
  363.     /**
  364.      * Redraws and position all the components of the chart instance.
  365.      *
  366.      * @method _redraw
  367.      * @private
  368.      */
  369.     _redraw: function()
  370.     {
  371.         if(this._drawing)
  372.         {
  373.             this._callLater = true;
  374.             return;
  375.         }
  376.         this._drawing = true;
  377.         this._callLater = false;
  378.         var w = this.get("width"),
  379.             h = this.get("height"),
  380.             layoutBoxDimensions = this._getLayoutBoxDimensions(),
  381.             leftPaneWidth = layoutBoxDimensions.left,
  382.             rightPaneWidth = layoutBoxDimensions.right,
  383.             topPaneHeight = layoutBoxDimensions.top,
  384.             bottomPaneHeight = layoutBoxDimensions.bottom,
  385.             leftAxesCollection = this.get("leftAxesCollection"),
  386.             rightAxesCollection = this.get("rightAxesCollection"),
  387.             topAxesCollection = this.get("topAxesCollection"),
  388.             bottomAxesCollection = this.get("bottomAxesCollection"),
  389.             i = 0,
  390.             l,
  391.             axis,
  392.             graphOverflow = "visible",
  393.             graph = this.get("graph"),
  394.             topOverflow,
  395.             bottomOverflow,
  396.             leftOverflow,
  397.             rightOverflow,
  398.             graphWidth,
  399.             graphHeight,
  400.             graphX,
  401.             graphY,
  402.             allowContentOverflow = this.get("allowContentOverflow"),
  403.             diff,
  404.             rightAxesXCoords,
  405.             leftAxesXCoords,
  406.             topAxesYCoords,
  407.             bottomAxesYCoords,
  408.             legend = this.get("legend"),
  409.             graphRect = {};

  410.         if(leftAxesCollection)
  411.         {
  412.             leftAxesXCoords = [];
  413.             l = leftAxesCollection.length;
  414.             for(i = l - 1; i > -1; --i)
  415.             {
  416.                 leftAxesXCoords.unshift(leftPaneWidth);
  417.                 leftPaneWidth += leftAxesCollection[i].get("width");
  418.             }
  419.         }
  420.         if(rightAxesCollection)
  421.         {
  422.             rightAxesXCoords = [];
  423.             l = rightAxesCollection.length;
  424.             i = 0;
  425.             for(i = l - 1; i > -1; --i)
  426.             {
  427.                 rightPaneWidth += rightAxesCollection[i].get("width");
  428.                 rightAxesXCoords.unshift(w - rightPaneWidth);
  429.             }
  430.         }
  431.         if(topAxesCollection)
  432.         {
  433.             topAxesYCoords = [];
  434.             l = topAxesCollection.length;
  435.             for(i = l - 1; i > -1; --i)
  436.             {
  437.                 topAxesYCoords.unshift(topPaneHeight);
  438.                 topPaneHeight += topAxesCollection[i].get("height");
  439.             }
  440.         }
  441.         if(bottomAxesCollection)
  442.         {
  443.             bottomAxesYCoords = [];
  444.             l = bottomAxesCollection.length;
  445.             for(i = l - 1; i > -1; --i)
  446.             {
  447.                 bottomPaneHeight += bottomAxesCollection[i].get("height");
  448.                 bottomAxesYCoords.unshift(h - bottomPaneHeight);
  449.             }
  450.         }

  451.         graphWidth = w - (leftPaneWidth + rightPaneWidth);
  452.         graphHeight = h - (bottomPaneHeight + topPaneHeight);
  453.         graphRect.left = leftPaneWidth;
  454.         graphRect.top = topPaneHeight;
  455.         graphRect.bottom = h - bottomPaneHeight;
  456.         graphRect.right = w - rightPaneWidth;
  457.         if(!allowContentOverflow)
  458.         {
  459.             topOverflow = this._getTopOverflow(leftAxesCollection, rightAxesCollection);
  460.             bottomOverflow = this._getBottomOverflow(leftAxesCollection, rightAxesCollection);
  461.             leftOverflow = this._getLeftOverflow(bottomAxesCollection, topAxesCollection);
  462.             rightOverflow = this._getRightOverflow(bottomAxesCollection, topAxesCollection);

  463.             diff = topOverflow - topPaneHeight;
  464.             if(diff > 0)
  465.             {
  466.                 graphRect.top = topOverflow;
  467.                 if(topAxesYCoords)
  468.                 {
  469.                     i = 0;
  470.                     l = topAxesYCoords.length;
  471.                     for(; i < l; ++i)
  472.                     {
  473.                         topAxesYCoords[i] += diff;
  474.                     }
  475.                 }
  476.             }

  477.             diff = bottomOverflow - bottomPaneHeight;
  478.             if(diff > 0)
  479.             {
  480.                 graphRect.bottom = h - bottomOverflow;
  481.                 if(bottomAxesYCoords)
  482.                 {
  483.                     i = 0;
  484.                     l = bottomAxesYCoords.length;
  485.                     for(; i < l; ++i)
  486.                     {
  487.                         bottomAxesYCoords[i] -= diff;
  488.                     }
  489.                 }
  490.             }

  491.             diff = leftOverflow - leftPaneWidth;
  492.             if(diff > 0)
  493.             {
  494.                 graphRect.left = leftOverflow;
  495.                 if(leftAxesXCoords)
  496.                 {
  497.                     i = 0;
  498.                     l = leftAxesXCoords.length;
  499.                     for(; i < l; ++i)
  500.                     {
  501.                         leftAxesXCoords[i] += diff;
  502.                     }
  503.                 }
  504.             }

  505.             diff = rightOverflow - rightPaneWidth;
  506.             if(diff > 0)
  507.             {
  508.                 graphRect.right = w - rightOverflow;
  509.                 if(rightAxesXCoords)
  510.                 {
  511.                     i = 0;
  512.                     l = rightAxesXCoords.length;
  513.                     for(; i < l; ++i)
  514.                     {
  515.                         rightAxesXCoords[i] -= diff;
  516.                     }
  517.                 }
  518.             }
  519.         }
  520.         graphWidth = graphRect.right - graphRect.left;
  521.         graphHeight = graphRect.bottom - graphRect.top;
  522.         graphX = graphRect.left;
  523.         graphY = graphRect.top;
  524.         if(legend)
  525.         {
  526.             if(legend.get("includeInChartLayout"))
  527.             {
  528.                 switch(legend.get("position"))
  529.                 {
  530.                     case "left" :
  531.                         legend.set("y", graphY);
  532.                         legend.set("height", graphHeight);
  533.                     break;
  534.                     case "top" :
  535.                         legend.set("x", graphX);
  536.                         legend.set("width", graphWidth);
  537.                     break;
  538.                     case "bottom" :
  539.                         legend.set("x", graphX);
  540.                         legend.set("width", graphWidth);
  541.                     break;
  542.                     case "right" :
  543.                         legend.set("y", graphY);
  544.                         legend.set("height", graphHeight);
  545.                     break;
  546.                 }
  547.             }
  548.         }
  549.         if(topAxesCollection)
  550.         {
  551.             l = topAxesCollection.length;
  552.             i = 0;
  553.             for(; i < l; i++)
  554.             {
  555.                 axis = topAxesCollection[i];
  556.                 if(axis.get("width") !== graphWidth)
  557.                 {
  558.                     axis.set("width", graphWidth);
  559.                 }
  560.                 axis.get("boundingBox").setStyle("left", graphX + PX);
  561.                 axis.get("boundingBox").setStyle("top", topAxesYCoords[i] + PX);
  562.             }
  563.             if(axis._hasDataOverflow())
  564.             {
  565.                 graphOverflow = "hidden";
  566.             }
  567.         }
  568.         if(bottomAxesCollection)
  569.         {
  570.             l = bottomAxesCollection.length;
  571.             i = 0;
  572.             for(; i < l; i++)
  573.             {
  574.                 axis = bottomAxesCollection[i];
  575.                 if(axis.get("width") !== graphWidth)
  576.                 {
  577.                     axis.set("width", graphWidth);
  578.                 }
  579.                 axis.get("boundingBox").setStyle("left", graphX + PX);
  580.                 axis.get("boundingBox").setStyle("top", bottomAxesYCoords[i] + PX);
  581.             }
  582.             if(axis._hasDataOverflow())
  583.             {
  584.                 graphOverflow = "hidden";
  585.             }
  586.         }
  587.         if(leftAxesCollection)
  588.         {
  589.             l = leftAxesCollection.length;
  590.             i = 0;
  591.             for(; i < l; ++i)
  592.             {
  593.                 axis = leftAxesCollection[i];
  594.                 axis.get("boundingBox").setStyle("top", graphY + PX);
  595.                 axis.get("boundingBox").setStyle("left", leftAxesXCoords[i] + PX);
  596.                 if(axis.get("height") !== graphHeight)
  597.                 {
  598.                     axis.set("height", graphHeight);
  599.                 }
  600.             }
  601.             if(axis._hasDataOverflow())
  602.             {
  603.                 graphOverflow = "hidden";
  604.             }
  605.         }
  606.         if(rightAxesCollection)
  607.         {
  608.             l = rightAxesCollection.length;
  609.             i = 0;
  610.             for(; i < l; ++i)
  611.             {
  612.                 axis = rightAxesCollection[i];
  613.                 axis.get("boundingBox").setStyle("top", graphY + PX);
  614.                 axis.get("boundingBox").setStyle("left", rightAxesXCoords[i] + PX);
  615.                 if(axis.get("height") !== graphHeight)
  616.                 {
  617.                     axis.set("height", graphHeight);
  618.                 }
  619.             }
  620.             if(axis._hasDataOverflow())
  621.             {
  622.                 graphOverflow = "hidden";
  623.             }
  624.         }
  625.         this._drawing = false;
  626.         if(this._callLater)
  627.         {
  628.             this._redraw();
  629.             return;
  630.         }
  631.         if(graph)
  632.         {
  633.             graph.get("boundingBox").setStyle("left", graphX + PX);
  634.             graph.get("boundingBox").setStyle("top", graphY + PX);
  635.             graph.set("width", graphWidth);
  636.             graph.set("height", graphHeight);
  637.             graph.get("boundingBox").setStyle("overflow", graphOverflow);
  638.         }

  639.         if(this._overlay)
  640.         {
  641.             this._overlay.setStyle("left", graphX + PX);
  642.             this._overlay.setStyle("top", graphY + PX);
  643.             this._overlay.setStyle("width", graphWidth + PX);
  644.             this._overlay.setStyle("height", graphHeight + PX);
  645.         }
  646.     },

  647.     /**
  648.      * Positions the legend in a chart and returns the properties of the legend to be used in the
  649.      * chart's layout algorithm.
  650.      *
  651.      * @method _getLayoutDimensions
  652.      * @return {Object} The left, top, right and bottom values for the legend.
  653.      * @protected
  654.      */
  655.     _getLayoutBoxDimensions: function()
  656.     {
  657.         var box = {
  658.                 top: 0,
  659.                 right: 0,
  660.                 bottom: 0,
  661.                 left: 0
  662.             },
  663.             legend = this.get("legend"),
  664.             position,
  665.             direction,
  666.             dimension,
  667.             size,
  668.             w = this.get(WIDTH),
  669.             h = this.get(HEIGHT),
  670.             gap;
  671.         if(legend && legend.get("includeInChartLayout"))
  672.         {
  673.             gap = legend.get("styles").gap;
  674.             position = legend.get(POSITION);
  675.             if(position != EXTERNAL)
  676.             {
  677.                 direction = legend.get("direction");
  678.                 dimension = direction == HORIZONTAL ? HEIGHT : WIDTH;
  679.                 size = legend.get(dimension);
  680.                 box[position] = size + gap;
  681.                 switch(position)
  682.                 {
  683.                     case TOP :
  684.                         legend.set(_Y, 0);
  685.                     break;
  686.                     case BOTTOM :
  687.                         legend.set(_Y, h - size);
  688.                     break;
  689.                     case RIGHT :
  690.                         legend.set(_X, w - size);
  691.                     break;
  692.                     case LEFT:
  693.                         legend.set(_X, 0);
  694.                     break;
  695.                 }
  696.             }
  697.         }
  698.         return box;
  699.     },

  700.     /**
  701.      * Destructor implementation for the CartesianChart class. Calls destroy on all axes, series, legend (if available) and the Graph instance.
  702.      * Removes the tooltip and overlay HTML elements.
  703.      *
  704.      * @method destructor
  705.      * @protected
  706.      */
  707.     destructor: function()
  708.     {
  709.         var legend = this.get("legend");
  710.         if(legend)
  711.         {
  712.             legend.destroy(true);
  713.         }
  714.     }
  715. }, {
  716.     ATTRS: {
  717.         legend: LEGEND
  718.     }
  719. });

  720. Y.CartesianChart = CartesianChartLegend;


  721.