Browse Source

Fix for issue #2536 (#2803)

* Fix for issue #2536

* Adjusted documentation for fix.

* Adjustments due to review

* Grrrrr whitespace

* Fixed Travis issue
dependencies
wimrijnders 7 years ago
committed by yotamberk
parent
commit
af86650c39
2 changed files with 35 additions and 10 deletions
  1. +4
    -4
      docs/graph3d/index.html
  2. +31
    -6
      lib/graph3d/Graph3d.js

+ 4
- 4
docs/graph3d/index.html View File

@ -532,8 +532,8 @@ var options = {
<td>xBarWidth</td> <td>xBarWidth</td>
<td>number</td> <td>number</td>
<td>none</td> <td>none</td>
<td>The width of bars in x direction. By default, the width is equal to the distance
between the data points, such that bars adjoin each other.
<td>The width of bars in x direction. By default, the width is equal to the smallest distance
between the data points.
Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td> Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td>
</tr> </tr>
@ -575,8 +575,8 @@ var options = {
<td>yBarWidth</td> <td>yBarWidth</td>
<td>number</td> <td>number</td>
<td>none</td> <td>none</td>
<td>The width of bars in y direction. By default, the width is equal to the distance
between the data points, such that bars adjoin each other.
<td>The width of bars in y direction. By default, the width is equal to the smallest distance
between the data points.
Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td> Only applicable for styles <code>'bar'</code> and <code>'bar-color'</code>.</td>
</tr> </tr>

+ 31
- 6
lib/graph3d/Graph3d.js View File

@ -327,7 +327,34 @@ Graph3d.prototype.getDistinctValues = function(data, column) {
distinctValues.push(data[i][column]); distinctValues.push(data[i][column]);
} }
} }
return distinctValues;
return distinctValues.sort(function(a,b) { return a - b; });
}
/**
* Determine the smallest difference between the values for given
* column in the passed data set.
*
* @returns {Number|null} Smallest difference value or
* null, if it can't be determined.
*/
Graph3d.prototype.getSmallestDifference = function(data, column) {
var values = this.getDistinctValues(data, column);
var diffs = [];
// Get all the distinct diffs
// Array values is assumed to be sorted here
var smallest_diff = null;
for (var i = 1; i < values.length; i++) {
var diff = values[i] - values[i - 1];
if (smallest_diff == null || smallest_diff > diff ) {
smallest_diff = diff;
}
}
return smallest_diff;
} }
@ -467,16 +494,14 @@ Graph3d.prototype._dataInitialize = function (rawData, style) {
this.xBarWidth = this.defaultXBarWidth; this.xBarWidth = this.defaultXBarWidth;
} }
else { else {
var dataX = this.getDistinctValues(data,this.colX);
this.xBarWidth = (dataX[1] - dataX[0]) || 1;
this.xBarWidth = this.getSmallestDifference(data, this.colX) || 1;
} }
if (this.defaultYBarWidth !== undefined) { if (this.defaultYBarWidth !== undefined) {
this.yBarWidth = this.defaultYBarWidth; this.yBarWidth = this.defaultYBarWidth;
} }
else { else {
var dataY = this.getDistinctValues(data,this.colY);
this.yBarWidth = (dataY[1] - dataY[0]) || 1;
this.yBarWidth = this.getSmallestDifference(data, this.colY) || 1;
} }
} }
@ -2449,4 +2474,4 @@ Graph3d.prototype.setSize = function(width, height) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
module.exports = Graph3d;
module.exports = Graph3d;

Loading…
Cancel
Save