8215dd9a19d775d6391d4f44be2ca8268952e048Tripp/**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * ChartLegend provides a legend for a chart.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
6f294bea19c397d53e471007448460655f4b8c6bTripp * @class ChartLegend
6f294bea19c397d53e471007448460655f4b8c6bTripp * @module charts
6f294bea19c397d53e471007448460655f4b8c6bTripp * @submodule charts-legend
da3ddd5c4296cb8a5aff1cee3e14b469fb5c6cc7Tripp * @extends Widget
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048TrippY.ChartLegend = Y.Base.create("chartlegend", Y.Widget, [Y.Renderer], {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Initializes the chart.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method initializer
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp initializer: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._items = [];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method renderUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp renderUI: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var bb = this.get("boundingBox"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cb = this.get("contentBox"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp styles = this.get("styles").background,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp background = new Y.Rect({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp graphic: cb,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: styles.fill,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp stroke: styles.border
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp });
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp bb.setStyle("display", "block");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp bb.setStyle("position", "absolute");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.set("background", background);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method bindUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp bindUI: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.get("chart").after("seriesCollectionChange", this._updateHandler);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.after("stylesChange", this._updateHandler);
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this.after("positionChange", this._positionChangeHandler);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.after("widthChange", this._handleSizeChange);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.after("heightChange", this._handleSizeChange);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method syncUI
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp syncUI: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var w = this.get("width"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp h = this.get("height");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(isFinite(w) && isFinite(h) && w > 0 && h > 0)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawLegend();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Handles changes to legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _updateHandler
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} e Event object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _updateHandler: function(e)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(this.get("rendered"))
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawLegend();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp /**
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * Handles position changes.
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp *
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * @method _positionChangeHandler
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * @parma {Object} e Event object
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp * @private
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp */
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp _positionChangeHandler: function(e)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp var chart = this.get("chart"),
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp parentNode = this._parentNode;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(parentNode && ((chart && this.get("includeInChartLayout"))))
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this.fire("legendRendered");
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp else if(this.get("rendered"))
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this._drawLegend();
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp },
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Updates the legend when the size changes.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _handleSizeChange
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} e Event object.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _handleSizeChange: function(e)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var attrName = e.attrName,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp pos = this.get(POSITION),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp vert = pos == LEFT || pos == RIGHT,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hor = pos == BOTTOM || pos == TOP;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if((hor && attrName == WIDTH) || (vert && attrName == HEIGHT))
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawLegend();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Draws the legend
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _drawLegend
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _drawLegend: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(this._drawing)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._callLater = true;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawing = true;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._callLater = false;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(this.get("includeInChartLayout"))
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.get("chart")._itemRenderQueue.unshift(this);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var chart = this.get("chart"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node = this.get("contentBox"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp seriesCollection = chart.get("seriesCollection"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp series,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp styles = this.get("styles"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp padding = styles.padding,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp itemStyles = styles.item,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp seriesStyles,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp hSpacing = itemStyles.hSpacing,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp vSpacing = itemStyles.vSpacing,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hAlign = styles.hAlign,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp vAlign = styles.vAlign,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp marker = styles.marker,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp labelStyles = itemStyles.label,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp displayName,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp layout = this._layout[this.get("direction")],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp i,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp len,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp isArray,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shapeClass,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fillColors,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp borderColors,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp borderWeight,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp items = [],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp markerWidth = marker.width,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp markerHeight = marker.height,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalWidth = 0 - hSpacing,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalHeight = 0 - vSpacing,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxWidth = 0,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxHeight = 0,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp itemWidth,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp itemHeight;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(marker && marker.shape)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = marker.shape;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._destroyLegendItems();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(chart instanceof Y.PieChart)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp series = seriesCollection[0];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp displayName = series.get("categoryAxis").getDataByKey(series.get("categoryKey"));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp seriesStyles = series.get("styles").marker;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fillColors = seriesStyles.fill.colors;
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp borderColors = seriesStyles.border.colors;
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp borderWeight = seriesStyles.border.weight;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp i = 0;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp len = displayName.length;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = shape || Y.Circle;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp isArray = Y.Lang.isArray(shape);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for(; i < len; ++i)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = isArray ? shape[i] : shape;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: fillColors[i]
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border = {
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp colors: borderColors[i],
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp weight: borderWeight
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp displayName = chart.getSeriesItems(series, i).category.value;
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp item = this._getLegendItem(node, this._getShapeClass(shape), fill, border, labelStyles, markerWidth, markerHeight, displayName);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp itemWidth = item.width;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp itemHeight = item.height;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxWidth = Math.max(maxWidth, itemWidth);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxHeight = Math.max(maxHeight, itemHeight);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalWidth += itemWidth + hSpacing;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalHeight += itemHeight + vSpacing;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp items.push(item);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp i = 0;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp len = seriesCollection.length;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for(; i < len; ++i)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp series = seriesCollection[i];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp seriesStyles = this._getStylesBySeriesType(series, shape);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(!shape)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = seriesStyles.shape;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(!shape)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = Y.Circle;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
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 itemWidth = item.width;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp itemHeight = item.height;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxWidth = Math.max(maxWidth, itemWidth);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp maxHeight = Math.max(maxHeight, itemHeight);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalWidth += itemWidth + hSpacing;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp totalHeight += itemHeight + vSpacing;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp items.push(item);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.set("items", items);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawing = false;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(this._callLater)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._drawLegend();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp layout._positionLegendItems.apply(this, [items, maxWidth, maxHeight, totalWidth, totalHeight, padding, hSpacing, vSpacing, hAlign, vAlign]);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._updateBackground(styles);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.fire("legendRendered");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Updates the background for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _updateBackground
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} styles Reference to the legend's styles attribute
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _updateBackground: function(styles)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var backgroundStyles = styles.background,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp contentRect = this._contentRect,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp padding = styles.padding,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp x = contentRect.left - padding.left,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp y = contentRect.top - padding.top,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp w = contentRect.right - x + padding.right,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp h = contentRect.bottom - y + padding.bottom;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.get("background").set({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: backgroundStyles.fill,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp stroke: backgroundStyles.border,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp width: w,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp height: h,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp x: x,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp y: y
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp });
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Retrieves the marker styles based on the type of series. For series that contain a marker, the marker styles are returned.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
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 * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getStylesBySeriesType: function(series)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var styles = series.get("styles");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(series instanceof Y.LineSeries || series instanceof Y.StackedLineSeries)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp styles = series.get("styles").line;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return {
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp weight: 1,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: styles.color
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: styles.color
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else if(series instanceof Y.AreaSeries || series instanceof Y.StackedAreaSeries)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp series = series.get("styles").fill;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return {
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp weight: 1,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: styles.color
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: styles.color
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp styles = series.get("styles").marker;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: styles.fill,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp weight: styles.border.weight,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color: styles.border.color,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape: styles.shape
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape: styles.shape
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns a legend item consisting of the following properties:
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <dl>
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>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </dl>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
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
da3ddd5c4296cb8a5aff1cee3e14b469fb5c6cc7Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp _getLegendItem: function(node, shapeClass, fill, border, labelStyles, w, h, text)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var containerNode = Y.one(DOCUMENT.createElement("div")),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField = Y.one(DOCUMENT.createElement("span")),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dimension,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp padding,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp left,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp containerNode.setStyle(POSITION, "absolute");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField.setStyle(POSITION, "absolute");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField.setStyles(labelStyles);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField.appendChild(DOCUMENT.createTextNode(text));
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp containerNode.appendChild(textField);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.appendChild(containerNode);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dimension = textField.get("offsetHeight");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp padding = dimension - h;
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp left = w + padding + 2;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField.setStyle("left", left + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp containerNode.setStyle("height", dimension + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp containerNode.setStyle("width", (left + textField.get("offsetWidth")) + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape = new shapeClass({
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill: fill,
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp stroke: border,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp width: w,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp height: h,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp x: padding * 0.5,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp y: padding * 0.5,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp w: w,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp h: h,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp graphic: containerNode
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp });
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textField.setStyle("left", dimension + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node: containerNode,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp width: containerNode.get("offsetWidth"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp height: containerNode.get("offsetHeight"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape: shape,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp textNode: textField,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp text: text
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._items.push(item);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return item;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Evaluates and returns correct class for drawing a shape.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getShapeClass
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Shape
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getShapeClass: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var graphic = this.get("background").get("graphic");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return graphic._getShapeClass.apply(graphic, arguments);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns the default hash for the `styles` attribute.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getDefaultStyles
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getDefaultStyles: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var styles = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp padding: {
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp top: 8,
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp right: 8,
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp bottom: 8,
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp left: 9
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp gap: 10,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hAlign: "center",
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp vAlign: "top",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp marker: this._getPlotDefaults(),
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp item: {
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp hSpacing: 10,
d1c376aafbfc53c1717827c05e73f9f2f3f579a8Tripp vSpacing: 5,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp label: {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp color:"#808080",
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp fontSize:"85%"
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp background: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp shape: "rect",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp fill:{
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color:"#faf9f2"
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp border: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp color:"#dad8c9",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp weight: 1
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return styles;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
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 *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getPlotDefaults
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return Object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getPlotDefaults: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var defs = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp width: 10,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp height: 10
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return defs;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Destroys legend items.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _destroyLegendItems
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _destroyLegendItems: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var item;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(this._items)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp while(this._items.length > 0)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item = this._items.shift();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item.shape.get("graphic").destroy();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item.node.empty();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item.node.remove(true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp item = null;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._items = [];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Maps layout classes.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @property _layout
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _layout: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp vertical: VerticalLegendLayout,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp horizontal: HorizontalLegendLayout
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Destructor implementation ChartLegend class. Removes all items and the Graphic instance from the widget.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method destructor
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp destructor: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var graphic = this.get("graphic");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._destroyLegendItems();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(graphic)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp graphic.destroy();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp}, {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ATTRS: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates whether the chart's contentBox is the parentNode for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute includeInChartLayout
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Boolean
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp includeInChartLayout: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value: false
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Reference to the `Chart` instance.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute chart
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Chart
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp chart: {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp setter: function(val)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this.after("legendRendered", Y.bind(val._itemRendered, val));
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return val;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8e068aa1d802b124b5647c0998209e82fee60addTripp * Indicates the direction in relation of the legend's layout. The `direction` of the legend is determined by its
8e068aa1d802b124b5647c0998209e82fee60addTripp * `position` value.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute direction
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type String
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp direction: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value: "vertical"
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
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 *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute position
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type String
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp position: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp lazyAdd: false,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value: "right",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp setter: function(val)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(val == TOP || val == BOTTOM)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.set("direction", HORIZONTAL);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp else if(val == LEFT || val == RIGHT)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.set("direction", VERTICAL);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
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 *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute width
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp width: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp getter: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var chart = this.get("chart"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp parentNode = this._parentNode;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(parentNode)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if((chart && this.get("includeInChartLayout")) || this._width)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(!this._width)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this._width = 0;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return this._width;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp else
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return parentNode.get("offsetWidth");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return "";
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp setter: function(val)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._width = val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
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 *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute height
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp height: {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp valueFn: "_heightGetter",
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp getter: function()
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var chart = this.get("chart"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp parentNode = this._parentNode;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(parentNode)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if((chart && this.get("includeInChartLayout")) || this._height)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp if(!this._height)
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp this._height = 0;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return this._height;
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp else
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp {
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return parentNode.get("offsetHeight");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
5d94d504e19f298c447f1f6a645f4be56e2f0fa9Tripp return "";
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp setter: function(val)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._height = val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates the x position of legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute x
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp x: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp lazyAdd: false,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value: 0,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp setter: function(val)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = this.get("boundingBox");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(node)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.setStyle(LEFT, val + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Indicates the y position of legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute y
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Number
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp y: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp lazyAdd: false,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value: 0,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp setter: function(val)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var node = this.get("boundingBox");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if(node)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp node.setStyle(TOP, val + PX);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return val;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Background for the legend.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute background
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Rect
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp background: {}
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp /**
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * Properties used to display and style the ChartLegend. This attribute is inherited from `Renderer`. Below are the default values:
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp *
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * <dl>
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 * <dl>
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 * <dl>
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 * </dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>marker</dt><dd>Properties for the `item` markers.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dl>
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 * </dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dl>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * </dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>background</dt><dd>Properties for the `ChartLegend` background.
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * <dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>fill</dt><dd>Properties for the background fill.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dt>color</dt><dd>Color for the fill. The default value is "#faf9f2".</dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dd>
51ee7e992d203c6f797c3ea193d031fed7a1b846Tripp * <dt>border</dt><dd>Properties for the background border.
6f294bea19c397d53e471007448460655f4b8c6bTripp * <dl>
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>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dl>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dd>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * </dl>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * </dd>
6f294bea19c397d53e471007448460655f4b8c6bTripp * </dl>
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp *
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @attribute styles
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @type Object
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp});