UNPKG

@visactor/vtable

Version:

canvas table width high performance

61 lines (55 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.TableAnimationManager = void 0; const vrender_1 = require("./../vrender"), vutils_1 = require("@visactor/vutils"); function isInteger(value) { return Math.floor(value) === value; } class Animateaaa extends vrender_1.ACustomAnimate { onUpdate(end, ratio, out) { if (this.from.x !== this.to.x) { const x = end ? this.to.x : this.from.x + Math.floor((this.to.x - this.from.x) * ratio); this.params.table.scrollLeft = x; } if (this.from.y !== this.to.y) { const y = end ? this.to.y : this.from.y + Math.floor((this.to.y - this.from.y) * ratio); this.params.table.scrollTop = y; } } } class TableAnimationManager { constructor(table) { this.table = table, this.timeline = new vrender_1.DefaultTimeline, this.ticker = new vrender_1.DefaultTicker, this.ticker.addTimeline(this.timeline); this.ticker.setFPS(60), this.tempGraphic = (0, vrender_1.createRect)({}); } scrollTo(position, animationOption) { var _a, _b; const from = { x: this.table.scrollLeft, y: this.table.scrollTop }, {col: col, row: row} = position; let colDecimal, rowDecimal, colInt = col, rowInt = row; (0, vutils_1.isNumber)(col) && !isInteger(col) && (colInt = Math.floor(col), colDecimal = col - colInt), (0, vutils_1.isNumber)(row) && !isInteger(row) && (rowInt = Math.floor(row), rowDecimal = row - rowInt); const cellRect = this.table.getCellRect(null != colInt ? colInt : 0, null != rowInt ? rowInt : 0); let {left: left, top: top} = cellRect; colDecimal && (left += colDecimal * cellRect.width), rowDecimal && (top += rowDecimal * cellRect.height); const to = { x: (0, vutils_1.isNumber)(col) ? left - this.table.getFrozenColsWidth() : this.table.scrollLeft, y: (0, vutils_1.isNumber)(row) ? top - this.table.getFrozenRowsHeight() : this.table.scrollTop }, duration = (0, vutils_1.isBoolean)(animationOption) ? animationOption ? 3e3 : 0 : null !== (_a = null == animationOption ? void 0 : animationOption.duration) && void 0 !== _a ? _a : 3e3, easing = (0, vutils_1.isBoolean)(animationOption) ? animationOption ? "linear" : "" : null !== (_b = null == animationOption ? void 0 : animationOption.easing) && void 0 !== _b ? _b : "linear"; new vrender_1.Animate(vrender_1.Generator.GenAutoIncrementId(), this.timeline).bind(this.tempGraphic).play(new Animateaaa(from, to, duration, easing, { graphic: this.tempGraphic, table: this.table })); this.ticker.start(); } clear() { this.timeline.clear(), this.ticker.stop(); } } exports.TableAnimationManager = TableAnimationManager; //# sourceMappingURL=animation.js.map