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.

95 lines
2.3 KiB

  1. /**
  2. * @constructor Group
  3. * @param {GroupSet} parent
  4. * @param {Number | String} groupId
  5. * @param {Object} [options] Options to set initial property values
  6. * // TODO: describe available options
  7. * @extends Component
  8. */
  9. function Group (parent, groupId, options) {
  10. this.id = util.randomUUID();
  11. this.parent = parent;
  12. this.groupId = groupId;
  13. this.itemsData = null; // DataSet
  14. this.items = null; // ItemSet
  15. this.options = Object.create(parent && parent.options || null);
  16. this.options.top = 0;
  17. this.top = 0;
  18. this.left = 0;
  19. this.width = 0;
  20. this.height = 0;
  21. this.setOptions(options);
  22. }
  23. Group.prototype = new Component();
  24. Group.prototype.setOptions = function setOptions(options) {
  25. if (options) {
  26. util.extend(this.options, options);
  27. }
  28. };
  29. /**
  30. * Get the container element of the panel, which can be used by a child to
  31. * add its own widgets.
  32. * @returns {HTMLElement} container
  33. */
  34. Group.prototype.getContainer = function () {
  35. return this.parent.getContainer();
  36. };
  37. /**
  38. * Set item set for the group. The group will create a view on the itemset,
  39. * filtered by the groups id.
  40. * @param {DataSet | DataView} items
  41. */
  42. Group.prototype.setItems = function setItems(items) {
  43. if (this.items) {
  44. // remove current item set
  45. this.items.hide();
  46. this.items.setItems();
  47. this.parent.controller.remove(this.items);
  48. }
  49. if (items || true) {
  50. var groupId = this.groupId;
  51. this.items = new ItemSet(this);
  52. this.items.setRange(this.parent.range);
  53. this.view = new DataView(items, {
  54. filter: function (item) {
  55. return item.group == groupId;
  56. }
  57. });
  58. this.items.setItems(this.view);
  59. this.parent.controller.add(this.items);
  60. }
  61. };
  62. /**
  63. * Repaint the item
  64. * @return {Boolean} changed
  65. */
  66. Group.prototype.repaint = function repaint() {
  67. return false;
  68. };
  69. /**
  70. * Reflow the item
  71. * @return {Boolean} resized
  72. */
  73. Group.prototype.reflow = function reflow() {
  74. var changed = 0,
  75. update = util.updateProperty;
  76. changed += update(this, 'top', this.items ? this.items.top : 0);
  77. changed += update(this, 'height', this.items ? this.items.height : 0);
  78. return (changed > 0);
  79. };