INNER CODE UNIT · TypeScript
getGraphDataIndex
margelo/react-native-graph · src/CreateGraphPath.ts:164
const getGraphDataIndex = (pixel: number) =>
endX === startX
? 0
: Math.round(
((pixel - startX) / (endX - startX)) * (graphData.length - 1)
);
const getNextPixelValue = (pixel: number) => {
if (pixel === endX || pixel + PIXEL_RATIO < endX)
return pixel + PIXEL_RATIO;
return endX;
};
for (
let pixel = startX;
startX <= pixel && pixel <= endX;
pixel = getNextPixelValue(pixel)
) {