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