12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Storytelling
- * (C) Copyright IBM Corp. 2014, 2018
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['baglass/core-client/js/core-client/ui/core/Events'], function (Events) {
- var ScaleManager = Events.extend({
- defaultPixelsPerSecond: 1,
- minScale: 1,
- maxScale: 250,
- scale: 1,
- duration: 0,
- availableWidth: 0,
- init: function init() {
- ScaleManager.inherited('init', this, arguments);
- },
- updateDuration: function updateDuration(duration, availableWidth) {
- this.duration = duration;
- this.availableWidth = availableWidth;
- },
- scaleToFit: function scaleToFit() {
- var scale = this._calculateFitToSizeScale();
- this.setScale(scale);
- },
- /**
- * @param step - a scale factor to apply
- */
- stepScale: function stepScale(step) {
- if (step !== 0) {
- this.setScale(this.scale * step);
- }
- },
- setScale: function setScale(scale) {
- var previousScale = this.scale;
- this.scale = Math.max(this.minScale, Math.min(this.maxScale, scale));
- this.trigger('scale:change', { scale: this.scale, previousScale: previousScale });
- },
- getScale: function getScale() {
- return this.scale;
- },
- getScaleToPixelRatio: function getScaleToPixelRatio() {
- return this.defaultPixelsPerSecond;
- },
- getMinScale: function getMinScale() {
- return this.minScale;
- },
- getMaxScale: function getMaxScale() {
- return this.maxScale;
- },
- convertTimeToPosition: function convertTimeToPosition(time) {
- return time / 1000 * this.defaultPixelsPerSecond * (this.scale || 1);
- },
- convertPositionToTime: function convertPositionToTime(position) {
- return position / (this.defaultPixelsPerSecond * (this.scale || 1)) * 1000;
- },
- /*
- * Helpers.
- */
- _calculateFitToSizeScale: function _calculateFitToSizeScale() {
- var position = this.convertTimeToPosition(this.duration);
- var ratio = position > 0 ? this.availableWidth / position : 1;
- return this.scale * ratio;
- }
- });
- return ScaleManager;
- });
- //# sourceMappingURL=ScaleManager.js.map
|