Browse Source

Fix couple of off-by-one errors

Add some enhancements for stacking (especially with regard to shading)
newShading
Ludo Stellingwerff 9 years ago
parent
commit
a582f7d762
4 changed files with 23 additions and 8 deletions
  1. +1
    -1
      lib/timeline/Graph2d.js
  2. +1
    -1
      lib/timeline/component/GraphGroup.js
  3. +20
    -5
      lib/timeline/component/LineGraph.js
  4. +1
    -1
      lib/timeline/component/graph2d_types/line.js

+ 1
- 1
lib/timeline/Graph2d.js View File

@ -217,7 +217,7 @@ Graph2d.prototype.getLegend = function(groupId, width, height) {
return this.linegraph.groups[groupId].getLegend(width,height);
}
else {
return "cannot find group:" + groupId;
return "cannot find group:'" + groupId + "'";
}
};

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

@ -73,7 +73,7 @@ GraphGroup.prototype.setZeroPosition = function (pos) {
*/
GraphGroup.prototype.setOptions = function (options) {
if (options !== undefined) {
var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'excludeFromLegend'];
var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'excludeFromLegend', 'excludeFromStacking'];
util.selectiveDeepExtend(fields, this.options, options);
// if the group's drawPoints is a function delegate the callback to the onRender property

+ 20
- 5
lib/timeline/component/LineGraph.js View File

@ -89,7 +89,7 @@ function LineGraph(body, options) {
}
};
// options is shared by this ItemSet and all its items
// options is shared by this lineGraph and all its items
this.options = util.extend({}, this.defaultOptions);
this.dom = {};
this.props = {};
@ -643,10 +643,25 @@ LineGraph.prototype._updateGraph = function () {
this.abortedGraphUpdate = false;
// With the yAxis scaled correctly, use this to get the Y values of the points.
var below = undefined;
for (i = 0; i < groupIds.length; i++) {
group = this.groups[groupIds[i]];
if (this.options.stack === true && this.options.style === 'line' && i > 0) {
this._stack(groupsData[groupIds[i]], groupsData[groupIds[i - 1]]);
if (this.options.stack === true && this.options.style === 'line') {
if (group.options.excludeFromStacking == undefined || !group.options.excludeFromStacking) {
if (below != undefined) {
this._stack(groupsData[group.id], groupsData[below.id]);
if (group.options.shaded.enabled == true && group.options.shaded.orientation !== "group"){
if (group.options.shaded.orientation == "top" && below.options.shaded.orientation !== "group"){
below.options.shaded.orientation="group";
below.options.shaded.groupId=group.id;
} else {
group.options.shaded.orientation="group";
group.options.shaded.groupId=below.id;
}
}
}
below = group;
}
}
this._convertYcoordinates(groupsData[groupIds[i]], group);
}
@ -780,8 +795,8 @@ LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate,
// optimization for sorted data
if (group.options.sort == true) {
var first = Math.max(0, util.binarySearchValue(itemsData, minDate, 'x', 'before'));
var last = Math.min(itemsData.length, util.binarySearchValue(itemsData, maxDate, 'x', 'after'));
if (last < 0) {
var last = Math.min(itemsData.length, util.binarySearchValue(itemsData, maxDate, 'x', 'after')+1);
if (last <= 0) {
last = itemsData.length;
}
var dataContainer = new Array(last-first);

+ 1
- 1
lib/timeline/component/graph2d_types/line.js View File

@ -85,7 +85,7 @@ Line.draw = function (pathArray, group, framework) {
};
Line.serializePath = function(pathArray,type,inverse){
if (pathArray.length <= 2){
if (pathArray.length < 2){
//Too little data to create a path.
return "";
}

Loading…
Cancel
Save