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.

766 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. 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. this.stackDirty = true; // if true, items will be restacked on next redraw
  18. if (data && data.nestedGroups) {
  19. this.nestedGroups = data.nestedGroups;
  20. if (data.showNested == false) {
  21. this.showNested = false;
  22. } else {
  23. this.showNested = true;
  24. }
  25. }
  26. this.nestedInGroup = null;
  27. this.dom = {};
  28. this.props = {
  29. label: {
  30. width: 0,
  31. height: 0
  32. }
  33. };
  34. this.className = null;
  35. this.items = {}; // items filtered by groupId of this group
  36. this.visibleItems = []; // items currently visible in window
  37. this.itemsInRange = []; // items currently in range
  38. this.orderedItems = {
  39. byStart: [],
  40. byEnd: []
  41. };
  42. this.checkRangedItems = false; // needed to refresh the ranged items if the window is programatically changed with NO overlap.
  43. var me = this;
  44. this.itemSet.body.emitter.on("checkRangedItems", function () {
  45. me.checkRangedItems = true;
  46. })
  47. this._create();
  48. this.setData(data);
  49. }
  50. /**
  51. * Create DOM elements for the group
  52. * @private
  53. */
  54. Group.prototype._create = function() {
  55. var label = document.createElement('div');
  56. if (this.itemSet.options.groupEditable.order) {
  57. label.className = 'vis-label draggable';
  58. } else {
  59. label.className = 'vis-label';
  60. }
  61. this.dom.label = label;
  62. var inner = document.createElement('div');
  63. inner.className = 'vis-inner';
  64. label.appendChild(inner);
  65. this.dom.inner = inner;
  66. var foreground = document.createElement('div');
  67. foreground.className = 'vis-group';
  68. foreground['timeline-group'] = this;
  69. this.dom.foreground = foreground;
  70. this.dom.background = document.createElement('div');
  71. this.dom.background.className = 'vis-group';
  72. this.dom.axis = document.createElement('div');
  73. this.dom.axis.className = 'vis-group';
  74. // create a hidden marker to detect when the Timelines container is attached
  75. // to the DOM, or the style of a parent of the Timeline is changed from
  76. // display:none is changed to visible.
  77. this.dom.marker = document.createElement('div');
  78. this.dom.marker.style.visibility = 'hidden';
  79. this.dom.marker.style.position = 'absolute';
  80. this.dom.marker.innerHTML = '';
  81. this.dom.background.appendChild(this.dom.marker);
  82. };
  83. /**
  84. * Set the group data for this group
  85. * @param {Object} data Group data, can contain properties content and className
  86. */
  87. Group.prototype.setData = function(data) {
  88. // update contents
  89. var content;
  90. var templateFunction;
  91. if (this.itemSet.options && this.itemSet.options.groupTemplate) {
  92. templateFunction = this.itemSet.options.groupTemplate.bind(this);
  93. content = templateFunction(data, this.dom.inner);
  94. } else {
  95. content = data && data.content;
  96. }
  97. if (content instanceof Element) {
  98. this.dom.inner.appendChild(content);
  99. while (this.dom.inner.firstChild) {
  100. this.dom.inner.removeChild(this.dom.inner.firstChild);
  101. }
  102. this.dom.inner.appendChild(content);
  103. } else if (content instanceof Object) {
  104. templateFunction(data, this.dom.inner);
  105. } else if (content !== undefined && content !== null) {
  106. this.dom.inner.innerHTML = content;
  107. } else {
  108. this.dom.inner.innerHTML = this.groupId || ''; // groupId can be null
  109. }
  110. // update title
  111. this.dom.label.title = data && data.title || '';
  112. if (!this.dom.inner.firstChild) {
  113. util.addClassName(this.dom.inner, 'vis-hidden');
  114. }
  115. else {
  116. util.removeClassName(this.dom.inner, 'vis-hidden');
  117. }
  118. if (data && data.nestedGroups) {
  119. if (!this.nestedGroups || this.nestedGroups != data.nestedGroups) {
  120. this.nestedGroups = data.nestedGroups;
  121. }
  122. if (data.showNested !== undefined || this.showNested === undefined) {
  123. if (data.showNested == false) {
  124. this.showNested = false;
  125. } else {
  126. this.showNested = true;
  127. }
  128. }
  129. util.addClassName(this.dom.label, 'vis-nesting-group');
  130. var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
  131. if (this.showNested) {
  132. util.removeClassName(this.dom.label, collapsedDirClassName);
  133. util.addClassName(this.dom.label, 'expanded');
  134. } else {
  135. util.removeClassName(this.dom.label, 'expanded');
  136. util.addClassName(this.dom.label, collapsedDirClassName);
  137. }
  138. } else if (this.nestedGroups) {
  139. this.nestedGroups = null;
  140. var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
  141. util.removeClassName(this.dom.label, collapsedDirClassName);
  142. util.removeClassName(this.dom.label, 'expanded');
  143. util.removeClassName(this.dom.label, 'vis-nesting-group');
  144. }
  145. if (data && data.nestedInGroup) {
  146. util.addClassName(this.dom.label, 'vis-nested-group');
  147. if (this.itemSet.options && this.itemSet.options.rtl) {
  148. this.dom.inner.style.paddingRight = '30px';
  149. } else {
  150. this.dom.inner.style.paddingLeft = '30px';
  151. }
  152. }
  153. // update className
  154. var className = data && data.className || null;
  155. if (className != this.className) {
  156. if (this.className) {
  157. util.removeClassName(this.dom.label, this.className);
  158. util.removeClassName(this.dom.foreground, this.className);
  159. util.removeClassName(this.dom.background, this.className);
  160. util.removeClassName(this.dom.axis, this.className);
  161. }
  162. util.addClassName(this.dom.label, className);
  163. util.addClassName(this.dom.foreground, className);
  164. util.addClassName(this.dom.background, className);
  165. util.addClassName(this.dom.axis, className);
  166. this.className = className;
  167. }
  168. // update style
  169. if (this.style) {
  170. util.removeCssText(this.dom.label, this.style);
  171. this.style = null;
  172. }
  173. if (data && data.style) {
  174. util.addCssText(this.dom.label, data.style);
  175. this.style = data.style;
  176. }
  177. };
  178. /**
  179. * Get the width of the group label
  180. * @return {number} width
  181. */
  182. Group.prototype.getLabelWidth = function() {
  183. return this.props.label.width;
  184. };
  185. /**
  186. * Repaint this group
  187. * @param {{start: number, end: number}} range
  188. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  189. * @param {boolean} [forceRestack=false] Force restacking of all items
  190. * @return {boolean} Returns true if the group is resized
  191. */
  192. Group.prototype.redraw = function(range, margin, forceRestack) {
  193. var resized = false;
  194. // force recalculation of the height of the items when the marker height changed
  195. // (due to the Timeline being attached to the DOM or changed from display:none to visible)
  196. var markerHeight = this.dom.marker.clientHeight;
  197. if (markerHeight != this.lastMarkerHeight) {
  198. this.lastMarkerHeight = markerHeight;
  199. util.forEach(this.items, function (item) {
  200. item.dirty = true;
  201. if (item.displayed) item.redraw();
  202. });
  203. forceRestack = true;
  204. }
  205. // recalculate the height of the subgroups
  206. this._calculateSubGroupHeights(margin);
  207. // calculate actual size and position
  208. var foreground = this.dom.foreground;
  209. this.top = foreground.offsetTop;
  210. this.right = foreground.offsetLeft;
  211. this.width = foreground.offsetWidth;
  212. var lastIsVisible = this.isVisible;
  213. this.isVisible = this._isGroupVisible(range, margin);
  214. var restack = forceRestack || this.stackDirty || (this.isVisible && !lastIsVisible);
  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.displayed) {
  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. this._updateSubgroupsSizes();
  250. // recalculate the height of the group
  251. var height = this._calculateHeight(margin);
  252. // calculate actual size and position
  253. var foreground = this.dom.foreground;
  254. this.top = foreground.offsetTop;
  255. this.right = foreground.offsetLeft;
  256. this.width = foreground.offsetWidth;
  257. resized = util.updateProperty(this, 'height', height) || resized;
  258. // recalculate size of label
  259. resized = util.updateProperty(this.props.label, 'width', this.dom.inner.clientWidth) || resized;
  260. resized = util.updateProperty(this.props.label, 'height', this.dom.inner.clientHeight) || resized;
  261. // apply new height
  262. this.dom.background.style.height = height + 'px';
  263. this.dom.foreground.style.height = height + 'px';
  264. this.dom.label.style.height = height + 'px';
  265. // update vertical position of items after they are re-stacked and the height of the group is calculated
  266. for (var i = 0, ii = this.visibleItems.length; i < ii; i++) {
  267. var item = this.visibleItems[i];
  268. item.repositionY(margin);
  269. if (!this.isVisible && this.groupId != "__background__") {
  270. if (item.displayed) item.hide();
  271. }
  272. }
  273. if (!this.isVisible && this.height) {
  274. return resized = false;
  275. }
  276. return resized;
  277. };
  278. /**
  279. * recalculate the height of the subgroups
  280. * @private
  281. */
  282. Group.prototype._calculateSubGroupHeights = function (margin) {
  283. if (Object.keys(this.subgroups).length > 0) {
  284. var me = this;
  285. this.resetSubgroups();
  286. util.forEach(this.visibleItems, function (item) {
  287. if (item.data.subgroup !== undefined) {
  288. me.subgroups[item.data.subgroup].height = Math.max(me.subgroups[item.data.subgroup].height, item.height + margin.item.vertical);
  289. me.subgroups[item.data.subgroup].visible = true;
  290. }
  291. });
  292. }
  293. };
  294. /**
  295. * check if group is visible
  296. * @private
  297. */
  298. Group.prototype._isGroupVisible = function (range, margin) {
  299. var isVisible =
  300. (this.top <= range.body.domProps.centerContainer.height - range.body.domProps.scrollTop + margin.axis)
  301. && (this.top + this.height + margin.axis >= - range.body.domProps.scrollTop);
  302. return isVisible;
  303. }
  304. /**
  305. * recalculate the height of the group
  306. * @param {{item: {horizontal: number, vertical: number}, axis: number}} margin
  307. * @returns {number} Returns the height
  308. * @private
  309. */
  310. Group.prototype._calculateHeight = function (margin) {
  311. // recalculate the height of the group
  312. var height;
  313. var itemsInRange = this.visibleItems;
  314. if (itemsInRange.length > 0) {
  315. var min = itemsInRange[0].top;
  316. var max = itemsInRange[0].top + itemsInRange[0].height;
  317. util.forEach(itemsInRange, function (item) {
  318. min = Math.min(min, item.top);
  319. max = Math.max(max, (item.top + item.height));
  320. });
  321. if (min > margin.axis) {
  322. // there is an empty gap between the lowest item and the axis
  323. var offset = min - margin.axis;
  324. max -= offset;
  325. util.forEach(itemsInRange, function (item) {
  326. item.top -= offset;
  327. });
  328. }
  329. height = max + margin.item.vertical / 2;
  330. }
  331. else {
  332. height = 0;
  333. }
  334. height = Math.max(height, this.props.label.height);
  335. return height;
  336. };
  337. /**
  338. * Show this group: attach to the DOM
  339. */
  340. Group.prototype.show = function() {
  341. if (!this.dom.label.parentNode) {
  342. this.itemSet.dom.labelSet.appendChild(this.dom.label);
  343. }
  344. if (!this.dom.foreground.parentNode) {
  345. this.itemSet.dom.foreground.appendChild(this.dom.foreground);
  346. }
  347. if (!this.dom.background.parentNode) {
  348. this.itemSet.dom.background.appendChild(this.dom.background);
  349. }
  350. if (!this.dom.axis.parentNode) {
  351. this.itemSet.dom.axis.appendChild(this.dom.axis);
  352. }
  353. };
  354. /**
  355. * Hide this group: remove from the DOM
  356. */
  357. Group.prototype.hide = function() {
  358. var label = this.dom.label;
  359. if (label.parentNode) {
  360. label.parentNode.removeChild(label);
  361. }
  362. var foreground = this.dom.foreground;
  363. if (foreground.parentNode) {
  364. foreground.parentNode.removeChild(foreground);
  365. }
  366. var background = this.dom.background;
  367. if (background.parentNode) {
  368. background.parentNode.removeChild(background);
  369. }
  370. var axis = this.dom.axis;
  371. if (axis.parentNode) {
  372. axis.parentNode.removeChild(axis);
  373. }
  374. };
  375. /**
  376. * Add an item to the group
  377. * @param {Item} item
  378. */
  379. Group.prototype.add = function(item) {
  380. this.items[item.id] = item;
  381. item.setParent(this);
  382. this.stackDirty = true;
  383. // add to
  384. if (item.data.subgroup !== undefined) {
  385. this._addToSubgroup(item);
  386. this.orderSubgroups();
  387. }
  388. if (this.visibleItems.indexOf(item) == -1) {
  389. var range = this.itemSet.body.range; // TODO: not nice accessing the range like this
  390. this._checkIfVisible(item, this.visibleItems, range);
  391. }
  392. };
  393. Group.prototype._addToSubgroup = function(item, subgroupId) {
  394. subgroupId = subgroupId || item.data.subgroup;
  395. if (subgroupId != undefined && this.subgroups[subgroupId] === undefined) {
  396. this.subgroups[subgroupId] = {
  397. height:0,
  398. top: 0,
  399. start: item.data.start,
  400. end: item.data.end,
  401. visible: false,
  402. index:this.subgroupIndex,
  403. items: []
  404. };
  405. this.subgroupIndex++;
  406. }
  407. if (new Date(item.data.start) < new Date(this.subgroups[subgroupId].start)) {
  408. this.subgroups[subgroupId].start = item.data.start;
  409. }
  410. if (new Date(item.data.end) > new Date(this.subgroups[subgroupId].end)) {
  411. this.subgroups[subgroupId].end = item.data.end;
  412. }
  413. this.subgroups[subgroupId].items.push(item);
  414. };
  415. Group.prototype._updateSubgroupsSizes = function () {
  416. var me = this;
  417. if (me.subgroups) {
  418. for (var subgroup in me.subgroups) {
  419. var newStart = me.subgroups[subgroup].items[0].data.start;
  420. var newEnd = me.subgroups[subgroup].items[0].data.end;
  421. me.subgroups[subgroup].items.forEach(function(item) {
  422. if (new Date(item.data.start) < new Date(newStart)) {
  423. newStart = item.data.start;
  424. }
  425. if (new Date(item.data.end) > new Date(newEnd)) {
  426. newEnd = item.data.end;
  427. }
  428. })
  429. me.subgroups[subgroup].start = newStart;
  430. me.subgroups[subgroup].end = newEnd;
  431. }
  432. }
  433. }
  434. Group.prototype.orderSubgroups = function() {
  435. if (this.subgroupOrderer !== undefined) {
  436. var sortArray = [];
  437. if (typeof this.subgroupOrderer == 'string') {
  438. for (var 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 (var 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 (var 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. for (var i = initialPos; i >= 0; i--) {
  589. var item = items[i];
  590. if (breakCondition(item)) {
  591. break;
  592. }
  593. else {
  594. if (visibleItemsLookup[item.id] === undefined) {
  595. visibleItemsLookup[item.id] = true;
  596. visibleItems.push(item);
  597. }
  598. }
  599. }
  600. for (var i = initialPos + 1; i < items.length; i++) {
  601. var item = items[i];
  602. if (breakCondition(item)) {
  603. break;
  604. }
  605. else {
  606. if (visibleItemsLookup[item.id] === undefined) {
  607. visibleItemsLookup[item.id] = true;
  608. visibleItems.push(item);
  609. }
  610. }
  611. }
  612. }
  613. }
  614. /**
  615. * this function is very similar to the _checkIfInvisible() but it does not
  616. * return booleans, hides the item if it should not be seen and always adds to
  617. * the visibleItems.
  618. * this one is for brute forcing and hiding.
  619. *
  620. * @param {Item} item
  621. * @param {Array} visibleItems
  622. * @param {{start:number, end:number}} range
  623. * @private
  624. */
  625. Group.prototype._checkIfVisible = function(item, visibleItems, range) {
  626. if (item.isVisible(range)) {
  627. if (!item.displayed) item.show();
  628. // reposition item horizontally
  629. item.repositionX();
  630. visibleItems.push(item);
  631. }
  632. else {
  633. if (item.displayed) item.hide();
  634. }
  635. };
  636. /**
  637. * this function is very similar to the _checkIfInvisible() but it does not
  638. * return booleans, hides the item if it should not be seen and always adds to
  639. * the visibleItems.
  640. * this one is for brute forcing and hiding.
  641. *
  642. * @param {Item} item
  643. * @param {Array} visibleItems
  644. * @param {{start:number, end:number}} range
  645. * @private
  646. */
  647. Group.prototype._checkIfVisibleWithReference = function(item, visibleItems, visibleItemsLookup, range) {
  648. if (item.isVisible(range)) {
  649. if (visibleItemsLookup[item.id] === undefined) {
  650. visibleItemsLookup[item.id] = true;
  651. visibleItems.push(item);
  652. }
  653. }
  654. else {
  655. if (item.displayed) item.hide();
  656. }
  657. };
  658. Group.prototype.changeSubgroup = function(item, oldSubgroup, newSubgroup) {
  659. this._removeFromSubgroup(item, oldSubgroup);
  660. this._addToSubgroup(item, newSubgroup);
  661. this.orderSubgroups();
  662. };
  663. module.exports = Group;