8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * ChartLegend provides a legend for a chart.
6f294bea19c397d53e471007448460655f4b8c6bTripp * @class ChartLegend
6f294bea19c397d53e471007448460655f4b8c6bTripp * @module charts
6f294bea19c397d53e471007448460655f4b8c6bTripp * @submodule charts-legend
da3ddd5c4296cb8a5aff1cee3e14b469fb5c6cc7Tripp * @extends Widget
8215dd9a19d775d6391d4f44be2ca8268952e048TrippY.ChartLegend = Y.Base.create("chartlegend", Y.Widget, [Y.Renderer], {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Initializes the chart.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method initializer
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method renderUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method bindUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp bindUI: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.get("chart").after("seriesCollectionChange", this._updateHandler);
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this.after("positionChange", this._positionChangeHandler);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method syncUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp syncUI: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Handles changes to legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _updateHandler
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} e Event object
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * Handles position changes.
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * @method _positionChangeHandler
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * @parma {Object} e Event object
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(parentNode && ((chart && this.get("includeInChartLayout"))))
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Updates the legend when the size changes.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _handleSizeChange
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} e Event object.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if((hor && attrName == WIDTH) || (vert && attrName == HEIGHT))
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Draws the legend
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _drawLegend
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._callLater = true;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawing = true;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._callLater = false;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp displayName = series.get("categoryAxis").getDataByKey(series.get("categoryKey"));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for(; i < len; ++i)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp displayName = chart.getSeriesItems(series, i).category.value;
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp item = this._getLegendItem(node, this._getShapeClass(shape), fill, border, labelStyles, markerWidth, markerHeight, displayName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for(; i < len; ++i)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp seriesStyles = this._getStylesBySeriesType(series, shape);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shapeClass = Y.Lang.isArray(shape) ? shape[i] : shape;
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp item = this._getLegendItem(node, this._getShapeClass(shape), seriesStyles.fill, seriesStyles.border, labelStyles, markerWidth, markerHeight, series.get("valueDisplayName"));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawing = false;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp layout._positionLegendItems.apply(this, [items, maxWidth, maxHeight, totalWidth, totalHeight, padding, hSpacing, vSpacing, hAlign, vAlign]);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Updates the background for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _updateBackground
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} styles Reference to the legend's styles attribute
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Retrieves the marker styles based on the type of series. For series that contain a marker, the marker styles are returned.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getStylesBySeriesType
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {CartesianSeries | PieSeries} The series in which the style properties will be received.
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * @return Object An object containing fill, border and shape information.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(series instanceof Y.LineSeries || series instanceof Y.StackedLineSeries)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else if(series instanceof Y.AreaSeries || series instanceof Y.StackedAreaSeries)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns a legend item consisting of the following properties:
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <dt>node</dt><dd>The `Node` containing the legend item elements.</dd>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <dt>shape</dt><dd>The `Shape` element for the legend item.</dd>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <dt>textNode</dt><dd>The `Node` containing the text></dd>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <dt>text</dt><dd></dd>
da3ddd5c4296cb8a5aff1cee3e14b469fb5c6cc7Tripp * @method _getLegendItem
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Node} shapeProps Reference to the `node` attribute.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {String | Class} shapeClass The type of shape
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} fill Properties for the shape's fill
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * @param {Object} border Properties for the shape's border
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {String} text String to be rendered as the legend's text
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Number} width Total width of the legend item
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Number} height Total height of the legend item
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {HTML | String} text Text for the legendItem
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Object
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp _getLegendItem: function(node, shapeClass, fill, border, labelStyles, w, h, text)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var containerNode = Y.one(DOCUMENT.createElement("div")),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp containerNode.setStyle("width", (left + textField.get("offsetWidth")) + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Evaluates and returns correct class for drawing a shape.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getShapeClass
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Shape
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return graphic._getShapeClass.apply(graphic, arguments);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns the default hash for the `styles` attribute.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getDefaultStyles
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Gets the default values for series that use the utility. This method is used by
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * the class' `styles` attribute's getter to get build default values.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getPlotDefaults
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Destroys legend items.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _destroyLegendItems
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Maps layout classes.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @property _layout
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Destructor implementation ChartLegend class. Removes all items and the Graphic instance from the widget.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method destructor
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates whether the chart's contentBox is the parentNode for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute includeInChartLayout
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Boolean
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Reference to the `Chart` instance.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute chart
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Chart
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this.after("legendRendered", Y.bind(val._itemRendered, val));
8e068aa1d802b124b5647c0998209e82fee60addTripp * Indicates the direction in relation of the legend's layout. The `direction` of the legend is determined by its
8e068aa1d802b124b5647c0998209e82fee60addTripp * `position` value.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute direction
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type String
8e068aa1d802b124b5647c0998209e82fee60addTripp * Indicates the position and direction of the legend. Possible values are `left`, `top`, `right` and `bottom`. Values of `left` and
8e068aa1d802b124b5647c0998209e82fee60addTripp * `right` values have a `direction` of `vertical`. Values of `top` and `bottom` values have a `direction` of `horizontal`.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute position
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type String
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The width of the legend. Depending on the implementation of the ChartLegend, this value is `readOnly`. By default, the legend is included in the layout of the `Chart` that
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * it references. Under this circumstance, `width` is always `readOnly`. When the legend is rendered in its own dom element, the `readOnly` status is determined by the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * direction of the legend. If the `position` is `left` or `right` or the `direction` is `vertical`, width is `readOnly`. If the position is `top` or `bottom` or the `direction`
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * is `horizontal`, width can be explicitly set. If width is not explicitly set, the width will be determined by the width of the legend's parent element.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute width
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp getter: function()
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if((chart && this.get("includeInChartLayout")) || this._width)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return this._width;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The height of the legend. Depending on the implementation of the ChartLegend, this value is `readOnly`. By default, the legend is included in the layout of the `Chart` that
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * it references. Under this circumstance, `height` is always `readOnly`. When the legend is rendered in its own dom element, the `readOnly` status is determined by the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * direction of the legend. If the `position` is `top` or `bottom` or the `direction` is `horizontal`, height is `readOnly`. If the position is `left` or `right` or the `direction`
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * is `vertical`, height can be explicitly set. If height is not explicitly set, the height will be determined by the width of the legend's parent element.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute height
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp getter: function()
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if((chart && this.get("includeInChartLayout")) || this._height)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return this._height;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates the x position of legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute x
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates the y position of legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute y
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Background for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute background
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Rect
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * Properties used to display and style the ChartLegend. This attribute is inherited from `Renderer`. Below are the default values:
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>gap</dt><dd>Distance, in pixels, between the `ChartLegend` instance and the chart's content. When `ChartLegend` is rendered within a `Chart` instance this value is applied.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>hAlign</dt><dd>Defines the horizontal alignment of the `items` in a `ChartLegend` rendered in a horizontal direction. This value is applied when the instance's `position` is set to top or bottom. This attribute can be set to left, center or right. The default value is center.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>vAlign</dt><dd>Defines the vertical alignment of the `items` in a `ChartLegend` rendered in vertical direction. This value is applied when the instance's `position` is set to left or right. The attribute can be set to top, middle or bottom. The default value is middle.</dd>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * <dt>item</dt><dd>Set of style properties applied to the `items` of the `ChartLegend`.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>hSpacing</dt><dd>Horizontal distance, in pixels, between legend `items`.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>vSpacing</dt><dd>Vertical distance, in pixels, between legend `items`.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>label</dt><dd>Properties for the text of an `item`.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>color</dt><dd>Color of the text. The default values is "#808080".</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>fontSize</dt><dd>Font size for the text. The default value is "85%".</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>marker</dt><dd>Properties for the `item` markers.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>width</dt><dd>Specifies the width of the markers.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>height</dt><dd>Specifies the height of the markers.</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>background</dt><dd>Properties for the `ChartLegend` background.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>fill</dt><dd>Properties for the background fill.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>color</dt><dd>Color for the fill. The default value is "#faf9f2".</dd>
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * <dt>border</dt><dd>Properties for the background border.
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * <dt>color</dt><dd>Color for the border. The default value is "#dad8c9".</dd>
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * <dt>weight</dt><dd>Weight of the border. The default values is 1.</dd>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @attribute styles
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @type Object