Browse Source

Prevent excessive rerendering and unknown group warnings.

codeClimate
Ludo Stellingwerff 8 years ago
parent
commit
af8971f572
1 changed files with 33 additions and 22 deletions
  1. +33
    -22
      lib/timeline/component/LineGraph.js

+ 33
- 22
lib/timeline/component/LineGraph.js View File

@ -361,12 +361,6 @@ LineGraph.prototype.setGroups = function (groups) {
this._onUpdate();
};
/**
* Update the data
* @param [ids]
* @private
*/
LineGraph.prototype._onUpdate = function (ids) {
this._updateAllGroupData();
this.redraw(true);
@ -385,7 +379,6 @@ LineGraph.prototype._onAddGroups = function (groupIds) {
this._onUpdateGroups(groupIds);
};
/**
* this cleans the group out off the legends and the dataaxis, updates the ungrouped and updates the graph
* @param {Array} groupIds
@ -393,23 +386,31 @@ LineGraph.prototype._onAddGroups = function (groupIds) {
*/
LineGraph.prototype._onRemoveGroups = function (groupIds) {
for (var i = 0; i < groupIds.length; i++) {
if (this.groups.hasOwnProperty(groupIds[i])) {
if (this.groups[groupIds[i]].options.yAxisOrientation == 'right') {
this.yAxisRight.removeGroup(groupIds[i]);
this.legendRight.removeGroup(groupIds[i]);
this.legendRight.redraw();
}
else {
this.yAxisLeft.removeGroup(groupIds[i]);
this.legendLeft.removeGroup(groupIds[i]);
this.legendLeft.redraw();
}
delete this.groups[groupIds[i]];
}
this._removeGroup(groupIds[i]);
}
this.redraw(true);
};
/**
* this cleans the group out off the legends and the dataaxis
* @param groupId
* @private
*/
LineGraph.prototype._removeGroup = function (groupId) {
if (this.groups.hasOwnProperty(groupId)) {
if (this.groups[groupId].options.yAxisOrientation == 'right') {
this.yAxisRight.removeGroup(groupId);
this.legendRight.removeGroup(groupId);
this.legendRight.redraw();
}
else {
this.yAxisLeft.removeGroup(groupId);
this.legendLeft.removeGroup(groupId);
this.legendLeft.redraw();
}
delete this.groups[groupId];
}
}
/**
* update a group object with the group dataset entree
@ -485,12 +486,22 @@ LineGraph.prototype._updateAllGroupData = function () {
var index= groupsContent[groupId].length - groupCounts[groupId]--;
groupsContent[groupId][index] = extended;
}
//Make sure all groups are present, to allow removal of old groups
for (var groupId in this.groups){
if (this.groups.hasOwnProperty(groupId)){
if (!groupsContent.hasOwnProperty(groupId)) {
groupsContent[groupId] = new Array(0);
}
}
}
//Update legendas, style and axis
for (var groupId in groupsContent) {
if (groupsContent.hasOwnProperty(groupId)) {
if (groupsContent[groupId].length == 0) {
if (this.groups.hasOwnProperty(groupId)) {
this._onRemoveGroups([groupId]);
this._removeGroup(groupId);
}
} else {
var group = undefined;
@ -678,7 +689,7 @@ LineGraph.prototype._updateGraph = function () {
if (group.options.shaded.orientation === "group") {
var subGroupId = group.options.shaded.groupId;
if (groupIds.indexOf(subGroupId) === -1) {
console.log("Unknown shading group target given:" + subGroupId);
console.log(group.id + ": Unknown shading group target given:" + subGroupId);
continue;
}
if (!paths.hasOwnProperty(subGroupId)) {

Loading…
Cancel
Save