Browse Source

lint timeline component (#3311)

revert-3409-performance
macleodbroad-wf 7 years ago
committed by Yotam Berkowitz
parent
commit
ca5662c6d5
9 changed files with 174 additions and 173 deletions
  1. +1
    -2
      lib/timeline/component/BackgroundGroup.js
  2. +1
    -1
      lib/timeline/component/Component.js
  3. +0
    -4
      lib/timeline/component/DataScale.js
  4. +0
    -1
      lib/timeline/component/GraphGroup.js
  5. +12
    -12
      lib/timeline/component/Group.js
  6. +134
    -128
      lib/timeline/component/ItemSet.js
  7. +2
    -2
      lib/timeline/component/Legend.js
  8. +18
    -18
      lib/timeline/component/LineGraph.js
  9. +6
    -5
      lib/timeline/component/TimeAxis.js

+ 1
- 2
lib/timeline/component/BackgroundGroup.js View File

@ -1,4 +1,3 @@
var util = require('../../util');
var Group = require('./Group'); var Group = require('./Group');
/** /**
@ -25,7 +24,7 @@ BackgroundGroup.prototype = Object.create(Group.prototype);
* @param {boolean} [forceRestack=false] Force restacking of all items * @param {boolean} [forceRestack=false] Force restacking of all items
* @return {boolean} Returns true if the group is resized * @return {boolean} Returns true if the group is resized
*/ */
BackgroundGroup.prototype.redraw = function(range, margin, forceRestack) {
BackgroundGroup.prototype.redraw = function(range, margin, forceRestack) { // eslint-disable-line no-unused-vars
var resized = false; var resized = false;
this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range); this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);

+ 1
- 1
lib/timeline/component/Component.js View File

@ -5,7 +5,7 @@ var util = require('../../util');
* @param {{dom: Object, domProps: Object, emitter: Emitter, range: Range}} [body] * @param {{dom: Object, domProps: Object, emitter: Emitter, range: Range}} [body]
* @param {Object} [options] * @param {Object} [options]
*/ */
function Component (body, options) {
function Component (body, options) { // eslint-disable-line no-unused-vars
this.options = null; this.options = null;
this.props = null; this.props = null;
} }

+ 0
- 4
lib/timeline/component/DataScale.js View File

@ -1,6 +1,3 @@
/**
* Created by ludo on 25-1-16.
*/
function DataScale(start, end, autoScaleStart, autoScaleEnd, containerHeight, majorCharHeight, zeroAlign = false, formattingFunction=false) { function DataScale(start, end, autoScaleStart, autoScaleEnd, containerHeight, majorCharHeight, zeroAlign = false, formattingFunction=false) {
this.majorSteps = [1, 2, 5, 10]; this.majorSteps = [1, 2, 5, 10];
@ -167,7 +164,6 @@ DataScale.prototype.followScale = function (other) {
} }
//Get masters stats: //Get masters stats:
var lines = other.getLines();
var otherZero = other.convertValue(0); var otherZero = other.convertValue(0);
var otherStep = other.getStep() * other.scale; var otherStep = other.getStep() * other.scale;

+ 0
- 1
lib/timeline/component/GraphGroup.js View File

@ -1,5 +1,4 @@
var util = require('../../util'); var util = require('../../util');
var DOMutil = require('../../DOMutil');
var Bars = require('./graph2d_types/bar'); var Bars = require('./graph2d_types/bar');
var Lines = require('./graph2d_types/line'); var Lines = require('./graph2d_types/line');
var Points = require('./graph2d_types/points'); var Points = require('./graph2d_types/points');

+ 12
- 12
lib/timeline/component/Group.js View File

@ -1,6 +1,5 @@
var util = require('../../util'); var util = require('../../util');
var stack = require('../Stack'); var stack = require('../Stack');
var RangeItem = require('./item/RangeItem');
/** /**
* @constructor Group * @constructor Group
@ -157,8 +156,7 @@ Group.prototype.setData = function(data) {
} }
} else if (this.nestedGroups) { } else if (this.nestedGroups) {
this.nestedGroups = null; this.nestedGroups = null;
var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed'
util.removeClassName(this.dom.label, collapsedDirClassName); util.removeClassName(this.dom.label, collapsedDirClassName);
util.removeClassName(this.dom.label, 'expanded'); util.removeClassName(this.dom.label, 'expanded');
util.removeClassName(this.dom.label, 'vis-nesting-group'); util.removeClassName(this.dom.label, 'vis-nesting-group');
@ -290,7 +288,7 @@ Group.prototype.redraw = function(range, margin, forceRestack) {
var height = this._calculateHeight(margin); var height = this._calculateHeight(margin);
// calculate actual size and position // calculate actual size and position
var foreground = this.dom.foreground;
foreground = this.dom.foreground;
this.top = foreground.offsetTop; this.top = foreground.offsetTop;
this.right = foreground.offsetLeft; this.right = foreground.offsetLeft;
this.width = foreground.offsetWidth; this.width = foreground.offsetWidth;
@ -505,8 +503,9 @@ Group.prototype._updateSubgroupsSizes = function () {
Group.prototype.orderSubgroups = function() { Group.prototype.orderSubgroups = function() {
if (this.subgroupOrderer !== undefined) { if (this.subgroupOrderer !== undefined) {
var sortArray = []; var sortArray = [];
var subgroup;
if (typeof this.subgroupOrderer == 'string') { if (typeof this.subgroupOrderer == 'string') {
for (var subgroup in this.subgroups) {
for (subgroup in this.subgroups) {
sortArray.push({subgroup: subgroup, sortField: this.subgroups[subgroup].items[0].data[this.subgroupOrderer]}) sortArray.push({subgroup: subgroup, sortField: this.subgroups[subgroup].items[0].data[this.subgroupOrderer]})
} }
sortArray.sort(function (a, b) { sortArray.sort(function (a, b) {
@ -514,7 +513,7 @@ Group.prototype.orderSubgroups = function() {
}) })
} }
else if (typeof this.subgroupOrderer == 'function') { else if (typeof this.subgroupOrderer == 'function') {
for (var subgroup in this.subgroups) {
for (subgroup in this.subgroups) {
sortArray.push(this.subgroups[subgroup].items[0].data); sortArray.push(this.subgroups[subgroup].items[0].data);
} }
sortArray.sort(this.subgroupOrderer); sortArray.sort(this.subgroupOrderer);
@ -629,7 +628,7 @@ Group.prototype._updateItemsInRange = function(orderedItems, oldVisibleItems, ra
if (value < lowerBound) {return -1;} if (value < lowerBound) {return -1;}
else if (value <= upperBound) {return 0;} else if (value <= upperBound) {return 0;}
else {return 1;} else {return 1;}
}
};
// first check if the items that were in view previously are still in view. // first check if the items that were in view previously are still in view.
// IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window! // IMPORTANT: this handles the case for the items with startdate before the window and enddate after the window!
@ -667,7 +666,7 @@ Group.prototype._updateItemsInRange = function(orderedItems, oldVisibleItems, ra
} }
// finally, we reposition all the visible items. // finally, we reposition all the visible items.
for (var i = 0; i < visibleItems.length; i++) {
for (i = 0; i < visibleItems.length; i++) {
var item = visibleItems[i]; var item = visibleItems[i];
if (!item.displayed) item.show(); if (!item.displayed) item.show();
// reposition item horizontally // reposition item horizontally
@ -679,8 +678,9 @@ Group.prototype._updateItemsInRange = function(orderedItems, oldVisibleItems, ra
Group.prototype._traceVisible = function (initialPos, items, visibleItems, visibleItemsLookup, breakCondition) { Group.prototype._traceVisible = function (initialPos, items, visibleItems, visibleItemsLookup, breakCondition) {
if (initialPos != -1) { if (initialPos != -1) {
for (var i = initialPos; i >= 0; i--) {
var item = items[i];
var i, item;
for (i = initialPos; i >= 0; i--) {
item = items[i];
if (breakCondition(item)) { if (breakCondition(item)) {
break; break;
} }
@ -692,8 +692,8 @@ Group.prototype._traceVisible = function (initialPos, items, visibleItems, visib
} }
} }
for (var i = initialPos + 1; i < items.length; i++) {
var item = items[i];
for (i = initialPos + 1; i < items.length; i++) {
item = items[i];
if (breakCondition(item)) { if (breakCondition(item)) {
break; break;
} }

+ 134
- 128
lib/timeline/component/ItemSet.js View File

@ -35,10 +35,10 @@ function ItemSet(body, options) {
align: 'auto', // alignment of box items align: 'auto', // alignment of box items
stack: true, stack: true,
stackSubgroups: true, stackSubgroups: true,
groupOrderSwap: function(fromGroup, toGroup, groups) {
var targetOrder = toGroup.order;
toGroup.order = fromGroup.order;
fromGroup.order = targetOrder;
groupOrderSwap: function(fromGroup, toGroup, groups) { // eslint-disable-line no-unused-vars
var targetOrder = toGroup.order;
toGroup.order = fromGroup.order;
fromGroup.order = targetOrder;
}, },
groupOrder: 'order', groupOrder: 'order',
@ -131,26 +131,26 @@ function ItemSet(body, options) {
// listeners for the DataSet of the items // listeners for the DataSet of the items
this.itemListeners = { this.itemListeners = {
'add': function (event, params, senderId) {
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onAdd(params.items); me._onAdd(params.items);
}, },
'update': function (event, params, senderId) {
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onUpdate(params.items); me._onUpdate(params.items);
}, },
'remove': function (event, params, senderId) {
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onRemove(params.items); me._onRemove(params.items);
} }
}; };
// listeners for the DataSet of the groups // listeners for the DataSet of the groups
this.groupListeners = { this.groupListeners = {
'add': function (event, params, senderId) {
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onAddGroups(params.items); me._onAddGroups(params.items);
}, },
'update': function (event, params, senderId) {
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onUpdateGroups(params.items); me._onUpdateGroups(params.items);
}, },
'remove': function (event, params, senderId) {
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onRemoveGroups(params.items); me._onRemoveGroups(params.items);
} }
}; };
@ -550,13 +550,14 @@ ItemSet.prototype.getSelection = function() {
*/ */
ItemSet.prototype.getVisibleItems = function() { ItemSet.prototype.getVisibleItems = function() {
var range = this.body.range.getRange(); var range = this.body.range.getRange();
var right, left;
if (this.options.rtl) { if (this.options.rtl) {
var right = this.body.util.toScreen(range.start);
var left = this.body.util.toScreen(range.end);
right = this.body.util.toScreen(range.start);
left = this.body.util.toScreen(range.end);
} else { } else {
var left = this.body.util.toScreen(range.start);
var right = this.body.util.toScreen(range.end);
left = this.body.util.toScreen(range.start);
right = this.body.util.toScreen(range.end);
} }
var ids = []; var ids = [];
@ -634,8 +635,8 @@ ItemSet.prototype.redraw = function() {
var visibleInterval = range.end - range.start; var visibleInterval = range.end - range.start;
var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.props.width != this.props.lastWidth); var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.props.width != this.props.lastWidth);
var scrolled = range.start != this.lastRangeStart; var scrolled = range.start != this.lastRangeStart;
var changedStackOption = options.stack != this.lastStack
var changedStackSubgroupsOption = options.stackSubgroups != this.lastStackSubgroups
var changedStackOption = options.stack != this.lastStack;
var changedStackSubgroupsOption = options.stackSubgroups != this.lastStackSubgroups;
var forceRestack = (zoomed || scrolled || changedStackOption || changedStackSubgroupsOption); var forceRestack = (zoomed || scrolled || changedStackOption || changedStackSubgroupsOption);
this.lastVisibleInterval = visibleInterval; this.lastVisibleInterval = visibleInterval;
this.lastRangeStart = range.start; this.lastRangeStart = range.start;
@ -712,7 +713,6 @@ 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; var item, itemId;
if (this.groupsData) { if (this.groupsData) {
@ -866,7 +866,7 @@ ItemSet.prototype.setGroups = function(groups) {
groupsData.update(updatedNestedGroup); groupsData.update(updatedNestedGroup);
}) })
} }
})
});
// subscribe to new dataset // subscribe to new dataset
@ -903,8 +903,7 @@ ItemSet.prototype.getGroups = function() {
*/ */
ItemSet.prototype.removeItem = function(id) { ItemSet.prototype.removeItem = function(id) {
var item = this.itemsData.get(id), var item = this.itemsData.get(id),
dataset = this.itemsData.getDataSet(),
itemObj = this.items[id];
dataset = this.itemsData.getDataSet();
if (item) { if (item) {
// confirm deletion // confirm deletion
@ -1178,12 +1177,12 @@ ItemSet.prototype._orderNestedGroups = function(groupIds) {
}, },
order: this.options.groupOrder order: this.options.groupOrder
}); });
var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id })
var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id });
newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds); newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds);
} }
}, this)
}, this);
return newGroupIdsOrder; return newGroupIdsOrder;
}
};
/** /**
@ -1199,9 +1198,9 @@ ItemSet.prototype._addItem = function(item) {
var group = this.groups[groupId]; var group = this.groups[groupId];
if (!group) { if (!group) {
item.groupShowing = false;
item.groupShowing = false;
} else if (group && group.data && group.data.showNested) { } else if (group && group.data && group.data.showNested) {
item.groupShowing = true;
item.groupShowing = true;
} }
if (group) group.add(item); if (group) group.add(item);
@ -1383,14 +1382,16 @@ ItemSet.prototype._onDragStart = function (event) {
* @private * @private
*/ */
ItemSet.prototype._onDragStartAddItem = function (event) { ItemSet.prototype._onDragStartAddItem = function (event) {
var xAbs;
var x;
var snap = this.options.snap || null; var snap = this.options.snap || null;
if (this.options.rtl) { if (this.options.rtl) {
var xAbs = util.getAbsoluteRight(this.dom.frame);
var x = xAbs - event.center.x + 10; // plus 10 to compensate for the drag starting as soon as you've moved 10px
xAbs = util.getAbsoluteRight(this.dom.frame);
x = xAbs - event.center.x + 10; // plus 10 to compensate for the drag starting as soon as you've moved 10px
} else { } else {
var xAbs = util.getAbsoluteLeft(this.dom.frame);
var x = event.center.x - xAbs - 10; // minus 10 to compensate for the drag starting as soon as you've moved 10px
xAbs = util.getAbsoluteLeft(this.dom.frame);
x = event.center.x - xAbs - 10; // minus 10 to compensate for the drag starting as soon as you've moved 10px
} }
var time = this.body.util.toTime(x); var time = this.body.util.toTime(x);
@ -1446,11 +1447,12 @@ ItemSet.prototype._onDrag = function (event) {
var me = this; var me = this;
var snap = this.options.snap || null; var snap = this.options.snap || null;
var xOffset;
if (this.options.rtl) { if (this.options.rtl) {
var xOffset = this.body.dom.root.offsetLeft + this.body.domProps.right.width;
xOffset = this.body.dom.root.offsetLeft + this.body.domProps.right.width;
} else { } else {
var xOffset = this.body.dom.root.offsetLeft + this.body.domProps.left.width;
xOffset = this.body.dom.root.offsetLeft + this.body.domProps.left.width;
} }
var scale = this.body.util.getScale(); var scale = this.body.util.getScale();
@ -1477,11 +1479,16 @@ ItemSet.prototype._onDrag = function (event) {
this.touchParams.itemProps.forEach(function (props) { this.touchParams.itemProps.forEach(function (props) {
var current = me.body.util.toTime(event.center.x - xOffset); var current = me.body.util.toTime(event.center.x - xOffset);
var initial = me.body.util.toTime(props.initialX - xOffset); var initial = me.body.util.toTime(props.initialX - xOffset);
var offset;
var initialStart;
var initialEnd;
var start;
var end;
if (this.options.rtl) { if (this.options.rtl) {
var offset = -(current - initial); // ms
offset = -(current - initial); // ms
} else { } else {
var offset = (current - initial); // ms
offset = (current - initial); // ms
} }
var itemData = this._cloneItemData(props.item.data); // clone the data var itemData = this._cloneItemData(props.item.data); // clone the data
@ -1499,15 +1506,15 @@ ItemSet.prototype._onDrag = function (event) {
// drag left side of a range item // drag left side of a range item
if (this.options.rtl) { if (this.options.rtl) {
if (itemData.end != undefined) { if (itemData.end != undefined) {
var initialEnd = util.convert(props.data.end, 'Date');
var end = new Date(initialEnd.valueOf() + offset);
initialEnd = util.convert(props.data.end, 'Date');
end = new Date(initialEnd.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.end = snap ? snap(end, scale, step) : end; itemData.end = snap ? snap(end, scale, step) : end;
} }
} else { } else {
if (itemData.start != undefined) { if (itemData.start != undefined) {
var initialStart = util.convert(props.data.start, 'Date');
var start = new Date(initialStart.valueOf() + offset);
initialStart = util.convert(props.data.start, 'Date');
start = new Date(initialStart.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.start = snap ? snap(start, scale, step) : start; itemData.start = snap ? snap(start, scale, step) : start;
} }
@ -1517,15 +1524,15 @@ ItemSet.prototype._onDrag = function (event) {
// drag right side of a range item // drag right side of a range item
if (this.options.rtl) { if (this.options.rtl) {
if (itemData.start != undefined) { if (itemData.start != undefined) {
var initialStart = util.convert(props.data.start, 'Date');
var start = new Date(initialStart.valueOf() + offset);
initialStart = util.convert(props.data.start, 'Date');
start = new Date(initialStart.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.start = snap ? snap(start, scale, step) : start; itemData.start = snap ? snap(start, scale, step) : start;
} }
} else { } else {
if (itemData.end != undefined) { if (itemData.end != undefined) {
var initialEnd = util.convert(props.data.end, 'Date');
var end = new Date(initialEnd.valueOf() + offset);
initialEnd = util.convert(props.data.end, 'Date');
end = new Date(initialEnd.valueOf() + offset);
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.end = snap ? snap(end, scale, step) : end; itemData.end = snap ? snap(end, scale, step) : end;
} }
@ -1535,11 +1542,11 @@ ItemSet.prototype._onDrag = function (event) {
// drag both start and end // drag both start and end
if (itemData.start != undefined) { if (itemData.start != undefined) {
var initialStart = util.convert(props.data.start, 'Date').valueOf();
var start = new Date(initialStart + offset);
initialStart = util.convert(props.data.start, 'Date').valueOf();
start = new Date(initialStart + offset);
if (itemData.end != undefined) { if (itemData.end != undefined) {
var initialEnd = util.convert(props.data.end, 'Date');
initialEnd = util.convert(props.data.end, 'Date');
var duration = initialEnd.valueOf() - initialStart.valueOf(); var duration = initialEnd.valueOf() - initialStart.valueOf();
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
@ -1550,13 +1557,10 @@ ItemSet.prototype._onDrag = function (event) {
// TODO: pass a Moment instead of a Date to snap(). (Breaking change) // TODO: pass a Moment instead of a Date to snap(). (Breaking change)
itemData.start = snap ? snap(start, scale, step) : start; itemData.start = snap ? snap(start, scale, step) : start;
} }
} }
} }
} }
if (updateGroupAllowed && (!props.dragLeft && !props.dragRight) && newGroupBase!=null) { if (updateGroupAllowed && (!props.dragLeft && !props.dragRight) && newGroupBase!=null) {
if (itemData.group != undefined) { if (itemData.group != undefined) {
var newOffset = newGroupBase - props.groupOffset; var newOffset = newGroupBase - props.groupOffset;
@ -1677,10 +1681,10 @@ ItemSet.prototype._onGroupClick = function (event) {
util.addClassName(group.dom.label, 'expanded'); util.addClassName(group.dom.label, 'expanded');
} else { } else {
util.removeClassName(group.dom.label, 'expanded'); util.removeClassName(group.dom.label, 'expanded');
var collapsedDirClassName = this.options.rtl ? 'collapsed-rtl' : 'collapsed'
var collapsedDirClassName = this.options.rtl ? 'collapsed-rtl' : 'collapsed';
util.addClassName(group.dom.label, collapsedDirClassName); util.addClassName(group.dom.label, collapsedDirClassName);
} }
}
};
ItemSet.prototype._onGroupDragStart = function (event) { ItemSet.prototype._onGroupDragStart = function (event) {
if (this.options.groupEditable.order) { if (this.options.groupEditable.order) {
@ -1690,11 +1694,11 @@ ItemSet.prototype._onGroupDragStart = function (event) {
event.stopPropagation(); event.stopPropagation();
this.groupTouchParams.originalOrder = this.groupsData.getIds({ this.groupTouchParams.originalOrder = this.groupsData.getIds({
order: this.options.groupOrder
});
order: this.options.groupOrder
});
} }
} }
}
};
ItemSet.prototype._onGroupDrag = function (event) { ItemSet.prototype._onGroupDrag = function (event) {
if (this.options.groupEditable.order && this.groupTouchParams.group) { if (this.options.groupEditable.order && this.groupTouchParams.group) {
@ -1740,8 +1744,8 @@ ItemSet.prototype._onGroupDrag = function (event) {
// fetch current order of groups // fetch current order of groups
var newOrder = groupsData.getIds({ var newOrder = groupsData.getIds({
order: this.options.groupOrder
});
order: this.options.groupOrder
});
// in case of changes since _onGroupDragStart // in case of changes since _onGroupDragStart
@ -1769,17 +1773,17 @@ ItemSet.prototype._onGroupDrag = function (event) {
// if dragged group was move upwards everything below should have an offset // if dragged group was move upwards everything below should have an offset
if (newOrder[curPos+newOffset] == draggedId) { if (newOrder[curPos+newOffset] == draggedId) {
newOffset = 1; newOffset = 1;
continue;
} }
// if dragged group was move downwards everything above should have an offset // if dragged group was move downwards everything above should have an offset
else if (origOrder[curPos+orgOffset] == draggedId) { else if (origOrder[curPos+orgOffset] == draggedId) {
orgOffset = 1; orgOffset = 1;
continue;
} }
// found a group (apart from dragged group) that has the wrong position -> switch with the // found a group (apart from dragged group) that has the wrong position -> switch with the
// group at the position where other one should be, fix index arrays and continue // group at the position where other one should be, fix index arrays and continue
else { else {
var slippedPosition = newOrder.indexOf(origOrder[curPos+orgOffset])
var slippedPosition = newOrder.indexOf(origOrder[curPos+orgOffset]);
var switchGroup = groupsData.get(newOrder[curPos+newOffset]); var switchGroup = groupsData.get(newOrder[curPos+newOffset]);
var shouldBeGroup = groupsData.get(origOrder[curPos+orgOffset]); var shouldBeGroup = groupsData.get(origOrder[curPos+orgOffset]);
this.options.groupOrderSwap(switchGroup, shouldBeGroup, groupsData); this.options.groupOrderSwap(switchGroup, shouldBeGroup, groupsData);
@ -1797,69 +1801,68 @@ ItemSet.prototype._onGroupDrag = function (event) {
} }
} }
}
};
ItemSet.prototype._onGroupDragEnd = function (event) { ItemSet.prototype._onGroupDragEnd = function (event) {
if (this.options.groupEditable.order && this.groupTouchParams.group) {
event.stopPropagation();
if (this.options.groupEditable.order && this.groupTouchParams.group) {
event.stopPropagation();
// update existing group
var me = this;
var id = me.groupTouchParams.group.groupId;
var dataset = me.groupsData.getDataSet();
var groupData = util.extend({}, dataset.get(id)); // clone the data
me.options.onMoveGroup(groupData, function (groupData) {
if (groupData) {
// apply changes
groupData[dataset._fieldId] = id; // ensure the group contains its id (can be undefined)
dataset.update(groupData);
}
else {
// fetch current order of groups
var newOrder = dataset.getIds({
order: me.options.groupOrder
});
// restore original order
if (!util.equalArray(newOrder, me.groupTouchParams.originalOrder)) {
var origOrder = me.groupTouchParams.originalOrder;
var numGroups = Math.min(origOrder.length, newOrder.length);
var curPos = 0;
while (curPos < numGroups) {
// as long as the groups are where they should be step down along the groups order
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) {
curPos++;
}
// all ok
if (curPos >= numGroups) {
break;
}
// found a group that has the wrong position -> switch with the
// group at the position where other one should be, fix index arrays and continue
var slippedPosition = newOrder.indexOf(origOrder[curPos])
var switchGroup = dataset.get(newOrder[curPos]);
var shouldBeGroup = dataset.get(origOrder[curPos]);
me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset);
dataset.update(switchGroup);
dataset.update(shouldBeGroup);
var switchGroupId = newOrder[curPos];
newOrder[curPos] = origOrder[curPos];
newOrder[slippedPosition] = switchGroupId;
curPos++;
}
}
// update existing group
var me = this;
var id = me.groupTouchParams.group.groupId;
var dataset = me.groupsData.getDataSet();
var groupData = util.extend({}, dataset.get(id)); // clone the data
me.options.onMoveGroup(groupData, function (groupData) {
if (groupData) {
// apply changes
groupData[dataset._fieldId] = id; // ensure the group contains its id (can be undefined)
dataset.update(groupData);
}
else {
}
// fetch current order of groups
var newOrder = dataset.getIds({
order: me.options.groupOrder
}); });
me.body.emitter.emit('groupDragged', { groupId: id });
}
}
// restore original order
if (!util.equalArray(newOrder, me.groupTouchParams.originalOrder)) {
var origOrder = me.groupTouchParams.originalOrder;
var numGroups = Math.min(origOrder.length, newOrder.length);
var curPos = 0;
while (curPos < numGroups) {
// as long as the groups are where they should be step down along the groups order
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) {
curPos++;
}
// all ok
if (curPos >= numGroups) {
break;
}
// found a group that has the wrong position -> switch with the
// group at the position where other one should be, fix index arrays and continue
var slippedPosition = newOrder.indexOf(origOrder[curPos]);
var switchGroup = dataset.get(newOrder[curPos]);
var shouldBeGroup = dataset.get(origOrder[curPos]);
me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset);
dataset.update(switchGroup);
dataset.update(shouldBeGroup);
var switchGroupId = newOrder[curPos];
newOrder[curPos] = origOrder[curPos];
newOrder[slippedPosition] = switchGroupId;
curPos++;
}
}
}
});
me.body.emitter.emit('groupDragged', { groupId: id });
}
};
/** /**
* Handle selecting/deselecting an item when tapping it * Handle selecting/deselecting an item when tapping it
@ -1984,7 +1987,7 @@ ItemSet.prototype._onMouseWheel = function(event) {
if (this.touchParams.itemIsDragging) { if (this.touchParams.itemIsDragging) {
this._onDragEnd(event); this._onDragEnd(event);
} }
}
};
/** /**
* Handle updates of an item on double tap * Handle updates of an item on double tap
@ -2006,7 +2009,7 @@ ItemSet.prototype._onUpdateItem = function (item) {
} }
}); });
} }
}
};
/** /**
* Handle creation of an item on double tap * Handle creation of an item on double tap
@ -2022,30 +2025,33 @@ ItemSet.prototype._onAddItem = function (event) {
var item = this.itemFromTarget(event); var item = this.itemFromTarget(event);
if (!item) { if (!item) {
var xAbs;
var x;
// add item // add item
if (this.options.rtl) { if (this.options.rtl) {
var xAbs = util.getAbsoluteRight(this.dom.frame);
var x = xAbs - event.center.x;
xAbs = util.getAbsoluteRight(this.dom.frame);
x = xAbs - event.center.x;
} else { } else {
var xAbs = util.getAbsoluteLeft(this.dom.frame);
var x = event.center.x - xAbs;
xAbs = util.getAbsoluteLeft(this.dom.frame);
x = event.center.x - xAbs;
} }
// var xAbs = util.getAbsoluteLeft(this.dom.frame); // var xAbs = util.getAbsoluteLeft(this.dom.frame);
// var x = event.center.x - xAbs; // var x = event.center.x - xAbs;
var start = this.body.util.toTime(x); var start = this.body.util.toTime(x);
var scale = this.body.util.getScale(); var scale = this.body.util.getScale();
var step = this.body.util.getStep(); var step = this.body.util.getStep();
var end;
var newItemData; var newItemData;
if (event.type == 'drop') { if (event.type == 'drop') {
newItemData = JSON.parse(event.dataTransfer.getData("text"))
newItemData.content = newItemData.content ? newItemData.content : 'new item'
newItemData.start = newItemData.start ? newItemData.start : (snap ? snap(start, scale, step) : start)
newItemData = JSON.parse(event.dataTransfer.getData("text"));
newItemData.content = newItemData.content ? newItemData.content : 'new item';
newItemData.start = newItemData.start ? newItemData.start : (snap ? snap(start, scale, step) : start);
newItemData.type = newItemData.type || 'box'; newItemData.type = newItemData.type || 'box';
newItemData[this.itemsData._fieldId] = newItemData.id || util.randomUUID(); newItemData[this.itemsData._fieldId] = newItemData.id || util.randomUUID();
if (newItemData.type == 'range' && !newItemData.end) { if (newItemData.type == 'range' && !newItemData.end) {
var end = this.body.util.toTime(x + this.props.width / 5);
end = this.body.util.toTime(x + this.props.width / 5);
newItemData.end = snap ? snap(end, scale, step) : end; newItemData.end = snap ? snap(end, scale, step) : end;
} }
} else { } else {
@ -2057,7 +2063,7 @@ ItemSet.prototype._onAddItem = function (event) {
// when default type is a range, add a default end date to the new item // when default type is a range, add a default end date to the new item
if (this.options.type === 'range') { if (this.options.type === 'range') {
var end = this.body.util.toTime(x + this.props.width / 5);
end = this.body.util.toTime(x + this.props.width / 5);
newItemData.end = snap ? snap(end, scale, step) : end; newItemData.end = snap ? snap(end, scale, step) : end;
} }
} }
@ -2103,7 +2109,7 @@ ItemSet.prototype._onMultiSelectItem = function (event) {
if (shiftKey && this.options.multiselect) { if (shiftKey && this.options.multiselect) {
// select all items between the old selection and the tapped item // select all items between the old selection and the tapped item
var itemGroup = this.itemsData.get(item.id).group; var itemGroup = this.itemsData.get(item.id).group;
// when filtering get the group of the last selected item // when filtering get the group of the last selected item
var lastSelectedGroup = undefined; var lastSelectedGroup = undefined;
if (this.options.multiselectPerGroup) { if (this.options.multiselectPerGroup) {
@ -2111,7 +2117,7 @@ ItemSet.prototype._onMultiSelectItem = function (event) {
lastSelectedGroup = this.itemsData.get(selection[0]).group; lastSelectedGroup = this.itemsData.get(selection[0]).group;
} }
} }
// determine the selection range // determine the selection range
if (!this.options.multiselectPerGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) { if (!this.options.multiselectPerGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) {
selection.push(item.id); selection.push(item.id);

+ 2
- 2
lib/timeline/component/Legend.js View File

@ -173,8 +173,8 @@ Legend.prototype.redraw = function() {
} }
var content = ''; var content = '';
for (var i = 0; i < groupArray.length; i++) {
var groupId = groupArray[i];
for (i = 0; i < groupArray.length; i++) {
groupId = groupArray[i];
if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) { if (this.groups[groupId].visible == true && (this.linegraphOptions.visibility[groupId] === undefined || this.linegraphOptions.visibility[groupId] == true)) {
content += this.groups[groupId].content + '<br />'; content += this.groups[groupId].content + '<br />';
} }

+ 18
- 18
lib/timeline/component/LineGraph.js View File

@ -74,26 +74,26 @@ function LineGraph(body, options) {
// listeners for the DataSet of the items // listeners for the DataSet of the items
this.itemListeners = { this.itemListeners = {
'add': function (event, params, senderId) {
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onAdd(params.items); me._onAdd(params.items);
}, },
'update': function (event, params, senderId) {
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onUpdate(params.items); me._onUpdate(params.items);
}, },
'remove': function (event, params, senderId) {
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onRemove(params.items); me._onRemove(params.items);
} }
}; };
// listeners for the DataSet of the groups // listeners for the DataSet of the groups
this.groupListeners = { this.groupListeners = {
'add': function (event, params, senderId) {
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onAddGroups(params.items); me._onAddGroups(params.items);
}, },
'update': function (event, params, senderId) {
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onUpdateGroups(params.items); me._onUpdateGroups(params.items);
}, },
'remove': function (event, params, senderId) {
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
me._onRemoveGroups(params.items); me._onRemoveGroups(params.items);
} }
}; };
@ -455,9 +455,9 @@ LineGraph.prototype._updateAllGroupData = function (ids, groupIds) {
//Pre-load arrays from existing groups if items are not changed (not in ids) //Pre-load arrays from existing groups if items are not changed (not in ids)
var existingItemsMap = {}; var existingItemsMap = {};
if (!groupIds && ids) { if (!groupIds && ids) {
for (var groupId in this.groups) {
for (groupId in this.groups) {
if (this.groups.hasOwnProperty(groupId)) { if (this.groups.hasOwnProperty(groupId)) {
var group = this.groups[groupId];
group = this.groups[groupId];
var existing_items = group.getItems(); var existing_items = group.getItems();
groupsContent[groupId] = existing_items.filter(function (item) { groupsContent[groupId] = existing_items.filter(function (item) {
@ -474,9 +474,9 @@ LineGraph.prototype._updateAllGroupData = function (ids, groupIds) {
} }
//Now insert data into the arrays. //Now insert data into the arrays.
for (var i = 0; i < items.length; i++) {
var item = items[i];
var groupId = item.group;
for (i = 0; i < items.length; i++) {
item = items[i];
groupId = item.group;
if (groupId === null || groupId === undefined) { if (groupId === null || groupId === undefined) {
groupId = UNGROUPED; groupId = UNGROUPED;
} }
@ -499,7 +499,7 @@ LineGraph.prototype._updateAllGroupData = function (ids, groupIds) {
} }
//Make sure all groups are present, to allow removal of old groups //Make sure all groups are present, to allow removal of old groups
for (var groupId in this.groups){
for (groupId in this.groups){
if (this.groups.hasOwnProperty(groupId)){ if (this.groups.hasOwnProperty(groupId)){
if (!groupsContent.hasOwnProperty(groupId)) { if (!groupsContent.hasOwnProperty(groupId)) {
groupsContent[groupId] = new Array(0); groupsContent[groupId] = new Array(0);
@ -508,7 +508,7 @@ LineGraph.prototype._updateAllGroupData = function (ids, groupIds) {
} }
//Update legendas, style and axis //Update legendas, style and axis
for (var groupId in groupsContent) {
for (groupId in groupsContent) {
if (groupsContent.hasOwnProperty(groupId)) { if (groupsContent.hasOwnProperty(groupId)) {
if (groupsContent[groupId].length == 0) { if (groupsContent[groupId].length == 0) {
if (this.groups.hasOwnProperty(groupId)) { if (this.groups.hasOwnProperty(groupId)) {
@ -736,9 +736,9 @@ LineGraph.prototype._updateGraph = function () {
paths[groupIds[i]] = Lines.calcPath(groupsData[groupIds[i]], group); paths[groupIds[i]] = Lines.calcPath(groupsData[groupIds[i]], group);
} }
Lines.draw(paths[groupIds[i]], group, this.framework); Lines.draw(paths[groupIds[i]], group, this.framework);
//explicit no break;
// eslint-disable-line no-fallthrough
case "point": case "point":
//explicit no break;
// eslint-disable-line no-fallthrough
case "points": case "points":
if (group.options.style == "point" || group.options.style == "points" || group.options.drawPoints.enabled == true) { if (group.options.style == "point" || group.options.style == "points" || group.options.drawPoints.enabled == true) {
Points.draw(groupsData[groupIds[i]], group, this.framework); Points.draw(groupsData[groupIds[i]], group, this.framework);
@ -746,7 +746,7 @@ LineGraph.prototype._updateGraph = function () {
break; break;
case "bar": case "bar":
// bar needs to be drawn enmasse // bar needs to be drawn enmasse
//explicit no break
// eslint-disable-line no-fallthrough
default: default:
//do nothing... //do nothing...
} }
@ -959,7 +959,7 @@ LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
} }
// if there are items: // if there are items:
for (var i = 0; i < groupIds.length; i++) {
for (i = 0; i < groupIds.length; i++) {
if (groupRanges.hasOwnProperty(groupIds[i])) { if (groupRanges.hasOwnProperty(groupIds[i])) {
if (groupRanges[groupIds[i]].ignore !== true) { if (groupRanges[groupIds[i]].ignore !== true) {
minVal = groupRanges[groupIds[i]].min; minVal = groupRanges[groupIds[i]].min;
@ -1017,7 +1017,7 @@ LineGraph.prototype._updateYAxis = function (groupIds, groupRanges) {
// clean the accumulated lists // clean the accumulated lists
var tempGroups = ['__barStackLeft', '__barStackRight', '__lineStackLeft', '__lineStackRight']; var tempGroups = ['__barStackLeft', '__barStackRight', '__lineStackLeft', '__lineStackRight'];
for (var i = 0; i < tempGroups.length; i++) {
for (i = 0; i < tempGroups.length; i++) {
if (groupIds.indexOf(tempGroups[i]) != -1) { if (groupIds.indexOf(tempGroups[i]) != -1) {
groupIds.splice(groupIds.indexOf(tempGroups[i]), 1); groupIds.splice(groupIds.indexOf(tempGroups[i]), 1);
} }

+ 6
- 5
lib/timeline/component/TimeAxis.js View File

@ -222,11 +222,12 @@ TimeAxis.prototype._repaintLabels = function () {
dom.majorTexts = []; dom.majorTexts = [];
dom.minorTexts = []; dom.minorTexts = [];
var current;
var current; // eslint-disable-line no-unused-vars
var next; var next;
var x; var x;
var xNext; var xNext;
var isMajor, nextIsMajor;
var isMajor;
var nextIsMajor; // eslint-disable-line no-unused-vars
var showMinorGrid; var showMinorGrid;
var width = 0, prevWidth; var width = 0, prevWidth;
var line; var line;
@ -345,7 +346,7 @@ TimeAxis.prototype._repaintMinorText = function (x, text, orientation, className
label.style.right = x + 'px'; label.style.right = x + 'px';
} else { } else {
label.style.left = x + 'px'; label.style.left = x + 'px';
};
}
label.className = 'vis-text vis-minor ' + className; label.className = 'vis-text vis-minor ' + className;
//label.title = title; // TODO: this is a heavy operation //label.title = title; // TODO: this is a heavy operation
@ -383,7 +384,7 @@ TimeAxis.prototype._repaintMajorText = function (x, text, orientation, className
label.style.right = x + 'px'; label.style.right = x + 'px';
} else { } else {
label.style.left = x + 'px'; label.style.left = x + 'px';
};
}
this.dom.majorTexts.push(label); this.dom.majorTexts.push(label);
return label; return label;
@ -423,7 +424,7 @@ TimeAxis.prototype._repaintMinorLine = function (x, width, orientation, classNam
} else { } else {
line.style.left = (x - props.minorLineWidth / 2) + 'px'; line.style.left = (x - props.minorLineWidth / 2) + 'px';
line.className = 'vis-grid vis-vertical vis-minor ' + className; line.className = 'vis-grid vis-vertical vis-minor ' + className;
};
}
line.style.width = width + 'px'; line.style.width = width + 'px';

Loading…
Cancel
Save