Browse Source

Timeline now accepts a DataSet with items having any type of start and end.

css_transitions
jos 10 years ago
parent
commit
106983fad4
9 changed files with 28 additions and 27 deletions
  1. +1
    -1
      docs/timeline.html
  2. +1
    -4
      examples/timeline/02_interactive.html
  3. +1
    -4
      examples/timeline/03_a_lot_of_data.html
  4. +1
    -4
      examples/timeline/06_event_listeners.html
  5. +3
    -1
      src/DataSet.js
  6. +6
    -4
      src/timeline/Timeline.js
  7. +11
    -4
      src/timeline/component/ItemSet.js
  8. +1
    -2
      src/util.js
  9. +3
    -3
      test/timeline.html

+ 1
- 1
docs/timeline.html View File

@ -915,7 +915,7 @@ var options = {
</p>
<ul>
<li><code>item</code>: the item being manipulated</li>
<li><code>callback</code>: a callback function which must be invoked to report back. The callback must be invoked as <code>callback(item | null)</code>. Here, <code>item</code> can contain changes to the passed item. When invoked as <code>callback(null)</code>, the action will be cancelled.</li>
<li><code>callback</code>: a callback function which must be invoked to report back. The callback must be invoked as <code>callback(item | null)</code>. Here, <code>item</code> can contain changes to the passed item. Parameter `item` typically contains fields `content`, `start`, and optionally `end`. The type of `start` and `end` is determined by the DataSet type configuration and is `Date` by default. When invoked as <code>callback(null)</code>, the action will be cancelled.</li>
</ul>
<p>

+ 1
- 4
examples/timeline/02_interactive.html View File

@ -22,10 +22,7 @@
<script>
// create a dataset with items
var items = new vis.DataSet({
type: {
start: 'Date',
end: 'Date'
}
type: { start: 'ISODate', end: 'ISODate' }
});
items.add([
{id: 1, content: 'item 1<br>start', start: '2014-01-23'},

+ 1
- 4
examples/timeline/03_a_lot_of_data.html View File

@ -31,10 +31,7 @@
// create a dataset with items
var now = moment().minutes(0).seconds(0).milliseconds(0);
var items = new vis.DataSet({
type: {
start: 'Date',
end: 'Date'
}
type: {start: 'ISODate', end: 'ISODate' }
});
// create data

+ 1
- 4
examples/timeline/06_event_listeners.html View File

@ -18,10 +18,7 @@
<div id="log"></div>
<script type="text/javascript">
var items = new vis.DataSet({
type: { start: 'Date', end: 'Date' }
});
items.add([
var items = new vis.DataSet([
{id: 1, content: 'item 1', start: '2013-04-20'},
{id: 2, content: 'item 2', start: '2013-04-14'},
{id: 3, content: 'item 3', start: '2013-04-18'},

+ 3
- 1
src/DataSet.js View File

@ -48,9 +48,11 @@ function DataSet (data, options) {
this.options = options || {};
this.data = {}; // map with data indexed by id
this.fieldId = this.options.fieldId || 'id'; // name of the field containing id
this.type = {}; // field types by field name
this.type = {}; // internal field types (NOTE: this can differ from this.options.type)
this.showInternalIds = this.options.showInternalIds || false; // show internal ids with the get function
// all variants of a Date are internally stored as Date, so we can convert
// from everything to everything (also from ISODate to Number for example)
if (this.options.type) {
for (var field in this.options.type) {
if (this.options.type.hasOwnProperty(field)) {

+ 6
- 4
src/timeline/Timeline.js View File

@ -413,20 +413,22 @@ Timeline.prototype.getItemRange = function() {
if (itemsData) {
// calculate the minimum value of the field 'start'
var minItem = itemsData.min('start');
min = minItem ? minItem.start.valueOf() : null;
min = minItem ? util.convert(minItem.start, 'Date').valueOf() : null;
// Note: we convert first to Date and then to number because else
// a conversion from ISODate to Number will fail
// calculate maximum value of fields 'start' and 'end'
var maxStartItem = itemsData.max('start');
if (maxStartItem) {
max = maxStartItem.start.valueOf();
max = util.convert(maxStartItem.start, 'Date').valueOf();
}
var maxEndItem = itemsData.max('end');
if (maxEndItem) {
if (max == null) {
max = maxEndItem.end.valueOf();
max = util.convert(maxEndItem.end, 'Date').valueOf();
}
else {
max = Math.max(max, maxEndItem.end.valueOf());
max = Math.max(max, util.convert(maxEndItem.end, 'Date').valueOf());
}
}
}

+ 11
- 4
src/timeline/component/ItemSet.js View File

@ -50,6 +50,11 @@ function ItemSet(body, options) {
// options is shared by this ItemSet and all its items
this.options = util.extend({}, this.defaultOptions);
// options for getting items from the DataSet with the correct type
this.itemOptions = {
type: {start: 'Date', end: 'Date'}
};
this.conversion = {
toScreen: body.util.toScreen,
toTime: body.util.toTime
@ -650,7 +655,7 @@ ItemSet.prototype._onUpdate = function(ids) {
var me = this;
ids.forEach(function (id) {
var itemData = me.itemsData.get(id),
var itemData = me.itemsData.get(id, me.itemOptions),
item = me.items[id],
type = itemData.type ||
(itemData.start && itemData.end && 'range') ||
@ -1070,16 +1075,18 @@ ItemSet.prototype._onDragEnd = function (event) {
this.touchParams.itemProps.forEach(function (props) {
var id = props.item.id,
itemData = me.itemsData.get(id);
itemData = me.itemsData.get(id, me.itemOptions);
var changed = false;
if ('start' in props.item.data) {
changed = (props.start != props.item.data.start.valueOf());
itemData.start = util.convert(props.item.data.start, dataset.convert['start']);
itemData.start = util.convert(props.item.data.start,
dataset.options.type && dataset.options.type.start || 'Date');
}
if ('end' in props.item.data) {
changed = changed || (props.end != props.item.data.end.valueOf());
itemData.end = util.convert(props.item.data.end, dataset.convert['end']);
itemData.end = util.convert(props.item.data.end,
dataset.options.type && dataset.options.type.end || 'Date');
}
if ('group' in props.item.data) {
changed = changed || (props.group != props.item.data.group);

+ 1
- 2
src/util.js View File

@ -319,8 +319,7 @@ util.convert = function(object, type) {
}
default:
throw new Error('Cannot convert object of type ' + util.getType(object) +
' to type "' + type + '"');
throw new Error('Unknown type "' + type + '"');
}
};

+ 3
- 3
test/timeline.html View File

@ -58,9 +58,9 @@
// create a dataset with items
var now = moment().minutes(0).seconds(0).milliseconds(0);
var items = new vis.DataSet({
convert: {
start: 'Date',
end: 'Date'
type: {
start: 'ISODate',
end: 'ISODate'
},
fieldId: '_id'
});

Loading…
Cancel
Save