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.

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