@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
23 lines (18 loc) • 752 B
JavaScript
/**
* Modify the axis start and end value based on given scaling
* @param {number} axisLength
* @param {number} cursorToGraphPos
* @param {number} axisStart
* @param {number} axisEnd
* @param {number} scaling
* @returns {(number|*)[]}
*/
export function updateAxisRange(axisLength,cursorToGraphPos, axisStart, axisEnd, scaling){
let axisRange = axisEnd - axisStart;
const ratioCursorToGraphX = cursorToGraphPos / axisLength;
const axisCentre = axisStart + (ratioCursorToGraphX * axisRange);
axisRange = (axisEnd - axisStart) / scaling;
axisStart = axisCentre - (ratioCursorToGraphX * axisRange);
axisEnd = axisCentre + (1 - ratioCursorToGraphX) * axisRange;
return [axisStart, axisEnd];
}