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.

702 lines
23 KiB

  1. var Emitter = require('emitter-component');
  2. var Hammer = require('../module/hammer');
  3. var util = require('../util');
  4. var DataSet = require('../DataSet');
  5. var DataView = require('../DataView');
  6. var Range = require('./Range');
  7. var TimeAxis = require('./component/TimeAxis');
  8. var CurrentTime = require('./component/CurrentTime');
  9. var CustomTime = require('./component/CustomTime');
  10. var ItemSet = require('./component/ItemSet');
  11. /**
  12. * Create a timeline visualization
  13. * @param {HTMLElement} container
  14. * @param {vis.DataSet | Array | google.visualization.DataTable} [items]
  15. * @param {Object} [options] See Core.setOptions for the available options.
  16. * @constructor
  17. */
  18. function Core () {}
  19. // turn Core into an event emitter
  20. Emitter(Core.prototype);
  21. /**
  22. * Create the main DOM for the Core: a root panel containing left, right,
  23. * top, bottom, content, and background panel.
  24. * @param {Element} container The container element where the Core will
  25. * be attached.
  26. * @private
  27. */
  28. Core.prototype._create = function (container) {
  29. this.dom = {};
  30. this.dom.root = document.createElement('div');
  31. this.dom.background = document.createElement('div');
  32. this.dom.backgroundVertical = document.createElement('div');
  33. this.dom.backgroundHorizontal = document.createElement('div');
  34. this.dom.centerContainer = document.createElement('div');
  35. this.dom.leftContainer = document.createElement('div');
  36. this.dom.rightContainer = document.createElement('div');
  37. this.dom.center = document.createElement('div');
  38. this.dom.left = document.createElement('div');
  39. this.dom.right = document.createElement('div');
  40. this.dom.top = document.createElement('div');
  41. this.dom.bottom = document.createElement('div');
  42. this.dom.shadowTop = document.createElement('div');
  43. this.dom.shadowBottom = document.createElement('div');
  44. this.dom.shadowTopLeft = document.createElement('div');
  45. this.dom.shadowBottomLeft = document.createElement('div');
  46. this.dom.shadowTopRight = document.createElement('div');
  47. this.dom.shadowBottomRight = document.createElement('div');
  48. this.dom.background.className = 'vispanel background';
  49. this.dom.backgroundVertical.className = 'vispanel background vertical';
  50. this.dom.backgroundHorizontal.className = 'vispanel background horizontal';
  51. this.dom.centerContainer.className = 'vispanel center';
  52. this.dom.leftContainer.className = 'vispanel left';
  53. this.dom.rightContainer.className = 'vispanel right';
  54. this.dom.top.className = 'vispanel top';
  55. this.dom.bottom.className = 'vispanel bottom';
  56. this.dom.left.className = 'content';
  57. this.dom.center.className = 'content';
  58. this.dom.right.className = 'content';
  59. this.dom.shadowTop.className = 'shadow top';
  60. this.dom.shadowBottom.className = 'shadow bottom';
  61. this.dom.shadowTopLeft.className = 'shadow top';
  62. this.dom.shadowBottomLeft.className = 'shadow bottom';
  63. this.dom.shadowTopRight.className = 'shadow top';
  64. this.dom.shadowBottomRight.className = 'shadow bottom';
  65. this.dom.root.appendChild(this.dom.background);
  66. this.dom.root.appendChild(this.dom.backgroundVertical);
  67. this.dom.root.appendChild(this.dom.backgroundHorizontal);
  68. this.dom.root.appendChild(this.dom.centerContainer);
  69. this.dom.root.appendChild(this.dom.leftContainer);
  70. this.dom.root.appendChild(this.dom.rightContainer);
  71. this.dom.root.appendChild(this.dom.top);
  72. this.dom.root.appendChild(this.dom.bottom);
  73. this.dom.centerContainer.appendChild(this.dom.center);
  74. this.dom.leftContainer.appendChild(this.dom.left);
  75. this.dom.rightContainer.appendChild(this.dom.right);
  76. this.dom.centerContainer.appendChild(this.dom.shadowTop);
  77. this.dom.centerContainer.appendChild(this.dom.shadowBottom);
  78. this.dom.leftContainer.appendChild(this.dom.shadowTopLeft);
  79. this.dom.leftContainer.appendChild(this.dom.shadowBottomLeft);
  80. this.dom.rightContainer.appendChild(this.dom.shadowTopRight);
  81. this.dom.rightContainer.appendChild(this.dom.shadowBottomRight);
  82. this.on('rangechange', this.redraw.bind(this));
  83. this.on('change', this.redraw.bind(this));
  84. this.on('touch', this._onTouch.bind(this));
  85. this.on('pinch', this._onPinch.bind(this));
  86. this.on('dragstart', this._onDragStart.bind(this));
  87. this.on('drag', this._onDrag.bind(this));
  88. // create event listeners for all interesting events, these events will be
  89. // emitted via emitter
  90. this.hammer = Hammer(this.dom.root, {
  91. prevent_default: true
  92. });
  93. this.listeners = {};
  94. var me = this;
  95. var events = [
  96. 'touch', 'pinch',
  97. 'tap', 'doubletap', 'hold',
  98. 'dragstart', 'drag', 'dragend',
  99. 'mousewheel', 'DOMMouseScroll' // DOMMouseScroll is needed for Firefox
  100. ];
  101. events.forEach(function (event) {
  102. var listener = function () {
  103. var args = [event].concat(Array.prototype.slice.call(arguments, 0));
  104. me.emit.apply(me, args);
  105. };
  106. me.hammer.on(event, listener);
  107. me.listeners[event] = listener;
  108. });
  109. // size properties of each of the panels
  110. this.props = {
  111. root: {},
  112. background: {},
  113. centerContainer: {},
  114. leftContainer: {},
  115. rightContainer: {},
  116. center: {},
  117. left: {},
  118. right: {},
  119. top: {},
  120. bottom: {},
  121. border: {},
  122. scrollTop: 0,
  123. scrollTopMin: 0
  124. };
  125. this.touch = {}; // store state information needed for touch events
  126. // attach the root panel to the provided container
  127. if (!container) throw new Error('No container provided');
  128. container.appendChild(this.dom.root);
  129. };
  130. /**
  131. * Destroy the Core, clean up all DOM elements and event listeners.
  132. */
  133. Core.prototype.destroy = function () {
  134. // unbind datasets
  135. this.clear();
  136. // remove all event listeners
  137. this.off();
  138. // stop checking for changed size
  139. this._stopAutoResize();
  140. // remove from DOM
  141. if (this.dom.root.parentNode) {
  142. this.dom.root.parentNode.removeChild(this.dom.root);
  143. }
  144. this.dom = null;
  145. // cleanup hammer touch events
  146. for (var event in this.listeners) {
  147. if (this.listeners.hasOwnProperty(event)) {
  148. delete this.listeners[event];
  149. }
  150. }
  151. this.listeners = null;
  152. this.hammer = null;
  153. // give all components the opportunity to cleanup
  154. this.components.forEach(function (component) {
  155. component.destroy();
  156. });
  157. this.body = null;
  158. };
  159. /**
  160. * Set a custom time bar
  161. * @param {Date} time
  162. */
  163. Core.prototype.setCustomTime = function (time) {
  164. if (!this.customTime) {
  165. throw new Error('Cannot get custom time: Custom time bar is not enabled');
  166. }
  167. this.customTime.setCustomTime(time);
  168. };
  169. /**
  170. * Retrieve the current custom time.
  171. * @return {Date} customTime
  172. */
  173. Core.prototype.getCustomTime = function() {
  174. if (!this.customTime) {
  175. throw new Error('Cannot get custom time: Custom time bar is not enabled');
  176. }
  177. return this.customTime.getCustomTime();
  178. };
  179. /**
  180. * Get the id's of the currently visible items.
  181. * @returns {Array} The ids of the visible items
  182. */
  183. Core.prototype.getVisibleItems = function() {
  184. return this.itemSet && this.itemSet.getVisibleItems() || [];
  185. };
  186. /**
  187. * Clear the Core. By Default, items, groups and options are cleared.
  188. * Example usage:
  189. *
  190. * timeline.clear(); // clear items, groups, and options
  191. * timeline.clear({options: true}); // clear options only
  192. *
  193. * @param {Object} [what] Optionally specify what to clear. By default:
  194. * {items: true, groups: true, options: true}
  195. */
  196. Core.prototype.clear = function(what) {
  197. // clear items
  198. if (!what || what.items) {
  199. this.setItems(null);
  200. }
  201. // clear groups
  202. if (!what || what.groups) {
  203. this.setGroups(null);
  204. }
  205. // clear options of timeline and of each of the components
  206. if (!what || what.options) {
  207. this.components.forEach(function (component) {
  208. component.setOptions(component.defaultOptions);
  209. });
  210. this.setOptions(this.defaultOptions); // this will also do a redraw
  211. }
  212. };
  213. /**
  214. * Set Core window such that it fits all items
  215. */
  216. Core.prototype.fit = function() {
  217. // apply the data range as range
  218. var dataRange = this.getItemRange();
  219. // add 5% space on both sides
  220. var start = dataRange.min;
  221. var end = dataRange.max;
  222. if (start != null && end != null) {
  223. var interval = (end.valueOf() - start.valueOf());
  224. if (interval <= 0) {
  225. // prevent an empty interval
  226. interval = 24 * 60 * 60 * 1000; // 1 day
  227. }
  228. start = new Date(start.valueOf() - interval * 0.05);
  229. end = new Date(end.valueOf() + interval * 0.05);
  230. }
  231. // skip range set if there is no start and end date
  232. if (start === null && end === null) {
  233. return;
  234. }
  235. this.range.setRange(start, end);
  236. };
  237. /**
  238. * Get the data range of the item set.
  239. * @returns {{min: Date, max: Date}} range A range with a start and end Date.
  240. * When no minimum is found, min==null
  241. * When no maximum is found, max==null
  242. */
  243. Core.prototype.getItemRange = function() {
  244. // calculate min from start filed
  245. var dataset = this.itemsData.getDataSet(),
  246. min = null,
  247. max = null;
  248. if (dataset) {
  249. // calculate the minimum value of the field 'start'
  250. var minItem = dataset.min('start');
  251. min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
  252. // Note: we convert first to Date and then to number because else
  253. // a conversion from ISODate to Number will fail
  254. // calculate maximum value of fields 'start' and 'end'
  255. var maxStartItem = dataset.max('start');
  256. if (maxStartItem) {
  257. max = util.convert(maxStartItem.start, 'Date').valueOf();
  258. }
  259. var maxEndItem = dataset.max('end');
  260. if (maxEndItem) {
  261. if (max == null) {
  262. max = util.convert(maxEndItem.end, 'Date').valueOf();
  263. }
  264. else {
  265. max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
  266. }
  267. }
  268. }
  269. return {
  270. min: (min != null) ? new Date(min) : null,
  271. max: (max != null) ? new Date(max) : null
  272. };
  273. };
  274. /**
  275. * Set the visible window. Both parameters are optional, you can change only
  276. * start or only end. Syntax:
  277. *
  278. * TimeLine.setWindow(start, end)
  279. * TimeLine.setWindow(range)
  280. *
  281. * Where start and end can be a Date, number, or string, and range is an
  282. * object with properties start and end.
  283. *
  284. * @param {Date | Number | String | Object} [start] Start date of visible window
  285. * @param {Date | Number | String} [end] End date of visible window
  286. */
  287. Core.prototype.setWindow = function(start, end) {
  288. if (arguments.length == 1) {
  289. var range = arguments[0];
  290. this.range.setRange(range.start, range.end);
  291. }
  292. else {
  293. this.range.setRange(start, end);
  294. }
  295. };
  296. /**
  297. * Get the visible window
  298. * @return {{start: Date, end: Date}} Visible range
  299. */
  300. Core.prototype.getWindow = function() {
  301. var range = this.range.getRange();
  302. return {
  303. start: new Date(range.start),
  304. end: new Date(range.end)
  305. };
  306. };
  307. /**
  308. * Force a redraw of the Core. Can be useful to manually redraw when
  309. * option autoResize=false
  310. */
  311. Core.prototype.redraw = function() {
  312. var resized = false,
  313. options = this.options,
  314. props = this.props,
  315. dom = this.dom;
  316. if (!dom) return; // when destroyed
  317. // update class names
  318. dom.root.className = 'vis timeline root ' + options.orientation;
  319. // update root width and height options
  320. dom.root.style.maxHeight = util.option.asSize(options.maxHeight, '');
  321. dom.root.style.minHeight = util.option.asSize(options.minHeight, '');
  322. dom.root.style.width = util.option.asSize(options.width, '');
  323. // calculate border widths
  324. props.border.left = (dom.centerContainer.offsetWidth - dom.centerContainer.clientWidth) / 2;
  325. props.border.right = props.border.left;
  326. props.border.top = (dom.centerContainer.offsetHeight - dom.centerContainer.clientHeight) / 2;
  327. props.border.bottom = props.border.top;
  328. var borderRootHeight= dom.root.offsetHeight - dom.root.clientHeight;
  329. var borderRootWidth = dom.root.offsetWidth - dom.root.clientWidth;
  330. // calculate the heights. If any of the side panels is empty, we set the height to
  331. // minus the border width, such that the border will be invisible
  332. props.center.height = dom.center.offsetHeight;
  333. props.left.height = dom.left.offsetHeight;
  334. props.right.height = dom.right.offsetHeight;
  335. props.top.height = dom.top.clientHeight || -props.border.top;
  336. props.bottom.height = dom.bottom.clientHeight || -props.border.bottom;
  337. // TODO: compensate borders when any of the panels is empty.
  338. // apply auto height
  339. // TODO: only calculate autoHeight when needed (else we cause an extra reflow/repaint of the DOM)
  340. var contentHeight = Math.max(props.left.height, props.center.height, props.right.height);
  341. var autoHeight = props.top.height + contentHeight + props.bottom.height +
  342. borderRootHeight + props.border.top + props.border.bottom;
  343. dom.root.style.height = util.option.asSize(options.height, autoHeight + 'px');
  344. // calculate heights of the content panels
  345. props.root.height = dom.root.offsetHeight;
  346. props.background.height = props.root.height - borderRootHeight;
  347. var containerHeight = props.root.height - props.top.height - props.bottom.height -
  348. borderRootHeight;
  349. props.centerContainer.height = containerHeight;
  350. props.leftContainer.height = containerHeight;
  351. props.rightContainer.height = props.leftContainer.height;
  352. // calculate the widths of the panels
  353. props.root.width = dom.root.offsetWidth;
  354. props.background.width = props.root.width - borderRootWidth;
  355. props.left.width = dom.leftContainer.clientWidth || -props.border.left;
  356. props.leftContainer.width = props.left.width;
  357. props.right.width = dom.rightContainer.clientWidth || -props.border.right;
  358. props.rightContainer.width = props.right.width;
  359. var centerWidth = props.root.width - props.left.width - props.right.width - borderRootWidth;
  360. props.center.width = centerWidth;
  361. props.centerContainer.width = centerWidth;
  362. props.top.width = centerWidth;
  363. props.bottom.width = centerWidth;
  364. // resize the panels
  365. dom.background.style.height = props.background.height + 'px';
  366. dom.backgroundVertical.style.height = props.background.height + 'px';
  367. dom.backgroundHorizontal.style.height = props.centerContainer.height + 'px';
  368. dom.centerContainer.style.height = props.centerContainer.height + 'px';
  369. dom.leftContainer.style.height = props.leftContainer.height + 'px';
  370. dom.rightContainer.style.height = props.rightContainer.height + 'px';
  371. dom.background.style.width = props.background.width + 'px';
  372. dom.backgroundVertical.style.width = props.centerContainer.width + 'px';
  373. dom.backgroundHorizontal.style.width = props.background.width + 'px';
  374. dom.centerContainer.style.width = props.center.width + 'px';
  375. dom.top.style.width = props.top.width + 'px';
  376. dom.bottom.style.width = props.bottom.width + 'px';
  377. // reposition the panels
  378. dom.background.style.left = '0';
  379. dom.background.style.top = '0';
  380. dom.backgroundVertical.style.left = props.left.width + 'px';
  381. dom.backgroundVertical.style.top = '0';
  382. dom.backgroundHorizontal.style.left = '0';
  383. dom.backgroundHorizontal.style.top = props.top.height + 'px';
  384. dom.centerContainer.style.left = props.left.width + 'px';
  385. dom.centerContainer.style.top = props.top.height + 'px';
  386. dom.leftContainer.style.left = '0';
  387. dom.leftContainer.style.top = props.top.height + 'px';
  388. dom.rightContainer.style.left = (props.left.width + props.center.width) + 'px';
  389. dom.rightContainer.style.top = props.top.height + 'px';
  390. dom.top.style.left = props.left.width + 'px';
  391. dom.top.style.top = '0';
  392. dom.bottom.style.left = props.left.width + 'px';
  393. dom.bottom.style.top = (props.top.height + props.centerContainer.height) + 'px';
  394. // update the scrollTop, feasible range for the offset can be changed
  395. // when the height of the Core or of the contents of the center changed
  396. this._updateScrollTop();
  397. // reposition the scrollable contents
  398. var offset = this.props.scrollTop;
  399. if (options.orientation == 'bottom') {
  400. offset += Math.max(this.props.centerContainer.height - this.props.center.height -
  401. this.props.border.top - this.props.border.bottom, 0);
  402. }
  403. dom.center.style.left = '0';
  404. dom.center.style.top = offset + 'px';
  405. dom.left.style.left = '0';
  406. dom.left.style.top = offset + 'px';
  407. dom.right.style.left = '0';
  408. dom.right.style.top = offset + 'px';
  409. // show shadows when vertical scrolling is available
  410. var visibilityTop = this.props.scrollTop == 0 ? 'hidden' : '';
  411. var visibilityBottom = this.props.scrollTop == this.props.scrollTopMin ? 'hidden' : '';
  412. dom.shadowTop.style.visibility = visibilityTop;
  413. dom.shadowBottom.style.visibility = visibilityBottom;
  414. dom.shadowTopLeft.style.visibility = visibilityTop;
  415. dom.shadowBottomLeft.style.visibility = visibilityBottom;
  416. dom.shadowTopRight.style.visibility = visibilityTop;
  417. dom.shadowBottomRight.style.visibility = visibilityBottom;
  418. // redraw all components
  419. this.components.forEach(function (component) {
  420. resized = component.redraw() || resized;
  421. });
  422. if (resized) {
  423. // keep repainting until all sizes are settled
  424. this.redraw();
  425. }
  426. };
  427. // TODO: deprecated since version 1.1.0, remove some day
  428. Core.prototype.repaint = function () {
  429. throw new Error('Function repaint is deprecated. Use redraw instead.');
  430. };
  431. /**
  432. * Convert a position on screen (pixels) to a datetime
  433. * @param {int} x Position on the screen in pixels
  434. * @return {Date} time The datetime the corresponds with given position x
  435. * @private
  436. */
  437. // TODO: move this function to Range
  438. Core.prototype._toTime = function(x) {
  439. var conversion = this.range.conversion(this.props.center.width);
  440. return new Date(x / conversion.scale + conversion.offset);
  441. };
  442. /**
  443. * Convert a position on the global screen (pixels) to a datetime
  444. * @param {int} x Position on the screen in pixels
  445. * @return {Date} time The datetime the corresponds with given position x
  446. * @private
  447. */
  448. // TODO: move this function to Range
  449. Core.prototype._toGlobalTime = function(x) {
  450. var conversion = this.range.conversion(this.props.root.width);
  451. return new Date(x / conversion.scale + conversion.offset);
  452. };
  453. /**
  454. * Convert a datetime (Date object) into a position on the screen
  455. * @param {Date} time A date
  456. * @return {int} x The position on the screen in pixels which corresponds
  457. * with the given date.
  458. * @private
  459. */
  460. // TODO: move this function to Range
  461. Core.prototype._toScreen = function(time) {
  462. var conversion = this.range.conversion(this.props.center.width);
  463. return (time.valueOf() - conversion.offset) * conversion.scale;
  464. };
  465. /**
  466. * Convert a datetime (Date object) into a position on the root
  467. * This is used to get the pixel density estimate for the screen, not the center panel
  468. * @param {Date} time A date
  469. * @return {int} x The position on root in pixels which corresponds
  470. * with the given date.
  471. * @private
  472. */
  473. // TODO: move this function to Range
  474. Core.prototype._toGlobalScreen = function(time) {
  475. var conversion = this.range.conversion(this.props.root.width);
  476. return (time.valueOf() - conversion.offset) * conversion.scale;
  477. };
  478. /**
  479. * Initialize watching when option autoResize is true
  480. * @private
  481. */
  482. Core.prototype._initAutoResize = function () {
  483. if (this.options.autoResize == true) {
  484. this._startAutoResize();
  485. }
  486. else {
  487. this._stopAutoResize();
  488. }
  489. };
  490. /**
  491. * Watch for changes in the size of the container. On resize, the Panel will
  492. * automatically redraw itself.
  493. * @private
  494. */
  495. Core.prototype._startAutoResize = function () {
  496. var me = this;
  497. this._stopAutoResize();
  498. this._onResize = function() {
  499. if (me.options.autoResize != true) {
  500. // stop watching when the option autoResize is changed to false
  501. me._stopAutoResize();
  502. return;
  503. }
  504. if (me.dom.root) {
  505. // check whether the frame is resized
  506. if ((me.dom.root.clientWidth != me.props.lastWidth) ||
  507. (me.dom.root.clientHeight != me.props.lastHeight)) {
  508. me.props.lastWidth = me.dom.root.clientWidth;
  509. me.props.lastHeight = me.dom.root.clientHeight;
  510. me.emit('change');
  511. }
  512. }
  513. };
  514. // add event listener to window resize
  515. util.addEventListener(window, 'resize', this._onResize);
  516. this.watchTimer = setInterval(this._onResize, 1000);
  517. };
  518. /**
  519. * Stop watching for a resize of the frame.
  520. * @private
  521. */
  522. Core.prototype._stopAutoResize = function () {
  523. if (this.watchTimer) {
  524. clearInterval(this.watchTimer);
  525. this.watchTimer = undefined;
  526. }
  527. // remove event listener on window.resize
  528. util.removeEventListener(window, 'resize', this._onResize);
  529. this._onResize = null;
  530. };
  531. /**
  532. * Start moving the timeline vertically
  533. * @param {Event} event
  534. * @private
  535. */
  536. Core.prototype._onTouch = function (event) {
  537. this.touch.allowDragging = true;
  538. };
  539. /**
  540. * Start moving the timeline vertically
  541. * @param {Event} event
  542. * @private
  543. */
  544. Core.prototype._onPinch = function (event) {
  545. this.touch.allowDragging = false;
  546. };
  547. /**
  548. * Start moving the timeline vertically
  549. * @param {Event} event
  550. * @private
  551. */
  552. Core.prototype._onDragStart = function (event) {
  553. this.touch.initialScrollTop = this.props.scrollTop;
  554. };
  555. /**
  556. * Move the timeline vertically
  557. * @param {Event} event
  558. * @private
  559. */
  560. Core.prototype._onDrag = function (event) {
  561. // refuse to drag when we where pinching to prevent the timeline make a jump
  562. // when releasing the fingers in opposite order from the touch screen
  563. if (!this.touch.allowDragging) return;
  564. var delta = event.gesture.deltaY;
  565. var oldScrollTop = this._getScrollTop();
  566. var newScrollTop = this._setScrollTop(this.touch.initialScrollTop + delta);
  567. if (newScrollTop != oldScrollTop) {
  568. this.redraw(); // TODO: this causes two redraws when dragging, the other is triggered by rangechange already
  569. }
  570. };
  571. /**
  572. * Apply a scrollTop
  573. * @param {Number} scrollTop
  574. * @returns {Number} scrollTop Returns the applied scrollTop
  575. * @private
  576. */
  577. Core.prototype._setScrollTop = function (scrollTop) {
  578. this.props.scrollTop = scrollTop;
  579. this._updateScrollTop();
  580. return this.props.scrollTop;
  581. };
  582. /**
  583. * Update the current scrollTop when the height of the containers has been changed
  584. * @returns {Number} scrollTop Returns the applied scrollTop
  585. * @private
  586. */
  587. Core.prototype._updateScrollTop = function () {
  588. // recalculate the scrollTopMin
  589. var scrollTopMin = Math.min(this.props.centerContainer.height - this.props.center.height, 0); // is negative or zero
  590. if (scrollTopMin != this.props.scrollTopMin) {
  591. // in case of bottom orientation, change the scrollTop such that the contents
  592. // do not move relative to the time axis at the bottom
  593. if (this.options.orientation == 'bottom') {
  594. this.props.scrollTop += (scrollTopMin - this.props.scrollTopMin);
  595. }
  596. this.props.scrollTopMin = scrollTopMin;
  597. }
  598. // limit the scrollTop to the feasible scroll range
  599. if (this.props.scrollTop > 0) this.props.scrollTop = 0;
  600. if (this.props.scrollTop < scrollTopMin) this.props.scrollTop = scrollTopMin;
  601. return this.props.scrollTop;
  602. };
  603. /**
  604. * Get the current scrollTop
  605. * @returns {number} scrollTop
  606. * @private
  607. */
  608. Core.prototype._getScrollTop = function () {
  609. return this.props.scrollTop;
  610. };
  611. module.exports = Core;