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.

57 lines
1.6 KiB

  1. var Group = require('./Group');
  2. /**
  3. * @constructor BackgroundGroup
  4. * @param {number | string} groupId
  5. * @param {Object} data
  6. * @param {ItemSet} itemSet
  7. * @extends Group
  8. */
  9. function BackgroundGroup (groupId, data, itemSet) {
  10. Group.call(this, groupId, data, itemSet);
  11. this.width = 0;
  12. this.height = 0;
  13. this.top = 0;
  14. this.left = 0;
  15. }
  16. BackgroundGroup.prototype = Object.create(Group.prototype);
  17. /**
  18. * Repaint this group
  19. * @param {{start: number, end: number}} range
  20. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  21. * @param {boolean} [forceRestack=false] Force restacking of all items
  22. * @return {boolean} Returns true if the group is resized
  23. */
  24. BackgroundGroup.prototype.redraw = function(range, margin, forceRestack) { // eslint-disable-line no-unused-vars
  25. var resized = false;
  26. this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
  27. // calculate actual size
  28. this.width = this.dom.background.offsetWidth;
  29. // apply new height (just always zero for BackgroundGroup
  30. this.dom.background.style.height = '0';
  31. // update vertical position of items after they are re-stacked and the height of the group is calculated
  32. for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
  33. var item = this.visibleItems[i];
  34. item.repositionY(margin);
  35. }
  36. return resized;
  37. };
  38. /**
  39. * Show this group: attach to the DOM
  40. */
  41. BackgroundGroup.prototype.show = function() {
  42. if (!this.dom.background.parentNode) {
  43. this.itemSet.dom.background.appendChild(this.dom.background);
  44. }
  45. };
  46. module.exports = BackgroundGroup;