|
@ -4,14 +4,15 @@ var DataSet = require('../../DataSet'); |
|
|
var DataView = require('../../DataView'); |
|
|
var DataView = require('../../DataView'); |
|
|
var Component = require('./Component'); |
|
|
var Component = require('./Component'); |
|
|
var Group = require('./Group'); |
|
|
var Group = require('./Group'); |
|
|
|
|
|
var BackgroundGroup = require('./BackgroundGroup'); |
|
|
var BoxItem = require('./item/BoxItem'); |
|
|
var BoxItem = require('./item/BoxItem'); |
|
|
var PointItem = require('./item/PointItem'); |
|
|
var PointItem = require('./item/PointItem'); |
|
|
var RangeItem = require('./item/RangeItem'); |
|
|
var RangeItem = require('./item/RangeItem'); |
|
|
var BackgroundItem = require('./item/BackgroundItem'); |
|
|
var BackgroundItem = require('./item/BackgroundItem'); |
|
|
var DateUtil = require('../DateUtil'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var UNGROUPED = '__ungrouped__'; // reserved group id for ungrouped items
|
|
|
|
|
|
|
|
|
var UNGROUPED = '__ungrouped__'; // reserved group id for ungrouped items
|
|
|
|
|
|
var BACKGROUND = '__background__'; // reserved group id for background items without group
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* An ItemSet holds a set of items and ranges which can be displayed in a |
|
|
* An ItemSet holds a set of items and ranges which can be displayed in a |
|
@ -171,6 +172,11 @@ ItemSet.prototype._create = function(){ |
|
|
// create ungrouped Group
|
|
|
// create ungrouped Group
|
|
|
this._updateUngrouped(); |
|
|
this._updateUngrouped(); |
|
|
|
|
|
|
|
|
|
|
|
// create background Group
|
|
|
|
|
|
var backgroundGroup = new BackgroundGroup(BACKGROUND, null, this); |
|
|
|
|
|
backgroundGroup.show(); |
|
|
|
|
|
this.groups[BACKGROUND] = backgroundGroup; |
|
|
|
|
|
|
|
|
// attach event listeners
|
|
|
// attach event listeners
|
|
|
// Note: we bind to the centerContainer for the case where the height
|
|
|
// Note: we bind to the centerContainer for the case where the height
|
|
|
// of the center container is larger than of the ItemSet, so we
|
|
|
// of the center container is larger than of the ItemSet, so we
|
|
@ -497,7 +503,10 @@ ItemSet.prototype.redraw = function() { |
|
|
this.lastVisibleInterval = visibleInterval; |
|
|
this.lastVisibleInterval = visibleInterval; |
|
|
this.props.lastWidth = this.props.width; |
|
|
this.props.lastWidth = this.props.width; |
|
|
|
|
|
|
|
|
// redraw all groups
|
|
|
|
|
|
|
|
|
// redraw the background group
|
|
|
|
|
|
this.groups[BACKGROUND].redraw(range, nonFirstMargin, restack); |
|
|
|
|
|
|
|
|
|
|
|
// redraw all regular groups
|
|
|
var restack = this.stackDirty, |
|
|
var restack = this.stackDirty, |
|
|
firstGroup = this._firstGroup(), |
|
|
firstGroup = this._firstGroup(), |
|
|
firstMargin = { |
|
|
firstMargin = { |
|
@ -560,12 +569,24 @@ ItemSet.prototype._firstGroup = function() { |
|
|
*/ |
|
|
*/ |
|
|
ItemSet.prototype._updateUngrouped = function() { |
|
|
ItemSet.prototype._updateUngrouped = function() { |
|
|
var ungrouped = this.groups[UNGROUPED]; |
|
|
var ungrouped = this.groups[UNGROUPED]; |
|
|
|
|
|
var background = this.groups[BACKGROUND]; |
|
|
|
|
|
var item, itemId; |
|
|
|
|
|
|
|
|
if (this.groupsData) { |
|
|
if (this.groupsData) { |
|
|
// remove the group holding all ungrouped items
|
|
|
// remove the group holding all ungrouped items
|
|
|
if (ungrouped) { |
|
|
if (ungrouped) { |
|
|
ungrouped.hide(); |
|
|
ungrouped.hide(); |
|
|
delete this.groups[UNGROUPED]; |
|
|
delete this.groups[UNGROUPED]; |
|
|
|
|
|
|
|
|
|
|
|
// var background = this.groups[BACKGROUND];
|
|
|
|
|
|
// for (itemId in this.items) {
|
|
|
|
|
|
// if (this.items.hasOwnProperty(itemId)) {
|
|
|
|
|
|
// item = this.items[itemId];
|
|
|
|
|
|
// if ((item instanceof BackgroundItem)) {
|
|
|
|
|
|
// background.add(item);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
@ -576,9 +597,15 @@ ItemSet.prototype._updateUngrouped = function() { |
|
|
ungrouped = new Group(id, data, this); |
|
|
ungrouped = new Group(id, data, this); |
|
|
this.groups[UNGROUPED] = ungrouped; |
|
|
this.groups[UNGROUPED] = ungrouped; |
|
|
|
|
|
|
|
|
for (var itemId in this.items) { |
|
|
|
|
|
|
|
|
for (itemId in this.items) { |
|
|
if (this.items.hasOwnProperty(itemId)) { |
|
|
if (this.items.hasOwnProperty(itemId)) { |
|
|
ungrouped.add(this.items[itemId]); |
|
|
|
|
|
|
|
|
item = this.items[itemId]; |
|
|
|
|
|
if (item instanceof BackgroundItem) { |
|
|
|
|
|
background.add(item); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
ungrouped.add(item); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -730,6 +757,33 @@ ItemSet.prototype.removeItem = function(id) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get the time of an item based on it's data and options.type |
|
|
|
|
|
* @param {Object} itemData |
|
|
|
|
|
* @returns {string} Returns the type |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
ItemSet.prototype._getType = function (itemData) { |
|
|
|
|
|
return itemData.type || this.options.type || (itemData.end ? 'range' : 'box'); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get the group id for an item |
|
|
|
|
|
* @param {Object} itemData |
|
|
|
|
|
* @returns {string} Returns the groupId |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
ItemSet.prototype._getGroupId = function (itemData) { |
|
|
|
|
|
var type = this._getType(itemData); |
|
|
|
|
|
if (type == 'background') { |
|
|
|
|
|
return itemData.group != undefined ? itemData.group : BACKGROUND; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return this.groupsData ? itemData.group : UNGROUPED; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Handle updated items |
|
|
* Handle updated items |
|
|
* @param {Number[]} ids |
|
|
* @param {Number[]} ids |
|
@ -739,9 +793,9 @@ ItemSet.prototype._onUpdate = function(ids) { |
|
|
var me = this; |
|
|
var me = this; |
|
|
|
|
|
|
|
|
ids.forEach(function (id) { |
|
|
ids.forEach(function (id) { |
|
|
var itemData = me.itemsData.get(id, me.itemOptions), |
|
|
|
|
|
item = me.items[id], |
|
|
|
|
|
type = itemData.type || me.options.type || (itemData.end ? 'range' : 'box'); |
|
|
|
|
|
|
|
|
var itemData = me.itemsData.get(id, me.itemOptions); |
|
|
|
|
|
var item = me.items[id]; |
|
|
|
|
|
var type = me._getType(itemData); |
|
|
|
|
|
|
|
|
var constructor = ItemSet.types[type]; |
|
|
var constructor = ItemSet.types[type]; |
|
|
|
|
|
|
|
@ -846,7 +900,7 @@ ItemSet.prototype._onAddGroups = function(ids) { |
|
|
|
|
|
|
|
|
if (!group) { |
|
|
if (!group) { |
|
|
// check for reserved ids
|
|
|
// check for reserved ids
|
|
|
if (id == UNGROUPED) { |
|
|
|
|
|
|
|
|
if (id == UNGROUPED || id == BACKGROUND) { |
|
|
throw new Error('Illegal group id. ' + id + ' is a reserved id.'); |
|
|
throw new Error('Illegal group id. ' + id + ' is a reserved id.'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -945,7 +999,7 @@ ItemSet.prototype._addItem = function(item) { |
|
|
this.items[item.id] = item; |
|
|
this.items[item.id] = item; |
|
|
|
|
|
|
|
|
// add to group
|
|
|
// add to group
|
|
|
var groupId = this.groupsData ? item.data.group : UNGROUPED; |
|
|
|
|
|
|
|
|
var groupId = this._getGroupId(item.data); |
|
|
var group = this.groups[groupId]; |
|
|
var group = this.groups[groupId]; |
|
|
if (group) group.add(item); |
|
|
if (group) group.add(item); |
|
|
}; |
|
|
}; |
|
@ -967,7 +1021,7 @@ ItemSet.prototype._updateItem = function(item, itemData) { |
|
|
var oldGroup = this.groups[oldGroupId]; |
|
|
var oldGroup = this.groups[oldGroupId]; |
|
|
if (oldGroup) oldGroup.remove(item); |
|
|
if (oldGroup) oldGroup.remove(item); |
|
|
|
|
|
|
|
|
var groupId = this.groupsData ? item.data.group : UNGROUPED; |
|
|
|
|
|
|
|
|
var groupId = this._getGroupId(item.data); |
|
|
var group = this.groups[groupId]; |
|
|
var group = this.groups[groupId]; |
|
|
if (group) group.add(item); |
|
|
if (group) group.add(item); |
|
|
} |
|
|
} |
|
@ -991,7 +1045,7 @@ ItemSet.prototype._removeItem = function(item) { |
|
|
if (index != -1) this.selection.splice(index, 1); |
|
|
if (index != -1) this.selection.splice(index, 1); |
|
|
|
|
|
|
|
|
// remove from group
|
|
|
// remove from group
|
|
|
var groupId = this.groupsData ? item.data.group : UNGROUPED; |
|
|
|
|
|
|
|
|
var groupId = this._getGroupId(item.data); |
|
|
var group = this.groups[groupId]; |
|
|
var group = this.groups[groupId]; |
|
|
if (group) group.remove(item); |
|
|
if (group) group.remove(item); |
|
|
}; |
|
|
}; |
|
|