vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1356 lines
47 KiB

  1. var Emitter = require('emitter-component');
  2. var Hammer = require('../module/hammer');
  3. var hammerUtil = require('../hammerUtil');
  4. var util = require('../util');
  5. var TimeAxis = require('./component/TimeAxis');
  6. var Activator = require('../shared/Activator');
  7. var DateUtil = require('./DateUtil');
  8. var CustomTime = require('./component/CustomTime');
  9. /**
  10. * Create a timeline visualization
  11. * @constructor Core
  12. */
  13. function Core () {}
  14. // turn Core into an event emitter
  15. Emitter(Core.prototype);
  16. /**
  17. * Create the main DOM for the Core: a root panel containing left, right,
  18. * top, bottom, content, and background panel.
  19. * @param {Element} container The container element where the Core will
  20. * be attached.
  21. * @protected
  22. */
  23. Core.prototype._create = function (container) {
  24. this.dom = {};
  25. this.dom.container = container;
  26. this.dom.container.style.position = 'relative';
  27. this.dom.root = document.createElement('div');
  28. this.dom.background = document.createElement('div');
  29. this.dom.backgroundVertical = document.createElement('div');
  30. this.dom.backgroundHorizontal = document.createElement('div');
  31. this.dom.centerContainer = document.createElement('div');
  32. this.dom.leftContainer = document.createElement('div');
  33. this.dom.rightContainer = document.createElement('div');
  34. this.dom.center = document.createElement('div');
  35. this.dom.left = document.createElement('div');
  36. this.dom.right = document.createElement('div');
  37. this.dom.top = document.createElement('div');
  38. this.dom.bottom = document.createElement('div');
  39. this.dom.shadowTop = document.createElement('div');
  40. this.dom.shadowBottom = document.createElement('div');
  41. this.dom.shadowTopLeft = document.createElement('div');
  42. this.dom.shadowBottomLeft = document.createElement('div');
  43. this.dom.shadowTopRight = document.createElement('div');
  44. this.dom.shadowBottomRight = document.createElement('div');
  45. this.dom.rollingModeBtn = document.createElement('div');
  46. this.dom.loadingScreen = document.createElement('div');
  47. this.dom.root.className = 'vis-timeline';
  48. this.dom.background.className = 'vis-panel vis-background';
  49. this.dom.backgroundVertical.className = 'vis-panel vis-background vis-vertical';
  50. this.dom.backgroundHorizontal.className = 'vis-panel vis-background vis-horizontal';
  51. this.dom.centerContainer.className = 'vis-panel vis-center';
  52. this.dom.leftContainer.className = 'vis-panel vis-left';
  53. this.dom.rightContainer.className = 'vis-panel vis-right';
  54. this.dom.top.className = 'vis-panel vis-top';
  55. this.dom.bottom.className = 'vis-panel vis-bottom';
  56. this.dom.left.className = 'vis-content';
  57. this.dom.center.className = 'vis-content';
  58. this.dom.right.className = 'vis-content';
  59. this.dom.shadowTop.className = 'vis-shadow vis-top';
  60. this.dom.shadowBottom.className = 'vis-shadow vis-bottom';
  61. this.dom.shadowTopLeft.className = 'vis-shadow vis-top';
  62. this.dom.shadowBottomLeft.className = 'vis-shadow vis-bottom';
  63. this.dom.shadowTopRight.className = 'vis-shadow vis-top';
  64. this.dom.shadowBottomRight.className = 'vis-shadow vis-bottom';
  65. this.dom.rollingModeBtn.className = 'vis-rolling-mode-btn';
  66. this.dom.loadingScreen.className = 'vis-loading-screen';
  67. this.dom.root.appendChild(this.dom.background);
  68. this.dom.root.appendChild(this.dom.backgroundVertical);
  69. this.dom.root.appendChild(this.dom.backgroundHorizontal);
  70. this.dom.root.appendChild(this.dom.centerContainer);
  71. this.dom.root.appendChild(this.dom.leftContainer);
  72. this.dom.root.appendChild(this.dom.rightContainer);
  73. this.dom.root.appendChild(this.dom.top);
  74. this.dom.root.appendChild(this.dom.bottom);
  75. this.dom.root.appendChild(this.dom.rollingModeBtn);
  76. this.dom.centerContainer.appendChild(this.dom.center);
  77. this.dom.leftContainer.appendChild(this.dom.left);
  78. this.dom.rightContainer.appendChild(this.dom.right);
  79. this.dom.centerContainer.appendChild(this.dom.shadowTop);
  80. this.dom.centerContainer.appendChild(this.dom.shadowBottom);
  81. this.dom.leftContainer.appendChild(this.dom.shadowTopLeft);
  82. this.dom.leftContainer.appendChild(this.dom.shadowBottomLeft);
  83. this.dom.rightContainer.appendChild(this.dom.shadowTopRight);
  84. this.dom.rightContainer.appendChild(this.dom.shadowBottomRight);
  85. // size properties of each of the panels
  86. this.props = {
  87. root: {},
  88. background: {},
  89. centerContainer: {},
  90. leftContainer: {},
  91. rightContainer: {},
  92. center: {},
  93. left: {},
  94. right: {},
  95. top: {},
  96. bottom: {},
  97. border: {},
  98. scrollTop: 0,
  99. scrollTopMin: 0
  100. };
  101. this.on('rangechange', function () {
  102. if (this.initialDrawDone === true) {
  103. this._redraw();
  104. }
  105. }.bind(this));
  106. this.on('rangechanged', function () {
  107. if (!this.initialRangeChangeDone) {
  108. this.initialRangeChangeDone = true;
  109. }
  110. }.bind(this));
  111. this.on('touch', this._onTouch.bind(this));
  112. this.on('panmove', this._onDrag.bind(this));
  113. var me = this;
  114. this._origRedraw = this._redraw.bind(this);
  115. this._redraw = util.throttle(this._origRedraw);
  116. this.on('_change', function (properties) {
  117. if (me.itemSet && me.itemSet.initialItemSetDrawn && properties && properties.queue == true) {
  118. me._redraw()
  119. } else {
  120. me._origRedraw();
  121. }
  122. });
  123. // create event listeners for all interesting events, these events will be
  124. // emitted via emitter
  125. this.hammer = new Hammer(this.dom.root);
  126. var pinchRecognizer = this.hammer.get('pinch').set({enable: true});
  127. pinchRecognizer && hammerUtil.disablePreventDefaultVertically(pinchRecognizer);
  128. this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
  129. this.listeners = {};
  130. var events = [
  131. 'tap', 'doubletap', 'press',
  132. 'pinch',
  133. 'pan', 'panstart', 'panmove', 'panend'
  134. // TODO: cleanup
  135. //'touch', 'pinch',
  136. //'tap', 'doubletap', 'hold',
  137. //'dragstart', 'drag', 'dragend',
  138. //'mousewheel', 'DOMMouseScroll' // DOMMouseScroll is needed for Firefox
  139. ];
  140. events.forEach(function (type) {
  141. var listener = function (event) {
  142. if (me.isActive()) {
  143. me.emit(type, event);
  144. }
  145. };
  146. me.hammer.on(type, listener);
  147. me.listeners[type] = listener;
  148. });
  149. // emulate a touch event (emitted before the start of a pan, pinch, tap, or press)
  150. hammerUtil.onTouch(this.hammer, function (event) {
  151. me.emit('touch', event);
  152. }.bind(this));
  153. // emulate a release event (emitted after a pan, pinch, tap, or press)
  154. hammerUtil.onRelease(this.hammer, function (event) {
  155. me.emit('release', event);
  156. }.bind(this));
  157. /**
  158. *
  159. * @param {WheelEvent} event
  160. */
  161. function onMouseWheel(event) {
  162. if (this.isActive()) {
  163. this.emit('mousewheel', event);
  164. }
  165. // deltaX and deltaY normalization from jquery.mousewheel.js
  166. var deltaX = 0;
  167. var deltaY = 0;
  168. // Old school scrollwheel delta
  169. if ( 'detail' in event ) { deltaY = event.detail * -1; }
  170. if ( 'wheelDelta' in event ) { deltaY = event.wheelDelta; }
  171. if ( 'wheelDeltaY' in event ) { deltaY = event.wheelDeltaY; }
  172. if ( 'wheelDeltaX' in event ) { deltaX = event.wheelDeltaX * -1; }
  173. // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
  174. if ( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  175. deltaX = deltaY * -1;
  176. deltaY = 0;
  177. }
  178. // New school wheel delta (wheel event)
  179. if ( 'deltaY' in event ) {
  180. deltaY = event.deltaY * -1;
  181. }
  182. if ( 'deltaX' in event ) {
  183. deltaX = event.deltaX;
  184. }
  185. // Prevent scrolling when zooming (no zoom key, or pressing zoom key)
  186. if (!this.options.zoomKey || event[this.options.zoomKey]) return;
  187. // Don't preventDefault if you can't scroll
  188. if (!this.options.verticalScroll && !this.options.horizontalScroll) return;
  189. // Prevent default actions caused by mouse wheel
  190. // (else the page and timeline both scroll)
  191. event.preventDefault();
  192. if (this.options.verticalScroll && Math.abs(deltaY) >= Math.abs(deltaX)) {
  193. var current = this.props.scrollTop;
  194. var adjusted = current + deltaY;
  195. if (this.isActive()) {
  196. this._setScrollTop(adjusted);
  197. this._redraw();
  198. this.emit('scroll', event);
  199. }
  200. } else if (this.options.horizontalScroll) {
  201. var delta = Math.abs(deltaX) >= Math.abs(deltaY) ? deltaX : deltaY;
  202. // calculate a single scroll jump relative to the range scale
  203. var diff = (delta / 120) * (this.range.end - this.range.start) / 20;
  204. // calculate new start and end
  205. var newStart = this.range.start + diff;
  206. var newEnd = this.range.end + diff;
  207. var options = {
  208. animation: false,
  209. byUser: true,
  210. event: event
  211. };
  212. this.range.setRange(newStart, newEnd, options);
  213. }
  214. }
  215. if (this.dom.centerContainer.addEventListener) {
  216. // IE9, Chrome, Safari, Opera
  217. this.dom.centerContainer.addEventListener("mousewheel", onMouseWheel.bind(this), false);
  218. // Firefox
  219. this.dom.centerContainer.addEventListener("DOMMouseScroll", onMouseWheel.bind(this), false);
  220. } else {
  221. // IE 6/7/8
  222. this.dom.centerContainer.attachEvent("onmousewheel", onMouseWheel.bind(this));
  223. }
  224. /**
  225. *
  226. * @param {scroll} event
  227. */
  228. function onMouseScrollSide(event) {
  229. if (!me.options.verticalScroll) return;
  230. event.preventDefault();
  231. if (me.isActive()) {
  232. var adjusted = -event.target.scrollTop;
  233. me._setScrollTop(adjusted);
  234. me._redraw();
  235. me.emit('scrollSide', event);
  236. }
  237. }
  238. this.dom.left.parentNode.addEventListener('scroll', onMouseScrollSide.bind(this));
  239. this.dom.right.parentNode.addEventListener('scroll', onMouseScrollSide.bind(this));
  240. var itemAddedToTimeline = false;
  241. /**
  242. *
  243. * @param {dragover} event
  244. * @returns {boolean}
  245. */
  246. function handleDragOver(event) {
  247. if (event.preventDefault) {
  248. event.preventDefault(); // Necessary. Allows us to drop.
  249. }
  250. // make sure your target is a vis element
  251. if (!event.target.className.indexOf("vis") > -1) return;
  252. // make sure only one item is added every time you're over the timeline
  253. if (itemAddedToTimeline) return;
  254. event.dataTransfer.dropEffect = 'move';
  255. itemAddedToTimeline = true;
  256. return false;
  257. }
  258. /**
  259. *
  260. * @param {drop} event
  261. * @returns {boolean}
  262. */
  263. function handleDrop(event) {
  264. // prevent redirect to blank page - Firefox
  265. if(event.preventDefault) { event.preventDefault(); }
  266. if(event.stopPropagation) { event.stopPropagation(); }
  267. // return when dropping non-vis items
  268. try {
  269. var itemData = JSON.parse(event.dataTransfer.getData("text"))
  270. if (!itemData || !itemData.content) return
  271. } catch (err) {
  272. return false;
  273. }
  274. itemAddedToTimeline = false;
  275. event.center = {
  276. x: event.clientX,
  277. y: event.clientY
  278. };
  279. if (itemData.target !== 'item') {
  280. me.itemSet._onAddItem(event);
  281. } else {
  282. me.itemSet._onDropObjectOnItem(event);
  283. }
  284. me.emit('drop', me.getEventProperties(event))
  285. return false;
  286. }
  287. this.dom.center.addEventListener('dragover', handleDragOver.bind(this), false);
  288. this.dom.center.addEventListener('drop', handleDrop.bind(this), false);
  289. this.customTimes = [];
  290. // store state information needed for touch events
  291. this.touch = {};
  292. this.redrawCount = 0;
  293. this.initialDrawDone = false;
  294. this.initialRangeChangeDone = false;
  295. // attach the root panel to the provided container
  296. if (!container) throw new Error('No container provided');
  297. container.appendChild(this.dom.root);
  298. container.appendChild(this.dom.loadingScreen);
  299. };
  300. /**
  301. * Set options. Options will be passed to all components loaded in the Timeline.
  302. * @param {Object} [options]
  303. * {String} orientation
  304. * Vertical orientation for the Timeline,
  305. * can be 'bottom' (default) or 'top'.
  306. * {string | number} width
  307. * Width for the timeline, a number in pixels or
  308. * a css string like '1000px' or '75%'. '100%' by default.
  309. * {string | number} height
  310. * Fixed height for the Timeline, a number in pixels or
  311. * a css string like '400px' or '75%'. If undefined,
  312. * The Timeline will automatically size such that
  313. * its contents fit.
  314. * {string | number} minHeight
  315. * Minimum height for the Timeline, a number in pixels or
  316. * a css string like '400px' or '75%'.
  317. * {string | number} maxHeight
  318. * Maximum height for the Timeline, a number in pixels or
  319. * a css string like '400px' or '75%'.
  320. * {number | Date | string} start
  321. * Start date for the visible window
  322. * {number | Date | string} end
  323. * End date for the visible window
  324. */
  325. Core.prototype.setOptions = function (options) {
  326. if (options) {
  327. // copy the known options
  328. var fields = [
  329. 'width', 'height', 'minHeight', 'maxHeight', 'autoResize',
  330. 'start', 'end', 'clickToUse', 'dataAttributes', 'hiddenDates',
  331. 'locale', 'locales', 'moment', 'rtl', 'zoomKey', 'horizontalScroll', 'verticalScroll'
  332. ];
  333. util.selectiveExtend(fields, this.options, options);
  334. this.dom.rollingModeBtn.style.visibility = 'hidden';
  335. if (this.options.rtl) {
  336. this.dom.container.style.direction = "rtl";
  337. this.dom.backgroundVertical.className = 'vis-panel vis-background vis-vertical-rtl';
  338. }
  339. if (this.options.verticalScroll) {
  340. if (this.options.rtl) {
  341. this.dom.rightContainer.className = 'vis-panel vis-right vis-vertical-scroll';
  342. } else {
  343. this.dom.leftContainer.className = 'vis-panel vis-left vis-vertical-scroll';
  344. }
  345. }
  346. if (typeof this.options.orientation !== 'object') {
  347. this.options.orientation = {item:undefined,axis:undefined};
  348. }
  349. if ('orientation' in options) {
  350. if (typeof options.orientation === 'string') {
  351. this.options.orientation = {
  352. item: options.orientation,
  353. axis: options.orientation
  354. };
  355. }
  356. else if (typeof options.orientation === 'object') {
  357. if ('item' in options.orientation) {
  358. this.options.orientation.item = options.orientation.item;
  359. }
  360. if ('axis' in options.orientation) {
  361. this.options.orientation.axis = options.orientation.axis;
  362. }
  363. }
  364. }
  365. if (this.options.orientation.axis === 'both') {
  366. if (!this.timeAxis2) {
  367. var timeAxis2 = this.timeAxis2 = new TimeAxis(this.body);
  368. timeAxis2.setOptions = function (options) {
  369. var _options = options ? util.extend({}, options) : {};
  370. _options.orientation = 'top'; // override the orientation option, always top
  371. TimeAxis.prototype.setOptions.call(timeAxis2, _options);
  372. };
  373. this.components.push(timeAxis2);
  374. }
  375. }
  376. else {
  377. if (this.timeAxis2) {
  378. var index = this.components.indexOf(this.timeAxis2);
  379. if (index !== -1) {
  380. this.components.splice(index, 1);
  381. }
  382. this.timeAxis2.destroy();
  383. this.timeAxis2 = null;
  384. }
  385. }
  386. // if the graph2d's drawPoints is a function delegate the callback to the onRender property
  387. if (typeof options.drawPoints == 'function') {
  388. options.drawPoints = {
  389. onRender: options.drawPoints
  390. };
  391. }
  392. if ('hiddenDates' in this.options) {
  393. DateUtil.convertHiddenOptions(this.options.moment, this.body, this.options.hiddenDates);
  394. }
  395. if ('clickToUse' in options) {
  396. if (options.clickToUse) {
  397. if (!this.activator) {
  398. this.activator = new Activator(this.dom.root);
  399. }
  400. }
  401. else {
  402. if (this.activator) {
  403. this.activator.destroy();
  404. delete this.activator;
  405. }
  406. }
  407. }
  408. if ('showCustomTime' in options) {
  409. throw new Error('Option `showCustomTime` is deprecated. Create a custom time bar via timeline.addCustomTime(time [, id])');
  410. }
  411. // enable/disable autoResize
  412. this._initAutoResize();
  413. }
  414. // propagate options to all components
  415. this.components.forEach(component => component.setOptions(options));
  416. // enable/disable configure
  417. if ('configure' in options) {
  418. if (!this.configurator) {
  419. this.configurator = this._createConfigurator();
  420. }
  421. this.configurator.setOptions(options.configure);
  422. // collect the settings of all components, and pass them to the configuration system
  423. var appliedOptions = util.deepExtend({}, this.options);
  424. this.components.forEach(function (component) {
  425. util.deepExtend(appliedOptions, component.options);
  426. });
  427. this.configurator.setModuleOptions({global: appliedOptions});
  428. }
  429. this._redraw();
  430. };
  431. /**
  432. * Returns true when the Timeline is active.
  433. * @returns {boolean}
  434. */
  435. Core.prototype.isActive = function () {
  436. return !this.activator || this.activator.active;
  437. };
  438. /**
  439. * Destroy the Core, clean up all DOM elements and event listeners.
  440. */
  441. Core.prototype.destroy = function () {
  442. // unbind datasets
  443. this.setItems(null);
  444. this.setGroups(null);
  445. // remove all event listeners
  446. this.off();
  447. // stop checking for changed size
  448. this._stopAutoResize();
  449. // remove from DOM
  450. if (this.dom.root.parentNode) {
  451. this.dom.root.parentNode.removeChild(this.dom.root);
  452. }
  453. this.dom = null;
  454. // remove Activator
  455. if (this.activator) {
  456. this.activator.destroy();
  457. delete this.activator;
  458. }
  459. // cleanup hammer touch events
  460. for (var event in this.listeners) {
  461. if (this.listeners.hasOwnProperty(event)) {
  462. delete this.listeners[event];
  463. }
  464. }
  465. this.listeners = null;
  466. this.hammer && this.hammer.destroy();
  467. this.hammer = null;
  468. // give all components the opportunity to cleanup
  469. this.components.forEach(component => component.destroy());
  470. this.body = null;
  471. };
  472. /**
  473. * Set a custom time bar
  474. * @param {Date} time
  475. * @param {number} [id=undefined] Optional id of the custom time bar to be adjusted.
  476. */
  477. Core.prototype.setCustomTime = function (time, id) {
  478. var customTimes = this.customTimes.filter(function (component) {
  479. return id === component.options.id;
  480. });
  481. if (customTimes.length === 0) {
  482. throw new Error('No custom time bar found with id ' + JSON.stringify(id))
  483. }
  484. if (customTimes.length > 0) {
  485. customTimes[0].setCustomTime(time);
  486. }
  487. };
  488. /**
  489. * Retrieve the current custom time.
  490. * @param {number} [id=undefined] Id of the custom time bar.
  491. * @return {Date | undefined} customTime
  492. */
  493. Core.prototype.getCustomTime = function(id) {
  494. var customTimes = this.customTimes.filter(function (component) {
  495. return component.options.id === id;
  496. });
  497. if (customTimes.length === 0) {
  498. throw new Error('No custom time bar found with id ' + JSON.stringify(id))
  499. }
  500. return customTimes[0].getCustomTime();
  501. };
  502. /**
  503. * Set a custom title for the custom time bar.
  504. * @param {string} [title] Custom title
  505. * @param {number} [id=undefined] Id of the custom time bar.
  506. * @returns {*}
  507. */
  508. Core.prototype.setCustomTimeTitle = function(title, id) {
  509. var customTimes = this.customTimes.filter(function (component) {
  510. return component.options.id === id;
  511. });
  512. if (customTimes.length === 0) {
  513. throw new Error('No custom time bar found with id ' + JSON.stringify(id))
  514. }
  515. if (customTimes.length > 0) {
  516. return customTimes[0].setCustomTitle(title);
  517. }
  518. };
  519. /**
  520. * Retrieve meta information from an event.
  521. * Should be overridden by classes extending Core
  522. * @param {Event} event
  523. * @return {Object} An object with related information.
  524. */
  525. Core.prototype.getEventProperties = function (event) {
  526. return { event: event };
  527. };
  528. /**
  529. * Add custom vertical bar
  530. * @param {Date | string | number} [time] A Date, unix timestamp, or
  531. * ISO date string. Time point where
  532. * the new bar should be placed.
  533. * If not provided, `new Date()` will
  534. * be used.
  535. * @param {number | string} [id=undefined] Id of the new bar. Optional
  536. * @param {object} [options={}] Control options for the new bar. Supported
  537. * optoins are:
  538. * editable {true, false} determines whether the
  539. * bar can be dragged by the user. Default is true.
  540. * @return {number | string} Returns the id of the new bar
  541. */
  542. Core.prototype.addCustomTime = function (time, id, options) {
  543. var timestamp = time !== undefined
  544. ? util.convert(time, 'Date').valueOf()
  545. : new Date();
  546. var exists = this.customTimes.some(function (customTime) {
  547. return customTime.options.id === id;
  548. });
  549. if (exists) {
  550. throw new Error('A custom time with id ' + JSON.stringify(id) + ' already exists');
  551. }
  552. var customTime = new CustomTime(this.body, util.extend({}, this.options, options, {
  553. time : timestamp,
  554. id : id
  555. }));
  556. this.customTimes.push(customTime);
  557. this.components.push(customTime);
  558. this._redraw();
  559. return id;
  560. };
  561. /**
  562. * Remove previously added custom bar
  563. * @param {int} id ID of the custom bar to be removed
  564. * [at]returns {boolean} True if the bar exists and is removed, false otherwise
  565. */
  566. Core.prototype.removeCustomTime = function (id) {
  567. var customTimes = this.customTimes.filter(function (bar) {
  568. return (bar.options.id === id);
  569. });
  570. if (customTimes.length === 0) {
  571. throw new Error('No custom time bar found with id ' + JSON.stringify(id))
  572. }
  573. customTimes.forEach(function (customTime) {
  574. this.customTimes.splice(this.customTimes.indexOf(customTime), 1);
  575. this.components.splice(this.components.indexOf(customTime), 1);
  576. customTime.destroy();
  577. }.bind(this))
  578. };
  579. /**
  580. * Get the id's of the currently visible items.
  581. * @returns {Array} The ids of the visible items
  582. */
  583. Core.prototype.getVisibleItems = function() {
  584. return this.itemSet && this.itemSet.getVisibleItems() || [];
  585. };
  586. /**
  587. * Get the id's of the currently visible groups.
  588. * @returns {Array} The ids of the visible groups
  589. */
  590. Core.prototype.getVisibleGroups = function() {
  591. return this.itemSet && this.itemSet.getVisibleGroups() || [];
  592. };
  593. /**
  594. * Set Core window such that it fits all items
  595. * @param {Object} [options] Available options:
  596. * `animation: boolean | {duration: number, easingFunction: string}`
  597. * If true (default), the range is animated
  598. * smoothly to the new window. An object can be
  599. * provided to specify duration and easing function.
  600. * Default duration is 500 ms, and default easing
  601. * function is 'easeInOutQuad'.
  602. * @param {function} [callback] a callback funtion to be executed at the end of this function
  603. */
  604. Core.prototype.fit = function(options, callback) {
  605. var range = this.getDataRange();
  606. // skip range set if there is no min and max date
  607. if (range.min === null && range.max === null) {
  608. return;
  609. }
  610. // apply a margin of 1% left and right of the data
  611. var interval = range.max - range.min;
  612. var min = new Date(range.min.valueOf() - interval * 0.01);
  613. var max = new Date(range.max.valueOf() + interval * 0.01);
  614. var animation = (options && options.animation !== undefined) ? options.animation : true;
  615. this.range.setRange(min, max, { animation: animation }, callback);
  616. };
  617. /**
  618. * Calculate the data range of the items start and end dates
  619. * [at]returns {{min: [Date], max: [Date]}}
  620. * @protected
  621. */
  622. Core.prototype.getDataRange = function() {
  623. // must be implemented by Timeline and Graph2d
  624. throw new Error('Cannot invoke abstract method getDataRange');
  625. };
  626. /**
  627. * Set the visible window. Both parameters are optional, you can change only
  628. * start or only end. Syntax:
  629. *
  630. * TimeLine.setWindow(start, end)
  631. * TimeLine.setWindow(start, end, options)
  632. * TimeLine.setWindow(range)
  633. *
  634. * Where start and end can be a Date, number, or string, and range is an
  635. * object with properties start and end.
  636. *
  637. * @param {Date | number | string | Object} [start] Start date of visible window
  638. * @param {Date | number | string} [end] End date of visible window
  639. * @param {Object} [options] Available options:
  640. * `animation: boolean | {duration: number, easingFunction: string}`
  641. * If true (default), the range is animated
  642. * smoothly to the new window. An object can be
  643. * provided to specify duration and easing function.
  644. * Default duration is 500 ms, and default easing
  645. * function is 'easeInOutQuad'.
  646. * @param {function} [callback] a callback funtion to be executed at the end of this function
  647. */
  648. Core.prototype.setWindow = function(start, end, options, callback) {
  649. if (typeof arguments[2] == "function") {
  650. callback = arguments[2];
  651. options = {};
  652. }
  653. var animation;
  654. var range;
  655. if (arguments.length == 1) {
  656. range = arguments[0];
  657. animation = (range.animation !== undefined) ? range.animation : true;
  658. this.range.setRange(range.start, range.end, { animation: animation });
  659. }
  660. else if (arguments.length == 2 && typeof arguments[1] == "function") {
  661. range = arguments[0];
  662. callback = arguments[1];
  663. animation = (range.animation !== undefined) ? range.animation : true;
  664. this.range.setRange(range.start, range.end, { animation: animation }, callback);
  665. }
  666. else {
  667. animation = (options && options.animation !== undefined) ? options.animation : true;
  668. this.range.setRange(start, end, { animation: animation }, callback);
  669. }
  670. };
  671. /**
  672. * Move the window such that given time is centered on screen.
  673. * @param {Date | number | string} time
  674. * @param {Object} [options] Available options:
  675. * `animation: boolean | {duration: number, easingFunction: string}`
  676. * If true (default), the range is animated
  677. * smoothly to the new window. An object can be
  678. * provided to specify duration and easing function.
  679. * Default duration is 500 ms, and default easing
  680. * function is 'easeInOutQuad'.
  681. * @param {function} [callback] a callback funtion to be executed at the end of this function
  682. */
  683. Core.prototype.moveTo = function(time, options, callback) {
  684. if (typeof arguments[1] == "function") {
  685. callback = arguments[1];
  686. options = {};
  687. }
  688. var interval = this.range.end - this.range.start;
  689. var t = util.convert(time, 'Date').valueOf();
  690. var start = t - interval / 2;
  691. var end = t + interval / 2;
  692. var animation = (options && options.animation !== undefined) ? options.animation : true;
  693. this.range.setRange(start, end, { animation: animation }, callback);
  694. };
  695. /**
  696. * Get the visible window
  697. * @return {{start: Date, end: Date}} Visible range
  698. */
  699. Core.prototype.getWindow = function() {
  700. var range = this.range.getRange();
  701. return {
  702. start: new Date(range.start),
  703. end: new Date(range.end)
  704. };
  705. };
  706. /**
  707. * Zoom in the window such that given time is centered on screen.
  708. * @param {number} percentage - must be between [0..1]
  709. * @param {Object} [options] Available options:
  710. * `animation: boolean | {duration: number, easingFunction: string}`
  711. * If true (default), the range is animated
  712. * smoothly to the new window. An object can be
  713. * provided to specify duration and easing function.
  714. * Default duration is 500 ms, and default easing
  715. * function is 'easeInOutQuad'.
  716. * @param {function} [callback] a callback funtion to be executed at the end of this function
  717. */
  718. Core.prototype.zoomIn = function(percentage, options, callback) {
  719. if (!percentage || percentage < 0 || percentage > 1) return;
  720. if (typeof arguments[1] == "function") {
  721. callback = arguments[1];
  722. options = {};
  723. }
  724. var range = this.getWindow();
  725. var start = range.start.valueOf();
  726. var end = range.end.valueOf();
  727. var interval = end - start;
  728. var newInterval = interval / (1 + percentage);
  729. var distance = (interval - newInterval) / 2;
  730. var newStart = start + distance;
  731. var newEnd = end - distance;
  732. this.setWindow(newStart, newEnd, options, callback);
  733. };
  734. /**
  735. * Zoom out the window such that given time is centered on screen.
  736. * @param {number} percentage - must be between [0..1]
  737. * @param {Object} [options] Available options:
  738. * `animation: boolean | {duration: number, easingFunction: string}`
  739. * If true (default), the range is animated
  740. * smoothly to the new window. An object can be
  741. * provided to specify duration and easing function.
  742. * Default duration is 500 ms, and default easing
  743. * function is 'easeInOutQuad'.
  744. * @param {function} [callback] a callback funtion to be executed at the end of this function
  745. */
  746. Core.prototype.zoomOut = function(percentage, options, callback) {
  747. if (!percentage || percentage < 0 || percentage > 1) return
  748. if (typeof arguments[1] == "function") {
  749. callback = arguments[1];
  750. options = {};
  751. }
  752. var range = this.getWindow();
  753. var start = range.start.valueOf();
  754. var end = range.end.valueOf();
  755. var interval = end - start;
  756. var newStart = start - interval * percentage / 2;
  757. var newEnd = end + interval * percentage / 2;
  758. this.setWindow(newStart, newEnd, options, callback);
  759. };
  760. /**
  761. * Force a redraw. Can be overridden by implementations of Core
  762. *
  763. * Note: this function will be overridden on construction with a trottled version
  764. */
  765. Core.prototype.redraw = function() {
  766. this._redraw();
  767. };
  768. /**
  769. * Redraw for internal use. Redraws all components. See also the public
  770. * method redraw.
  771. * @protected
  772. */
  773. Core.prototype._redraw = function() {
  774. this.redrawCount++;
  775. var resized = false;
  776. var options = this.options;
  777. var props = this.props;
  778. var dom = this.dom;
  779. if (!dom || !dom.container || dom.root.offsetWidth == 0) return; // when destroyed, or invisible
  780. DateUtil.updateHiddenDates(this.options.moment, this.body, this.options.hiddenDates);
  781. // update class names
  782. if (options.orientation == 'top') {
  783. util.addClassName(dom.root, 'vis-top');
  784. util.removeClassName(dom.root, 'vis-bottom');
  785. }
  786. else {
  787. util.removeClassName(dom.root, 'vis-top');
  788. util.addClassName(dom.root, 'vis-bottom');
  789. }
  790. // update root width and height options
  791. dom.root.style.maxHeight = util.option.asSize(options.maxHeight, '');
  792. dom.root.style.minHeight = util.option.asSize(options.minHeight, '');
  793. dom.root.style.width = util.option.asSize(options.width, '');
  794. // calculate border widths
  795. props.border.left = (dom.centerContainer.offsetWidth - dom.centerContainer.clientWidth) / 2;
  796. props.border.right = props.border.left;
  797. props.border.top = (dom.centerContainer.offsetHeight - dom.centerContainer.clientHeight) / 2;
  798. props.border.bottom = props.border.top;
  799. props.borderRootHeight= dom.root.offsetHeight - dom.root.clientHeight;
  800. props.borderRootWidth = dom.root.offsetWidth - dom.root.clientWidth;
  801. // workaround for a bug in IE: the clientWidth of an element with
  802. // a height:0px and overflow:hidden is not calculated and always has value 0
  803. if (dom.centerContainer.clientHeight === 0) {
  804. props.border.left = props.border.top;
  805. props.border.right = props.border.left;
  806. }
  807. if (dom.root.clientHeight === 0) {
  808. props.borderRootWidth = props.borderRootHeight;
  809. }
  810. // calculate the heights. If any of the side panels is empty, we set the height to
  811. // minus the border width, such that the border will be invisible
  812. props.center.height = dom.center.offsetHeight;
  813. props.left.height = dom.left.offsetHeight;
  814. props.right.height = dom.right.offsetHeight;
  815. props.top.height = dom.top.clientHeight || -props.border.top;
  816. props.bottom.height = dom.bottom.clientHeight || -props.border.bottom;
  817. // TODO: compensate borders when any of the panels is empty.
  818. // apply auto height
  819. // TODO: only calculate autoHeight when needed (else we cause an extra reflow/repaint of the DOM)
  820. var contentHeight = Math.max(props.left.height, props.center.height, props.right.height);
  821. var autoHeight = props.top.height + contentHeight + props.bottom.height +
  822. props.borderRootHeight + props.border.top + props.border.bottom;
  823. dom.root.style.height = util.option.asSize(options.height, autoHeight + 'px');
  824. // calculate heights of the content panels
  825. props.root.height = dom.root.offsetHeight;
  826. props.background.height = props.root.height - props.borderRootHeight;
  827. var containerHeight = props.root.height - props.top.height - props.bottom.height -
  828. props.borderRootHeight;
  829. props.centerContainer.height = containerHeight;
  830. props.leftContainer.height = containerHeight;
  831. props.rightContainer.height = props.leftContainer.height;
  832. // calculate the widths of the panels
  833. props.root.width = dom.root.offsetWidth;
  834. props.background.width = props.root.width - props.borderRootWidth;
  835. if (!this.initialDrawDone) {
  836. props.scrollbarWidth = util.getScrollBarWidth();
  837. }
  838. if (options.verticalScroll) {
  839. if (options.rtl) {
  840. props.left.width = dom.leftContainer.clientWidth || -props.border.left;
  841. props.right.width = dom.rightContainer.clientWidth + props.scrollbarWidth || -props.border.right;
  842. } else {
  843. props.left.width = dom.leftContainer.clientWidth + props.scrollbarWidth || -props.border.left;
  844. props.right.width = dom.rightContainer.clientWidth || -props.border.right;
  845. }
  846. } else {
  847. props.left.width = dom.leftContainer.clientWidth || -props.border.left;
  848. props.right.width = dom.rightContainer.clientWidth || -props.border.right;
  849. }
  850. this._setDOM();
  851. // update the scrollTop, feasible range for the offset can be changed
  852. // when the height of the Core or of the contents of the center changed
  853. var offset = this._updateScrollTop();
  854. // reposition the scrollable contents
  855. if (options.orientation.item != 'top') {
  856. offset += Math.max(props.centerContainer.height - props.center.height -
  857. props.border.top - props.border.bottom, 0);
  858. }
  859. dom.center.style.top = offset + 'px';
  860. // show shadows when vertical scrolling is available
  861. var visibilityTop = props.scrollTop == 0 ? 'hidden' : '';
  862. var visibilityBottom = props.scrollTop == props.scrollTopMin ? 'hidden' : '';
  863. dom.shadowTop.style.visibility = visibilityTop;
  864. dom.shadowBottom.style.visibility = visibilityBottom;
  865. dom.shadowTopLeft.style.visibility = visibilityTop;
  866. dom.shadowBottomLeft.style.visibility = visibilityBottom;
  867. dom.shadowTopRight.style.visibility = visibilityTop;
  868. dom.shadowBottomRight.style.visibility = visibilityBottom;
  869. if (options.verticalScroll) {
  870. dom.rightContainer.className = 'vis-panel vis-right vis-vertical-scroll';
  871. dom.leftContainer.className = 'vis-panel vis-left vis-vertical-scroll';
  872. dom.shadowTopRight.style.visibility = "hidden";
  873. dom.shadowBottomRight.style.visibility = "hidden";
  874. dom.shadowTopLeft.style.visibility = "hidden";
  875. dom.shadowBottomLeft.style.visibility = "hidden";
  876. dom.left.style.top = '0px';
  877. dom.right.style.top = '0px';
  878. }
  879. if (!options.verticalScroll || props.center.height < props.centerContainer.height) {
  880. dom.left.style.top = offset + 'px';
  881. dom.right.style.top = offset + 'px';
  882. dom.rightContainer.className = dom.rightContainer.className.replace(new RegExp('(?:^|\\s)'+ 'vis-vertical-scroll' + '(?:\\s|$)'), ' ');
  883. dom.leftContainer.className = dom.leftContainer.className.replace(new RegExp('(?:^|\\s)'+ 'vis-vertical-scroll' + '(?:\\s|$)'), ' ');
  884. props.left.width = dom.leftContainer.clientWidth || -props.border.left;
  885. props.right.width = dom.rightContainer.clientWidth || -props.border.right;
  886. this._setDOM();
  887. }
  888. // enable/disable vertical panning
  889. var contentsOverflow = props.center.height > props.centerContainer.height;
  890. this.hammer.get('pan').set({
  891. direction: contentsOverflow ? Hammer.DIRECTION_ALL : Hammer.DIRECTION_HORIZONTAL
  892. });
  893. // redraw all components
  894. this.components.forEach(function (component) {
  895. resized = component.redraw() || resized;
  896. });
  897. var MAX_REDRAW = 5;
  898. if (resized) {
  899. if (this.redrawCount < MAX_REDRAW) {
  900. this.body.emitter.emit('_change');
  901. return;
  902. }
  903. else {
  904. console.log('WARNING: infinite loop in redraw?');
  905. }
  906. } else {
  907. this.redrawCount = 0;
  908. }
  909. //Emit public 'changed' event for UI updates, see issue #1592
  910. this.body.emitter.emit("changed");
  911. };
  912. Core.prototype._setDOM = function () {
  913. var props = this.props;
  914. var dom = this.dom;
  915. props.leftContainer.width = props.left.width;
  916. props.rightContainer.width = props.right.width;
  917. var centerWidth = props.root.width - props.left.width - props.right.width - props.borderRootWidth;
  918. props.center.width = centerWidth;
  919. props.centerContainer.width = centerWidth;
  920. props.top.width = centerWidth;
  921. props.bottom.width = centerWidth;
  922. // resize the panels
  923. dom.background.style.height = props.background.height + 'px';
  924. dom.backgroundVertical.style.height = props.background.height + 'px';
  925. dom.backgroundHorizontal.style.height = props.centerContainer.height + 'px';
  926. dom.centerContainer.style.height = props.centerContainer.height + 'px';
  927. dom.leftContainer.style.height = props.leftContainer.height + 'px';
  928. dom.rightContainer.style.height = props.rightContainer.height + 'px';
  929. dom.background.style.width = props.background.width + 'px';
  930. dom.backgroundVertical.style.width = props.centerContainer.width + 'px';
  931. dom.backgroundHorizontal.style.width = props.background.width + 'px';
  932. dom.centerContainer.style.width = props.center.width + 'px';
  933. dom.top.style.width = props.top.width + 'px';
  934. dom.bottom.style.width = props.bottom.width + 'px';
  935. // reposition the panels
  936. dom.background.style.left = '0';
  937. dom.background.style.top = '0';
  938. dom.backgroundVertical.style.left = (props.left.width + props.border.left) + 'px';
  939. dom.backgroundVertical.style.top = '0';
  940. dom.backgroundHorizontal.style.left = '0';
  941. dom.backgroundHorizontal.style.top = props.top.height + 'px';
  942. dom.centerContainer.style.left = props.left.width + 'px';
  943. dom.centerContainer.style.top = props.top.height + 'px';
  944. dom.leftContainer.style.left = '0';
  945. dom.leftContainer.style.top = props.top.height + 'px';
  946. dom.rightContainer.style.left = (props.left.width + props.center.width) + 'px';
  947. dom.rightContainer.style.top = props.top.height + 'px';
  948. dom.top.style.left = props.left.width + 'px';
  949. dom.top.style.top = '0';
  950. dom.bottom.style.left = props.left.width + 'px';
  951. dom.bottom.style.top = (props.top.height + props.centerContainer.height) + 'px';
  952. dom.center.style.left = '0';
  953. dom.left.style.left = '0';
  954. dom.right.style.left = '0';
  955. };
  956. // TODO: deprecated since version 1.1.0, remove some day
  957. Core.prototype.repaint = function () {
  958. throw new Error('Function repaint is deprecated. Use redraw instead.');
  959. };
  960. /**
  961. * Set a current time. This can be used for example to ensure that a client's
  962. * time is synchronized with a shared server time.
  963. * Only applicable when option `showCurrentTime` is true.
  964. * @param {Date | string | number} time A Date, unix timestamp, or
  965. * ISO date string.
  966. */
  967. Core.prototype.setCurrentTime = function(time) {
  968. if (!this.currentTime) {
  969. throw new Error('Option showCurrentTime must be true');
  970. }
  971. this.currentTime.setCurrentTime(time);
  972. };
  973. /**
  974. * Get the current time.
  975. * Only applicable when option `showCurrentTime` is true.
  976. * @return {Date} Returns the current time.
  977. */
  978. Core.prototype.getCurrentTime = function() {
  979. if (!this.currentTime) {
  980. throw new Error('Option showCurrentTime must be true');
  981. }
  982. return this.currentTime.getCurrentTime();
  983. };
  984. /**
  985. * Convert a position on screen (pixels) to a datetime
  986. * @param {int} x Position on the screen in pixels
  987. * @return {Date} time The datetime the corresponds with given position x
  988. * @protected
  989. */
  990. // TODO: move this function to Range
  991. Core.prototype._toTime = function(x) {
  992. return DateUtil.toTime(this, x, this.props.center.width);
  993. };
  994. /**
  995. * Convert a position on the global screen (pixels) to a datetime
  996. * @param {int} x Position on the screen in pixels
  997. * @return {Date} time The datetime the corresponds with given position x
  998. * @protected
  999. */
  1000. // TODO: move this function to Range
  1001. Core.prototype._toGlobalTime = function(x) {
  1002. return DateUtil.toTime(this, x, this.props.root.width);
  1003. //var conversion = this.range.conversion(this.props.root.width);
  1004. //return new Date(x / conversion.scale + conversion.offset);
  1005. };
  1006. /**
  1007. * Convert a datetime (Date object) into a position on the screen
  1008. * @param {Date} time A date
  1009. * @return {int} x The position on the screen in pixels which corresponds
  1010. * with the given date.
  1011. * @protected
  1012. */
  1013. // TODO: move this function to Range
  1014. Core.prototype._toScreen = function(time) {
  1015. return DateUtil.toScreen(this, time, this.props.center.width);
  1016. };
  1017. /**
  1018. * Convert a datetime (Date object) into a position on the root
  1019. * This is used to get the pixel density estimate for the screen, not the center panel
  1020. * @param {Date} time A date
  1021. * @return {int} x The position on root in pixels which corresponds
  1022. * with the given date.
  1023. * @protected
  1024. */
  1025. // TODO: move this function to Range
  1026. Core.prototype._toGlobalScreen = function(time) {
  1027. return DateUtil.toScreen(this, time, this.props.root.width);
  1028. //var conversion = this.range.conversion(this.props.root.width);
  1029. //return (time.valueOf() - conversion.offset) * conversion.scale;
  1030. };
  1031. /**
  1032. * Initialize watching when option autoResize is true
  1033. * @private
  1034. */
  1035. Core.prototype._initAutoResize = function () {
  1036. if (this.options.autoResize == true) {
  1037. this._startAutoResize();
  1038. }
  1039. else {
  1040. this._stopAutoResize();
  1041. }
  1042. };
  1043. /**
  1044. * Watch for changes in the size of the container. On resize, the Panel will
  1045. * automatically redraw itself.
  1046. * @private
  1047. */
  1048. Core.prototype._startAutoResize = function () {
  1049. var me = this;
  1050. this._stopAutoResize();
  1051. this._onResize = function() {
  1052. if (me.options.autoResize != true) {
  1053. // stop watching when the option autoResize is changed to false
  1054. me._stopAutoResize();
  1055. return;
  1056. }
  1057. if (me.dom.root) {
  1058. // check whether the frame is resized
  1059. // Note: we compare offsetWidth here, not clientWidth. For some reason,
  1060. // IE does not restore the clientWidth from 0 to the actual width after
  1061. // changing the timeline's container display style from none to visible
  1062. if ((me.dom.root.offsetWidth != me.props.lastWidth) ||
  1063. (me.dom.root.offsetHeight != me.props.lastHeight)) {
  1064. me.props.lastWidth = me.dom.root.offsetWidth;
  1065. me.props.lastHeight = me.dom.root.offsetHeight;
  1066. me.props.scrollbarWidth = util.getScrollBarWidth();
  1067. me.body.emitter.emit('_change');
  1068. }
  1069. }
  1070. };
  1071. // add event listener to window resize
  1072. util.addEventListener(window, 'resize', this._onResize);
  1073. //Prevent initial unnecessary redraw
  1074. if (me.dom.root) {
  1075. me.props.lastWidth = me.dom.root.offsetWidth;
  1076. me.props.lastHeight = me.dom.root.offsetHeight;
  1077. }
  1078. this.watchTimer = setInterval(this._onResize, 1000);
  1079. };
  1080. /**
  1081. * Stop watching for a resize of the frame.
  1082. * @private
  1083. */
  1084. Core.prototype._stopAutoResize = function () {
  1085. if (this.watchTimer) {
  1086. clearInterval(this.watchTimer);
  1087. this.watchTimer = undefined;
  1088. }
  1089. // remove event listener on window.resize
  1090. if (this._onResize) {
  1091. util.removeEventListener(window, 'resize', this._onResize);
  1092. this._onResize = null;
  1093. }
  1094. };
  1095. /**
  1096. * Start moving the timeline vertically
  1097. * @param {Event} event
  1098. * @private
  1099. */
  1100. Core.prototype._onTouch = function (event) { // eslint-disable-line no-unused-vars
  1101. this.touch.allowDragging = true;
  1102. this.touch.initialScrollTop = this.props.scrollTop;
  1103. };
  1104. /**
  1105. * Start moving the timeline vertically
  1106. * @param {Event} event
  1107. * @private
  1108. */
  1109. Core.prototype._onPinch = function (event) { // eslint-disable-line no-unused-vars
  1110. this.touch.allowDragging = false;
  1111. };
  1112. /**
  1113. * Move the timeline vertically
  1114. * @param {Event} event
  1115. * @private
  1116. */
  1117. Core.prototype._onDrag = function (event) {
  1118. if (!event) return
  1119. // refuse to drag when we where pinching to prevent the timeline make a jump
  1120. // when releasing the fingers in opposite order from the touch screen
  1121. if (!this.touch.allowDragging) return;
  1122. var delta = event.deltaY;
  1123. var oldScrollTop = this._getScrollTop();
  1124. var newScrollTop = this._setScrollTop(this.touch.initialScrollTop + delta);
  1125. if (this.options.verticalScroll) {
  1126. this.dom.left.parentNode.scrollTop = -this.props.scrollTop;
  1127. this.dom.right.parentNode.scrollTop = -this.props.scrollTop;
  1128. }
  1129. if (newScrollTop != oldScrollTop) {
  1130. this.emit("verticalDrag");
  1131. }
  1132. };
  1133. /**
  1134. * Apply a scrollTop
  1135. * @param {number} scrollTop
  1136. * @returns {number} scrollTop Returns the applied scrollTop
  1137. * @private
  1138. */
  1139. Core.prototype._setScrollTop = function (scrollTop) {
  1140. this.props.scrollTop = scrollTop;
  1141. this._updateScrollTop();
  1142. return this.props.scrollTop;
  1143. };
  1144. /**
  1145. * Update the current scrollTop when the height of the containers has been changed
  1146. * @returns {number} scrollTop Returns the applied scrollTop
  1147. * @private
  1148. */
  1149. Core.prototype._updateScrollTop = function () {
  1150. // recalculate the scrollTopMin
  1151. var scrollTopMin = Math.min(this.props.centerContainer.height - this.props.center.height, 0); // is negative or zero
  1152. if (scrollTopMin != this.props.scrollTopMin) {
  1153. // in case of bottom orientation, change the scrollTop such that the contents
  1154. // do not move relative to the time axis at the bottom
  1155. if (this.options.orientation.item != 'top') {
  1156. this.props.scrollTop += (scrollTopMin - this.props.scrollTopMin);
  1157. }
  1158. this.props.scrollTopMin = scrollTopMin;
  1159. }
  1160. // limit the scrollTop to the feasible scroll range
  1161. if (this.props.scrollTop > 0) this.props.scrollTop = 0;
  1162. if (this.props.scrollTop < scrollTopMin) this.props.scrollTop = scrollTopMin;
  1163. if (this.options.verticalScroll) {
  1164. this.dom.left.parentNode.scrollTop = -this.props.scrollTop;
  1165. this.dom.right.parentNode.scrollTop = -this.props.scrollTop;
  1166. }
  1167. return this.props.scrollTop;
  1168. };
  1169. /**
  1170. * Get the current scrollTop
  1171. * @returns {number} scrollTop
  1172. * @private
  1173. */
  1174. Core.prototype._getScrollTop = function () {
  1175. return this.props.scrollTop;
  1176. };
  1177. /**
  1178. * Load a configurator
  1179. * [at]returns {Object}
  1180. * @private
  1181. */
  1182. Core.prototype._createConfigurator = function () {
  1183. throw new Error('Cannot invoke abstract method _createConfigurator');
  1184. };
  1185. module.exports = Core;