Sha256: b466e0fbb93ed1528a0641f59f666b1f5c537f111b26da255ede846f209dade8

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

var DataGenerator = function(dataPointCount, startingValue) {
  this.dataPointCount = dataPointCount;
  this.dataSet        = [];
  this.startingValue  = startingValue || 40;
}

DataGenerator.prototype.getRandomizedData = function() {
  if (this.dataSet.length > 0) {
      this.dataSet = this.dataSet.slice(1);
    }

    while (this.dataSet.length < this.dataPointCount) {
      var lastYCoord = this.dataSet.length > 0 ? this.dataSet[this.dataSet.length - 1] : this.startingValue,
          newYCoord = lastYCoord + Math.random() * 8 - 4;
      newYCoord = Math.min(Math.max(newYCoord, 0), 100);
      this.dataSet.push(newYCoord);
    }

    var res = [];
    for (var i = 0; i < this.dataSet.length; ++i) {
      res.push([i, this.dataSet[i]])
    }

    return res;
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kiso_themes-1.0.2 app/assets/javascripts/kiso_themes/demo/data_generator.js