"),
textField = Y.Node.create("
"),
shape,
dimension,
padding,
left,
item,
ShapeClass = shapeClass;
containerNode.setStyle(POSITION, "absolute");
textField.setStyle(POSITION, "absolute");
textField.setStyles(labelStyles);
textField.set("text", text);
containerNode.appendChild(textField);
node.append(containerNode);
dimension = textField.get("offsetHeight");
padding = dimension - h;
left = w + padding + 2;
textField.setStyle("left", left + PX);
containerNode.setStyle("height", dimension + PX);
containerNode.setStyle("width", (left + textField.get("offsetWidth")) + PX);
shape = new ShapeClass({
fill: fill,
stroke: border,
width: w,
height: h,
x: padding * 0.5,
y: padding * 0.5,
w: w,
h: h,
graphic: containerNode
});
textField.setStyle("left", dimension + PX);
item = {
node: containerNode,
width: containerNode.get("offsetWidth"),
height: containerNode.get("offsetHeight"),
shape: shape,
textNode: textField,
text: text
};
this._items.push(item);
return item;
},
/**
* Evaluates and returns correct class for drawing a shape.
*
* @method _getShapeClass
* @return Shape
* @private
*/
_getShapeClass: function()
{
var graphic = this.get("background").get("graphic");
return graphic._getShapeClass.apply(graphic, arguments);
},
/**
* Returns the default hash for the `styles` attribute.
*
* @method _getDefaultStyles
* @return Object
* @protected
*/
_getDefaultStyles: function()
{
var styles = {
padding: {
top: 8,
right: 8,
bottom: 8,
left: 9
},
gap: 10,
hAlign: "center",
vAlign: "top",
marker: this._getPlotDefaults(),
item: {
hSpacing: 10,
vSpacing: 5,
label: {
color:"#808080",
fontSize:"85%",
whiteSpace: "nowrap"
}
},
background: {
shape: "rect",
fill:{
color:"#faf9f2"
},
border: {
color:"#dad8c9",
weight: 1
}
}
};
return styles;
},
/**
* Gets the default values for series that use the utility. This method is used by
* the class' `styles` attribute's getter to get build default values.
*
* @method _getPlotDefaults
* @return Object
* @protected
*/
_getPlotDefaults: function()
{
var defs = {
width: 10,
height: 10
};
return defs;
},
/**
* Destroys legend items.
*
* @method _destroyLegendItems
* @private
*/
_destroyLegendItems: function()
{
var item;
if(this._items)
{
while(this._items.length > 0)
{
item = this._items.shift();
item.shape.get("graphic").destroy();
item.node.empty();
item.node.destroy(true);
item.node = null;
item = null;
}
}
this._items = [];
},
/**
* Maps layout classes.
*
* @property _layout
* @private
*/
_layout: {
vertical: VerticalLegendLayout,
horizontal: HorizontalLegendLayout
},
/**
* Destructor implementation ChartLegend class. Removes all items and the Graphic instance from the widget.
*
* @method destructor
* @protected
*/
destructor: function()
{
var background = this.get("background"),
backgroundGraphic;
this._destroyLegendItems();
if(background)
{
backgroundGraphic = background.get("graphic");
if(backgroundGraphic)
{
backgroundGraphic.destroy();
}
else
{
background.destroy();
}
}
}
}, {
ATTRS: {
/**
* Indicates whether the chart's contentBox is the parentNode for the legend.
*
* @attribute includeInChartLayout
* @type Boolean
* @private
*/
includeInChartLayout: {
value: false
},
/**
* Reference to the `Chart` instance.
*
* @attribute chart
* @type Chart
*/
chart: {
setter: function(val)
{
this.after("legendRendered", Y.bind(val._itemRendered, val));
return val;
}
},
/**
* Indicates the direction in relation of the legend's layout. The `direction` of the legend is determined by its
* `position` value.
*
* @attribute direction
* @type String
*/
direction: {
value: "vertical"
},
/**
* Indicates the position and direction of the legend. Possible values are `left`, `top`, `right` and `bottom`.
* Values of `left` and `right` values have a `direction` of `vertical`. Values of `top` and `bottom` values have
* a `direction` of `horizontal`.
*
* @attribute position
* @type String
*/
position: {
lazyAdd: false,
value: "right",
setter: function(val)
{
if(val === TOP || val === BOTTOM)
{
this.set("direction", HORIZONTAL);
}
else if(val === LEFT || val === RIGHT)
{
this.set("direction", VERTICAL);
}
return val;
}
},
/**
* 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 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 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` 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.
*
* @attribute width
* @type Number
*/
width: {
getter: function()
{
var chart = this.get("chart"),
parentNode = this._parentNode;
if(parentNode)
{
if((chart && this.get("includeInChartLayout")) || this._width)
{
if(!this._width)
{
this._width = 0;
}
return this._width;
}
else
{
return parentNode.get("offsetWidth");
}
}
return "";
},
setter: function(val)
{
this._width = val;
return val;
}
},
/**
* 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 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 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` 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.
*
* @attribute height
* @type Number
*/
height: {
valueFn: "_heightGetter",
getter: function()
{
var chart = this.get("chart"),
parentNode = this._parentNode;
if(parentNode)
{
if((chart && this.get("includeInChartLayout")) || this._height)
{
if(!this._height)
{
this._height = 0;
}
return this._height;
}
else
{
return parentNode.get("offsetHeight");
}
}
return "";
},
setter: function(val)
{
this._height = val;
return val;
}
},
/**
* Indicates the x position of legend.
*
* @attribute x
* @type Number
* @readOnly
*/
x: {
lazyAdd: false,
value: 0,
setter: function(val)
{
var node = this.get("boundingBox");
if(node)
{
node.setStyle(LEFT, val + PX);
}
return val;
}
},
/**
* Indicates the y position of legend.
*
* @attribute y
* @type Number
* @readOnly
*/
y: {
lazyAdd: false,
value: 0,
setter: function(val)
{
var node = this.get("boundingBox");
if(node)
{
node.setStyle(TOP, val + PX);
}
return val;
}
},
/**
* Array of items contained in the legend. Each item is an object containing the following properties:
*
*
* - node
- Node containing text for the legend item.
* - marker
- Shape for the legend item.
*
*
* @attribute items
* @type Array
* @readOnly
*/
items: {
getter: function()
{
return this._items;
}
},
/**
* Background for the legend.
*
* @attribute background
* @type Rect
*/
background: {}
/**
* Properties used to display and style the ChartLegend. This attribute is inherited from `Renderer`.
* Below are the default values:
*
*
* - gap
- Distance, in pixels, between the `ChartLegend` instance and the chart's content. When `ChartLegend`
* is rendered within a `Chart` instance this value is applied.
* - hAlign
- 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.
* - vAlign
- 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.
* - item
- Set of style properties applied to the `items` of the `ChartLegend`.
*
* - hSpacing
- Horizontal distance, in pixels, between legend `items`.
* - vSpacing
- Vertical distance, in pixels, between legend `items`.
* - label
- Properties for the text of an `item`.
*
* - color
- Color of the text. The default values is "#808080".
* - fontSize
- Font size for the text. The default value is "85%".
*
*
* - marker
- Properties for the `item` markers.
*
* - width
- Specifies the width of the markers.
* - height
- Specifies the height of the markers.
*
*
*
*
* - background
- Properties for the `ChartLegend` background.
*
* - fill
- Properties for the background fill.
*
* - color
- Color for the fill. The default value is "#faf9f2".
*
*
* - border
- Properties for the background border.
*
* - color
- Color for the border. The default value is "#dad8c9".
* - weight
- Weight of the border. The default values is 1.
*
*
*
*
*
*
* @attribute styles
* @type Object
*/
}
});
}, '3.17.2', {"requires": ["charts-base"]});