UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

100 lines (99 loc) 5.96 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PolarMountainSeriesHitTestProvider = void 0; var Point_1 = require("../../../../../Core/Point"); var HitTestInfo_1 = require("../../HitTest/HitTestInfo"); var hitTestHelpers_1 = require("../../HitTest/hitTestHelpers"); var annotationHelpers_1 = require("../../../Annotations/annotationHelpers"); var AnnotationBase_1 = require("../../../Annotations/AnnotationBase"); var pointUtil_1 = require("../../../../../utils/pointUtil"); var PolarDataPointHitTestProvider_1 = require("./PolarDataPointHitTestProvider"); var DpiHelper_1 = require("../../../TextureManager/DpiHelper"); var polarHitTestHelpers_1 = require("./polarHitTestHelpers"); var DEFAULT_RADIUS = 10; /** * Hit-test provider for {@link PolarMountainRenderableSeries}. See base class {@link BaseHitTestProvider} for further info. * Does not support vertical charts */ var PolarMountainSeriesHitTestProvider = /** @class */ (function (_super) { __extends(PolarMountainSeriesHitTestProvider, _super); function PolarMountainSeriesHitTestProvider() { return _super !== null && _super.apply(this, arguments) || this; } /** @inheritDoc */ PolarMountainSeriesHitTestProvider.prototype.hitTest = function (x, y) { return this.hitTestMountainBody(x, y); }; /** @inheritDoc */ PolarMountainSeriesHitTestProvider.prototype.hitTestDataPoint = function (x, y, hitTestRadius) { var radius = hitTestRadius > 0 ? hitTestRadius : DEFAULT_RADIUS; return _super.prototype.hitTestDataPoint.call(this, x, y, radius); }; /** @inheritDoc */ PolarMountainSeriesHitTestProvider.prototype.hitTestXSlice = function (x, y) { return this.hitTestMountainBody(x, y); }; /** * Does not support ve * @param x * @param y * @returns */ PolarMountainSeriesHitTestProvider.prototype.hitTestMountainBody = function (x, y) { var _this = this; // convert to polar and add necessary offset var hitTestPoint = this.getTranslatedHitTestPoint(x, y); if (!hitTestPoint) { return HitTestInfo_1.HitTestInfo.empty(); } var xPolarAxis = this.parentSeries.xAxis; var hitTestPointPolar = xPolarAxis.reverseTransform(hitTestPoint.x, hitTestPoint.y); var _a = this.currentRenderPassData, xCoordinateCalculator = _a.xCoordinateCalculator, yCoordinateCalculator = _a.yCoordinateCalculator; var xHitPolarCoord = hitTestPointPolar.x; var yHitPolarCoord = hitTestPointPolar.y; var dataSeries = this.parentSeries.dataSeries; if (!dataSeries) { return HitTestInfo_1.HitTestInfo.empty(); } var _b = polarHitTestHelpers_1.polarHitTestHelpers.getNearestPolarPointXDirSorted(this.webAssemblyContext, xCoordinateCalculator, yCoordinateCalculator, dataSeries, xHitPolarCoord, yHitPolarCoord), nearestPointIndex = _b.nearestPointIndex, distance = _b.distance, secondNearestPointIndex = _b.secondNearestPointIndex; var isCategoryAxis = xCoordinateCalculator.isCategoryCoordinateCalculator; var xNativeValues = isCategoryAxis ? dataSeries.getNativeIndexes() : dataSeries.getNativeXValues(); var yNativeValues = dataSeries.getNativeYValues(); var isHit = false; var isWithinDataBounds = false; if (secondNearestPointIndex != -1) { isWithinDataBounds = true; var getCartesianCoordsFn = function (xValue$, yValue$) { var angle = xCoordinateCalculator.getCoordinate(xValue$); var radius = yCoordinateCalculator.getCoordinate(yValue$); var res = annotationHelpers_1.annotationHelpers.convertPolarToCartesian(xPolarAxis, false, _this.webAssemblyContext, AnnotationBase_1.ECoordinateMode.Pixel, angle * DpiHelper_1.DpiHelper.PIXEL_RATIO, radius); return new Point_1.Point(res.x, res.y); }; var centerPointCoord = getCartesianCoordsFn(0, 0); var firstPointCoord = getCartesianCoordsFn(xNativeValues.get(nearestPointIndex), yNativeValues.get(nearestPointIndex)); var secondPointCoord = getCartesianCoordsFn(xNativeValues.get(secondNearestPointIndex), yNativeValues.get(secondNearestPointIndex)); isHit = (0, pointUtil_1.testPointInTriangle)(hitTestPoint.x, hitTestPoint.y, centerPointCoord.x, centerPointCoord.y, firstPointCoord.x, firstPointCoord.y, secondPointCoord.x, secondPointCoord.y); } var hitTestInfo = hitTestHelpers_1.hitTestHelpers.createHitTestInfo(this.parentSeries, xCoordinateCalculator, yCoordinateCalculator, false, dataSeries, xNativeValues, yNativeValues, xHitPolarCoord, yHitPolarCoord, nearestPointIndex, distance); hitTestInfo.isHit = isHit; hitTestInfo.isWithinDataBounds = isWithinDataBounds; return hitTestInfo; }; return PolarMountainSeriesHitTestProvider; }(PolarDataPointHitTestProvider_1.PolarDataPointHitTestProvider)); exports.PolarMountainSeriesHitTestProvider = PolarMountainSeriesHitTestProvider;