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.

56 lines
1.7 KiB

11 years ago
  1. /**
  2. * @constructor ItemRangeOverflow
  3. * @extends ItemRange
  4. * @param {Object} data Object containing parameters start, end
  5. * content, className.
  6. * @param {Object} [options] Options to set initial property values
  7. * @param {Object} [defaultOptions] default options
  8. * // TODO: describe available options
  9. */
  10. function ItemRangeOverflow (data, options, defaultOptions) {
  11. this.props = {
  12. content: {
  13. left: 0,
  14. width: 0
  15. }
  16. };
  17. ItemRange.call(this, data, options, defaultOptions);
  18. }
  19. ItemRangeOverflow.prototype = new ItemRange (null);
  20. ItemRangeOverflow.prototype.baseClassName = 'item rangeoverflow';
  21. /**
  22. * Reposition the item horizontally
  23. * @Override
  24. */
  25. ItemRangeOverflow.prototype.repositionX = function repositionX() {
  26. var parentWidth = this.parent.width,
  27. start = this.defaultOptions.toScreen(this.data.start),
  28. end = this.defaultOptions.toScreen(this.data.end),
  29. padding = 'padding' in this.options ? this.options.padding : this.defaultOptions.padding,
  30. contentLeft;
  31. // limit the width of the this, as browsers cannot draw very wide divs
  32. if (start < -parentWidth) {
  33. start = -parentWidth;
  34. }
  35. if (end > 2 * parentWidth) {
  36. end = 2 * parentWidth;
  37. }
  38. // when range exceeds left of the window, position the contents at the left of the visible area
  39. contentLeft = Math.max(-start, 0);
  40. this.left = start;
  41. var boxWidth = Math.max(end - start, 1);
  42. this.width = (this.props.content.width < boxWidth) ?
  43. boxWidth :
  44. start + contentLeft + this.props.content.width;
  45. this.dom.box.style.left = this.left + 'px';
  46. this.dom.box.style.width = boxWidth + 'px';
  47. this.dom.content.style.left = contentLeft + 'px';
  48. };