Browse Source

Fix ordering for arbitrarily nested groups (#3990)

* Fix ordering for arbitrarily nested groups

Fixes #1934

* Fix linting
develop
Austin 6 years ago
committed by Yotam Berkowitz
parent
commit
01b3fc6f1d
1 changed files with 30 additions and 18 deletions
  1. +30
    -18
      lib/timeline/component/ItemSet.js

+ 30
- 18
lib/timeline/component/ItemSet.js View File

@ -1241,25 +1241,37 @@ ItemSet.prototype._orderGroups = function () {
* @private
*/
ItemSet.prototype._orderNestedGroups = function(groupIds) {
var newGroupIdsOrder = [];
/**
* Recursively order nested groups
*
* @param {ItemSet} t
* @param {Array.<number>} groupIds
* @returns {Array.<number>}
* @private
*/
function getOrderedNestedGroups(t, groupIds) {
var result = [];
groupIds.forEach(function (groupId) {
result.push(groupId);
var groupData = t.groupsData.get(groupId);
if (groupData.nestedGroups) {
var nestedGroupIds = t.groupsData.get({
filter: function(nestedGroup) {
return nestedGroup.nestedInGroup == groupId;
},
order: t.options.groupOrder
}).map(function(nestedGroup) { return nestedGroup.id });
result = result.concat(getOrderedNestedGroups(t, nestedGroupIds));
}
});
return result;
}
var topGroupIds = groupIds.filter(groupId => !this.groupsData.get(groupId).nestedInGroup);
return getOrderedNestedGroups(this, topGroupIds);
groupIds.forEach(function(groupId){
var groupData = this.groupsData.get(groupId);
if (!groupData.nestedInGroup) {
newGroupIdsOrder.push(groupId)
}
if (groupData.nestedGroups) {
var nestedGroups = this.groupsData.get({
filter: function(nestedGroup) {
return nestedGroup.nestedInGroup == groupId;
},
order: this.options.groupOrder
});
var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id });
newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds);
}
}, this);
return newGroupIdsOrder;
};

Loading…
Cancel
Save