2
YUI 3.13.0 (build 508226d)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('charts-legend', function (Y, NAME) {
11
* Adds legend functionality to charts.
14
* @submodule charts-legend
16
var DOCUMENT = Y.config.doc,
21
EXTERNAL = "external",
22
HORIZONTAL = "horizontal",
23
VERTICAL = "vertical",
26
POSITION = "position",
34
var legend = this.get("legend");
39
if(val instanceof Y.ChartLegend)
42
legend.set("chart", this);
47
if(!val.hasOwnProperty("render"))
49
val.render = this.get("contentBox");
50
val.includeInChartLayout = true;
52
legend = new Y.ChartLegend(val);
59
* Contains methods for displaying items horizontally in a legend.
62
* @submodule charts-legend
63
* @class HorizontalLegendLayout
65
HorizontalLegendLayout = {
67
* Displays items horizontally in a legend.
69
* @method _positionLegendItems
70
* @param {Array} items Array of items to display in the legend.
71
* @param {Number} maxWidth The width of the largest item in the legend.
72
* @param {Number} maxHeight The height of the largest item in the legend.
73
* @param {Number} totalWidth The total width of all items in a legend.
74
* @param {Number} totalHeight The total height of all items in a legend.
75
* @param {Number} padding The left, top, right and bottom padding properties for the legend.
76
* @param {Number} horizontalGap The horizontal distance between items in a legend.
77
* @param {Number} verticalGap The vertical distance between items in a legend.
78
* @param {String} hAlign The horizontal alignment of the legend.
81
_positionLegendItems: function(items, maxWidth, maxHeight, totalWidth, totalHeight, padding, horizontalGap, verticalGap, hAlign)
90
width = this.get("width"),
96
topHeight = padding.top - verticalGap,
97
limit = width - (padding.left + padding.right),
102
HorizontalLegendLayout._setRowArrays(items, limit, horizontalGap);
103
rows = HorizontalLegendLayout.rowArray;
104
totalWidthArray = HorizontalLegendLayout.totalWidthArray;
105
rowsLen = rows.length;
106
for(; rowIterator < rowsLen; ++ rowIterator)
108
topHeight += verticalGap;
109
row = rows[rowIterator];
111
legendWidth = HorizontalLegendLayout.getStartPoint(width, totalWidthArray[rowIterator], hAlign, padding);
112
for(i = 0; i < len; ++i)
116
itemWidth = item.width;
117
itemHeight = item.height;
118
item.x = legendWidth;
120
left = !isNaN(left) ? Math.min(left, legendWidth) : legendWidth;
121
top = !isNaN(top) ? Math.min(top, topHeight) : topHeight;
122
right = !isNaN(right) ? Math.max(legendWidth + itemWidth, right) : legendWidth + itemWidth;
123
bottom = !isNaN(bottom) ? Math.max(topHeight + itemHeight, bottom) : topHeight + itemHeight;
124
node.setStyle("left", legendWidth + PX);
125
node.setStyle("top", topHeight + PX);
126
legendWidth += itemWidth + horizontalGap;
128
topHeight += item.height;
130
this._contentRect = {
136
if(this.get("includeInChartLayout"))
138
this.set("height", topHeight + padding.bottom);
143
* Creates row and total width arrays used for displaying multiple rows of
144
* legend items based on the items, available width and horizontalGap for the legend.
146
* @method _setRowArrays
147
* @param {Array} items Array of legend items to display in a legend.
148
* @param {Number} limit Total available width for displaying items in a legend.
149
* @param {Number} horizontalGap Horizontal distance between items in a legend.
152
_setRowArrays: function(items, limit, horizontalGap)
159
totalWidth = item.width,
161
totalWidthArray = [[totalWidth]];
165
itemWidth = item.width;
166
if((totalWidth + horizontalGap + itemWidth) <= limit)
168
totalWidth += horizontalGap + itemWidth;
169
rowArray[rowIterator].push(item);
173
totalWidth = horizontalGap + itemWidth;
174
if(rowArray[rowIterator])
178
rowArray[rowIterator] = [item];
180
totalWidthArray[rowIterator] = totalWidth;
182
HorizontalLegendLayout.rowArray = rowArray;
183
HorizontalLegendLayout.totalWidthArray = totalWidthArray;
187
* Returns the starting x-coordinate for a row of legend items.
189
* @method getStartPoint
190
* @param {Number} w Width of the legend.
191
* @param {Number} totalWidth Total width of all labels in the row.
192
* @param {String} align Horizontal alignment of items for the legend.
193
* @param {Object} padding Object contain left, top, right and bottom padding properties.
197
getStartPoint: function(w, totalWidth, align, padding)
203
startPoint = padding.left;
206
startPoint = (w - totalWidth) * 0.5;
209
startPoint = w - totalWidth - padding.right;
217
* Contains methods for displaying items vertically in a legend.
220
* @submodule charts-legend
221
* @class VerticalLegendLayout
223
VerticalLegendLayout = {
225
* Displays items vertically in a legend.
227
* @method _positionLegendItems
228
* @param {Array} items Array of items to display in the legend.
229
* @param {Number} maxWidth The width of the largest item in the legend.
230
* @param {Number} maxHeight The height of the largest item in the legend.
231
* @param {Number} totalWidth The total width of all items in a legend.
232
* @param {Number} totalHeight The total height of all items in a legend.
233
* @param {Number} padding The left, top, right and bottom padding properties for the legend.
234
* @param {Number} horizontalGap The horizontal distance between items in a legend.
235
* @param {Number} verticalGap The vertical distance between items in a legend.
236
* @param {String} vAlign The vertical alignment of the legend.
239
_positionLegendItems: function(items, maxWidth, maxHeight, totalWidth, totalHeight, padding, horizontalGap, verticalGap, vAlign)
248
height = this.get("height"),
254
leftWidth = padding.left - horizontalGap,
256
limit = height - (padding.top + padding.bottom),
261
VerticalLegendLayout._setColumnArrays(items, limit, verticalGap);
262
columns = VerticalLegendLayout.columnArray;
263
totalHeightArray = VerticalLegendLayout.totalHeightArray;
264
columnsLen = columns.length;
265
for(; columnIterator < columnsLen; ++ columnIterator)
267
leftWidth += horizontalGap;
268
column = columns[columnIterator];
270
legendHeight = VerticalLegendLayout.getStartPoint(height, totalHeightArray[columnIterator], vAlign, padding);
272
for(i = 0; i < len; ++i)
276
itemHeight = item.height;
277
itemWidth = item.width;
278
item.y = legendHeight;
280
left = !isNaN(left) ? Math.min(left, leftWidth) : leftWidth;
281
top = !isNaN(top) ? Math.min(top, legendHeight) : legendHeight;
282
right = !isNaN(right) ? Math.max(leftWidth + itemWidth, right) : leftWidth + itemWidth;
283
bottom = !isNaN(bottom) ? Math.max(legendHeight + itemHeight, bottom) : legendHeight + itemHeight;
284
node.setStyle("left", leftWidth + PX);
285
node.setStyle("top", legendHeight + PX);
286
legendHeight += itemHeight + verticalGap;
287
legendWidth = Math.max(legendWidth, item.width);
289
leftWidth += legendWidth;
291
this._contentRect = {
297
if(this.get("includeInChartLayout"))
299
this.set("width", leftWidth + padding.right);
304
* Creates column and total height arrays used for displaying multiple columns of
305
* legend items based on the items, available height and verticalGap for the legend.
307
* @method _setColumnArrays
308
* @param {Array} items Array of legend items to display in a legend.
309
* @param {Number} limit Total available height for displaying items in a legend.
310
* @param {Number} verticalGap Vertical distance between items in a legend.
313
_setColumnArrays: function(items, limit, verticalGap)
316
columnArray = [[item]],
320
totalHeight = item.height,
322
totalHeightArray = [[totalHeight]];
326
itemHeight = item.height;
327
if((totalHeight + verticalGap + itemHeight) <= limit)
329
totalHeight += verticalGap + itemHeight;
330
columnArray[columnIterator].push(item);
334
totalHeight = verticalGap + itemHeight;
335
if(columnArray[columnIterator])
339
columnArray[columnIterator] = [item];
341
totalHeightArray[columnIterator] = totalHeight;
343
VerticalLegendLayout.columnArray = columnArray;
344
VerticalLegendLayout.totalHeightArray = totalHeightArray;
348
* Returns the starting y-coordinate for a column of legend items.
350
* @method getStartPoint
351
* @param {Number} h Height of the legend.
352
* @param {Number} totalHeight Total height of all labels in the column.
353
* @param {String} align Vertical alignment of items for the legend.
354
* @param {Object} padding Object contain left, top, right and bottom padding properties.
358
getStartPoint: function(h, totalHeight, align, padding)
364
startPoint = padding.top;
367
startPoint = (h - totalHeight) * 0.5;
370
startPoint = h - totalHeight - padding.bottom;
377
CartesianChartLegend = Y.Base.create("cartesianChartLegend", Y.CartesianChart, [], {
379
* Redraws and position all the components of the chart instance.
388
this._callLater = true;
391
this._drawing = true;
392
this._callLater = false;
393
var w = this.get("width"),
394
h = this.get("height"),
395
layoutBoxDimensions = this._getLayoutBoxDimensions(),
396
leftPaneWidth = layoutBoxDimensions.left,
397
rightPaneWidth = layoutBoxDimensions.right,
398
topPaneHeight = layoutBoxDimensions.top,
399
bottomPaneHeight = layoutBoxDimensions.bottom,
400
leftAxesCollection = this.get("leftAxesCollection"),
401
rightAxesCollection = this.get("rightAxesCollection"),
402
topAxesCollection = this.get("topAxesCollection"),
403
bottomAxesCollection = this.get("bottomAxesCollection"),
407
graphOverflow = "visible",
408
graph = this.get("graph"),
417
allowContentOverflow = this.get("allowContentOverflow"),
423
legend = this.get("legend"),
426
if(leftAxesCollection)
428
leftAxesXCoords = [];
429
l = leftAxesCollection.length;
430
for(i = l - 1; i > -1; --i)
432
leftAxesXCoords.unshift(leftPaneWidth);
433
leftPaneWidth += leftAxesCollection[i].get("width");
436
if(rightAxesCollection)
438
rightAxesXCoords = [];
439
l = rightAxesCollection.length;
441
for(i = l - 1; i > -1; --i)
443
rightPaneWidth += rightAxesCollection[i].get("width");
444
rightAxesXCoords.unshift(w - rightPaneWidth);
447
if(topAxesCollection)
450
l = topAxesCollection.length;
451
for(i = l - 1; i > -1; --i)
453
topAxesYCoords.unshift(topPaneHeight);
454
topPaneHeight += topAxesCollection[i].get("height");
457
if(bottomAxesCollection)
459
bottomAxesYCoords = [];
460
l = bottomAxesCollection.length;
461
for(i = l - 1; i > -1; --i)
463
bottomPaneHeight += bottomAxesCollection[i].get("height");
464
bottomAxesYCoords.unshift(h - bottomPaneHeight);
468
graphWidth = w - (leftPaneWidth + rightPaneWidth);
469
graphHeight = h - (bottomPaneHeight + topPaneHeight);
470
graphRect.left = leftPaneWidth;
471
graphRect.top = topPaneHeight;
472
graphRect.bottom = h - bottomPaneHeight;
473
graphRect.right = w - rightPaneWidth;
474
if(!allowContentOverflow)
476
topOverflow = this._getTopOverflow(leftAxesCollection, rightAxesCollection);
477
bottomOverflow = this._getBottomOverflow(leftAxesCollection, rightAxesCollection);
478
leftOverflow = this._getLeftOverflow(bottomAxesCollection, topAxesCollection);
479
rightOverflow = this._getRightOverflow(bottomAxesCollection, topAxesCollection);
481
diff = topOverflow - topPaneHeight;
484
graphRect.top = topOverflow;
488
l = topAxesYCoords.length;
491
topAxesYCoords[i] += diff;
496
diff = bottomOverflow - bottomPaneHeight;
499
graphRect.bottom = h - bottomOverflow;
500
if(bottomAxesYCoords)
503
l = bottomAxesYCoords.length;
506
bottomAxesYCoords[i] -= diff;
511
diff = leftOverflow - leftPaneWidth;
514
graphRect.left = leftOverflow;
518
l = leftAxesXCoords.length;
521
leftAxesXCoords[i] += diff;
526
diff = rightOverflow - rightPaneWidth;
529
graphRect.right = w - rightOverflow;
533
l = rightAxesXCoords.length;
536
rightAxesXCoords[i] -= diff;
541
graphWidth = graphRect.right - graphRect.left;
542
graphHeight = graphRect.bottom - graphRect.top;
543
graphX = graphRect.left;
544
graphY = graphRect.top;
547
if(legend.get("includeInChartLayout"))
549
switch(legend.get("position"))
552
legend.set("y", graphY);
553
legend.set("height", graphHeight);
556
legend.set("x", graphX);
557
legend.set("width", graphWidth);
560
legend.set("x", graphX);
561
legend.set("width", graphWidth);
564
legend.set("y", graphY);
565
legend.set("height", graphHeight);
570
if(topAxesCollection)
572
l = topAxesCollection.length;
576
axis = topAxesCollection[i];
577
if(axis.get("width") !== graphWidth)
579
axis.set("width", graphWidth);
581
axis.get("boundingBox").setStyle("left", graphX + PX);
582
axis.get("boundingBox").setStyle("top", topAxesYCoords[i] + PX);
584
if(axis._hasDataOverflow())
586
graphOverflow = "hidden";
589
if(bottomAxesCollection)
591
l = bottomAxesCollection.length;
595
axis = bottomAxesCollection[i];
596
if(axis.get("width") !== graphWidth)
598
axis.set("width", graphWidth);
600
axis.get("boundingBox").setStyle("left", graphX + PX);
601
axis.get("boundingBox").setStyle("top", bottomAxesYCoords[i] + PX);
603
if(axis._hasDataOverflow())
605
graphOverflow = "hidden";
608
if(leftAxesCollection)
610
l = leftAxesCollection.length;
614
axis = leftAxesCollection[i];
615
axis.get("boundingBox").setStyle("top", graphY + PX);
616
axis.get("boundingBox").setStyle("left", leftAxesXCoords[i] + PX);
617
if(axis.get("height") !== graphHeight)
619
axis.set("height", graphHeight);
622
if(axis._hasDataOverflow())
624
graphOverflow = "hidden";
627
if(rightAxesCollection)
629
l = rightAxesCollection.length;
633
axis = rightAxesCollection[i];
634
axis.get("boundingBox").setStyle("top", graphY + PX);
635
axis.get("boundingBox").setStyle("left", rightAxesXCoords[i] + PX);
636
if(axis.get("height") !== graphHeight)
638
axis.set("height", graphHeight);
641
if(axis._hasDataOverflow())
643
graphOverflow = "hidden";
646
this._drawing = false;
654
graph.get("boundingBox").setStyle("left", graphX + PX);
655
graph.get("boundingBox").setStyle("top", graphY + PX);
656
graph.set("width", graphWidth);
657
graph.set("height", graphHeight);
658
graph.get("boundingBox").setStyle("overflow", graphOverflow);
663
this._overlay.setStyle("left", graphX + PX);
664
this._overlay.setStyle("top", graphY + PX);
665
this._overlay.setStyle("width", graphWidth + PX);
666
this._overlay.setStyle("height", graphHeight + PX);
671
* Positions the legend in a chart and returns the properties of the legend to be used in the
672
* chart's layout algorithm.
674
* @method _getLayoutDimensions
675
* @return {Object} The left, top, right and bottom values for the legend.
678
_getLayoutBoxDimensions: function()
686
legend = this.get("legend"),
692
h = this.get(HEIGHT),
694
if(legend && legend.get("includeInChartLayout"))
696
gap = legend.get("styles").gap;
697
position = legend.get(POSITION);
698
if(position !== EXTERNAL)
700
direction = legend.get("direction");
701
dimension = direction === HORIZONTAL ? HEIGHT : WIDTH;
702
size = legend.get(dimension);
703
box[position] = size + gap;
710
legend.set(_Y, h - size);
713
legend.set(_X, w - size);
725
* Destructor implementation for the CartesianChart class. Calls destroy on all axes, series, legend (if available) and the Graph instance.
726
* Removes the tooltip and overlay HTML elements.
731
destructor: function()
733
var legend = this.get("legend");
736
legend.destroy(true);
745
Y.CartesianChart = CartesianChartLegend;
747
PieChartLegend = Y.Base.create("pieChartLegend", Y.PieChart, [], {
749
* Redraws the chart instance.
758
this._callLater = true;
761
this._drawing = true;
762
this._callLater = false;
763
var graph = this.get("graph"),
764
w = this.get("width"),
765
h = this.get("height"),
768
legend = this.get("legend"),
783
position = legend.get("position");
784
direction = legend.get("direction");
785
graphWidth = graph.get("width");
786
graphHeight = graph.get("height");
787
legendWidth = legend.get("width");
788
legendHeight = legend.get("height");
789
gap = legend.get("styles").gap;
791
if((direction === "vertical" && (graphWidth + legendWidth + gap !== w)) ||
792
(direction === "horizontal" && (graphHeight + legendHeight + gap !== h)))
794
switch(legend.get("position"))
797
dimension = Math.min(w - (legendWidth + gap), h);
799
x = legendWidth + gap;
800
legend.set(HEIGHT, legendHeight);
803
dimension = Math.min(h - (legendHeight + gap), w);
805
y = legendHeight + gap;
806
legend.set(WIDTH, legendWidth);
809
dimension = Math.min(w - (legendWidth + gap), h);
811
legendX = dimension + gap;
812
legend.set(HEIGHT, legendHeight);
815
dimension = Math.min(h - (legendHeight + gap), w);
817
legendY = dimension + gap;
818
legend.set(WIDTH, legendWidth);
821
graph.set(WIDTH, dimension);
822
graph.set(HEIGHT, dimension);
826
switch(legend.get("position"))
829
x = legendWidth + gap;
832
y = legendHeight + gap;
835
legendX = graphWidth + gap;
838
legendY = graphHeight + gap;
848
graph.set(HEIGHT, h);
851
this._drawing = false;
864
legend.set(_X, legendX);
865
legend.set(_Y, legendY);
871
* The legend for the chart.
879
Y.PieChart = PieChartLegend;
881
* ChartLegend provides a legend for a chart.
885
* @submodule charts-legend
888
Y.ChartLegend = Y.Base.create("chartlegend", Y.Widget, [Y.Renderer], {
890
* Initializes the chart.
892
* @method initializer
895
initializer: function()
906
var bb = this.get("boundingBox"),
907
cb = this.get("contentBox"),
908
styles = this.get("styles").background,
909
background = new Y.Rect({
912
stroke: styles.border
914
bb.setStyle("display", "block");
915
bb.setStyle("position", "absolute");
916
this.set("background", background);
925
this.get("chart").after("seriesCollectionChange", Y.bind(this._updateHandler, this));
926
this.get("chart").after("stylesChange", Y.bind(this._updateHandler, this));
927
this.after("stylesChange", this._updateHandler);
928
this.after("positionChange", this._positionChangeHandler);
929
this.after("widthChange", this._handleSizeChange);
930
this.after("heightChange", this._handleSizeChange);
939
var w = this.get("width"),
940
h = this.get("height");
941
if(isFinite(w) && isFinite(h) && w > 0 && h > 0)
948
* Handles changes to legend.
950
* @method _updateHandler
951
* @param {Object} e Event object
954
_updateHandler: function()
956
if(this.get("rendered"))
963
* Handles position changes.
965
* @method _positionChangeHandler
966
* @param {Object} e Event object
969
_positionChangeHandler: function()
971
var chart = this.get("chart"),
972
parentNode = this._parentNode;
973
if(parentNode && ((chart && this.get("includeInChartLayout"))))
975
this.fire("legendRendered");
977
else if(this.get("rendered"))
984
* Updates the legend when the size changes.
986
* @method _handleSizeChange
987
* @param {Object} e Event object.
990
_handleSizeChange: function(e)
992
var attrName = e.attrName,
993
pos = this.get(POSITION),
994
vert = pos === LEFT || pos === RIGHT,
995
hor = pos === BOTTOM || pos === TOP;
996
if((hor && attrName === WIDTH) || (vert && attrName === HEIGHT))
1005
* @method _drawLegend
1008
_drawLegend: function()
1012
this._callLater = true;
1015
this._drawing = true;
1016
this._callLater = false;
1017
if(this.get("includeInChartLayout"))
1019
this.get("chart")._itemRenderQueue.unshift(this);
1021
var chart = this.get("chart"),
1022
node = this.get("contentBox"),
1023
seriesCollection = chart.get("seriesCollection"),
1025
styles = this.get("styles"),
1026
padding = styles.padding,
1027
itemStyles = styles.item,
1029
hSpacing = itemStyles.hSpacing,
1030
vSpacing = itemStyles.vSpacing,
1031
direction = this.get("direction"),
1032
align = direction === "vertical" ? styles.vAlign : styles.hAlign,
1033
marker = styles.marker,
1034
labelStyles = itemStyles.label,
1036
layout = this._layout[direction],
1050
markerWidth = marker.width,
1051
markerHeight = marker.height,
1052
totalWidth = 0 - hSpacing,
1053
totalHeight = 0 - vSpacing,
1058
if(marker && marker.shape)
1060
legendShape = marker.shape;
1062
this._destroyLegendItems();
1063
if(chart instanceof Y.PieChart)
1065
series = seriesCollection[0];
1066
displayName = series.get("categoryAxis").getDataByKey(series.get("categoryKey"));
1067
seriesStyles = series.get("styles").marker;
1068
fillColors = seriesStyles.fill.colors;
1069
borderColors = seriesStyles.border.colors;
1070
borderWeight = seriesStyles.border.weight;
1072
len = displayName.length;
1073
shape = legendShape || Y.Circle;
1074
isArray = Y.Lang.isArray(shape);
1077
shape = isArray ? shape[i] : shape;
1079
color: fillColors[i]
1082
colors: borderColors[i],
1083
weight: borderWeight
1085
displayName = chart.getSeriesItems(series, i).category.value;
1086
item = this._getLegendItem(node, this._getShapeClass(shape), fill, border, labelStyles, markerWidth, markerHeight, displayName);
1087
itemWidth = item.width;
1088
itemHeight = item.height;
1089
maxWidth = Math.max(maxWidth, itemWidth);
1090
maxHeight = Math.max(maxHeight, itemHeight);
1091
totalWidth += itemWidth + hSpacing;
1092
totalHeight += itemHeight + vSpacing;
1099
len = seriesCollection.length;
1102
series = seriesCollection[i];
1103
seriesStyles = this._getStylesBySeriesType(series, shape);
1106
shape = seriesStyles.shape;
1112
shapeClass = Y.Lang.isArray(shape) ? shape[i] : shape;
1113
item = this._getLegendItem(
1115
this._getShapeClass(shape),
1117
seriesStyles.border,
1121
series.get("valueDisplayName")
1123
itemWidth = item.width;
1124
itemHeight = item.height;
1125
maxWidth = Math.max(maxWidth, itemWidth);
1126
maxHeight = Math.max(maxHeight, itemHeight);
1127
totalWidth += itemWidth + hSpacing;
1128
totalHeight += itemHeight + vSpacing;
1132
this._drawing = false;
1139
layout._positionLegendItems.apply(
1141
[items, maxWidth, maxHeight, totalWidth, totalHeight, padding, hSpacing, vSpacing, align]
1143
this._updateBackground(styles);
1144
this.fire("legendRendered");
1149
* Updates the background for the legend.
1151
* @method _updateBackground
1152
* @param {Object} styles Reference to the legend's styles attribute
1155
_updateBackground: function(styles)
1157
var backgroundStyles = styles.background,
1158
contentRect = this._contentRect,
1159
padding = styles.padding,
1160
x = contentRect.left - padding.left,
1161
y = contentRect.top - padding.top,
1162
w = contentRect.right - x + padding.right,
1163
h = contentRect.bottom - y + padding.bottom;
1164
this.get("background").set({
1165
fill: backgroundStyles.fill,
1166
stroke: backgroundStyles.border,
1175
* Retrieves the marker styles based on the type of series. For series that contain a marker, the marker styles are returned.
1177
* @method _getStylesBySeriesType
1178
* @param {CartesianSeries | PieSeries} The series in which the style properties will be received.
1179
* @return Object An object containing fill, border and shape information.
1182
_getStylesBySeriesType: function(series)
1184
var styles = series.get("styles"),
1186
if(series instanceof Y.LineSeries || series instanceof Y.StackedLineSeries)
1188
styles = series.get("styles").line;
1189
color = styles.color || series._getDefaultColor(series.get("graphOrder"), "line");
1200
else if(series instanceof Y.AreaSeries || series instanceof Y.StackedAreaSeries)
1202
styles = series.get("styles").area;
1203
color = styles.color || series._getDefaultColor(series.get("graphOrder"), "slice");
1216
styles = series.get("styles").marker;
1221
weight: styles.border.weight,
1223
color: styles.border.color,
1233
* Returns a legend item consisting of the following properties:
1235
* <dt>node</dt><dd>The `Node` containing the legend item elements.</dd>
1236
* <dt>shape</dt><dd>The `Shape` element for the legend item.</dd>
1237
* <dt>textNode</dt><dd>The `Node` containing the text></dd>
1238
* <dt>text</dt><dd></dd>
1241
* @method _getLegendItem
1242
* @param {Node} shapeProps Reference to the `node` attribute.
1243
* @param {String | Class} shapeClass The type of shape
1244
* @param {Object} fill Properties for the shape's fill
1245
* @param {Object} border Properties for the shape's border
1246
* @param {String} text String to be rendered as the legend's text
1247
* @param {Number} width Total width of the legend item
1248
* @param {Number} height Total height of the legend item
1249
* @param {HTML | String} text Text for the legendItem
1253
_getLegendItem: function(node, shapeClass, fill, border, labelStyles, w, h, text)
1255
var containerNode = Y.one(DOCUMENT.createElement("div")),
1256
textField = Y.one(DOCUMENT.createElement("span")),
1262
ShapeClass = shapeClass;
1263
containerNode.setStyle(POSITION, "absolute");
1264
textField.setStyle(POSITION, "absolute");
1265
textField.setStyles(labelStyles);
1266
textField.appendChild(DOCUMENT.createTextNode(text));
1267
containerNode.appendChild(textField);
1268
node.appendChild(containerNode);
1269
dimension = textField.get("offsetHeight");
1270
padding = dimension - h;
1271
left = w + padding + 2;
1272
textField.setStyle("left", left + PX);
1273
containerNode.setStyle("height", dimension + PX);
1274
containerNode.setStyle("width", (left + textField.get("offsetWidth")) + PX);
1275
shape = new ShapeClass({
1284
graphic: containerNode
1286
textField.setStyle("left", dimension + PX);
1288
node: containerNode,
1289
width: containerNode.get("offsetWidth"),
1290
height: containerNode.get("offsetHeight"),
1292
textNode: textField,
1295
this._items.push(item);
1300
* Evaluates and returns correct class for drawing a shape.
1302
* @method _getShapeClass
1306
_getShapeClass: function()
1308
var graphic = this.get("background").get("graphic");
1309
return graphic._getShapeClass.apply(graphic, arguments);
1313
* Returns the default hash for the `styles` attribute.
1315
* @method _getDefaultStyles
1319
_getDefaultStyles: function()
1331
marker: this._getPlotDefaults(),
1338
whiteSpace: "nowrap"
1356
* Gets the default values for series that use the utility. This method is used by
1357
* the class' `styles` attribute's getter to get build default values.
1359
* @method _getPlotDefaults
1363
_getPlotDefaults: function()
1373
* Destroys legend items.
1375
* @method _destroyLegendItems
1378
_destroyLegendItems: function()
1383
while(this._items.length > 0)
1385
item = this._items.shift();
1386
item.shape.get("graphic").destroy();
1388
item.node.destroy(true);
1397
* Maps layout classes.
1403
vertical: VerticalLegendLayout,
1404
horizontal: HorizontalLegendLayout
1408
* Destructor implementation ChartLegend class. Removes all items and the Graphic instance from the widget.
1410
* @method destructor
1413
destructor: function()
1415
var background = this.get("background"),
1417
this._destroyLegendItems();
1420
backgroundGraphic = background.get("graphic");
1421
if(backgroundGraphic)
1423
backgroundGraphic.destroy();
1427
background.destroy();
1435
* Indicates whether the chart's contentBox is the parentNode for the legend.
1437
* @attribute includeInChartLayout
1441
includeInChartLayout: {
1446
* Reference to the `Chart` instance.
1452
setter: function(val)
1454
this.after("legendRendered", Y.bind(val._itemRendered, val));
1460
* Indicates the direction in relation of the legend's layout. The `direction` of the legend is determined by its
1463
* @attribute direction
1471
* Indicates the position and direction of the legend. Possible values are `left`, `top`, `right` and `bottom`.
1472
* Values of `left` and `right` values have a `direction` of `vertical`. Values of `top` and `bottom` values have
1473
* a `direction` of `horizontal`.
1475
* @attribute position
1483
setter: function(val)
1485
if(val === TOP || val === BOTTOM)
1487
this.set("direction", HORIZONTAL);
1489
else if(val === LEFT || val === RIGHT)
1491
this.set("direction", VERTICAL);
1498
* The width of the legend. Depending on the implementation of the ChartLegend, this value is `readOnly`.
1499
* By default, the legend is included in the layout of the `Chart` that it references. Under this circumstance,
1500
* `width` is always `readOnly`. When the legend is rendered in its own dom element, the `readOnly` status is
1501
* determined by the direction of the legend. If the `position` is `left` or `right` or the `direction` is
1502
* `vertical`, width is `readOnly`. If the position is `top` or `bottom` or the `direction` is `horizontal`,
1503
* width can be explicitly set. If width is not explicitly set, the width will be determined by the width of the
1504
* legend's parent element.
1512
var chart = this.get("chart"),
1513
parentNode = this._parentNode;
1516
if((chart && this.get("includeInChartLayout")) || this._width)
1526
return parentNode.get("offsetWidth");
1532
setter: function(val)
1540
* The height of the legend. Depending on the implementation of the ChartLegend, this value is `readOnly`.
1541
* By default, the legend is included in the layout of the `Chart` that it references. Under this circumstance,
1542
* `height` is always `readOnly`. When the legend is rendered in its own dom element, the `readOnly` status is
1543
* determined by the direction of the legend. If the `position` is `top` or `bottom` or the `direction` is
1544
* `horizontal`, height is `readOnly`. If the position is `left` or `right` or the `direction` is `vertical`,
1545
* height can be explicitly set. If height is not explicitly set, the height will be determined by the width of the
1546
* legend's parent element.
1552
valueFn: "_heightGetter",
1556
var chart = this.get("chart"),
1557
parentNode = this._parentNode;
1560
if((chart && this.get("includeInChartLayout")) || this._height)
1566
return this._height;
1570
return parentNode.get("offsetHeight");
1576
setter: function(val)
1584
* Indicates the x position of legend.
1595
setter: function(val)
1597
var node = this.get("boundingBox");
1600
node.setStyle(LEFT, val + PX);
1607
* Indicates the y position of legend.
1618
setter: function(val)
1620
var node = this.get("boundingBox");
1623
node.setStyle(TOP, val + PX);
1630
* Array of items contained in the legend. Each item is an object containing the following properties:
1633
* <dt>node</dt><dd>Node containing text for the legend item.</dd>
1634
* <dt>marker</dt><dd>Shape for the legend item.</dd>
1649
* Background for the legend.
1651
* @attribute background
1657
* Properties used to display and style the ChartLegend. This attribute is inherited from `Renderer`.
1658
* Below are the default values:
1661
* <dt>gap</dt><dd>Distance, in pixels, between the `ChartLegend` instance and the chart's content. When `ChartLegend`
1662
* is rendered within a `Chart` instance this value is applied.</dd>
1663
* <dt>hAlign</dt><dd>Defines the horizontal alignment of the `items` in a `ChartLegend` rendered in a horizontal direction.
1664
* This value is applied when the instance's `position` is set to top or bottom. This attribute can be set to left, center
1665
* or right. The default value is center.</dd>
1666
* <dt>vAlign</dt><dd>Defines the vertical alignment of the `items` in a `ChartLegend` rendered in vertical direction. This
1667
* value is applied when the instance's `position` is set to left or right. The attribute can be set to top, middle or
1668
* bottom. The default value is middle.</dd>
1669
* <dt>item</dt><dd>Set of style properties applied to the `items` of the `ChartLegend`.
1671
* <dt>hSpacing</dt><dd>Horizontal distance, in pixels, between legend `items`.</dd>
1672
* <dt>vSpacing</dt><dd>Vertical distance, in pixels, between legend `items`.</dd>
1673
* <dt>label</dt><dd>Properties for the text of an `item`.
1675
* <dt>color</dt><dd>Color of the text. The default values is "#808080".</dd>
1676
* <dt>fontSize</dt><dd>Font size for the text. The default value is "85%".</dd>
1679
* <dt>marker</dt><dd>Properties for the `item` markers.
1681
* <dt>width</dt><dd>Specifies the width of the markers.</dd>
1682
* <dt>height</dt><dd>Specifies the height of the markers.</dd>
1687
* <dt>background</dt><dd>Properties for the `ChartLegend` background.
1689
* <dt>fill</dt><dd>Properties for the background fill.
1691
* <dt>color</dt><dd>Color for the fill. The default value is "#faf9f2".</dd>
1694
* <dt>border</dt><dd>Properties for the background border.
1696
* <dt>color</dt><dd>Color for the border. The default value is "#dad8c9".</dd>
1697
* <dt>weight</dt><dd>Weight of the border. The default values is 1.</dd>
1711
}, '3.13.0', {"requires": ["charts-base"]});