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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 24× 24× 24× 24× 24× 1× 24× 24× 24× 24× 24× 24× 24× 50× 50× 51× 51× 51× 51× 51× 51× 51× 47× 47× 47× 47× 30× 2× 2× 2× 28× 24× 1× 30× 30× 30× 30× 30× 1× 30× 30× 30× 30× 30× 30× 30× 2876× 2876× 30× 2846× 2787× 30× 30× 30× 30× 1× 30× 30× 30× 30× 30× 30× 30× 30× 20× 20× 20× 20× 20× 4× 4× 4× 4× 4× 4× 4× 4× 4× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 4× 4× 4× 4× 4× 4× 4× 4× 2× 2× 2× 2× 2× 2× 2× 2× 2× 1× 7× 7× 7× 7× 1× 1× 1× 6× 1× 4× 4× 1× 1× 1× 1× 1× 1× 1× 1× 4× 1× 4× 3× 4× 4× 4× 4× 4× 1× 4× 4× 4× 1× 16× 10× 1× 141× 141× 141× 1× 1× 1× 24× 24× 25× 25× 51× 25× 24× | /* istanbul ignore next */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { 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 extendStatics(d, b); }; 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", "../../common/utils/helper", "../../common/user-interaction/tooltip", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../../common/model/constants"], function (require, exports, helper_1, tooltip_1, ej2_svg_base_1, ej2_base_1, ej2_data_1, constants_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var StockEvents = (function (_super) { __extends(StockEvents, _super); function StockEvents(stockChart) { var _this = _super.call(this, stockChart.chart) || this; _this.symbolLocations = []; _this.stockChart = stockChart; _this.chartId = _this.stockChart.element.id; return _this; } StockEvents.prototype.renderStockEvents = function () { var sChart = this.stockChart; var stockEvent; var stockEventElement; var textSize; var stockEventsElementGroup = sChart.renderer.createGroup({ id: this.chartId + '_StockEvents' }); this.symbolLocations = initialArray(sChart.series.length, sChart.stockEvents.length, new helper_1.ChartLocation(0, 0)); for (var i = 0; i < sChart.stockEvents.length; i++) { stockEvent = this.stockChart.stockEvents[i]; for (var _i = 0, _a = sChart.chart.series; _i < _a.length; _i++) { var series = _a[_i]; var argsData = { name: constants_1.stockEventRender, stockChart: sChart, text: stockEvent.text, type: stockEvent.type, cancel: false, series: series }; sChart.trigger(constants_1.stockEventRender, argsData); stockEvent.text = argsData.text; stockEvent.type = argsData.type; textSize = ej2_svg_base_1.measureText(stockEvent.text + 'W', stockEvent.textStyle, this.stockChart.themeStyle.axisLabelFont); if (!argsData.cancel) { stockEventElement = sChart.renderer.createGroup({ id: this.chartId + '_Series_' + series.index + '_StockEvents_' + i }); var stockEventDate = this.dateParse(stockEvent.date).getTime(); stockEventDate = this.stockChart.isDateTimeCategory ? series.xAxis.labels.indexOf(stockEventDate.toString()) : stockEventDate; if (helper_1.withIn(stockEventDate, series.xAxis.visibleRange) && (stockEventDate >= series.xMin && stockEventDate <= series.xMax)) { if (stockEvent.seriesIndexes.length > 0) { for (var j = 0; j < stockEvent.seriesIndexes.length; j++) { Eif (stockEvent.seriesIndexes[j] === series.index) { stockEventsElementGroup.appendChild(this.creatEventGroup(stockEventElement, series, stockEvent, i, textSize)); } } } else { stockEventsElementGroup.appendChild(this.creatEventGroup(stockEventElement, series, stockEvent, i, textSize)); } } } } } return stockEventsElementGroup; }; StockEvents.prototype.creatEventGroup = function (stockEventElement, series, stockEvent, i, textSize) { var symbolLocation = this.findClosePoint(series, stockEvent); Iif (!stockEvent.showOnSeries) { symbolLocation.y = series.yAxis.rect.y + series.yAxis.rect.height; } this.symbolLocations[series.index][i] = symbolLocation; this.createStockElements(stockEventElement, stockEvent, series, i, symbolLocation, textSize); return stockEventElement; }; StockEvents.prototype.findClosePoint = function (series, sEvent) { var stockEventDate = this.dateParse(sEvent.date).getTime(); stockEventDate = this.stockChart.isDateTimeCategory ? series.xAxis.labels.indexOf(stockEventDate.toString()) : stockEventDate; var closeIndex = this.getClosest(series, stockEventDate); var pointData; var point; var yPixel; for (var k = 0; k < series.points.length; k++) { point = series.points[k]; if (closeIndex === point.xValue && point.visible) { pointData = new helper_1.PointData(point, series); } else if (k !== 0 && k !== series.points.length - 1) { Iif (closeIndex > series.points[k - 1].xValue && closeIndex < series.points[k + 1].xValue) { pointData = new helper_1.PointData(point, series); } } } var xPixel = series.xAxis.rect.x + helper_1.valueToCoefficient(pointData.point.xValue, series.xAxis) * series.xAxis.rect.width; yPixel = helper_1.valueToCoefficient(pointData.point[sEvent.placeAt], series.yAxis) * series.yAxis.rect.height; yPixel = (yPixel * -1) + (series.yAxis.rect.y + series.yAxis.rect.height); return new helper_1.ChartLocation(xPixel, yPixel); }; StockEvents.prototype.createStockElements = function (stockEventElement, stockEve, series, i, symbolLocation, textSize) { var result = new ej2_svg_base_1.Size(textSize.width > 20 ? textSize.width : 20, textSize.height > 20 ? textSize.height : 20); var pathString; var pathOption; var lx = symbolLocation.x; var ly = symbolLocation.y; var stockId = this.chartId + '_Series_' + series.index + '_StockEvents_' + i; var border = stockEve.border; switch (stockEve.type) { case 'Flag': case 'Circle': case 'Square': stockEventElement.appendChild(helper_1.drawSymbol(new helper_1.ChartLocation(lx, ly), 'Circle', new ej2_svg_base_1.Size(2, 2), '', new ej2_svg_base_1.PathOption(stockId + '_Circle', 'transparent', border.width, border.color), this.dateParse(stockEve.date).toISOString())); stockEventElement.appendChild(helper_1.drawSymbol(new helper_1.ChartLocation(lx, ly - 5), 'VerticalLine', new ej2_svg_base_1.Size(9, 9), '', new ej2_svg_base_1.PathOption(stockId + '_Path', border.color, border.width, border.color), this.dateParse(stockEve.date).toISOString())); stockEventElement.appendChild(helper_1.drawSymbol(new helper_1.ChartLocation(stockEve.type !== 'Flag' ? lx : lx + result.width / 2, ly - result.height), stockEve.type, result, '', new ej2_svg_base_1.PathOption(stockId + '_Shape', stockEve.background, border.width, border.color), this.dateParse(stockEve.date).toISOString())); helper_1.textElement(this.stockChart.renderer, new ej2_svg_base_1.TextOption(stockId + '_Text', stockEve.type !== 'Flag' ? symbolLocation.x : symbolLocation.x + result.width / 2, (symbolLocation.y - result.height), 'middle', stockEve.text, '', 'middle'), stockEve.textStyle, stockEve.textStyle.color, stockEventElement); break; case 'ArrowUp': case 'ArrowDown': case 'ArrowRight': case 'ArrowLeft': pathString = 'M' + ' ' + lx + ' ' + ly + ' ' + this.findArrowpaths(stockEve.type); pathOption = new ej2_svg_base_1.PathOption(stockId + '_Shape', stockEve.background, border.width, border.color, 1, '', pathString); stockEventElement.appendChild(this.stockChart.renderer.drawPath(pathOption)); break; case 'Triangle': case 'InvertedTriangle': result.height = 3 * textSize.height; result.width = textSize.width + (1.5 * textSize.width); stockEventElement.appendChild(helper_1.drawSymbol(new helper_1.ChartLocation(symbolLocation.x, symbolLocation.y), stockEve.type, new ej2_svg_base_1.Size(20, 20), '', new ej2_svg_base_1.PathOption(stockId + '_Shape', stockEve.background, border.width, border.color), this.dateParse(stockEve.date).toISOString())); helper_1.textElement(this.stockChart.renderer, new ej2_svg_base_1.TextOption(stockId + '_Text', symbolLocation.x, symbolLocation.y, 'middle', stockEve.text, '', 'middle'), stockEve.textStyle, stockEve.textStyle.color, stockEventElement); break; case 'Text': textSize.height += 8; pathString = 'M' + ' ' + (lx) + ' ' + (ly) + ' ' + 'L' + ' ' + (lx - 5) + ' ' + (ly - 5) + ' ' + 'L' + ' ' + (lx - ((textSize.width) / 2)) + ' ' + (ly - 5) + ' ' + 'L' + ' ' + (lx - ((textSize.width) / 2)) + ' ' + (ly - textSize.height) + ' ' + 'L' + ' ' + (lx + ((textSize.width) / 2)) + ' ' + (ly - textSize.height) + ' ' + 'L' + ' ' + (lx + ((textSize.width) / 2)) + ' ' + (ly - 5) + ' ' + 'L' + ' ' + (lx + 5) + ' ' + (ly - 5) + ' ' + 'Z'; pathOption = new ej2_svg_base_1.PathOption(stockId + '_Shape', stockEve.background, border.width, border.color, 1, '', pathString); stockEventElement.appendChild(this.stockChart.renderer.drawPath(pathOption)); helper_1.textElement(this.stockChart.renderer, new ej2_svg_base_1.TextOption(stockId + '_Text', lx, ly - (textSize.height / 2), 'middle', stockEve.text, '', 'middle'), stockEve.textStyle, stockEve.textStyle.color, stockEventElement); break; default: pathString = 'M' + ' ' + lx + ' ' + ly + ' ' + 'L' + ' ' + (lx - ((textSize.width) / 2)) + ' ' + (ly - textSize.height / 3) + ' ' + 'L' + ' ' + (lx - ((textSize.width) / 2)) + ' ' + (ly - textSize.height) + ' ' + 'L' + ' ' + (lx + ((textSize.width) / 2)) + ' ' + (ly - textSize.height) + ' ' + 'L' + ' ' + (lx + ((textSize.width) / 2)) + ' ' + (ly - textSize.height / 3) + ' ' + 'Z'; pathOption = new ej2_svg_base_1.PathOption(stockId + '_Shape', stockEve.background, border.width, border.color, 1, '', pathString); stockEventElement.appendChild(this.stockChart.renderer.drawPath(pathOption)); helper_1.textElement(this.stockChart.renderer, new ej2_svg_base_1.TextOption(stockId + '_Text', lx, ly - (textSize.height / 2), 'middle', stockEve.text, '', 'middle'), stockEve.textStyle, stockEve.textStyle.color, stockEventElement); } }; StockEvents.prototype.renderStockEventTooltip = function (targetId) { var seriesIndex = parseInt((targetId.split('_StockEvents_')[0]).split(this.chartId + '_Series_')[1], 10); var pointIndex = parseInt(targetId.split('_StockEvents_')[1].replace(/\D+/g, ''), 10); var updatedLocation = this.symbolLocations[seriesIndex][pointIndex]; var pointLocation = new helper_1.ChartLocation(updatedLocation.x, updatedLocation.y + this.stockChart.toolbarHeight + this.stockChart.titleSize.height); this.applyHighLights(pointIndex, seriesIndex); var svgElement = this.getElement(this.chartId + '_StockEvents_Tooltip_svg'); var isTooltip = (this.stockEventTooltip && svgElement && parseInt(svgElement.getAttribute('opacity'), 10) > 0); if (!isTooltip) { Iif (helper_1.getElement(this.chartId + '_StockEvents_Tooltip_svg')) { ej2_base_1.remove(helper_1.getElement(this.chartId + '_StockEvents_Tooltip')); } var tooltipElement = ej2_base_1.createElement('div', { id: this.chartId + '_StockEvents_Tooltip', className: 'ejSVGTooltip', attrs: { 'style': 'pointer-events:none; position:absolute;z-index: 1' } }); helper_1.getElement(this.chartId + '_Secondary_Element').appendChild(tooltipElement); this.stockEventTooltip = new ej2_svg_base_1.Tooltip({ opacity: 1, header: '', content: [(this.stockChart.stockEvents[pointIndex].description)], enableAnimation: true, location: pointLocation, theme: this.stockChart.theme, inverted: true, areaBounds: this.stockChart.chart.chartAxisLayoutPanel.seriesClipRect }); this.stockEventTooltip.areaBounds.y += this.stockChart.toolbarHeight + this.stockChart.titleSize.height; this.stockEventTooltip.appendTo('#' + tooltipElement.id); } else { this.stockEventTooltip.content = [(this.stockChart.stockEvents[pointIndex].description)]; this.stockEventTooltip.location = pointLocation; this.stockEventTooltip.dataBind(); } }; StockEvents.prototype.removeStockEventTooltip = function (duration) { var _this = this; var tooltipElement = this.getElement(this.chartId + '_StockEvents_Tooltip'); this.stopAnimation(); if (tooltipElement && this.stockEventTooltip) { this.toolTipInterval = +setTimeout(function () { _this.stockEventTooltip.fadeOut(); _this.removeHighLights(); }, duration); } else Iif (tooltipElement && this.stockChart.onPanning) { ej2_base_1.remove(tooltipElement); } }; StockEvents.prototype.findArrowpaths = function (type) { var arrowString = ''; switch (type) { case 'ArrowUp': arrowString = 'l -10 10 l 5 0 l 0 10 l 10 0 l 0 -10 l 5 0 z'; break; case 'ArrowDown': arrowString = 'l -10 -10 l 5 0 l 0 -10 l 10 0 l 0 10 l 5 0 z'; break; case 'ArrowLeft': arrowString = 'l -10 -10 l 0 5 l -10 0 l 0 10 l 10 0 l 0 5 z'; break; case 'ArrowRight': arrowString = 'l 10 -10 l 0 5 l 10 0 l 0 10 l -10 0 l 0 5 z'; break; } return arrowString; }; StockEvents.prototype.applyHighLights = function (pointIndex, seriesIndex) { if (this.pointIndex !== pointIndex || this.seriesIndex !== seriesIndex) { this.removeHighLights(); } this.pointIndex = pointIndex; this.seriesIndex = seriesIndex; var stockId = this.chartId + '_Series_' + seriesIndex + '_StockEvents_' + pointIndex; this.setOpacity(stockId + '_Shape', 0.5); this.setOpacity(stockId + '_Text', 0.5); }; StockEvents.prototype.removeHighLights = function () { var stockId = this.chartId + '_Series_' + this.seriesIndex + '_StockEvents_' + this.pointIndex; this.setOpacity(stockId + '_Shape', 1); this.setOpacity(stockId + '_Text', 1); }; StockEvents.prototype.setOpacity = function (elementId, opacity) { if (helper_1.getElement(elementId)) { helper_1.getElement(elementId).setAttribute('opacity', opacity.toString()); } }; StockEvents.prototype.dateParse = function (value) { var dateParser = this.chart.intl.getDateParser({ skeleton: 'full', type: 'dateTime' }); var dateFormatter = this.chart.intl.getDateFormat({ skeleton: 'full', type: 'dateTime' }); return new Date((Date.parse(dateParser(dateFormatter(new Date(ej2_data_1.DataUtil.parse.parseJson({ val: value }).val)))))); }; return StockEvents; }(tooltip_1.BaseTooltip)); exports.StockEvents = StockEvents; function initialArray(numrows, numcols, initial) { var arr = []; for (var i = 0; i < numrows; ++i) { var columns = []; for (var j = 0; j < numcols; ++j) { columns[j] = initial; } arr[i] = columns; } return arr; } }); |