UNPKG

@nativescript-community/ui-chart

Version:

A powerful chart / graph plugin, supporting line, bar, pie, radar, bubble, and candlestick charts as well as scaling, panning and animations.

95 lines 2.85 kB
import { Tween } from './Tween'; function clamp(value) { return Math.min(1, Math.max(0, value)); } export class ChartAnimator { constructor(listener) { /** The phase of drawn values on the y-axis. 0 - 1 */ this.mPhaseY = 1; /** The phase of drawn values on the x-axis. 0 - 1 */ this.mPhaseX = 1; this.mListener = listener; } startAnim(duration, easing, listener) { const anim = new Tween({ onRender: listener }); anim.tween({ value: 0 }, { value: 1 }, duration); return anim; } startXAnim(duration, easing, listener) { return this.startAnim(duration, easing, (state) => { this.phaseX = state.value; listener?.(state); }); } startYAnim(duration, easing, listener) { return this.startAnim(duration, easing, (state) => { this.phaseY = state.value; listener?.(state); }); } /** * Animates values along the X axis. * * @param durationMillis animation duration * @param easing EasingFunction */ animateX(durationMillis, easing) { this.startXAnim(durationMillis, easing, this.mListener); } /** * Animates values along both the X and Y axes. * * @param durationMillisX animation duration along the X axis * @param durationMillisY animation duration along the Y axis * @param easingX EasingFunction for the X axis * @param easingY EasingFunction for the Y axis */ animateXY(durationMillisX, durationMillisY, easingX, easingY) { this.startXAnim(durationMillisX, easingX, durationMillisX > durationMillisY ? this.mListener : undefined); this.startYAnim(durationMillisY, easingY || easingX, durationMillisX > durationMillisY ? undefined : this.mListener); } /** * Animates values along the Y axis. * * @param durationMillis animation duration * @param easing EasingFunction */ animateY(durationMillis, easing) { this.startYAnim(durationMillis, easing, this.mListener); } /** * Gets the Y axis phase of the animation. * * @return let value of {@link #mPhaseY} */ get phaseY() { return this.mPhaseY; } /** * Sets the Y axis phase of the animation. * * @param phase let value between 0 - 1 */ set phaseY(phase) { this.mPhaseY = clamp(phase); } /** * Gets the X axis phase of the animation. * * @return let value of {@link #mPhaseX} */ get phaseX() { return this.mPhaseX; } /** * Sets the X axis phase of the animation. * * @param phase let value between 0 - 1 */ set phaseX(phase) { this.mPhaseX = clamp(phase); } } //# sourceMappingURL=ChartAnimator.js.map