Browse Source

Merge pull request #1496 from almende/newShading

Update to the last pull request
codeClimate
Ludo Stellingwerff 9 years ago
parent
commit
6dcb5e654e
5 changed files with 31 additions and 10 deletions
  1. +8
    -2
      docs/graph2d/index.html
  2. +1
    -1
      lib/timeline/Graph2d.js
  3. +1
    -1
      lib/timeline/component/GraphGroup.js
  4. +20
    -5
      lib/timeline/component/LineGraph.js
  5. +1
    -1
      lib/timeline/component/graph2d_types/line.js

+ 8
- 2
docs/graph2d/index.html View File

@ -741,7 +741,7 @@ onRender: function(item, group, graph2d) {
<td>stack</td> <td>stack</td>
<td>Boolean</td> <td>Boolean</td>
<td>true</td> <td>true</td>
<td>If stack is enabled, the graphs will be stacked upon eachother when applicable. This currently only works with bar graphs but linegraph support is being worked on.</td>
<td>If stack is enabled, the graphs will be stacked upon each-other when applicable. A group can opt-out of stacking through the "excludeFromStacking" option.</td>
</tr> </tr>
<tr class='toggle collapsible' onclick="toggleTable('g2dOptions','shaded', this);"> <tr class='toggle collapsible' onclick="toggleTable('g2dOptions','shaded', this);">
<td class="greenField"><span parent="shaded" class="right-caret"></span> shaded</td> <td class="greenField"><span parent="shaded" class="right-caret"></span> shaded</td>
@ -794,7 +794,13 @@ onRender: function(item, group, graph2d) {
<td class="greenField">excludeFromLegend</td> <td class="greenField">excludeFromLegend</td>
<td>Boolean</td> <td>Boolean</td>
<td>false</td> <td>false</td>
<td>Group option only. Excludes the the group from beeing listed in the legend.</td>
<td>Group option only. Excludes the group from being listed in the legend.</td>
</tr>
<tr>
<td class="greenField">excludeFromStacking</td>
<td>Boolean</td>
<td>false</td>
<td>Group option only. Excludes the group from being included in the stacking.</td>
</tr> </tr>
</table> </table>

+ 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); return this.linegraph.groups[groupId].getLegend(width,height);
} }
else { 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) { GraphGroup.prototype.setOptions = function (options) {
if (options !== undefined) { 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); util.selectiveDeepExtend(fields, this.options, options);
// if the group's drawPoints is a function delegate the callback to the onRender property // 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.options = util.extend({}, this.defaultOptions);
this.dom = {}; this.dom = {};
this.props = {}; this.props = {};
@ -643,10 +643,25 @@ LineGraph.prototype._updateGraph = function () {
this.abortedGraphUpdate = false; this.abortedGraphUpdate = false;
// With the yAxis scaled correctly, use this to get the Y values of the points. // 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++) { for (i = 0; i < groupIds.length; i++) {
group = this.groups[groupIds[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); this._convertYcoordinates(groupsData[groupIds[i]], group);
} }
@ -780,8 +795,8 @@ LineGraph.prototype._getRelevantData = function (groupIds, groupsData, minDate,
// optimization for sorted data // optimization for sorted data
if (group.options.sort == true) { if (group.options.sort == true) {
var first = Math.max(0, util.binarySearchValue(itemsData, minDate, 'x', 'before')); 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; last = itemsData.length;
} }
var dataContainer = new Array(last-first); 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){ Line.serializePath = function(pathArray,type,inverse){
if (pathArray.length <= 2){
if (pathArray.length < 2){
//Too little data to create a path. //Too little data to create a path.
return ""; return "";
} }

Loading…
Cancel
Save