UNPKG

@hms-dbmi-bgm/react-workflow-viz

Version:

React component for visualizing CWL-like workflows and provenance graphs.

50 lines (42 loc) 2.07 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.cancelAnimationFrame = cancelAnimationFrame; exports.requestAnimationFrame = requestAnimationFrame; exports.roundScaled = roundScaled; var _react = _interopRequireDefault(require("react")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } /** * Helper function for window.requestAnimationFrame. Falls back to browser-prefixed versions if default not available, or falls back to setTimeout with 0ms delay if no requestAnimationFrame available at all. * * @param {function} cb - Callback method. * @returns {undefined|string} Undefined or timeout ID if falling back to setTimeout. */ function requestAnimationFrame(cb) { if ( /*!isServerSide() && */ typeof window !== 'undefined') { if (typeof window.requestAnimationFrame !== 'undefined') return window.requestAnimationFrame(cb); if (typeof window.webkitRequestAnimationFrame !== 'undefined') return window.webkitRequestAnimationFrame(cb); if (typeof window.mozRequestAnimationFrame !== 'undefined') return window.mozRequestAnimationFrame(cb); } return setTimeout(cb, 0); // Mock it for old browsers and server-side. } function cancelAnimationFrame(identifier) { if ( /*!isServerSide() && */ typeof window !== 'undefined') { if (typeof window.cancelAnimationFrame !== 'undefined') return window.cancelAnimationFrame(identifier); if (typeof window.webkitCancelAnimationFrame !== 'undefined') return window.webkitCancelAnimationFrame(identifier); if (typeof window.mozCancelAnimationFrame !== 'undefined') return window.mozCancelAnimationFrame(identifier); } return clearTimeout(identifier); // Mock it for old browsers and server-side. } function roundScaled(value, scale) { var decimals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2; //shortcut - useful for most cases if (scale === 1) return value; var factor = Math.pow(10, decimals); return Math.round(value * scale * factor) / factor; }