Browse Source

GroupSet now reckons with changes in the connected DataSet with groups

css_transitions
josdejong 11 years ago
parent
commit
fc11f82f45
5 changed files with 55 additions and 47 deletions
  1. +13
    -12
      src/component/group.js
  2. +3
    -1
      src/component/groupset.js
  3. +10
    -9
      src/visualization/timeline.js
  4. +26
    -22
      vis.js
  5. +3
    -3
      vis.min.js

+ 13
- 12
src/component/group.js View File

@ -12,7 +12,7 @@ function Group (parent, groupId, options) {
this.groupId = groupId;
this.itemsData = null; // DataSet
this.items = null; // ItemSet
this.itemset = null; // ItemSet
this.options = Object.create(parent && parent.options || null);
this.options.top = 0;
@ -47,28 +47,29 @@ Group.prototype.getContainer = function () {
* @param {DataSet | DataView} items
*/
Group.prototype.setItems = function setItems(items) {
if (this.items) {
if (this.itemset) {
// remove current item set
this.items.hide();
this.items.setItems();
this.itemset.hide();
this.itemset.setItems();
this.parent.controller.remove(this.items);
this.parent.controller.remove(this.itemset);
this.itemset = null;
}
if (items || true) {
if (items) {
var groupId = this.groupId;
this.items = new ItemSet(this);
this.items.setRange(this.parent.range);
this.itemset = new ItemSet(this);
this.itemset.setRange(this.parent.range);
this.view = new DataView(items, {
filter: function (item) {
return item.group == groupId;
}
});
this.items.setItems(this.view);
this.itemset.setItems(this.view);
this.parent.controller.add(this.items);
this.parent.controller.add(this.itemset);
}
};
@ -88,8 +89,8 @@ Group.prototype.reflow = function reflow() {
var changed = 0,
update = util.updateProperty;
changed += update(this, 'top', this.items ? this.items.top : 0);
changed += update(this, 'height', this.items ? this.items.height : 0);
changed += update(this, 'top', this.itemset ? this.itemset.top : 0);
changed += update(this, 'height', this.itemset ? this.itemset.height : 0);
return (changed > 0);
};

+ 3
- 1
src/component/groupset.js View File

@ -199,7 +199,7 @@ GroupSet.prototype.repaint = function repaint() {
var group = null;
var groupIndex = -1;
for (var i = 0; i < groups.length; i++) {
if (groups[i].id == id) {
if (groups[i].groupId == id) {
group = groups[i];
groupIndex = i;
break;
@ -249,6 +249,7 @@ GroupSet.prototype.repaint = function repaint() {
top = 0;
if (prevGroup) {
top = function () {
// TODO: top must reckon with options.maxHeight
return prevGroup.top + prevGroup.height;
}
}
@ -257,6 +258,7 @@ GroupSet.prototype.repaint = function repaint() {
});
});
changed++;
}
return (changed > 0);

+ 10
- 9
src/visualization/timeline.js View File

@ -23,7 +23,7 @@ function Timeline (container, items, options) {
// controller
this.controller = new Controller();
// main panel
// root panel
if (!container) {
throw new Error('No container element provided');
}
@ -38,8 +38,8 @@ function Timeline (container, items, options) {
return me.timeaxis.height + me.content.height;
}
};
this.main = new RootPanel(container, mainOptions);
this.controller.add(this.main);
this.root = new RootPanel(container, mainOptions);
this.controller.add(this.root);
// range
var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0);
@ -48,8 +48,8 @@ function Timeline (container, items, options) {
end: now.clone().add('days', 4).valueOf()
});
// TODO: reckon with options moveable and zoomable
this.range.subscribe(this.main, 'move', 'horizontal');
this.range.subscribe(this.main, 'zoom', 'horizontal');
this.range.subscribe(this.root, 'move', 'horizontal');
this.range.subscribe(this.root, 'zoom', 'horizontal');
this.range.on('rangechange', function () {
var force = true;
me.controller.requestReflow(force);
@ -64,7 +64,7 @@ function Timeline (container, items, options) {
// time axis
var timeaxisOptions = Object.create(this.options);
timeaxisOptions.range = this.range;
this.timeaxis = new TimeAxis(this.main, [], timeaxisOptions);
this.timeaxis = new TimeAxis(this.root, [], timeaxisOptions);
this.timeaxis.setRange(this.range);
this.controller.add(this.timeaxis);
@ -92,6 +92,7 @@ Timeline.prototype.setOptions = function (options) {
util.extend(this.options, options);
}
this.controller.reflow();
this.controller.repaint();
};
@ -182,12 +183,12 @@ Timeline.prototype.setGroups = function(groups) {
return me.timeaxis.height;
}
else {
return me.main.height - me.timeaxis.height - me.content.height;
return me.root.height - me.timeaxis.height - me.content.height;
}
},
height: function () {
if (me.options.height) {
return me.main.height - me.timeaxis.height;
return me.root.height - me.timeaxis.height;
}
else {
return null;
@ -205,7 +206,7 @@ Timeline.prototype.setGroups = function(groups) {
}
}
};
this.content = new type(this.main, [this.timeaxis], options);
this.content = new type(this.root, [this.timeaxis], options);
if (this.content.setRange) {
this.content.setRange(this.range);
}

+ 26
- 22
vis.js View File

@ -6018,7 +6018,7 @@ function Group (parent, groupId, options) {
this.groupId = groupId;
this.itemsData = null; // DataSet
this.items = null; // ItemSet
this.itemset = null; // ItemSet
this.options = Object.create(parent && parent.options || null);
this.options.top = 0;
@ -6053,28 +6053,29 @@ Group.prototype.getContainer = function () {
* @param {DataSet | DataView} items
*/
Group.prototype.setItems = function setItems(items) {
if (this.items) {
if (this.itemset) {
// remove current item set
this.items.hide();
this.items.setItems();
this.itemset.hide();
this.itemset.setItems();
this.parent.controller.remove(this.items);
this.parent.controller.remove(this.itemset);
this.itemset = null;
}
if (items || true) {
if (items) {
var groupId = this.groupId;
this.items = new ItemSet(this);
this.items.setRange(this.parent.range);
this.itemset = new ItemSet(this);
this.itemset.setRange(this.parent.range);
this.view = new DataView(items, {
filter: function (item) {
return item.group == groupId;
}
});
this.items.setItems(this.view);
this.itemset.setItems(this.view);
this.parent.controller.add(this.items);
this.parent.controller.add(this.itemset);
}
};
@ -6094,8 +6095,8 @@ Group.prototype.reflow = function reflow() {
var changed = 0,
update = util.updateProperty;
changed += update(this, 'top', this.items ? this.items.top : 0);
changed += update(this, 'height', this.items ? this.items.height : 0);
changed += update(this, 'top', this.itemset ? this.itemset.top : 0);
changed += update(this, 'height', this.itemset ? this.itemset.height : 0);
return (changed > 0);
};
@ -6301,7 +6302,7 @@ GroupSet.prototype.repaint = function repaint() {
var group = null;
var groupIndex = -1;
for (var i = 0; i < groups.length; i++) {
if (groups[i].id == id) {
if (groups[i].groupId == id) {
group = groups[i];
groupIndex = i;
break;
@ -6351,6 +6352,7 @@ GroupSet.prototype.repaint = function repaint() {
top = 0;
if (prevGroup) {
top = function () {
// TODO: top must reckon with options.maxHeight
return prevGroup.top + prevGroup.height;
}
}
@ -6359,6 +6361,7 @@ GroupSet.prototype.repaint = function repaint() {
});
});
changed++;
}
return (changed > 0);
@ -6509,7 +6512,7 @@ function Timeline (container, items, options) {
// controller
this.controller = new Controller();
// main panel
// root panel
if (!container) {
throw new Error('No container element provided');
}
@ -6524,8 +6527,8 @@ function Timeline (container, items, options) {
return me.timeaxis.height + me.content.height;
}
};
this.main = new RootPanel(container, mainOptions);
this.controller.add(this.main);
this.root = new RootPanel(container, mainOptions);
this.controller.add(this.root);
// range
var now = moment().hours(0).minutes(0).seconds(0).milliseconds(0);
@ -6534,8 +6537,8 @@ function Timeline (container, items, options) {
end: now.clone().add('days', 4).valueOf()
});
// TODO: reckon with options moveable and zoomable
this.range.subscribe(this.main, 'move', 'horizontal');
this.range.subscribe(this.main, 'zoom', 'horizontal');
this.range.subscribe(this.root, 'move', 'horizontal');
this.range.subscribe(this.root, 'zoom', 'horizontal');
this.range.on('rangechange', function () {
var force = true;
me.controller.requestReflow(force);
@ -6550,7 +6553,7 @@ function Timeline (container, items, options) {
// time axis
var timeaxisOptions = Object.create(this.options);
timeaxisOptions.range = this.range;
this.timeaxis = new TimeAxis(this.main, [], timeaxisOptions);
this.timeaxis = new TimeAxis(this.root, [], timeaxisOptions);
this.timeaxis.setRange(this.range);
this.controller.add(this.timeaxis);
@ -6578,6 +6581,7 @@ Timeline.prototype.setOptions = function (options) {
util.extend(this.options, options);
}
this.controller.reflow();
this.controller.repaint();
};
@ -6668,12 +6672,12 @@ Timeline.prototype.setGroups = function(groups) {
return me.timeaxis.height;
}
else {
return me.main.height - me.timeaxis.height - me.content.height;
return me.root.height - me.timeaxis.height - me.content.height;
}
},
height: function () {
if (me.options.height) {
return me.main.height - me.timeaxis.height;
return me.root.height - me.timeaxis.height;
}
else {
return null;
@ -6691,7 +6695,7 @@ Timeline.prototype.setGroups = function(groups) {
}
}
};
this.content = new type(this.main, [this.timeaxis], options);
this.content = new type(this.root, [this.timeaxis], options);
if (this.content.setRange) {
this.content.setRange(this.range);
}

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


Loading…
Cancel
Save