victory-native
Version:
A charting library for React Native with a focus on performance and customization.
28 lines (27 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getStackedBarTouchSegmentIndex = void 0;
const getStackedBarTouchSegmentIndex = ({ values, touchValue, }) => {
"worklet";
var _a;
if (!Number.isFinite(touchValue) || touchValue === 0)
return -1;
let cumulativeValue = 0;
const isPositiveTouch = touchValue > 0;
for (let i = 0; i < values.length; i++) {
const value = (_a = values[i]) !== null && _a !== void 0 ? _a : NaN;
if (!Number.isFinite(value) || value === 0)
continue;
if (value > 0 !== isPositiveTouch)
continue;
const startValue = cumulativeValue;
const endValue = cumulativeValue + value;
if ((isPositiveTouch && touchValue >= startValue && touchValue <= endValue) ||
(!isPositiveTouch && touchValue <= startValue && touchValue >= endValue)) {
return i;
}
cumulativeValue = endValue;
}
return -1;
};
exports.getStackedBarTouchSegmentIndex = getStackedBarTouchSegmentIndex;