UNPKG

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