1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1087× 1087× 1087× 1087× 1× 1087× 2× 1085× 1085× 1085× 1× 1085× 79× 1006× 1006× 1006× 1× 261× 212× 1× 104× 21× 1× 1327× 1327× 1327× 2863× 2863× 2272× 2272× 1× 1355× 1355× 1355× 1355× 1302× 53× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 1355× 2327× 2327× 2327× 2327× 2327× 2327× 2327× 2327× 2327× 2327× 2190× 2190× 2190× 2190× 166× 166× 13× 166× 166× 166× 1355× 1355× 1355× 1355× 1342× 13× 1× 2215× 2215× 2215× 1013× 1013× 1202× 1202× 2215× 2215× 1× 18× 18× 18× 18× 18× 9× 18× 16× 4× 12× 16× 16× 16× 144× 16× 16× 16× 16× 16× 16× 16× 16× 16× 4× 4× 2× 2× 1× 16× 43× 43× 1× 131× 131× 131× 131× 131× 393× 393× 18× 18× 131× 4× 127× 4× 1× 20665× 1× 1085× 1× 1× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../../common/legend/legend", "../../common/utils/helper", "../../common/model/constants"], function (require, exports, ej2_base_1, ej2_base_2, legend_1, helper_1, constants_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Legend = (function (_super) { __extends(Legend, _super); function Legend(chart) { var _this = _super.call(this, chart) || this; _this.library = _this; _this.addEventListener(); return _this; } Legend.prototype.addEventListener = function () { if (this.chart.isDestroyed) { return; } this.chart.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMove, this); this.chart.on('click', this.click, this); this.chart.on(ej2_base_1.Browser.touchEndEvent, this.mouseEnd, this); }; Legend.prototype.removeEventListener = function () { if (this.chart.isDestroyed) { return; } this.chart.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMove); this.chart.off('click', this.click); this.chart.off(ej2_base_1.Browser.touchEndEvent, this.mouseEnd); }; Legend.prototype.mouseMove = function (e) { if (this.chart.legendSettings.visible && !this.chart.isTouch) { this.move(e); } }; Legend.prototype.mouseEnd = function (e) { if (this.chart.legendSettings.visible && this.chart.isTouch) { this.move(e); } }; Legend.prototype.getLegendOptions = function (visibleSeriesCollection, chart) { this.legendCollections = []; var seriesType; for (var _i = 0, visibleSeriesCollection_1 = visibleSeriesCollection; _i < visibleSeriesCollection_1.length; _i++) { var series = visibleSeriesCollection_1[_i]; if (series.category !== 'Indicator') { seriesType = (chart.chartAreaType === 'PolarRadar') ? series.drawType : series.type; this.legendCollections.push(new legend_1.LegendOptions(series.name, series.interior, series.legendShape, series.visible, seriesType, series.marker.shape, series.marker.visible)); } } }; Legend.prototype.getLegendBounds = function (availableSize, legendBounds, legend) { var padding = legend.padding; var extraHeight = 0; var extraWidth = 0; if (!this.isVertical) { extraHeight = !legend.height ? ((availableSize.height / 100) * 5) : 0; } else { extraWidth = !legend.width ? ((availableSize.width / 100) * 5) : 0; } legendBounds.height += extraHeight; legendBounds.width += extraWidth; var shapeHeight = legend.shapeHeight; var shapeWidth = legend.shapeWidth; var shapePadding = legend.shapePadding; var maximumWidth = 0; var rowWidth = 0; var legendWidth = 0; var columnHeight = 0; var rowCount = 0; var legendEventArgs; this.maxItemHeight = Math.max(helper_1.measureText('MeasureText', legend.textStyle).height, legend.shapeHeight); var render = false; for (var _i = 0, _a = this.legendCollections; _i < _a.length; _i++) { var legendOption = _a[_i]; legendEventArgs = { fill: legendOption.fill, text: legendOption.text, shape: legendOption.shape, markerShape: legendOption.markerShape, name: constants_1.legendRender, cancel: false }; this.chart.trigger(constants_1.legendRender, legendEventArgs); legendOption.render = !legendEventArgs.cancel; legendOption.text = legendEventArgs.text; legendOption.fill = legendEventArgs.fill; legendOption.shape = legendEventArgs.shape; legendOption.markerShape = legendEventArgs.markerShape; legendOption.textSize = helper_1.measureText(legendOption.text, legend.textStyle); if (legendOption.render && legendOption.text !== '') { render = true; legendWidth = shapeWidth + shapePadding + legendOption.textSize.width + padding; rowWidth = rowWidth + legendWidth; if (legendBounds.width < (padding + rowWidth) || this.isVertical) { maximumWidth = Math.max(maximumWidth, (rowWidth + padding - (this.isVertical ? 0 : legendWidth))); if (rowCount === 0 && (legendWidth !== rowWidth)) { rowCount = 1; } rowWidth = this.isVertical ? 0 : legendWidth; rowCount++; columnHeight = (rowCount * (this.maxItemHeight + padding)) + padding; } } } columnHeight = Math.max(columnHeight, (this.maxItemHeight + padding) + padding); this.isPaging = legendBounds.height < columnHeight; this.totalPages = rowCount; if (render) { this.setBounds(Math.max((rowWidth + padding), maximumWidth), columnHeight, legend, legendBounds); } else { this.setBounds(0, 0, legend, legendBounds); } }; Legend.prototype.getRenderPoint = function (legendOption, start, textPadding, prevLegend, rect, count, firstLegend) { var padding = this.legend.padding; var previousBound = (prevLegend.location.x + textPadding + prevLegend.textSize.width); if ((previousBound + (legendOption.textSize.width + textPadding)) > (rect.x + rect.width + this.legend.shapeWidth / 2) || this.isVertical) { legendOption.location.x = start.x; legendOption.location.y = (count === firstLegend) ? prevLegend.location.y : prevLegend.location.y + this.maxItemHeight + padding; } else { legendOption.location.x = (count === firstLegend) ? prevLegend.location.x : previousBound; legendOption.location.y = prevLegend.location.y; } var availwidth = (this.legendBounds.x + this.legendBounds.width) - (legendOption.location.x + textPadding - this.legend.shapeWidth / 2); legendOption.text = helper_1.textTrim(+availwidth.toFixed(4), legendOption.text, this.legend.textStyle); }; Legend.prototype.LegendClick = function (seriesIndex) { var chart = this.chart; var series = chart.visibleSeries[seriesIndex]; var legend = this.legendCollections[seriesIndex]; var selectedDataIndexes = []; if (chart.selectionModule) { selectedDataIndexes = ej2_base_2.extend([], chart.selectionModule.selectedDataIndexes, null, true); } if (chart.legendSettings.toggleVisibility) { if (!series.visible) { series.visible = true; } else { series.visible = false; } legend.visible = (series.visible); Eif (chart.svgObject.childNodes.length > 0) { while (chart.svgObject.lastChild) { chart.svgObject.removeChild(chart.svgObject.lastChild); } ej2_base_1.remove(chart.svgObject); } chart.animateSeries = false; chart.removeSvg(); chart.refreshAxis(); series.refreshAxisLabel(); this.refreshSeries(chart.visibleSeries); chart.refreshBound(); chart.trigger('loaded', { chart: chart }); if (selectedDataIndexes.length > 0) { chart.selectionModule.selectedDataIndexes = selectedDataIndexes; chart.selectionModule.redrawSelection(chart, chart.selectionMode); } } else Eif (chart.selectionModule) { chart.selectionModule.legendSelection(chart, seriesIndex); } }; Legend.prototype.refreshSeries = function (seriesCollection) { for (var _i = 0, seriesCollection_1 = seriesCollection; _i < seriesCollection_1.length; _i++) { var series = seriesCollection_1[_i]; series.position = undefined; } }; Legend.prototype.click = function (event) { Iif (!this.chart.legendSettings.visible) { return; } var targetId = event.target.id; var legendItemsId = [this.legendID + '_text_', this.legendID + '_shape_marker_', this.legendID + '_shape_']; var seriesIndex; for (var _i = 0, legendItemsId_1 = legendItemsId; _i < legendItemsId_1.length; _i++) { var id = legendItemsId_1[_i]; if (targetId.indexOf(id) > -1) { seriesIndex = parseInt(targetId.split(id)[1], 10); this.LegendClick(seriesIndex); } } if (targetId.indexOf(this.legendID + '_pageup') > -1) { this.changePage(event, true); } else if (targetId.indexOf(this.legendID + '_pagedown') > -1) { this.changePage(event, false); } }; Legend.prototype.getModuleName = function () { return 'Legend'; }; Legend.prototype.destroy = function (chart) { this.removeEventListener(); }; return Legend; }(legend_1.BaseLegend)); exports.Legend = Legend; }); |