scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
58 lines (57 loc) • 3.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.polarHitTestHelpers = void 0;
var Deleter_1 = require("../../../../../Core/Deleter");
function getNearestPolarPoint(webassemblyContext, xCoordinateCalculator, yCoordinateCalculator, dataSeries, xHitCoord, yHitCoord) {
var isCategoryAxis = xCoordinateCalculator.isCategoryCoordinateCalculator;
var dataX = isCategoryAxis ? dataSeries.getNativeIndexes() : dataSeries.getNativeXValues();
var dataY = dataSeries.getNativeYValues();
var result;
try {
result = webassemblyContext.SCRTHitTestHelper.GetNearestPolarXyPoint(xCoordinateCalculator.nativeCalculator, yCoordinateCalculator.nativeCalculator, dataX, dataY, xHitCoord, yHitCoord, false, false);
return { nearestPointIndex: result.minD, distance: result.maxD };
}
finally {
(0, Deleter_1.deleteSafe)(result);
}
}
function getNearestPolarPointXDirSorted(webassemblyContext, xCoordinateCalculator, yCoordinateCalculator, dataSeries, xHitPolarCoord, yHitPolarCoord) {
var isCategoryAxis = xCoordinateCalculator.isCategoryCoordinateCalculator;
var dataX = isCategoryAxis ? dataSeries.getNativeIndexes() : dataSeries.getNativeXValues();
var dataY = dataSeries.getNativeYValues();
var result;
try {
result = webassemblyContext.SCRTHitTestHelper.GetNearestPolarXyPoint(xCoordinateCalculator.nativeCalculator, yCoordinateCalculator.nativeCalculator, dataX, dataY, xHitPolarCoord, yHitPolarCoord, true, true);
var nearestPointIndex = result.minD, distance = result.maxD;
if (nearestPointIndex === -1 || dataSeries.count() === 0) {
return { nearestPointIndex: -1, distance: undefined, secondNearestPointIndex: -1 };
}
if (dataSeries.count() === 1) {
return { nearestPointIndex: nearestPointIndex, distance: distance, secondNearestPointIndex: -1 };
}
var isAscending = dataX.get(1) - dataX.get(0) > 0;
var xHitValue = xCoordinateCalculator.getDataValue(xHitPolarCoord);
var secondPointIndex = (xHitValue >= dataX.get(nearestPointIndex) && isAscending) ||
(xHitValue <= dataX.get(nearestPointIndex) && !isAscending)
? nearestPointIndex + 1
: nearestPointIndex - 1;
if (secondPointIndex < 0 || secondPointIndex >= dataSeries.count()) {
return { nearestPointIndex: nearestPointIndex, distance: distance, secondNearestPointIndex: -1 };
}
// handling the case when click is around 2PI - delta. This case used to return
// nearestPointIndex = 0, secondNearestPointIndex = 1
// but the correct result would be nearestPointIndex = 0, secondNearestPointIndex = -1
if (!(dataX.get(nearestPointIndex) <= xHitValue && xHitValue <= dataX.get(secondPointIndex)) &&
!(dataX.get(nearestPointIndex) >= xHitValue && xHitValue >= dataX.get(secondPointIndex))) {
return { nearestPointIndex: nearestPointIndex, distance: distance, secondNearestPointIndex: -1 };
}
return { nearestPointIndex: nearestPointIndex, distance: distance, secondNearestPointIndex: secondPointIndex };
}
finally {
(0, Deleter_1.deleteSafe)(result);
}
}
exports.polarHitTestHelpers = {
getNearestPolarPoint: getNearestPolarPoint,
getNearestPolarPointXDirSorted: getNearestPolarPointXDirSorted
};