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.

764 lines
23 KiB

9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. var util = require('../../util');
  2. var stack = require('../Stack');
  3. /**
  4. * @constructor Group
  5. * @param {Number | String} groupId
  6. * @param {Object} data
  7. * @param {ItemSet} itemSet
  8. */
  9. function Group (groupId, data, itemSet) {
  10. this.groupId = groupId;
  11. this.subgroups = {};
  12. this.subgroupIndex = 0;
  13. this.subgroupOrderer = data && data.subgroupOrder;
  14. this.itemSet = itemSet;
  15. this.isVisible = null;
  16. this.stackDirty = true; // if true, items will be restacked on next redraw
  17. if (data && data.nestedGroups) {
  18. this.nestedGroups = data.nestedGroups;
  19. if (data.showNested == false) {
  20. this.showNested = false;
  21. } else {
  22. this.showNested = true;
  23. }
  24. }
  25. this.nestedInGroup = null;
  26. this.dom = {};
  27. this.props = {
  28. label: {
  29. width: 0,
  30. height: 0
  31. }
  32. };
  33. this.className = null;
  34. this.items = {}; // items filtered by groupId of this group
  35. this.visibleItems = []; // items currently visible in window
  36. this.itemsInRange = []; // items currently in range
  37. this.orderedItems = {
  38. byStart: [],
  39. byEnd: []
  40. };
  41. this.checkRangedItems = false; // needed to refresh the ranged items if the window is programatically changed with NO overlap.
  42. var me = this;
  43. this.itemSet.body.emitter.on("checkRangedItems", function () {
  44. me.checkRangedItems = true;
  45. })
  46. this._create();
  47. this.setData(data);
  48. }
  49. /**
  50. * Create DOM elements for the group
  51. * @private
  52. */
  53. Group.prototype._create = function() {
  54. var label = document.createElement('div');
  55. if (this.itemSet.options.groupEditable.order) {
  56. label.className = 'vis-label draggable';
  57. } else {
  58. label.className = 'vis-label';
  59. }
  60. this.dom.label = label;
  61. var inner = document.createElement('div');
  62. inner.className = 'vis-inner';
  63. label.appendChild(inner);
  64. this.dom.inner = inner;
  65. var foreground = document.createElement('div');
  66. foreground.className = 'vis-group';
  67. foreground['timeline-group'] = this;
  68. this.dom.foreground = foreground;
  69. this.dom.background = document.createElement('div');
  70. this.dom.background.className = 'vis-group';
  71. this.dom.axis = document.createElement('div');
  72. this.dom.axis.className = 'vis-group';
  73. // create a hidden marker to detect when the Timelines container is attached
  74. // to the DOM, or the style of a parent of the Timeline is changed from
  75. // display:none is changed to visible.
  76. this.dom.marker = document.createElement('div');
  77. this.dom.marker.style.visibility = 'hidden';
  78. this.dom.marker.style.position = 'absolute';
  79. this.dom.marker.innerHTML = '';
  80. this.dom.background.appendChild(this.dom.marker);
  81. };
  82. /**
  83. * Set the group data for this group
  84. * @param {Object} data Group data, can contain properties content and className
  85. */
  86. Group.prototype.setData = function(data) {
  87. // update contents
  88. var content;
  89. var templateFunction;
  90. if (this.itemSet.options && this.itemSet.options.groupTemplate) {
  91. templateFunction = this.itemSet.options.groupTemplate.bind(this);
  92. content = templateFunction(data, this.dom.inner);
  93. } else {
  94. content = data && data.content;
  95. }
  96. if (content instanceof Element) {
  97. this.dom.inner.appendChild(content);
  98. while (this.dom.inner.firstChild) {
  99. this.dom.inner.removeChild(this.dom.inner.firstChild);
  100. }
  101. this.dom.inner.appendChild(content);
  102. } else if (content instanceof Object) {
  103. templateFunction(data, this.dom.inner);
  104. } else if (content !== undefined && content !== null) {
  105. this.dom.inner.innerHTML = content;
  106. } else {
  107. this.dom.inner.innerHTML = this.groupId || ''; // groupId can be null
  108. }
  109. // update title
  110. this.dom.label.title = data && data.title || '';
  111. if (!this.dom.inner.firstChild) {
  112. util.addClassName(this.dom.inner, 'vis-hidden');
  113. }
  114. else {
  115. util.removeClassName(this.dom.inner, 'vis-hidden');
  116. }
  117. if (data && data.nestedGroups) {
  118. if (!this.nestedGroups || this.nestedGroups != data.nestedGroups) {
  119. this.nestedGroups = data.nestedGroups;
  120. }
  121. if (data.showNested !== undefined || this.showNested === undefined) {
  122. if (data.showNested == false) {
  123. this.showNested = false;
  124. } else {
  125. this.showNested = true;
  126. }
  127. }
  128. util.addClassName(this.dom.label, 'vis-nesting-group');
  129. var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
  130. if (this.showNested) {
  131. util.removeClassName(this.dom.label, collapsedDirClassName);
  132. util.addClassName(this.dom.label, 'expanded');
  133. } else {
  134. util.removeClassName(this.dom.label, 'expanded');
  135. util.addClassName(this.dom.label, collapsedDirClassName);
  136. }
  137. } else if (this.nestedGroups) {
  138. this.nestedGroups = null;
  139. collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
  140. util.removeClassName(this.dom.label, collapsedDirClassName);
  141. util.removeClassName(this.dom.label, 'expanded');
  142. util.removeClassName(this.dom.label, 'vis-nesting-group');
  143. }
  144. if (data && data.nestedInGroup) {
  145. util.addClassName(this.dom.label, 'vis-nested-group');
  146. if (this.itemSet.options && this.itemSet.options.rtl) {
  147. this.dom.inner.style.paddingRight = '30px';
  148. } else {
  149. this.dom.inner.style.paddingLeft = '30px';
  150. }
  151. }
  152. // update className
  153. var className = data && data.className || null;
  154. if (className != this.className) {
  155. if (this.className) {
  156. util.removeClassName(this.dom.label, this.className);
  157. util.removeClassName(this.dom.foreground, this.className);
  158. util.removeClassName(this.dom.background, this.className);
  159. util.removeClassName(this.dom.axis, this.className);
  160. }
  161. util.addClassName(this.dom.label, className);
  162. util.addClassName(this.dom.foreground, className);
  163. util.addClassName(this.dom.background, className);
  164. util.addClassName(this.dom.axis, className);
  165. this.className = className;
  166. }
  167. // update style
  168. if (this.style) {
  169. util.removeCssText(this.dom.label, this.style);
  170. this.style = null;
  171. }
  172. if (data && data.style) {
  173. util.addCssText(this.dom.label, data.style);
  174. this.style = data.style;
  175. }
  176. };
  177. /**
  178. * Get the width of the group label
  179. * @return {number} width
  180. */
  181. Group.prototype.getLabelWidth = function() {
  182. return this.props.label.width;
  183. };
  184. /**
  185. * Repaint this group
  186. * @param {{start: number, end: number}} range
  187. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  188. * @param {boolean} [forceRestack=false] Force restacking of all items
  189. * @return {boolean} Returns true if the group is resized
  190. */
  191. Group.prototype.redraw = function(range, margin, forceRestack) {
  192. var resized = false;
  193. // force recalculation of the height of the items when the marker height changed
  194. // (due to the Timeline being attached to the DOM or changed from display:none to visible)
  195. var markerHeight = this.dom.marker.clientHeight;
  196. if (markerHeight != this.lastMarkerHeight) {
  197. this.lastMarkerHeight = markerHeight;
  198. util.forEach(this.items, function (item) {
  199. item.dirty = true;
  200. if (item.displayed) item.redraw();
  201. });
  202. forceRestack = true;
  203. }
  204. // recalculate the height of the subgroups
  205. this._calculateSubGroupHeights(margin);
  206. // calculate actual size and position
  207. var foreground = this.dom.foreground;
  208. this.top = foreground.offsetTop;
  209. this.right = foreground.offsetLeft;
  210. this.width = foreground.offsetWidth;
  211. var lastIsVisible = this.isVisible;
  212. this.isVisible = this._isGroupVisible(range, margin);
  213. var restack = forceRestack || this.stackDirty || (this.isVisible && !lastIsVisible);
  214. this._updateSubgroupsSizes();
  215. // if restacking, reposition visible items vertically
  216. if(restack) {
  217. if (typeof this.itemSet.options.order === 'function') {
  218. // a custom order function
  219. // brute force restack of all items
  220. // show all items
  221. var me = this;
  222. var limitSize = false;
  223. util.forEach(this.items, function (item) {
  224. if (!item.dom) { // If this item has never been displayed then the dom property will not be defined, this means we need to measure the size
  225. item.redraw();
  226. me.visibleItems.push(item);
  227. }
  228. item.repositionX(limitSize);
  229. });
  230. // order all items and force a restacking
  231. var customOrderedItems = this.orderedItems.byStart.slice().sort(function (a, b) {
  232. return me.itemSet.options.order(a.data, b.data);
  233. });
  234. stack.stack(customOrderedItems, margin, true /* restack=true */);
  235. this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
  236. }
  237. else {
  238. // no custom order function, lazy stacking
  239. this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
  240. if (this.itemSet.options.stack) { // TODO: ugly way to access options...
  241. stack.stack(this.visibleItems, margin, true /* restack=true */);
  242. }
  243. else { // no stacking
  244. stack.nostack(this.visibleItems, margin, this.subgroups, this.itemSet.options.stackSubgroups);
  245. }
  246. }
  247. this.stackDirty = false;
  248. }
  249. // recalculate the height of the group
  250. var height = this._calculateHeight(margin);
  251. // calculate actual size and position
  252. foreground = this.dom.foreground;
  253. this.top = foreground.offsetTop;
  254. this.right = foreground.offsetLeft;
  255. this.width = foreground.offsetWidth;
  256. resized = util.updateProperty(this, 'height', height) || resized;
  257. // recalculate size of label
  258. resized = util.updateProperty(this.props.label, 'width', this.dom.inner.clientWidth) || resized;
  259. resized = util.updateProperty(this.props.label, 'height', this.dom.inner.clientHeight) || resized;
  260. // apply new height
  261. this.dom.background.style.height = height + 'px';
  262. this.dom.foreground.style.height = height + 'px';
  263. this.dom.label.style.height = height + 'px';
  264. // update vertical position of items after they are re-stacked and the height of the group is calculated
  265. for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
  266. var item = this.visibleItems[i];
  267. item.repositionY(margin);
  268. if (!this.isVisible && this.groupId != "__background__") {
  269. if (item.displayed) item.hide();
  270. }
  271. }
  272. if (!this.isVisible && this.height) {
  273. return resized = false;
  274. }
  275. return resized;
  276. };
  277. /**
  278. * recalculate the height of the subgroups
  279. * @private
  280. */
  281. Group.prototype._calculateSubGroupHeights = function (margin) {
  282. if (Object.keys(this.subgroups).length > 0) {
  283. var me = this;
  284. this.resetSubgroups();
  285. util.forEach(this.visibleItems, function (item) {
  286. if (item.data.subgroup !== undefined) {
  287. me.subgroups[item.data.subgroup].height = Math.max(me.subgroups[item.data.subgroup].height, item.height + margin.item.vertical);
  288. me.subgroups[item.data.subgroup].visible = true;
  289. }
  290. });
  291. }
  292. };
  293. /**
  294. * check if group is visible
  295. * @private
  296. */
  297. Group.prototype._isGroupVisible = function (range, margin) {
  298. var isVisible =
  299. (this.top <= range.body.domProps.centerContainer.height - range.body.domProps.scrollTop + margin.axis)
  300. && (this.top + this.height + margin.axis >= - range.body.domProps.scrollTop);
  301. return isVisible;
  302. }
  303. /**
  304. * recalculate the height of the group
  305. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  306. * @returns {number} Returns the height
  307. * @private
  308. */
  309. Group.prototype._calculateHeight = function (margin) {
  310. // recalculate the height of the group
  311. var height;
  312. var itemsInRange = this.visibleItems;
  313. if (itemsInRange.length > 0) {
  314. var min = itemsInRange[0].top;
  315. var max = itemsInRange[0].top + itemsInRange[0].height;
  316. util.forEach(itemsInRange, function (item) {
  317. min = Math.min(min, item.top);
  318. max = Math.max(max, (item.top + item.height));
  319. });
  320. if (min > margin.axis) {
  321. // there is an empty gap between the lowest item and the axis
  322. var offset = min - margin.axis;
  323. max -= offset;
  324. util.forEach(itemsInRange, function (item) {
  325. item.top -= offset;
  326. });
  327. }
  328. height = max + margin.item.vertical / 2;
  329. }
  330. else {
  331. height = 0;
  332. }
  333. height = Math.max(height, this.props.label.height);
  334. return height;
  335. };
  336. /**
  337. * Show this group: attach to the DOM
  338. */
  339. Group.prototype.show = function() {
  340. if (!this.dom.label.parentNode) {
  341. this.itemSet.dom.labelSet.appendChild(this.dom.label);
  342. }
  343. if (!this.dom.foreground.parentNode) {
  344. this.itemSet.dom.foreground.appendChild(this.dom.foreground);
  345. }
  346. if (!this.dom.background.parentNode) {
  347. this.itemSet.dom.background.appendChild(this.dom.background);
  348. }
  349. if (!this.dom.axis.parentNode) {
  350. this.itemSet.dom.axis.appendChild(this.dom.axis);
  351. }
  352. };
  353. /**
  354. * Hide this group: remove from the DOM
  355. */
  356. Group.prototype.hide = function() {
  357. var label = this.dom.label;
  358. if (label.parentNode) {
  359. label.parentNode.removeChild(label);
  360. }
  361. var foreground = this.dom.foreground;
  362. if (foreground.parentNode) {
  363. foreground.parentNode.removeChild(foreground);
  364. }
  365. var background = this.dom.background;
  366. if (background.parentNode) {
  367. background.parentNode.removeChild(background);
  368. }
  369. var axis = this.dom.axis;
  370. if (axis.parentNode) {
  371. axis.parentNode.removeChild(axis);
  372. }
  373. };
  374. /**
  375. * Add an item to the group
  376. * @param {Item} item
  377. */
  378. Group.prototype.add = function(item) {
  379. this.items[item.id] = item;
  380. item.setParent(this);
  381. this.stackDirty = true;
  382. // add to
  383. if (item.data.subgroup !== undefined) {
  384. this._addToSubgroup(item);
  385. this.orderSubgroups();
  386. }
  387. if (this.visibleItems.indexOf(item) == -1) {
  388. var range = this.itemSet.body.range; // TODO: not nice accessing the range like this
  389. this._checkIfVisible(item, this.visibleItems, range);
  390. }
  391. };
  392. Group.prototype._addToSubgroup = function(item, subgroupId) {
  393. subgroupId = subgroupId || item.data.subgroup;
  394. if (subgroupId != undefined && this.subgroups[subgroupId] === undefined) {
  395. this.subgroups[subgroupId] = {
  396. height:0,
  397. top: 0,
  398. start: item.data.start,
  399. end: item.data.end,
  400. visible: false,
  401. index:this.subgroupIndex,
  402. items: []
  403. };
  404. this.subgroupIndex++;
  405. }
  406. if (new Date(item.data.start) < new Date(this.subgroups[subgroupId].start)) {
  407. this.subgroups[subgroupId].start = item.data.start;
  408. }
  409. if (new Date(item.data.end) > new Date(this.subgroups[subgroupId].end)) {
  410. this.subgroups[subgroupId].end = item.data.end;
  411. }
  412. this.subgroups[subgroupId].items.push(item);
  413. };
  414. Group.prototype._updateSubgroupsSizes = function () {
  415. var me = this;
  416. if (me.subgroups) {
  417. for (var subgroup in me.subgroups) {
  418. var newStart = me.subgroups[subgroup].items[0].data.start;
  419. var newEnd = me.subgroups[subgroup].items[0].data.end - 1;
  420. me.subgroups[subgroup].items.forEach(function(item) {
  421. if (new Date(item.data.start) < new Date(newStart)) {
  422. newStart = item.data.start;
  423. }
  424. if (new Date(item.data.end) > new Date(newEnd)) {
  425. newEnd = item.data.end;
  426. }
  427. })
  428. me.subgroups[subgroup].start = newStart;
  429. me.subgroups[subgroup].end = new Date(newEnd - 1) // -1 to compensate for colliding end to start subgroups;
  430. }
  431. }
  432. }
  433. Group.prototype.orderSubgroups = function() {
  434. if (this.subgroupOrderer !== undefined) {
  435. var sortArray = [];
  436. var subgroup;
  437. if (typeof this.subgroupOrderer == 'string') {
  438. for (subgroup in this.subgroups) {
  439. sortArray.push({subgroup: subgroup, sortField: this.subgroups[subgroup].items[0].data[this.subgroupOrderer]})
  440. }
  441. sortArray.sort(function (a, b) {
  442. return a.sortField - b.sortField;
  443. })
  444. }
  445. else if (typeof this.subgroupOrderer == 'function') {
  446. for (subgroup in this.subgroups) {
  447. sortArray.push(this.subgroups[subgroup].items[0].data);
  448. }
  449. sortArray.sort(this.subgroupOrderer);
  450. }
  451. if (sortArray.length > 0) {
  452. for (var i = 0; i < sortArray.length; i++) {
  453. this.subgroups[sortArray[i].subgroup].index = i;
  454. }
  455. }
  456. }
  457. };
  458. Group.prototype.resetSubgroups = function() {
  459. for (var subgroup in this.subgroups) {
  460. if (this.subgroups.hasOwnProperty(subgroup)) {
  461. this.subgroups[subgroup].visible = false;
  462. this.subgroups[subgroup].height = 0;
  463. }
  464. }
  465. };
  466. /**
  467. * Remove an item from the group
  468. * @param {Item} item
  469. */
  470. Group.prototype.remove = function(item) {
  471. delete this.items[item.id];
  472. item.setParent(null);
  473. this.stackDirty = true;
  474. // remove from visible items
  475. var index = this.visibleItems.indexOf(item);
  476. if (index != -1) this.visibleItems.splice(index, 1);
  477. if(item.data.subgroup !== undefined){
  478. this._removeFromSubgroup(item);
  479. this.orderSubgroups();
  480. }
  481. };
  482. Group.prototype._removeFromSubgroup = function(item, subgroupId) {
  483. subgroupId = subgroupId || item.data.subgroup;
  484. if (subgroupId != undefined) {
  485. var subgroup = this.subgroups[subgroupId];
  486. if (subgroup){
  487. var itemIndex = subgroup.items.indexOf(item);
  488. // Check the item is actually in this subgroup. How should items not in the group be handled?
  489. if (itemIndex >= 0) {
  490. subgroup.items.splice(itemIndex,1);
  491. if (!subgroup.items.length){
  492. delete this.subgroups[subgroupId];
  493. } else {
  494. this._updateSubgroupsSizes();
  495. }
  496. }
  497. }
  498. }
  499. };
  500. /**
  501. * Remove an item from the corresponding DataSet
  502. * @param {Item} item
  503. */
  504. Group.prototype.removeFromDataSet = function(item) {
  505. this.itemSet.removeItem(item.id);
  506. };
  507. /**
  508. * Reorder the items
  509. */
  510. Group.prototype.order = function() {
  511. var array = util.toArray(this.items);
  512. var startArray = [];
  513. var endArray = [];
  514. for (var i = 0; i < array.length; i++) {
  515. if (array[i].data.end !== undefined) {
  516. endArray.push(array[i]);
  517. }
  518. startArray.push(array[i]);
  519. }
  520. this.orderedItems = {
  521. byStart: startArray,
  522. byEnd: endArray
  523. };
  524. stack.orderByStart(this.orderedItems.byStart);
  525. stack.orderByEnd(this.orderedItems.byEnd);
  526. };
  527. /**
  528. * Update the visible items
  529. * @param {{byStart: Item[], byEnd: Item[]}} orderedItems All items ordered by start date and by end date
  530. * @param {Item[]} visibleItems The previously visible items.
  531. * @param {{start: number, end: number}} range Visible range
  532. * @return {Item[]} visibleItems The new visible items.
  533. * @private
  534. */
  535. Group.prototype._updateItemsInRange = function(orderedItems, oldVisibleItems, range) {
  536. var visibleItems = [];
  537. var visibleItemsLookup = {}; // we keep this to quickly look up if an item already exists in the list without using indexOf on visibleItems
  538. var interval = (range.end - range.start) / 4;
  539. var lowerBound = range.start - interval;
  540. var upperBound = range.end + interval;
  541. // this function is used to do the binary search.
  542. var searchFunction = function (value) {
  543. if (value < lowerBound) {return -1;}
  544. else if (value <= upperBound) {return 0;}
  545. else {return 1;}
  546. };
  547. // first check if the items that were in view previously are still in view.
  548. // IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
  549. // also cleans up invisible items.
  550. if (oldVisibleItems.length > 0) {
  551. for (var i = 0; i < oldVisibleItems.length; i++) {
  552. this._checkIfVisibleWithReference(oldVisibleItems[i], visibleItems, visibleItemsLookup, range);
  553. }
  554. }
  555. // we do a binary search for the items that have only start values.
  556. var initialPosByStart = util.binarySearchCustom(orderedItems.byStart, searchFunction, 'data','start');
  557. // trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the start values.
  558. this._traceVisible(initialPosByStart, orderedItems.byStart, visibleItems, visibleItemsLookup, function (item) {
  559. return (item.data.start < lowerBound || item.data.start > upperBound);
  560. });
  561. // if the window has changed programmatically without overlapping the old window, the ranged items with start < lowerBound and end > upperbound are not shown.
  562. // We therefore have to brute force check all items in the byEnd list
  563. if (this.checkRangedItems == true) {
  564. this.checkRangedItems = false;
  565. for (i = 0; i < orderedItems.byEnd.length; i++) {
  566. this._checkIfVisibleWithReference(orderedItems.byEnd[i], visibleItems, visibleItemsLookup, range);
  567. }
  568. }
  569. else {
  570. // we do a binary search for the items that have defined end times.
  571. var initialPosByEnd = util.binarySearchCustom(orderedItems.byEnd, searchFunction, 'data','end');
  572. // trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the end values.
  573. this._traceVisible(initialPosByEnd, orderedItems.byEnd, visibleItems, visibleItemsLookup, function (item) {
  574. return (item.data.end < lowerBound || item.data.end > upperBound);
  575. });
  576. }
  577. // finally, we reposition all the visible items.
  578. for (i = 0; i < visibleItems.length; i++) {
  579. var item = visibleItems[i];
  580. if (!item.displayed) item.show();
  581. // reposition item horizontally
  582. item.repositionX();
  583. }
  584. return visibleItems;
  585. };
  586. Group.prototype._traceVisible = function (initialPos, items, visibleItems, visibleItemsLookup, breakCondition) {
  587. if (initialPos != -1) {
  588. var i, item;
  589. for (i = initialPos; i >= 0; i--) {
  590. item = items[i];
  591. if (breakCondition(item)) {
  592. break;
  593. }
  594. else {
  595. if (visibleItemsLookup[item.id] === undefined) {
  596. visibleItemsLookup[item.id] = true;
  597. visibleItems.push(item);
  598. }
  599. }
  600. }
  601. for (i = initialPos + 1; i < items.length; i++) {
  602. item = items[i];
  603. if (breakCondition(item)) {
  604. break;
  605. }
  606. else {
  607. if (visibleItemsLookup[item.id] === undefined) {
  608. visibleItemsLookup[item.id] = true;
  609. visibleItems.push(item);
  610. }
  611. }
  612. }
  613. }
  614. }
  615. /**
  616. * this function is very similar to the _checkIfInvisible() but it does not
  617. * return booleans, hides the item if it should not be seen and always adds to
  618. * the visibleItems.
  619. * this one is for brute forcing and hiding.
  620. *
  621. * @param {Item} item
  622. * @param {Array} visibleItems
  623. * @param {{start:number, end:number}} range
  624. * @private
  625. */
  626. Group.prototype._checkIfVisible = function(item, visibleItems, range) {
  627. if (item.isVisible(range)) {
  628. if (!item.displayed) item.show();
  629. // reposition item horizontally
  630. item.repositionX();
  631. visibleItems.push(item);
  632. }
  633. else {
  634. if (item.displayed) item.hide();
  635. }
  636. };
  637. /**
  638. * this function is very similar to the _checkIfInvisible() but it does not
  639. * return booleans, hides the item if it should not be seen and always adds to
  640. * the visibleItems.
  641. * this one is for brute forcing and hiding.
  642. *
  643. * @param {Item} item
  644. * @param {Array} visibleItems
  645. * @param {{start:number, end:number}} range
  646. * @private
  647. */
  648. Group.prototype._checkIfVisibleWithReference = function(item, visibleItems, visibleItemsLookup, range) {
  649. if (item.isVisible(range)) {
  650. if (visibleItemsLookup[item.id] === undefined) {
  651. visibleItemsLookup[item.id] = true;
  652. visibleItems.push(item);
  653. }
  654. }
  655. else {
  656. if (item.displayed) item.hide();
  657. }
  658. };
  659. Group.prototype.changeSubgroup = function(item, oldSubgroup, newSubgroup) {
  660. this._removeFromSubgroup(item, oldSubgroup);
  661. this._addToSubgroup(item, newSubgroup);
  662. this.orderSubgroups();
  663. };
  664. module.exports = Group;