scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
112 lines (111 loc) • 6.41 kB
JavaScript
;
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.TriangleSeriesHitTestProvider = void 0;
var Point_1 = require("../../../../Core/Point");
var TriangleSeriesDrawMode_1 = require("../../../../types/TriangleSeriesDrawMode");
var BaseHitTestProvider_1 = require("./BaseHitTestProvider");
var hitTestHelpers_1 = require("./hitTestHelpers");
var HitTestInfo_1 = require("./HitTestInfo");
/**
* Hit-test provider for {@link FastTriangleRenderableSeries}. See base class {@link BaseHitTestProvider} for further info
*/
var TriangleSeriesHitTestProvider = /** @class */ (function (_super) {
__extends(TriangleSeriesHitTestProvider, _super);
function TriangleSeriesHitTestProvider() {
return _super !== null && _super.apply(this, arguments) || this;
}
/** @inheritDoc */
TriangleSeriesHitTestProvider.prototype.hitTest = function (x, y) {
var hitTestPoint = this.getTranslatedHitTestPoint(x, y);
if (!hitTestPoint) {
return HitTestInfo_1.HitTestInfo.empty();
}
var _a = this.currentRenderPassData, xCoordinateCalculator = _a.xCoordinateCalculator, yCoordinateCalculator = _a.yCoordinateCalculator, isVerticalChart = _a.isVerticalChart;
var xHitCoord = isVerticalChart ? hitTestPoint.y : hitTestPoint.x;
var yHitCoord = isVerticalChart ? hitTestPoint.x : hitTestPoint.y;
var dataSeries = this.parentSeries.dataSeries;
if (!dataSeries)
return HitTestInfo_1.HitTestInfo.empty();
var xNativeValues = dataSeries.getNativeXValues();
var yNativeValues = dataSeries.getNativeYValues();
var _b = this.parentSeries, drawMode = _b.drawMode, polygonVertices = _b.polygonVertices;
var _c = hitTestHelpers_1.hitTestHelpers.getNearestTriangle(this.webAssemblyContext, xCoordinateCalculator, yCoordinateCalculator, xNativeValues, yNativeValues, xHitCoord, yHitCoord, drawMode, polygonVertices), nearestPointIndex = _c.nearestPointIndex, nearestPointIndex2 = _c.nearestPointIndex2, isHit = _c.isHit;
var hitTestInfo = new HitTestInfo_1.HitTestInfo(this.parentSeries);
hitTestInfo.seriesName = this.parentSeries.seriesName;
hitTestInfo.dataSeriesType = dataSeries.type;
hitTestInfo.hitTestPoint = new Point_1.Point(xHitCoord, yHitCoord);
var hitTestPointXValue = xCoordinateCalculator.getDataValue(xHitCoord);
var hitTestPointYValue = yCoordinateCalculator.getDataValue(yHitCoord);
hitTestInfo.hitTestPointValues = new Point_1.Point(hitTestPointXValue, hitTestPointYValue);
hitTestInfo.dataSeriesIndex = nearestPointIndex;
hitTestInfo.point2dataSeriesIndex = nearestPointIndex2;
hitTestInfo.distance = isHit ? 0 : 1;
if (nearestPointIndex >= 0) {
var xValue = dataSeries.getNativeValue(xNativeValues, nearestPointIndex);
var yValue = dataSeries.getNativeValue(yNativeValues, nearestPointIndex);
hitTestInfo.xCoord = xCoordinateCalculator.getCoordinate(xValue);
hitTestInfo.yCoord = yCoordinateCalculator.getCoordinate(yValue);
hitTestInfo.xValue = xValue;
hitTestInfo.yValue = yValue;
hitTestInfo.metadata = dataSeries.getMetadataAt(nearestPointIndex);
}
if (nearestPointIndex2 >= 0) {
var xValue2 = dataSeries.getNativeValue(xNativeValues, nearestPointIndex2);
var yValue2 = dataSeries.getNativeValue(yNativeValues, nearestPointIndex2);
hitTestInfo.point2xCoord = xCoordinateCalculator.getCoordinate(xValue2);
hitTestInfo.point2yCoord = yCoordinateCalculator.getCoordinate(yValue2);
hitTestInfo.point2xValue = xValue2;
hitTestInfo.point2yValue = yValue2;
hitTestInfo.metadata = dataSeries.getMetadataAt(nearestPointIndex);
var point2yValueByName = dataSeries.valueNames.reduce(function (map, name) {
map[name] = dataSeries.getNativeValue(dataSeries.getYValuesByName(name), hitTestInfo.point2dataSeriesIndex);
return map;
}, {});
hitTestInfo.point2yValueByName = point2yValueByName;
}
if (nearestPointIndex >= 0) {
var vertCount = drawMode === TriangleSeriesDrawMode_1.ETriangleSeriesDrawMode.Polygon ? polygonVertices : 3;
var xValues = [];
var yValues = [];
for (var index = nearestPointIndex; index < nearestPointIndex + vertCount; index++) {
var x_1 = dataSeries.getNativeValue(xNativeValues, index);
var y_1 = dataSeries.getNativeValue(yNativeValues, index);
xValues.push(x_1);
yValues.push(y_1);
}
hitTestInfo.xValues = xValues;
hitTestInfo.yValues = yValues;
}
hitTestInfo.isHit = isHit;
return hitTestInfo;
};
/** @inheritDoc */
TriangleSeriesHitTestProvider.prototype.hitTestForDataPointSelectionModifier = function (x, y) {
return this.hitTest(x, y);
};
/** @inheritDoc */
TriangleSeriesHitTestProvider.prototype.hitTestXSlice = function (x, y) {
return this.hitTest(x, y);
};
/** @inheritDoc */
TriangleSeriesHitTestProvider.prototype.hitTestDataPoint = function (x, y, hitTestRadius) {
return this.hitTest(x, y);
};
return TriangleSeriesHitTestProvider;
}(BaseHitTestProvider_1.BaseHitTestProvider));
exports.TriangleSeriesHitTestProvider = TriangleSeriesHitTestProvider;