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.

759 lines
22 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. var RangeItem = require('./item/RangeItem');
  4. /**
  5. * @constructor Group
  6. * @param {Number | String} groupId
  7. * @param {Object} data
  8. * @param {ItemSet} itemSet
  9. */
  10. function Group (groupId, data, itemSet) {
  11. this.groupId = groupId;
  12. this.subgroups = {};
  13. this.subgroupIndex = 0;
  14. this.subgroupOrderer = data && data.subgroupOrder;
  15. this.itemSet = itemSet;
  16. this.isVisible = null;
  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. var 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} [restack=false] Force restacking of all items
  189. * @return {boolean} Returns true if the group is resized
  190. */
  191. Group.prototype.redraw = function(range, margin, restack) {
  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. restack = 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. this.isVisible = this._isGroupVisible(range, margin);
  212. // reposition visible items vertically
  213. if (typeof this.itemSet.options.order === 'function') {
  214. // a custom order function
  215. if (restack) {
  216. // brute force restack of all items
  217. // show all items
  218. var me = this;
  219. var limitSize = false;
  220. util.forEach(this.items, function (item) {
  221. if (!item.displayed) {
  222. item.redraw();
  223. me.visibleItems.push(item);
  224. }
  225. item.repositionX(limitSize);
  226. });
  227. // order all items and force a restacking
  228. var customOrderedItems = this.orderedItems.byStart.slice().sort(function (a, b) {
  229. return me.itemSet.options.order(a.data, b.data);
  230. });
  231. stack.stack(customOrderedItems, margin, true /* restack=true */);
  232. }
  233. this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
  234. }
  235. else {
  236. // no custom order function, lazy stacking
  237. this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
  238. if (this.itemSet.options.stack) { // TODO: ugly way to access options...
  239. stack.stack(this.visibleItems, margin, restack);
  240. }
  241. else { // no stacking
  242. stack.nostack(this.visibleItems, margin, this.subgroups, this.itemSet.options.stackSubgroups);
  243. }
  244. }
  245. this._updateSubgroupsSizes();
  246. // recalculate the height of the group
  247. var height = this._calculateHeight(margin);
  248. // calculate actual size and position
  249. var foreground = this.dom.foreground;
  250. this.top = foreground.offsetTop;
  251. this.right = foreground.offsetLeft;
  252. this.width = foreground.offsetWidth;
  253. resized = util.updateProperty(this, 'height', height) || resized;
  254. // recalculate size of label
  255. resized = util.updateProperty(this.props.label, 'width', this.dom.inner.clientWidth) || resized;
  256. resized = util.updateProperty(this.props.label, 'height', this.dom.inner.clientHeight) || resized;
  257. // apply new height
  258. this.dom.background.style.height = height + 'px';
  259. this.dom.foreground.style.height = height + 'px';
  260. this.dom.label.style.height = height + 'px';
  261. // update vertical position of items after they are re-stacked and the height of the group is calculated
  262. for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
  263. var item = this.visibleItems[i];
  264. item.repositionY(margin);
  265. if (!this.isVisible && this.groupId != "__background__") {
  266. if (item.displayed) item.hide();
  267. }
  268. }
  269. if (!this.isVisible && this.height) {
  270. return resized = false;
  271. }
  272. return resized;
  273. };
  274. /**
  275. * recalculate the height of the subgroups
  276. * @private
  277. */
  278. Group.prototype._calculateSubGroupHeights = function (margin) {
  279. if (Object.keys(this.subgroups).length > 0) {
  280. var me = this;
  281. this.resetSubgroups();
  282. util.forEach(this.visibleItems, function (item) {
  283. if (item.data.subgroup !== undefined) {
  284. me.subgroups[item.data.subgroup].height = Math.max(me.subgroups[item.data.subgroup].height, item.height + margin.item.vertical);
  285. me.subgroups[item.data.subgroup].visible = true;
  286. }
  287. });
  288. }
  289. };
  290. /**
  291. * check if group is visible
  292. * @private
  293. */
  294. Group.prototype._isGroupVisible = function (range, margin) {
  295. var isVisible =
  296. (this.top <= range.body.domProps.centerContainer.height - range.body.domProps.scrollTop + margin.axis)
  297. && (this.top + this.height + margin.axis >= - range.body.domProps.scrollTop);
  298. return isVisible;
  299. }
  300. /**
  301. * recalculate the height of the group
  302. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  303. * @returns {number} Returns the height
  304. * @private
  305. */
  306. Group.prototype._calculateHeight = function (margin) {
  307. // recalculate the height of the group
  308. var height;
  309. var itemsInRange = this.visibleItems;
  310. if (itemsInRange.length > 0) {
  311. var min = itemsInRange[0].top;
  312. var max = itemsInRange[0].top + itemsInRange[0].height;
  313. util.forEach(itemsInRange, function (item) {
  314. min = Math.min(min, item.top);
  315. max = Math.max(max, (item.top + item.height));
  316. });
  317. if (min > margin.axis) {
  318. // there is an empty gap between the lowest item and the axis
  319. var offset = min - margin.axis;
  320. max -= offset;
  321. util.forEach(itemsInRange, function (item) {
  322. item.top -= offset;
  323. });
  324. }
  325. height = max + margin.item.vertical / 2;
  326. }
  327. else {
  328. height = 0;
  329. }
  330. height = Math.max(height, this.props.label.height);
  331. return height;
  332. };
  333. /**
  334. * Show this group: attach to the DOM
  335. */
  336. Group.prototype.show = function() {
  337. if (!this.dom.label.parentNode) {
  338. this.itemSet.dom.labelSet.appendChild(this.dom.label);
  339. }
  340. if (!this.dom.foreground.parentNode) {
  341. this.itemSet.dom.foreground.appendChild(this.dom.foreground);
  342. }
  343. if (!this.dom.background.parentNode) {
  344. this.itemSet.dom.background.appendChild(this.dom.background);
  345. }
  346. if (!this.dom.axis.parentNode) {
  347. this.itemSet.dom.axis.appendChild(this.dom.axis);
  348. }
  349. };
  350. /**
  351. * Hide this group: remove from the DOM
  352. */
  353. Group.prototype.hide = function() {
  354. var label = this.dom.label;
  355. if (label.parentNode) {
  356. label.parentNode.removeChild(label);
  357. }
  358. var foreground = this.dom.foreground;
  359. if (foreground.parentNode) {
  360. foreground.parentNode.removeChild(foreground);
  361. }
  362. var background = this.dom.background;
  363. if (background.parentNode) {
  364. background.parentNode.removeChild(background);
  365. }
  366. var axis = this.dom.axis;
  367. if (axis.parentNode) {
  368. axis.parentNode.removeChild(axis);
  369. }
  370. };
  371. /**
  372. * Add an item to the group
  373. * @param {Item} item
  374. */
  375. Group.prototype.add = function(item) {
  376. this.items[item.id] = item;
  377. item.setParent(this);
  378. // add to
  379. if (item.data.subgroup !== undefined) {
  380. this._addToSubgroup(item);
  381. this.orderSubgroups();
  382. }
  383. if (this.visibleItems.indexOf(item) == -1) {
  384. var range = this.itemSet.body.range; // TODO: not nice accessing the range like this
  385. this._checkIfVisible(item, this.visibleItems, range);
  386. }
  387. };
  388. Group.prototype._addToSubgroup = function(item, subgroupId) {
  389. subgroupId = subgroupId || item.data.subgroup;
  390. if (subgroupId != undefined && this.subgroups[subgroupId] === undefined) {
  391. this.subgroups[subgroupId] = {
  392. height:0,
  393. top: 0,
  394. start: item.data.start,
  395. end: item.data.end,
  396. visible: false,
  397. index:this.subgroupIndex,
  398. items: []
  399. };
  400. this.subgroupIndex++;
  401. }
  402. if (new Date(item.data.start) < new Date(this.subgroups[subgroupId].start)) {
  403. this.subgroups[subgroupId].start = item.data.start;
  404. }
  405. if (new Date(item.data.end) > new Date(this.subgroups[subgroupId].end)) {
  406. this.subgroups[subgroupId].end = item.data.end;
  407. }
  408. this.subgroups[subgroupId].items.push(item);
  409. };
  410. Group.prototype._updateSubgroupsSizes = function () {
  411. var me = this;
  412. if (me.subgroups) {
  413. for (var subgroup in me.subgroups) {
  414. var newStart = me.subgroups[subgroup].items[0].data.start;
  415. var newEnd = me.subgroups[subgroup].items[0].data.end;
  416. me.subgroups[subgroup].items.forEach(function(item) {
  417. if (new Date(item.data.start) < new Date(newStart)) {
  418. newStart = item.data.start;
  419. }
  420. if (new Date(item.data.end) > new Date(newEnd)) {
  421. newEnd = item.data.end;
  422. }
  423. })
  424. me.subgroups[subgroup].start = newStart;
  425. me.subgroups[subgroup].end = newEnd;
  426. }
  427. }
  428. }
  429. Group.prototype.orderSubgroups = function() {
  430. if (this.subgroupOrderer !== undefined) {
  431. var sortArray = [];
  432. if (typeof this.subgroupOrderer == 'string') {
  433. for (var subgroup in this.subgroups) {
  434. sortArray.push({subgroup: subgroup, sortField: this.subgroups[subgroup].items[0].data[this.subgroupOrderer]})
  435. }
  436. sortArray.sort(function (a, b) {
  437. return a.sortField - b.sortField;
  438. })
  439. }
  440. else if (typeof this.subgroupOrderer == 'function') {
  441. for (var subgroup in this.subgroups) {
  442. sortArray.push(this.subgroups[subgroup].items[0].data);
  443. }
  444. sortArray.sort(this.subgroupOrderer);
  445. }
  446. if (sortArray.length > 0) {
  447. for (var i = 0; i < sortArray.length; i++) {
  448. this.subgroups[sortArray[i].subgroup].index = i;
  449. }
  450. }
  451. }
  452. };
  453. Group.prototype.resetSubgroups = function() {
  454. for (var subgroup in this.subgroups) {
  455. if (this.subgroups.hasOwnProperty(subgroup)) {
  456. this.subgroups[subgroup].visible = false;
  457. }
  458. }
  459. };
  460. /**
  461. * Remove an item from the group
  462. * @param {Item} item
  463. */
  464. Group.prototype.remove = function(item) {
  465. delete this.items[item.id];
  466. item.setParent(null);
  467. // remove from visible items
  468. var index = this.visibleItems.indexOf(item);
  469. if (index != -1) this.visibleItems.splice(index, 1);
  470. if(item.data.subgroup !== undefined){
  471. this._removeFromSubgroup(item);
  472. this.orderSubgroups();
  473. }
  474. };
  475. Group.prototype._removeFromSubgroup = function(item, subgroupId) {
  476. subgroupId = subgroupId || item.data.subgroup;
  477. if (subgroupId != undefined) {
  478. var subgroup = this.subgroups[subgroupId];
  479. if (subgroup){
  480. var itemIndex = subgroup.items.indexOf(item);
  481. // Check the item is actually in this subgroup. How should items not in the group be handled?
  482. if (itemIndex >= 0) {
  483. subgroup.items.splice(itemIndex,1);
  484. if (!subgroup.items.length){
  485. delete this.subgroups[subgroupId];
  486. } else {
  487. this._updateSubgroupsSizes();
  488. }
  489. }
  490. }
  491. }
  492. };
  493. /**
  494. * Remove an item from the corresponding DataSet
  495. * @param {Item} item
  496. */
  497. Group.prototype.removeFromDataSet = function(item) {
  498. this.itemSet.removeItem(item.id);
  499. };
  500. /**
  501. * Reorder the items
  502. */
  503. Group.prototype.order = function() {
  504. var array = util.toArray(this.items);
  505. var startArray = [];
  506. var endArray = [];
  507. for (var i = 0; i < array.length; i++) {
  508. if (array[i].data.end !== undefined) {
  509. endArray.push(array[i]);
  510. }
  511. startArray.push(array[i]);
  512. }
  513. this.orderedItems = {
  514. byStart: startArray,
  515. byEnd: endArray
  516. };
  517. stack.orderByStart(this.orderedItems.byStart);
  518. stack.orderByEnd(this.orderedItems.byEnd);
  519. };
  520. /**
  521. * Update the visible items
  522. * @param {{byStart: Item[], byEnd: Item[]}} orderedItems All items ordered by start date and by end date
  523. * @param {Item[]} visibleItems The previously visible items.
  524. * @param {{start: number, end: number}} range Visible range
  525. * @return {Item[]} visibleItems The new visible items.
  526. * @private
  527. */
  528. Group.prototype._updateItemsInRange = function(orderedItems, oldVisibleItems, range) {
  529. var visibleItems = [];
  530. var visibleItemsLookup = {}; // we keep this to quickly look up if an item already exists in the list without using indexOf on visibleItems
  531. var interval = (range.end - range.start) / 4;
  532. var lowerBound = range.start - interval;
  533. var upperBound = range.end + interval;
  534. // this function is used to do the binary search.
  535. var searchFunction = function (value) {
  536. if (value < lowerBound) {return -1;}
  537. else if (value <= upperBound) {return 0;}
  538. else {return 1;}
  539. }
  540. // first check if the items that were in view previously are still in view.
  541. // IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
  542. // also cleans up invisible items.
  543. if (oldVisibleItems.length > 0) {
  544. for (var i = 0; i < oldVisibleItems.length; i++) {
  545. this._checkIfVisibleWithReference(oldVisibleItems[i], visibleItems, visibleItemsLookup, range);
  546. }
  547. }
  548. // we do a binary search for the items that have only start values.
  549. var initialPosByStart = util.binarySearchCustom(orderedItems.byStart, searchFunction, 'data','start');
  550. // trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the start values.
  551. this._traceVisible(initialPosByStart, orderedItems.byStart, visibleItems, visibleItemsLookup, function (item) {
  552. return (item.data.start < lowerBound || item.data.start > upperBound);
  553. });
  554. // if the window has changed programmatically without overlapping the old window, the ranged items with start < lowerBound and end > upperbound are not shown.
  555. // We therefore have to brute force check all items in the byEnd list
  556. if (this.checkRangedItems == true) {
  557. this.checkRangedItems = false;
  558. for (i = 0; i < orderedItems.byEnd.length; i++) {
  559. this._checkIfVisibleWithReference(orderedItems.byEnd[i], visibleItems, visibleItemsLookup, range);
  560. }
  561. }
  562. else {
  563. // we do a binary search for the items that have defined end times.
  564. var initialPosByEnd = util.binarySearchCustom(orderedItems.byEnd, searchFunction, 'data','end');
  565. // trace the visible items from the inital start pos both ways until an invisible item is found, we only look at the end values.
  566. this._traceVisible(initialPosByEnd, orderedItems.byEnd, visibleItems, visibleItemsLookup, function (item) {
  567. return (item.data.end < lowerBound || item.data.end > upperBound);
  568. });
  569. }
  570. // finally, we reposition all the visible items.
  571. for (var i = 0; i < visibleItems.length; i++) {
  572. var item = visibleItems[i];
  573. if (!item.displayed) item.show();
  574. // reposition item horizontally
  575. item.repositionX();
  576. }
  577. return visibleItems;
  578. };
  579. Group.prototype._traceVisible = function (initialPos, items, visibleItems, visibleItemsLookup, breakCondition) {
  580. if (initialPos != -1) {
  581. for (var i = initialPos; i >= 0; i--) {
  582. var item = items[i];
  583. if (breakCondition(item)) {
  584. break;
  585. }
  586. else {
  587. if (visibleItemsLookup[item.id] === undefined) {
  588. visibleItemsLookup[item.id] = true;
  589. visibleItems.push(item);
  590. }
  591. }
  592. }
  593. for (var i = initialPos + 1; i < items.length; i++) {
  594. var item = items[i];
  595. if (breakCondition(item)) {
  596. break;
  597. }
  598. else {
  599. if (visibleItemsLookup[item.id] === undefined) {
  600. visibleItemsLookup[item.id] = true;
  601. visibleItems.push(item);
  602. }
  603. }
  604. }
  605. }
  606. }
  607. /**
  608. * this function is very similar to the _checkIfInvisible() but it does not
  609. * return booleans, hides the item if it should not be seen and always adds to
  610. * the visibleItems.
  611. * this one is for brute forcing and hiding.
  612. *
  613. * @param {Item} item
  614. * @param {Array} visibleItems
  615. * @param {{start:number, end:number}} range
  616. * @private
  617. */
  618. Group.prototype._checkIfVisible = function(item, visibleItems, range) {
  619. if (item.isVisible(range)) {
  620. if (!item.displayed) item.show();
  621. // reposition item horizontally
  622. item.repositionX();
  623. visibleItems.push(item);
  624. }
  625. else {
  626. if (item.displayed) item.hide();
  627. }
  628. };
  629. /**
  630. * this function is very similar to the _checkIfInvisible() but it does not
  631. * return booleans, hides the item if it should not be seen and always adds to
  632. * the visibleItems.
  633. * this one is for brute forcing and hiding.
  634. *
  635. * @param {Item} item
  636. * @param {Array} visibleItems
  637. * @param {{start:number, end:number}} range
  638. * @private
  639. */
  640. Group.prototype._checkIfVisibleWithReference = function(item, visibleItems, visibleItemsLookup, range) {
  641. if (item.isVisible(range)) {
  642. if (visibleItemsLookup[item.id] === undefined) {
  643. visibleItemsLookup[item.id] = true;
  644. visibleItems.push(item);
  645. }
  646. }
  647. else {
  648. if (item.displayed) item.hide();
  649. }
  650. };
  651. Group.prototype.changeSubgroup = function(item, oldSubgroup, newSubgroup) {
  652. this._removeFromSubgroup(item, oldSubgroup);
  653. this._addToSubgroup(item, newSubgroup);
  654. this.orderSubgroups();
  655. };
  656. module.exports = Group;