Last active
December 19, 2015 14:38
-
-
Save tripp/5970225 to your computer and use it in GitHub Desktop.
drawLegendPatch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Y.ChartLegend.prototype._drawLegend = function() | |
| { | |
| var chart = this.get("chart"), | |
| node, | |
| seriesCollection = chart.get("seriesCollection"), | |
| series, | |
| styles, | |
| padding, | |
| itemStyles, | |
| seriesStyles, | |
| hSpacing, | |
| vSpacing, | |
| direction, | |
| align, | |
| marker, | |
| labelStyles, | |
| displayName, | |
| layout, | |
| i, | |
| len, | |
| isArray, | |
| legendShape, | |
| shape, | |
| shapeClass, | |
| item, | |
| fill, | |
| border, | |
| fillColors, | |
| borderColors, | |
| borderWeight, | |
| items = [], | |
| markerWidth, | |
| markerHeight, | |
| totalWidth, | |
| totalHeight, | |
| maxWidth = 0, | |
| maxHeight = 0, | |
| itemWidth, | |
| itemHeight; | |
| this._destroyLegendItems(); | |
| if(seriesCollection && seriesCollection.length > 0) | |
| { | |
| if(this._drawing) | |
| { | |
| this._callLater = true; | |
| return; | |
| } | |
| this._drawing = true; | |
| this._callLater = false; | |
| if(this.get("includeInChartLayout")) | |
| { | |
| this.get("chart")._itemRenderQueue.unshift(this); | |
| } | |
| node = this.get("contentBox"); | |
| styles = this.get("styles"); | |
| padding = styles.padding; | |
| itemStyles = styles.item; | |
| hSpacing = itemStyles.hSpacing; | |
| vSpacing = itemStyles.vSpacing; | |
| labelStyles = itemStyles.label; | |
| direction = this.get("direction"); | |
| align = direction === "vertical" ? styles.vAlign : styles.hAlign; | |
| layout = this._layout[direction]; | |
| marker = styles.marker; | |
| markerWidth = marker.width; | |
| markerHeight = marker.height; | |
| totalWidth = 0 - hSpacing; | |
| totalHeight = 0 - vSpacing; | |
| if(marker && marker.shape) | |
| { | |
| legendShape = marker.shape; | |
| } | |
| if(chart instanceof Y.PieChart) | |
| { | |
| series = seriesCollection[0]; | |
| displayName = series.get("categoryAxis").getDataByKey(series.get("categoryKey")); | |
| seriesStyles = series.get("styles").marker; | |
| fillColors = seriesStyles.fill.colors; | |
| borderColors = seriesStyles.border.colors; | |
| borderWeight = seriesStyles.border.weight; | |
| i = 0; | |
| len = displayName.length; | |
| shape = legendShape || Y.Circle; | |
| isArray = Y.Lang.isArray(shape); | |
| for(; i < len; ++i) | |
| { | |
| shape = isArray ? shape[i] : shape; | |
| fill = { | |
| color: fillColors[i] | |
| }; | |
| border = { | |
| colors: borderColors[i], | |
| weight: borderWeight | |
| }; | |
| displayName = chart.getSeriesItems(series, i).category.value; | |
| item = this._getLegendItem(node, this._getShapeClass(shape), fill, border, labelStyles, markerWidth, markerHeight, displayName); | |
| itemWidth = item.width; | |
| itemHeight = item.height; | |
| maxWidth = Math.max(maxWidth, itemWidth); | |
| maxHeight = Math.max(maxHeight, itemHeight); | |
| totalWidth += itemWidth + hSpacing; | |
| totalHeight += itemHeight + vSpacing; | |
| items.push(item); | |
| } | |
| } | |
| else | |
| { | |
| i = 0; | |
| len = seriesCollection.length; | |
| for(; i < len; ++i) | |
| { | |
| series = seriesCollection[i]; | |
| seriesStyles = this._getStylesBySeriesType(series, shape); | |
| if(!legendShape) | |
| { | |
| shape = seriesStyles.shape; | |
| if(!shape) | |
| { | |
| shape = Y.Circle; | |
| } | |
| } | |
| shapeClass = Y.Lang.isArray(shape) ? shape[i] : shape; | |
| item = this._getLegendItem( | |
| node, | |
| this._getShapeClass(shape), | |
| seriesStyles.fill, | |
| seriesStyles.border, | |
| labelStyles, | |
| markerWidth, | |
| markerHeight, | |
| series.get("valueDisplayName") | |
| ); | |
| itemWidth = item.width; | |
| itemHeight = item.height; | |
| maxWidth = Math.max(maxWidth, itemWidth); | |
| maxHeight = Math.max(maxHeight, itemHeight); | |
| totalWidth += itemWidth + hSpacing; | |
| totalHeight += itemHeight + vSpacing; | |
| items.push(item); | |
| } | |
| } | |
| this._drawing = false; | |
| if(this._callLater) | |
| { | |
| this._drawLegend(); | |
| } | |
| else | |
| { | |
| layout._positionLegendItems.apply( | |
| this, | |
| [items, maxWidth, maxHeight, totalWidth, totalHeight, padding, hSpacing, vSpacing, align] | |
| ); | |
| this._updateBackground(styles); | |
| this.fire("legendRendered"); | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment