Browse Source

Renamed some properties for more clarity

css_transitions
josdejong 11 years ago
parent
commit
714a39ec03
6 changed files with 133 additions and 175 deletions
  1. +32
    -41
      src/component/groupset.js
  2. +19
    -31
      src/component/itemset.js
  3. +1
    -1
      src/stack.js
  4. +13
    -13
      src/visualization/timeline.js
  5. +65
    -86
      vis.js
  6. +3
    -3
      vis.min.js

+ 32
- 41
src/component/groupset.js View File

@ -15,11 +15,11 @@ function GroupSet(parent, depends, options) {
this.options = {}; this.options = {};
this.range = null; // Range or Object {start: number, end: number}
this.items = null; // dataset with items
this.groups = null; // dataset with groups
this.range = null; // Range or Object {start: number, end: number}
this.itemsData = null; // DataSet with items
this.groupsData = null; // DataSet with groups
this.contents = []; // array with groups
this.groups = []; // array with groups
// changes in groups are queued key/value map containing id/action // changes in groups are queued key/value map containing id/action
this.queue = {}; this.queue = {};
@ -55,7 +55,7 @@ GroupSet.prototype.setOptions = function setOptions(options) {
// TODO: implement options // TODO: implement options
var me = this; var me = this;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
group.itemset.setOptions(me.options); group.itemset.setOptions(me.options);
}); });
}; };
@ -69,9 +69,9 @@ GroupSet.prototype.setRange = function (range) {
* @param {vis.DataSet | null} items * @param {vis.DataSet | null} items
*/ */
GroupSet.prototype.setItems = function setItems(items) { GroupSet.prototype.setItems = function setItems(items) {
this.items = items;
this.itemsData = items;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
group.view.setData(items); group.view.setData(items);
}); });
}; };
@ -81,7 +81,7 @@ GroupSet.prototype.setItems = function setItems(items) {
* @return {vis.DataSet | null} items * @return {vis.DataSet | null} items
*/ */
GroupSet.prototype.getItems = function getItems() { GroupSet.prototype.getItems = function getItems() {
return this.items;
return this.itemsData;
}; };
/** /**
@ -98,54 +98,45 @@ GroupSet.prototype.setRange = function setRange(range) {
*/ */
GroupSet.prototype.setGroups = function setGroups(groups) { GroupSet.prototype.setGroups = function setGroups(groups) {
var me = this, var me = this,
dataGroups,
ids; ids;
// unsubscribe from current dataset // unsubscribe from current dataset
if (this.groups) {
if (this.groupsData) {
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.groups.unsubscribe(event, callback);
me.groupsData.unsubscribe(event, callback);
}); });
// remove all drawn groups // remove all drawn groups
dataGroups = this.groups.get({fields: ['id']});
ids = [];
util.forEach(dataGroups, function (dataGroup, index) {
ids[index] = dataGroup.id;
});
ids = this.groupsData.getIds();
this._onRemove(ids); this._onRemove(ids);
} }
// replace the dataset // replace the dataset
if (!groups) { if (!groups) {
this.groups = null;
this.groupsData = null;
} }
else if (groups instanceof DataSet) { else if (groups instanceof DataSet) {
this.groups = groups;
this.groupsData = groups;
} }
else { else {
this.groups = new DataSet({
this.groupsData = new DataSet({
fieldTypes: { fieldTypes: {
start: 'Date', start: 'Date',
end: 'Date' end: 'Date'
} }
}); });
this.groups.add(groups);
this.groupsData.add(groups);
} }
if (this.groups) {
if (this.groupsData) {
// subscribe to new dataset // subscribe to new dataset
var id = this.id; var id = this.id;
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.groups.subscribe(event, callback, id);
me.groupsData.subscribe(event, callback, id);
}); });
// draw all new groups // draw all new groups
dataGroups = this.groups.get({fields: ['id']});
ids = [];
util.forEach(dataGroups, function (dataGroup, index) {
ids[index] = dataGroup.id;
});
ids = this.groupsData.getIds();
this._onAdd(ids); this._onAdd(ids);
} }
}; };
@ -155,7 +146,7 @@ GroupSet.prototype.setGroups = function setGroups(groups) {
* @return {vis.DataSet | null} groups * @return {vis.DataSet | null} groups
*/ */
GroupSet.prototype.getGroups = function getGroups() { GroupSet.prototype.getGroups = function getGroups() {
return this.groups;
return this.groupsData;
}; };
/** /**
@ -201,9 +192,9 @@ GroupSet.prototype.repaint = function repaint() {
var me = this, var me = this,
queue = this.queue, queue = this.queue,
items = this.items,
contents = this.contents,
itemsData = this.itemsData,
groups = this.groups, groups = this.groups,
groupsData = this.groupsData,
dataOptions = { dataOptions = {
fields: ['id', 'content'] fields: ['id', 'content']
}; };
@ -217,9 +208,9 @@ GroupSet.prototype.repaint = function repaint() {
// find group // find group
var group = null; var group = null;
var groupIndex = -1; var groupIndex = -1;
for (var i = 0; i < contents.length; i++) {
if (contents[i].id == id) {
group = contents[i];
for (var i = 0; i < groups.length; i++) {
if (groups[i].id == id) {
group = groups[i];
groupIndex = i; groupIndex = i;
break; break;
} }
@ -234,7 +225,7 @@ GroupSet.prototype.repaint = function repaint() {
var itemset = new ItemSet(me); var itemset = new ItemSet(me);
itemset.setOptions(me.options); itemset.setOptions(me.options);
itemset.setRange(me.range); itemset.setRange(me.range);
var view = new DataView(me.items, {filter: function (item) {
var view = new DataView(me.itemsData, {filter: function (item) {
return item.group == id; return item.group == id;
}}); }});
itemset.setItems(view); itemset.setItems(view);
@ -245,11 +236,11 @@ GroupSet.prototype.repaint = function repaint() {
view: view, view: view,
itemset: itemset itemset: itemset
}; };
contents.push(group);
groups.push(group);
} }
// update group data // update group data
group.data = groups.get(id);
group.data = groupsData.get(id);
delete queue[id]; delete queue[id];
break; break;
@ -262,7 +253,7 @@ GroupSet.prototype.repaint = function repaint() {
me.controller.remove(group.itemset); me.controller.remove(group.itemset);
// remove group itself // remove group itself
contents.splice(groupIndex, 1);
groups.splice(groupIndex, 1);
} }
// update lists // update lists
@ -276,7 +267,7 @@ GroupSet.prototype.repaint = function repaint() {
// update the top position (TODO: optimize, needed only when groups are added/removed/reordered // update the top position (TODO: optimize, needed only when groups are added/removed/reordered
var prevGroup = null; var prevGroup = null;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
var prevItemset = prevGroup && prevGroup.itemset; var prevItemset = prevGroup && prevGroup.itemset;
if (prevItemset) { if (prevItemset) {
group.itemset.options.top = function () { group.itemset.options.top = function () {
@ -291,7 +282,7 @@ GroupSet.prototype.repaint = function repaint() {
} }
// reposition all groups // reposition all groups
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
changed += group.itemset.repaint(); changed += group.itemset.repaint();
}); });
@ -320,7 +311,7 @@ GroupSet.prototype.reflow = function reflow() {
if (frame) { if (frame) {
// reposition all groups // reposition all groups
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
changed += group.itemset.reflow(); changed += group.itemset.reflow();
}); });
@ -332,7 +323,7 @@ GroupSet.prototype.reflow = function reflow() {
else { else {
// height is not specified, calculate the sum of the height of all groups // height is not specified, calculate the sum of the height of all groups
height = 0; height = 0;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
height += group.itemset.height; height += group.itemset.height;
}); });
} }

+ 19
- 31
src/component/itemset.js View File

@ -31,8 +31,8 @@ function ItemSet(parent, depends, options) {
this.dom = {}; this.dom = {};
var me = this; var me = this;
this.items = null; // DataSet
this.range = null; // Range or Object {start: number, end: number}
this.itemsData = null; // DataSet
this.range = null; // Range or Object {start: number, end: number}
this.listeners = { this.listeners = {
'add': function (event, params, senderId) { 'add': function (event, params, senderId) {
@ -52,7 +52,7 @@ function ItemSet(parent, depends, options) {
} }
}; };
this.contents = {}; // object with an Item for every data item
this.items = {}; // object with an Item for every data item
this.queue = {}; // queue with id/actions: 'add', 'update', 'delete' this.queue = {}; // queue with id/actions: 'add', 'update', 'delete'
this.stack = new Stack(this); this.stack = new Stack(this);
this.conversion = null; this.conversion = null;
@ -193,10 +193,10 @@ ItemSet.prototype.repaint = function repaint() {
var me = this, var me = this,
queue = this.queue, queue = this.queue,
itemsData = this.itemsData,
items = this.items, items = this.items,
contents = this.contents,
dataOptions = { dataOptions = {
fields: [(items && items.fieldId || 'id'), 'start', 'end', 'content', 'type']
fields: [(itemsData && itemsData.fieldId || 'id'), 'start', 'end', 'content', 'type']
}; };
// TODO: copy options from the itemset itself? // TODO: copy options from the itemset itself?
@ -204,13 +204,13 @@ ItemSet.prototype.repaint = function repaint() {
Object.keys(queue).forEach(function (id) { Object.keys(queue).forEach(function (id) {
//var entry = queue[id]; //var entry = queue[id];
var action = queue[id]; var action = queue[id];
var item = contents[id];
var item = items[id];
//var item = entry.item; //var item = entry.item;
//noinspection FallthroughInSwitchStatementJS //noinspection FallthroughInSwitchStatementJS
switch (action) { switch (action) {
case 'add': case 'add':
case 'update': case 'update':
var itemData = items && items.get(id, dataOptions);
var itemData = itemsData && itemsData.get(id, dataOptions);
if (itemData) { if (itemData) {
var type = itemData.type || var type = itemData.type ||
@ -243,7 +243,7 @@ ItemSet.prototype.repaint = function repaint() {
} }
} }
contents[id] = item;
items[id] = item;
} }
// update queue // update queue
@ -257,7 +257,7 @@ ItemSet.prototype.repaint = function repaint() {
} }
// update lists // update lists
delete contents[id];
delete items[id];
delete queue[id]; delete queue[id];
break; break;
@ -267,7 +267,7 @@ ItemSet.prototype.repaint = function repaint() {
}); });
// reposition all items. Show items only when in the visible area // reposition all items. Show items only when in the visible area
util.forEach(this.contents, function (item) {
util.forEach(this.items, function (item) {
if (item.visible) { if (item.visible) {
changed += item.show(); changed += item.show();
item.reposition(); item.reposition();
@ -318,7 +318,7 @@ ItemSet.prototype.reflow = function reflow () {
if (frame) { if (frame) {
this._updateConversion(); this._updateConversion();
util.forEach(this.contents, function (item) {
util.forEach(this.items, function (item) {
changed += item.reflow(); changed += item.reflow();
}); });
@ -390,52 +390,40 @@ ItemSet.prototype.hide = function hide() {
*/ */
ItemSet.prototype.setItems = function setItems(items) { ItemSet.prototype.setItems = function setItems(items) {
var me = this, var me = this,
dataItems,
fieldId,
ids; ids;
// unsubscribe from current dataset // unsubscribe from current dataset
var current = this.items;
var current = this.itemsData;
if (current) { if (current) {
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
current.unsubscribe(event, callback); current.unsubscribe(event, callback);
}); });
// remove all drawn items // remove all drawn items
fieldId = this.items.fieldId;
dataItems = current.get({fields: [fieldId]});
ids = [];
util.forEach(dataItems, function (dataItem, index) {
ids[index] = dataItem[fieldId];
});
ids = current.getIds();
this._onRemove(ids); this._onRemove(ids);
} }
// replace the dataset // replace the dataset
if (!items) { if (!items) {
this.items = null;
this.itemsData = null;
} }
else if (items instanceof DataSet || items instanceof DataView) { else if (items instanceof DataSet || items instanceof DataView) {
this.items = items;
this.itemsData = items;
} }
else { else {
throw new TypeError('Data must be an instance of DataSet'); throw new TypeError('Data must be an instance of DataSet');
} }
if (this.items) {
if (this.itemsData) {
// subscribe to new dataset // subscribe to new dataset
var id = this.id; var id = this.id;
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.items.subscribe(event, callback, id);
me.itemsData.subscribe(event, callback, id);
}); });
// draw all new items // draw all new items
fieldId = this.items.fieldId;
dataItems = this.items.get({fields: [fieldId]});
ids = [];
util.forEach(dataItems, function (dataItem, index) {
ids[index] = dataItem[fieldId];
});
ids = this.itemsData.getIds();
this._onAdd(ids); this._onAdd(ids);
} }
}; };
@ -445,7 +433,7 @@ ItemSet.prototype.setItems = function setItems(items) {
* @returns {vis.DataSet | null} * @returns {vis.DataSet | null}
*/ */
ItemSet.prototype.getItems = function getItems() { ItemSet.prototype.getItems = function getItems() {
return this.items;
return this.itemsData;
}; };
/** /**

+ 1
- 1
src/stack.js View File

@ -67,7 +67,7 @@ Stack.prototype.update = function update() {
* @private * @private
*/ */
Stack.prototype._order = function _order () { Stack.prototype._order = function _order () {
var items = this.parent.contents;
var items = this.parent.items;
if (!items) { if (!items) {
throw new Error('Cannot stack items: parent does not contain items'); throw new Error('Cannot stack items: parent does not contain items');
} }

+ 13
- 13
src/visualization/timeline.js View File

@ -58,8 +58,8 @@ function Timeline (container, items, options) {
// create itemset or groupset // create itemset or groupset
this.setGroups(null); this.setGroups(null);
this.items = null; // DataSet
this.groups = null; // DataSet
this.itemsData = null; // DataSet
this.groupsData = null; // DataSet
// set options (must take place before setting the data) // set options (must take place before setting the data)
if (options) { if (options) {
@ -156,7 +156,7 @@ Timeline.prototype.setOptions = function (options) {
* @param {vis.DataSet | Array | DataTable | null} items * @param {vis.DataSet | Array | DataTable | null} items
*/ */
Timeline.prototype.setItems = function(items) { Timeline.prototype.setItems = function(items) {
var initialLoad = (this.items == null);
var initialLoad = (this.itemsData == null);
// convert to type DataSet when needed // convert to type DataSet when needed
var newItemSet; var newItemSet;
@ -177,7 +177,7 @@ Timeline.prototype.setItems = function(items) {
} }
// set items // set items
this.items = newItemSet;
this.itemsData = newItemSet;
this.content.setItems(newItemSet); this.content.setItems(newItemSet);
if (initialLoad && (this.options.start == undefined || this.options.end == undefined)) { if (initialLoad && (this.options.start == undefined || this.options.end == undefined)) {
@ -213,10 +213,10 @@ Timeline.prototype.setItems = function(items) {
* @param {vis.DataSet | Array | DataTable} groups * @param {vis.DataSet | Array | DataTable} groups
*/ */
Timeline.prototype.setGroups = function(groups) { Timeline.prototype.setGroups = function(groups) {
this.groups = groups;
this.groupsData = groups;
// switch content type between ItemSet or GroupSet when needed // switch content type between ItemSet or GroupSet when needed
var type = this.groups ? GroupSet : ItemSet;
var type = this.groupsData ? GroupSet : ItemSet;
if (!(this.content instanceof type)) { if (!(this.content instanceof type)) {
// remove old content set // remove old content set
if (this.content) { if (this.content) {
@ -236,10 +236,10 @@ Timeline.prototype.setGroups = function(groups) {
this.content.setRange(this.range); this.content.setRange(this.range);
} }
if (this.content.setItems) { if (this.content.setItems) {
this.content.setItems(this.items);
this.content.setItems(this.itemsData);
} }
if (this.content.setGroups) { if (this.content.setGroups) {
this.content.setGroups(this.groups);
this.content.setGroups(this.groupsData);
} }
this.controller.add(this.content); this.controller.add(this.content);
this.setOptions(this.options); this.setOptions(this.options);
@ -254,21 +254,21 @@ Timeline.prototype.setGroups = function(groups) {
*/ */
Timeline.prototype.getItemRange = function getItemRange() { Timeline.prototype.getItemRange = function getItemRange() {
// calculate min from start filed // calculate min from start filed
var items = this.items,
var itemsData = this.itemsData,
min = null, min = null,
max = null; max = null;
if (items) {
if (itemsData) {
// calculate the minimum value of the field 'start' // calculate the minimum value of the field 'start'
var minItem = items.min('start');
var minItem = itemsData.min('start');
min = minItem ? minItem.start.valueOf() : null; min = minItem ? minItem.start.valueOf() : null;
// calculate maximum value of fields 'start' and 'end' // calculate maximum value of fields 'start' and 'end'
var maxStartItem = items.max('start');
var maxStartItem = itemsData.max('start');
if (maxStartItem) { if (maxStartItem) {
max = maxStartItem.start.valueOf(); max = maxStartItem.start.valueOf();
} }
var maxEndItem = items.max('end');
var maxEndItem = itemsData.max('end');
if (maxEndItem) { if (maxEndItem) {
if (max == null) { if (max == null) {
max = maxEndItem.end.valueOf(); max = maxEndItem.end.valueOf();

+ 65
- 86
vis.js View File

@ -2637,7 +2637,7 @@ Stack.prototype.update = function update() {
* @private * @private
*/ */
Stack.prototype._order = function _order () { Stack.prototype._order = function _order () {
var items = this.parent.contents;
var items = this.parent.items;
if (!items) { if (!items) {
throw new Error('Cannot stack items: parent does not contain items'); throw new Error('Cannot stack items: parent does not contain items');
} }
@ -4531,8 +4531,8 @@ function ItemSet(parent, depends, options) {
this.dom = {}; this.dom = {};
var me = this; var me = this;
this.items = null; // DataSet
this.range = null; // Range or Object {start: number, end: number}
this.itemsData = null; // DataSet
this.range = null; // Range or Object {start: number, end: number}
this.listeners = { this.listeners = {
'add': function (event, params, senderId) { 'add': function (event, params, senderId) {
@ -4552,7 +4552,7 @@ function ItemSet(parent, depends, options) {
} }
}; };
this.contents = {}; // object with an Item for every data item
this.items = {}; // object with an Item for every data item
this.queue = {}; // queue with id/actions: 'add', 'update', 'delete' this.queue = {}; // queue with id/actions: 'add', 'update', 'delete'
this.stack = new Stack(this); this.stack = new Stack(this);
this.conversion = null; this.conversion = null;
@ -4693,10 +4693,10 @@ ItemSet.prototype.repaint = function repaint() {
var me = this, var me = this,
queue = this.queue, queue = this.queue,
itemsData = this.itemsData,
items = this.items, items = this.items,
contents = this.contents,
dataOptions = { dataOptions = {
fields: [(items && items.fieldId || 'id'), 'start', 'end', 'content', 'type']
fields: [(itemsData && itemsData.fieldId || 'id'), 'start', 'end', 'content', 'type']
}; };
// TODO: copy options from the itemset itself? // TODO: copy options from the itemset itself?
@ -4704,13 +4704,13 @@ ItemSet.prototype.repaint = function repaint() {
Object.keys(queue).forEach(function (id) { Object.keys(queue).forEach(function (id) {
//var entry = queue[id]; //var entry = queue[id];
var action = queue[id]; var action = queue[id];
var item = contents[id];
var item = items[id];
//var item = entry.item; //var item = entry.item;
//noinspection FallthroughInSwitchStatementJS //noinspection FallthroughInSwitchStatementJS
switch (action) { switch (action) {
case 'add': case 'add':
case 'update': case 'update':
var itemData = items && items.get(id, dataOptions);
var itemData = itemsData && itemsData.get(id, dataOptions);
if (itemData) { if (itemData) {
var type = itemData.type || var type = itemData.type ||
@ -4743,7 +4743,7 @@ ItemSet.prototype.repaint = function repaint() {
} }
} }
contents[id] = item;
items[id] = item;
} }
// update queue // update queue
@ -4757,7 +4757,7 @@ ItemSet.prototype.repaint = function repaint() {
} }
// update lists // update lists
delete contents[id];
delete items[id];
delete queue[id]; delete queue[id];
break; break;
@ -4767,7 +4767,7 @@ ItemSet.prototype.repaint = function repaint() {
}); });
// reposition all items. Show items only when in the visible area // reposition all items. Show items only when in the visible area
util.forEach(this.contents, function (item) {
util.forEach(this.items, function (item) {
if (item.visible) { if (item.visible) {
changed += item.show(); changed += item.show();
item.reposition(); item.reposition();
@ -4818,7 +4818,7 @@ ItemSet.prototype.reflow = function reflow () {
if (frame) { if (frame) {
this._updateConversion(); this._updateConversion();
util.forEach(this.contents, function (item) {
util.forEach(this.items, function (item) {
changed += item.reflow(); changed += item.reflow();
}); });
@ -4890,52 +4890,40 @@ ItemSet.prototype.hide = function hide() {
*/ */
ItemSet.prototype.setItems = function setItems(items) { ItemSet.prototype.setItems = function setItems(items) {
var me = this, var me = this,
dataItems,
fieldId,
ids; ids;
// unsubscribe from current dataset // unsubscribe from current dataset
var current = this.items;
var current = this.itemsData;
if (current) { if (current) {
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
current.unsubscribe(event, callback); current.unsubscribe(event, callback);
}); });
// remove all drawn items // remove all drawn items
fieldId = this.items.fieldId;
dataItems = current.get({fields: [fieldId]});
ids = [];
util.forEach(dataItems, function (dataItem, index) {
ids[index] = dataItem[fieldId];
});
ids = current.getIds();
this._onRemove(ids); this._onRemove(ids);
} }
// replace the dataset // replace the dataset
if (!items) { if (!items) {
this.items = null;
this.itemsData = null;
} }
else if (items instanceof DataSet || items instanceof DataView) { else if (items instanceof DataSet || items instanceof DataView) {
this.items = items;
this.itemsData = items;
} }
else { else {
throw new TypeError('Data must be an instance of DataSet'); throw new TypeError('Data must be an instance of DataSet');
} }
if (this.items) {
if (this.itemsData) {
// subscribe to new dataset // subscribe to new dataset
var id = this.id; var id = this.id;
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.items.subscribe(event, callback, id);
me.itemsData.subscribe(event, callback, id);
}); });
// draw all new items // draw all new items
fieldId = this.items.fieldId;
dataItems = this.items.get({fields: [fieldId]});
ids = [];
util.forEach(dataItems, function (dataItem, index) {
ids[index] = dataItem[fieldId];
});
ids = this.itemsData.getIds();
this._onAdd(ids); this._onAdd(ids);
} }
}; };
@ -4945,7 +4933,7 @@ ItemSet.prototype.setItems = function setItems(items) {
* @returns {vis.DataSet | null} * @returns {vis.DataSet | null}
*/ */
ItemSet.prototype.getItems = function getItems() { ItemSet.prototype.getItems = function getItems() {
return this.items;
return this.itemsData;
}; };
/** /**
@ -5947,11 +5935,11 @@ function GroupSet(parent, depends, options) {
this.options = {}; this.options = {};
this.range = null; // Range or Object {start: number, end: number}
this.items = null; // dataset with items
this.groups = null; // dataset with groups
this.range = null; // Range or Object {start: number, end: number}
this.itemsData = null; // DataSet with items
this.groupsData = null; // DataSet with groups
this.contents = []; // array with groups
this.groups = []; // array with groups
// changes in groups are queued key/value map containing id/action // changes in groups are queued key/value map containing id/action
this.queue = {}; this.queue = {};
@ -5987,7 +5975,7 @@ GroupSet.prototype.setOptions = function setOptions(options) {
// TODO: implement options // TODO: implement options
var me = this; var me = this;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
group.itemset.setOptions(me.options); group.itemset.setOptions(me.options);
}); });
}; };
@ -6001,9 +5989,9 @@ GroupSet.prototype.setRange = function (range) {
* @param {vis.DataSet | null} items * @param {vis.DataSet | null} items
*/ */
GroupSet.prototype.setItems = function setItems(items) { GroupSet.prototype.setItems = function setItems(items) {
this.items = items;
this.itemsData = items;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
group.view.setData(items); group.view.setData(items);
}); });
}; };
@ -6013,7 +6001,7 @@ GroupSet.prototype.setItems = function setItems(items) {
* @return {vis.DataSet | null} items * @return {vis.DataSet | null} items
*/ */
GroupSet.prototype.getItems = function getItems() { GroupSet.prototype.getItems = function getItems() {
return this.items;
return this.itemsData;
}; };
/** /**
@ -6030,54 +6018,45 @@ GroupSet.prototype.setRange = function setRange(range) {
*/ */
GroupSet.prototype.setGroups = function setGroups(groups) { GroupSet.prototype.setGroups = function setGroups(groups) {
var me = this, var me = this,
dataGroups,
ids; ids;
// unsubscribe from current dataset // unsubscribe from current dataset
if (this.groups) {
if (this.groupsData) {
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.groups.unsubscribe(event, callback);
me.groupsData.unsubscribe(event, callback);
}); });
// remove all drawn groups // remove all drawn groups
dataGroups = this.groups.get({fields: ['id']});
ids = [];
util.forEach(dataGroups, function (dataGroup, index) {
ids[index] = dataGroup.id;
});
ids = this.groupsData.getIds();
this._onRemove(ids); this._onRemove(ids);
} }
// replace the dataset // replace the dataset
if (!groups) { if (!groups) {
this.groups = null;
this.groupsData = null;
} }
else if (groups instanceof DataSet) { else if (groups instanceof DataSet) {
this.groups = groups;
this.groupsData = groups;
} }
else { else {
this.groups = new DataSet({
this.groupsData = new DataSet({
fieldTypes: { fieldTypes: {
start: 'Date', start: 'Date',
end: 'Date' end: 'Date'
} }
}); });
this.groups.add(groups);
this.groupsData.add(groups);
} }
if (this.groups) {
if (this.groupsData) {
// subscribe to new dataset // subscribe to new dataset
var id = this.id; var id = this.id;
util.forEach(this.listeners, function (callback, event) { util.forEach(this.listeners, function (callback, event) {
me.groups.subscribe(event, callback, id);
me.groupsData.subscribe(event, callback, id);
}); });
// draw all new groups // draw all new groups
dataGroups = this.groups.get({fields: ['id']});
ids = [];
util.forEach(dataGroups, function (dataGroup, index) {
ids[index] = dataGroup.id;
});
ids = this.groupsData.getIds();
this._onAdd(ids); this._onAdd(ids);
} }
}; };
@ -6087,7 +6066,7 @@ GroupSet.prototype.setGroups = function setGroups(groups) {
* @return {vis.DataSet | null} groups * @return {vis.DataSet | null} groups
*/ */
GroupSet.prototype.getGroups = function getGroups() { GroupSet.prototype.getGroups = function getGroups() {
return this.groups;
return this.groupsData;
}; };
/** /**
@ -6133,9 +6112,9 @@ GroupSet.prototype.repaint = function repaint() {
var me = this, var me = this,
queue = this.queue, queue = this.queue,
items = this.items,
contents = this.contents,
itemsData = this.itemsData,
groups = this.groups, groups = this.groups,
groupsData = this.groupsData,
dataOptions = { dataOptions = {
fields: ['id', 'content'] fields: ['id', 'content']
}; };
@ -6149,9 +6128,9 @@ GroupSet.prototype.repaint = function repaint() {
// find group // find group
var group = null; var group = null;
var groupIndex = -1; var groupIndex = -1;
for (var i = 0; i < contents.length; i++) {
if (contents[i].id == id) {
group = contents[i];
for (var i = 0; i < groups.length; i++) {
if (groups[i].id == id) {
group = groups[i];
groupIndex = i; groupIndex = i;
break; break;
} }
@ -6166,7 +6145,7 @@ GroupSet.prototype.repaint = function repaint() {
var itemset = new ItemSet(me); var itemset = new ItemSet(me);
itemset.setOptions(me.options); itemset.setOptions(me.options);
itemset.setRange(me.range); itemset.setRange(me.range);
var view = new DataView(me.items, {filter: function (item) {
var view = new DataView(me.itemsData, {filter: function (item) {
return item.group == id; return item.group == id;
}}); }});
itemset.setItems(view); itemset.setItems(view);
@ -6177,11 +6156,11 @@ GroupSet.prototype.repaint = function repaint() {
view: view, view: view,
itemset: itemset itemset: itemset
}; };
contents.push(group);
groups.push(group);
} }
// update group data // update group data
group.data = groups.get(id);
group.data = groupsData.get(id);
delete queue[id]; delete queue[id];
break; break;
@ -6194,7 +6173,7 @@ GroupSet.prototype.repaint = function repaint() {
me.controller.remove(group.itemset); me.controller.remove(group.itemset);
// remove group itself // remove group itself
contents.splice(groupIndex, 1);
groups.splice(groupIndex, 1);
} }
// update lists // update lists
@ -6208,7 +6187,7 @@ GroupSet.prototype.repaint = function repaint() {
// update the top position (TODO: optimize, needed only when groups are added/removed/reordered // update the top position (TODO: optimize, needed only when groups are added/removed/reordered
var prevGroup = null; var prevGroup = null;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
var prevItemset = prevGroup && prevGroup.itemset; var prevItemset = prevGroup && prevGroup.itemset;
if (prevItemset) { if (prevItemset) {
group.itemset.options.top = function () { group.itemset.options.top = function () {
@ -6223,7 +6202,7 @@ GroupSet.prototype.repaint = function repaint() {
} }
// reposition all groups // reposition all groups
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
changed += group.itemset.repaint(); changed += group.itemset.repaint();
}); });
@ -6252,7 +6231,7 @@ GroupSet.prototype.reflow = function reflow() {
if (frame) { if (frame) {
// reposition all groups // reposition all groups
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
changed += group.itemset.reflow(); changed += group.itemset.reflow();
}); });
@ -6264,7 +6243,7 @@ GroupSet.prototype.reflow = function reflow() {
else { else {
// height is not specified, calculate the sum of the height of all groups // height is not specified, calculate the sum of the height of all groups
height = 0; height = 0;
util.forEach(this.contents, function (group) {
util.forEach(this.groups, function (group) {
height += group.itemset.height; height += group.itemset.height;
}); });
} }
@ -6413,8 +6392,8 @@ function Timeline (container, items, options) {
// create itemset or groupset // create itemset or groupset
this.setGroups(null); this.setGroups(null);
this.items = null; // DataSet
this.groups = null; // DataSet
this.itemsData = null; // DataSet
this.groupsData = null; // DataSet
// set options (must take place before setting the data) // set options (must take place before setting the data)
if (options) { if (options) {
@ -6511,7 +6490,7 @@ Timeline.prototype.setOptions = function (options) {
* @param {vis.DataSet | Array | DataTable | null} items * @param {vis.DataSet | Array | DataTable | null} items
*/ */
Timeline.prototype.setItems = function(items) { Timeline.prototype.setItems = function(items) {
var initialLoad = (this.items == null);
var initialLoad = (this.itemsData == null);
// convert to type DataSet when needed // convert to type DataSet when needed
var newItemSet; var newItemSet;
@ -6532,7 +6511,7 @@ Timeline.prototype.setItems = function(items) {
} }
// set items // set items
this.items = newItemSet;
this.itemsData = newItemSet;
this.content.setItems(newItemSet); this.content.setItems(newItemSet);
if (initialLoad && (this.options.start == undefined || this.options.end == undefined)) { if (initialLoad && (this.options.start == undefined || this.options.end == undefined)) {
@ -6568,10 +6547,10 @@ Timeline.prototype.setItems = function(items) {
* @param {vis.DataSet | Array | DataTable} groups * @param {vis.DataSet | Array | DataTable} groups
*/ */
Timeline.prototype.setGroups = function(groups) { Timeline.prototype.setGroups = function(groups) {
this.groups = groups;
this.groupsData = groups;
// switch content type between ItemSet or GroupSet when needed // switch content type between ItemSet or GroupSet when needed
var type = this.groups ? GroupSet : ItemSet;
var type = this.groupsData ? GroupSet : ItemSet;
if (!(this.content instanceof type)) { if (!(this.content instanceof type)) {
// remove old content set // remove old content set
if (this.content) { if (this.content) {
@ -6591,10 +6570,10 @@ Timeline.prototype.setGroups = function(groups) {
this.content.setRange(this.range); this.content.setRange(this.range);
} }
if (this.content.setItems) { if (this.content.setItems) {
this.content.setItems(this.items);
this.content.setItems(this.itemsData);
} }
if (this.content.setGroups) { if (this.content.setGroups) {
this.content.setGroups(this.groups);
this.content.setGroups(this.groupsData);
} }
this.controller.add(this.content); this.controller.add(this.content);
this.setOptions(this.options); this.setOptions(this.options);
@ -6609,21 +6588,21 @@ Timeline.prototype.setGroups = function(groups) {
*/ */
Timeline.prototype.getItemRange = function getItemRange() { Timeline.prototype.getItemRange = function getItemRange() {
// calculate min from start filed // calculate min from start filed
var items = this.items,
var itemsData = this.itemsData,
min = null, min = null,
max = null; max = null;
if (items) {
if (itemsData) {
// calculate the minimum value of the field 'start' // calculate the minimum value of the field 'start'
var minItem = items.min('start');
var minItem = itemsData.min('start');
min = minItem ? minItem.start.valueOf() : null; min = minItem ? minItem.start.valueOf() : null;
// calculate maximum value of fields 'start' and 'end' // calculate maximum value of fields 'start' and 'end'
var maxStartItem = items.max('start');
var maxStartItem = itemsData.max('start');
if (maxStartItem) { if (maxStartItem) {
max = maxStartItem.start.valueOf(); max = maxStartItem.start.valueOf();
} }
var maxEndItem = items.max('end');
var maxEndItem = itemsData.max('end');
if (maxEndItem) { if (maxEndItem) {
if (max == null) { if (max == null) {
max = maxEndItem.end.valueOf(); max = maxEndItem.end.valueOf();

+ 3
- 3
vis.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save