UNPKG

@devexperts/dxcharts-lite

Version:
41 lines (40 loc) 1.42 kB
/* * Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ /** * Zooms to percentage of viewport proportionally. * @param vm * @param state * @param viewportPercent * @param zoomStrength - 0..1 number, 1=max strength * @param zoomIn * @doc-tags viewport,zoom,scaling */ export const zoomXToPercentViewportCalculator = (vm, state, viewportPercent, zoomStrength, zoomIn) => { const deltaWidth = (state.xEnd - state.xStart) * zoomStrength; const deltaStart = deltaWidth * viewportPercent; const deltaEnd = deltaWidth * (1 - viewportPercent); if (zoomIn) { state.xStart = state.xStart + deltaStart; state.xEnd = state.xEnd - deltaEnd; } else { state.xStart = state.xStart - deltaStart; state.xEnd = state.xEnd + deltaEnd; } state.zoomX = vm.calculateZoomX(state.xStart, state.xEnd); return state; }; /** * Zooms to viewports end. * @param vm * @param state * @param zoomStrength - 0..1 number, 1=max strength * @param zoomIn * @doc-tags viewport,zoom,scaling */ export const zoomXToEndViewportCalculator = (vm, state, zoomStrength, zoomIn) => { return zoomXToPercentViewportCalculator(vm, state, 1, zoomStrength, zoomIn); };