@arction/xydata
Advanced tools
Comparing version 1.2.1 to 1.3.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
@@ -8,2 +9,3 @@ | ||
## [Unreleased] - yyyy-mm-dd | ||
### Added | ||
@@ -19,3 +21,10 @@ | ||
## [1.3.0] - 2020-11-30 | ||
### Added | ||
- Spectrum Data Generator. | ||
## [1.2.1] - 2020-04-17 | ||
### Fixed | ||
@@ -26,2 +35,3 @@ | ||
## [1.2.0] - 2020-04-02 | ||
### Added | ||
@@ -37,2 +47,3 @@ | ||
## [1.1.0] - 2020-01-31 | ||
### Added | ||
@@ -49,6 +60,9 @@ | ||
## [1.0.1] - 2019-08-05 | ||
### Added | ||
- Changelog | ||
### Changed | ||
- Upgraded dependencies to latest released versions. | ||
@@ -58,6 +72,9 @@ - Updated documentation using latest TypeDoc generator. | ||
### Fixed | ||
- Typo in README.md | ||
## [1.0.0] - 2019-07-04 | ||
### Added | ||
- Progressive Random Generator. | ||
@@ -64,0 +81,0 @@ - Progressive Function Generator. |
@@ -245,2 +245,23 @@ type StreamContinueHandler = () => boolean; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, Stream, DataGenerator, DataHost }; | ||
interface SpectrumDataOptions { | ||
numberOfSamples: number; | ||
sampleSize: number; | ||
variation: number; | ||
frequencyStability: number; | ||
narrowFactor1: number; | ||
narrowFactor2: number; | ||
} | ||
declare function createSpectrumDataGenerator(): SpectrumDataGenerator; | ||
declare class SpectrumDataGenerator extends DataGenerator<number[], SpectrumDataOptions> { | ||
constructor(args: SpectrumDataOptions); | ||
setNumberOfSamples(numberOfSamples: number): SpectrumDataGenerator; | ||
setSampleSize(sampleSize: number): SpectrumDataGenerator; | ||
setVariation(variation: number): SpectrumDataGenerator; | ||
setFrequencyStability(frequencyStability: number): SpectrumDataGenerator; | ||
setNarrowFactor1(narrowFactor1: number): SpectrumDataGenerator; | ||
setNarrowFactor2(narrowFactor2: number): SpectrumDataGenerator; | ||
protected getPointCount(): number; | ||
protected generateDataPoint(iPoint: number): any[]; | ||
protected infiniteReset(dataToReset: number[], data: number[][]): number[]; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, createSpectrumDataGenerator, Stream, DataGenerator, DataHost }; |
@@ -245,2 +245,23 @@ type StreamContinueHandler = () => boolean; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, Stream, DataGenerator, DataHost }; | ||
interface SpectrumDataOptions { | ||
numberOfSamples: number; | ||
sampleSize: number; | ||
variation: number; | ||
frequencyStability: number; | ||
narrowFactor1: number; | ||
narrowFactor2: number; | ||
} | ||
declare function createSpectrumDataGenerator(): SpectrumDataGenerator; | ||
declare class SpectrumDataGenerator extends DataGenerator<number[], SpectrumDataOptions> { | ||
constructor(args: SpectrumDataOptions); | ||
setNumberOfSamples(numberOfSamples: number): SpectrumDataGenerator; | ||
setSampleSize(sampleSize: number): SpectrumDataGenerator; | ||
setVariation(variation: number): SpectrumDataGenerator; | ||
setFrequencyStability(frequencyStability: number): SpectrumDataGenerator; | ||
setNarrowFactor1(narrowFactor1: number): SpectrumDataGenerator; | ||
setNarrowFactor2(narrowFactor2: number): SpectrumDataGenerator; | ||
protected getPointCount(): number; | ||
protected generateDataPoint(iPoint: number): any[]; | ||
protected infiniteReset(dataToReset: number[], data: number[][]): number[]; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, createSpectrumDataGenerator, Stream, DataGenerator, DataHost }; |
@@ -791,3 +791,114 @@ /*! ***************************************************************************** | ||
export { DataGenerator, DataHost, Stream, createDeltaFunctionGenerator, createOHLCGenerator, createParametricFunctionGenerator, createProgressiveFunctionGenerator, createProgressiveRandomGenerator, createProgressiveTraceGenerator, createSampledDataGenerator, createTraceGenerator, createWhiteNoiseGenerator }; | ||
var defaultOptions = { | ||
numberOfSamples: 1000, | ||
sampleSize: 10, | ||
variation: 10.0, | ||
frequencyStability: 1.0, | ||
narrowFactor1: 8.0, | ||
narrowFactor2: 24.0 | ||
}; | ||
function createSpectrumDataGenerator() { | ||
return new SpectrumDataGenerator(defaultOptions); | ||
} | ||
var SpectrumDataGenerator = (function (_super) { | ||
__extends(SpectrumDataGenerator, _super); | ||
function SpectrumDataGenerator(args) { | ||
var _this = _super.call(this, args) || this; | ||
var opts = { | ||
sampleSize: args.sampleSize !== undefined ? args.sampleSize : defaultOptions.sampleSize, | ||
numberOfSamples: args.numberOfSamples !== undefined ? args.numberOfSamples : defaultOptions.numberOfSamples, | ||
variation: args.variation !== undefined ? args.variation : defaultOptions.variation, | ||
frequencyStability: args.frequencyStability !== undefined ? args.frequencyStability : defaultOptions.frequencyStability, | ||
narrowFactor1: args.narrowFactor1 !== undefined ? args.narrowFactor1 : defaultOptions.narrowFactor1, | ||
narrowFactor2: args.narrowFactor2 !== undefined ? args.narrowFactor2 : defaultOptions.narrowFactor2 | ||
}; | ||
_this.options = Object.freeze(opts); | ||
return _this; | ||
} | ||
SpectrumDataGenerator.prototype.setNumberOfSamples = function (numberOfSamples) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { numberOfSamples: numberOfSamples })); | ||
}; | ||
SpectrumDataGenerator.prototype.setSampleSize = function (sampleSize) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { sampleSize: sampleSize })); | ||
}; | ||
SpectrumDataGenerator.prototype.setVariation = function (variation) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { variation: variation })); | ||
}; | ||
SpectrumDataGenerator.prototype.setFrequencyStability = function (frequencyStability) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { frequencyStability: frequencyStability })); | ||
}; | ||
SpectrumDataGenerator.prototype.setNarrowFactor1 = function (narrowFactor1) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { narrowFactor1: narrowFactor1 })); | ||
}; | ||
SpectrumDataGenerator.prototype.setNarrowFactor2 = function (narrowFactor2) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { narrowFactor2: narrowFactor2 })); | ||
}; | ||
SpectrumDataGenerator.prototype.getPointCount = function () { | ||
return this.options.numberOfSamples; | ||
}; | ||
SpectrumDataGenerator.prototype.generateDataPoint = function (iPoint) { | ||
var m_dInitialValue = 10.0; | ||
var m_dMax = 100; | ||
var m_dMin = 0; | ||
var m_dVariation = this.options.variation; | ||
var m_iRowLength = this.options.sampleSize; | ||
var m_dFrequencyStability = this.options.frequencyStability; | ||
var m_dPeak1X = m_iRowLength / 8.0; | ||
var m_dPeak2X = m_iRowLength / 2.0; | ||
var aNewData = new Array(m_iRowLength); | ||
for (var i = 0; i < m_iRowLength; i++) | ||
aNewData[i] = m_dInitialValue; | ||
var dHalf = m_iRowLength / 2.0; | ||
m_dPeak1X += (Math.random() - 0.5) * m_dVariation / m_dFrequencyStability / 100.0 * m_iRowLength / 2.0; | ||
m_dPeak2X += (Math.random() - 0.5) * m_dVariation / m_dFrequencyStability / 100.0 * m_iRowLength; | ||
if (m_dPeak1X < 0) | ||
m_dPeak1X = 0; | ||
if (m_dPeak1X > m_iRowLength) | ||
m_dPeak1X = m_iRowLength; | ||
if (m_dPeak2X < 0) | ||
m_dPeak2X = 0; | ||
if (m_dPeak2X > m_iRowLength) | ||
m_dPeak2X = m_iRowLength; | ||
var dNewValue1; | ||
var dNewValue2; | ||
var dX1; | ||
var dX2; | ||
var dPeakY1 = m_dMax / 3.0 * 2.0; | ||
var dPeakY2 = m_dMax / 2.0; | ||
var dNarrowFactor1 = this.options.narrowFactor1; | ||
var dNarrowFactor2 = this.options.narrowFactor2; | ||
var dA1 = dPeakY1 / (dHalf * dHalf) * dNarrowFactor1; | ||
var dA2 = dPeakY2 / (dHalf * dHalf) * dNarrowFactor2; | ||
var dSum12; | ||
for (var i = 0; i < m_iRowLength; i++) { | ||
dX1 = 0.8 * i - m_dPeak1X; | ||
dX2 = 0.8 * i - m_dPeak2X; | ||
dNewValue1 = dPeakY1 - dX1 * dX1 * dA1; | ||
if (dNewValue1 < m_dMin) | ||
dNewValue1 = m_dMin; | ||
if (dNewValue1 > m_dMax) | ||
dNewValue1 = m_dMax; | ||
dNewValue2 = dPeakY2 - dX2 * dX2 * dA2; | ||
if (dNewValue2 < m_dMin) | ||
dNewValue2 = m_dMin; | ||
if (dNewValue2 > m_dMax) | ||
dNewValue2 = m_dMax; | ||
dSum12 = dNewValue1 + dNewValue2; | ||
dSum12 = dSum12 + dSum12 * (Math.random() - 0.5) * m_dVariation / 10.0; | ||
aNewData[i] = (aNewData[i] + dSum12) / 2.0; | ||
if (aNewData[i] < m_dMin) | ||
aNewData[i] = m_dMin; | ||
if (aNewData[i] > m_dMax) | ||
aNewData[i] = m_dMax; | ||
aNewData[i] = aNewData[i] * 0.02; | ||
} | ||
return aNewData; | ||
}; | ||
SpectrumDataGenerator.prototype.infiniteReset = function (dataToReset, data) { | ||
return dataToReset.slice(); | ||
}; | ||
return SpectrumDataGenerator; | ||
}(DataGenerator)); | ||
export { DataGenerator, DataHost, Stream, createDeltaFunctionGenerator, createOHLCGenerator, createParametricFunctionGenerator, createProgressiveFunctionGenerator, createProgressiveRandomGenerator, createProgressiveTraceGenerator, createSampledDataGenerator, createSpectrumDataGenerator, createTraceGenerator, createWhiteNoiseGenerator }; | ||
//# sourceMappingURL=xydata.es.js.map |
@@ -245,2 +245,23 @@ type StreamContinueHandler = () => boolean; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, Stream, DataGenerator, DataHost }; | ||
interface SpectrumDataOptions { | ||
numberOfSamples: number; | ||
sampleSize: number; | ||
variation: number; | ||
frequencyStability: number; | ||
narrowFactor1: number; | ||
narrowFactor2: number; | ||
} | ||
declare function createSpectrumDataGenerator(): SpectrumDataGenerator; | ||
declare class SpectrumDataGenerator extends DataGenerator<number[], SpectrumDataOptions> { | ||
constructor(args: SpectrumDataOptions); | ||
setNumberOfSamples(numberOfSamples: number): SpectrumDataGenerator; | ||
setSampleSize(sampleSize: number): SpectrumDataGenerator; | ||
setVariation(variation: number): SpectrumDataGenerator; | ||
setFrequencyStability(frequencyStability: number): SpectrumDataGenerator; | ||
setNarrowFactor1(narrowFactor1: number): SpectrumDataGenerator; | ||
setNarrowFactor2(narrowFactor2: number): SpectrumDataGenerator; | ||
protected getPointCount(): number; | ||
protected generateDataPoint(iPoint: number): any[]; | ||
protected infiniteReset(dataToReset: number[], data: number[][]): number[]; | ||
} | ||
export { createProgressiveRandomGenerator, createProgressiveTraceGenerator, createProgressiveFunctionGenerator, createTraceGenerator, createOHLCGenerator, createDeltaFunctionGenerator, createWhiteNoiseGenerator, createSampledDataGenerator, createParametricFunctionGenerator, createSpectrumDataGenerator, Stream, DataGenerator, DataHost }; |
@@ -1,1 +0,15 @@ | ||
var xydata=function(t){"use strict";var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i])})(t,i)};function i(t,i){function r(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var n,i=1,r=arguments.length;i<r;i++)for(var e in n=arguments[i])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t}).apply(this,arguments)};var e,s=function(){function t(t,n){this.options=t,this.streamActive=!1,this.data=[],this.interval=this.options.interval||1e3,this.batchSize=this.options.batchSize||1,this.batchesLeft=-2,this.runStream=this.runStream.bind(this),this.infiniteReset=n,void 0!==t.repeat&&("boolean"==typeof t.repeat?this.batchesLeft=t.repeat?-1:-2:"number"==typeof t.repeat?this.batchesLeft=t.repeat+1:"function"==typeof t.repeat&&(this.continueHandler=t.repeat))}return t.prototype.consume=function(){var t=this,n=this.batchSize;this.data.length<this.batchSize&&(n=this.data.length);var i=this.data.splice(0,n);if((this.batchesLeft>0||-1===this.batchesLeft)&&i.length>0&&(this.data=this.data.concat(i.map(function(n){return t.infiniteReset(n)})),i.length<this.batchSize))for(;i.length<this.batchSize;){var r=this.data.splice(0,1)[0];this.data=this.data.concat(this.infiniteReset(r)),i.push(r)}return i},t.prototype.checkStreamContinue=function(){var t=this.batchesLeft>0||-1===this.batchesLeft||-2===this.batchesLeft&&this.data.length>0;return this.continueHandler&&(t=!0===this.continueHandler()),t},t.prototype.runStream=function(){var t=this.checkStreamContinue();if(this.data&&this.data.length>0&&t){if(this.streamHandler){var n=this.consume();this.streamHandler(n)}setTimeout(this.runStream,this.interval)}else this.streamActive=!1;this.batchesLeft>0&&this.batchesLeft--},t.prototype.activateStream=function(){this.streamActive||(this.streamActive=!0,this.runStream())},t.prototype.push=function(t){Array.isArray(t)?this.data=this.data.concat(t):this.data.push(t),this.activateStream()},t.prototype.map=function(n){return this.outputStream=new t(r(r({},this.options),{repeat:!1}),this.infiniteReset),this.mapHandler=n,this.streamHandler=this.i,this.activateStream(),this.outputStream},t.prototype.i=function(t){if(this.mapHandler&&this.outputStream){var n=t.map(this.mapHandler);this.outputStream.push(n)}},t.prototype.forEach=function(t){this.forEachHandler=t,this.streamHandler=this.s,this.activateStream()},t.prototype.s=function(t){this.forEachHandler&&t.forEach(this.forEachHandler)},t}(),u=function(){function t(t,n){this.data=[],this.derivativeDataHosts=[],this.promisesToResolve=[],this.streamsToPush=[],this.infiniteReset=this.infiniteReset.bind(this),this.infiniteResetHandler=t;var i={interval:n.interval,batchSize:n.batchSize,repeat:void 0!==n.repeat&&n.repeat};this.streamOptions=Object.freeze(i)}return t.prototype.toStream=function(){var t=new s(this.streamOptions,this.infiniteReset);return this.frozenData?t.push(this.frozenData):this.streamsToPush.push(t),t},t.prototype.toPromise=function(){var t=this;return this.frozenData?Promise.resolve(this.frozenData):new Promise(function(n){t.promisesToResolve.push(n)})},t.prototype.infiniteReset=function(t){return this.infiniteResetHandler(t,this.frozenData?this.frozenData:[])},t.prototype.push=function(t){var n,i;if(!this.frozenData)if(Array.isArray(t))try{for(var r=function(t){var n="function"==typeof Symbol&&Symbol.iterator,i=n&&t[n],r=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),e=r.next();!e.done;e=r.next()){var s=e.value;this.data.push(s)}}catch(t){n={error:t}}finally{try{e&&!e.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}else this.data.push(t)},t.prototype.setData=function(t){this.data=t},t.prototype.freeze=function(){var t=this;this.frozenData||(this.frozenData=this.data,setTimeout(function(){t.promisesToResolve.forEach(function(n){return n(t.frozenData)}),t.promisesToResolve=[]},0),setTimeout(function(){t.streamsToPush.forEach(function(n){return n.push(t.frozenData||[])}),t.streamsToPush=[]},0),setTimeout(function(){t.handleDerivativeDataHosts()},0),this.data=[])},t.prototype.getPointCount=function(){return this.frozenData?this.frozenData.length:0},t.prototype.handleDerivativeDataHosts=function(){var t=this;this.frozenData&&this.derivativeDataHosts.length>0&&(this.derivativeDataHosts.forEach(function(n){t.frozenData&&n.setData(t.frozenData),n.freeze()}),this.derivativeDataHosts=[])},t.prototype.setStreamInterval=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{interval:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t.prototype.setStreamBatchSize=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{batchSize:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t.prototype.setStreamRepeat=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{repeat:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t}();if("undefined"!=typeof window&&window.performance&&window.performance.now)e=window.performance.now.bind(window.performance);else try{if("undefined"==typeof require)throw new Error;e=require("perf_hooks").performance.now}catch(t){throw new Error('Failed to detect "performance.now" API')}var h=function(){function t(t){this.options=t}return t.prototype.generate=function(){var t=new u(this.infiniteReset,{interval:500,batchSize:10,repeat:!1}),n=this.getPointCount(),i=this.generateChunks.bind(this,0,n,t);return setTimeout(i,0),t},t.prototype.generateChunks=function(t,n,i){for(var r=e(),s=[],u=0;e()-r<15&&t<n;u++){var h=this.generateDataPoint(t);t++,s.push(h)}if(i.push(s),t<n){var o=this.generateChunks.bind(this,t,n,i);setTimeout(o,0)}else i.freeze()},t}();var o=function(t){function n(n){var i=t.call(this,n)||this;i.offset=.5;var r={numberOfPoints:n.numberOfPoints,offsetStep:0===n.offsetStep?0:n.offsetStep,offsetDeltaMax:Math.min(n.offsetDeltaMax,1),offsetDeltaMin:Math.max(0===n.offsetDeltaMin?0:n.offsetDeltaMin,0),dataMax:Math.min(n.dataMax,1)};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setOffsetStep=function(t){return new n(r(r({},this.options),{offsetStep:t}))},n.prototype.setOffsetDeltaMax=function(t){return new n(r(r({},this.options),{offsetDeltaMax:t}))},n.prototype.setOffsetDeltaMin=function(t){return new n(r(r({},this.options),{offsetDeltaMin:t}))},n.prototype.setDataMax=function(t){return new n(r(r({},this.options),{dataMax:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){if(t%this.options.offsetStep==0||0===t){var n=Math.random()*(this.options.offsetDeltaMax-this.options.offsetDeltaMin)+this.options.offsetDeltaMin;this.offset=Math.random()>.5?this.offset+n:this.offset-n}return this.offset+this.options.dataMax>1?this.offset=1-this.options.dataMax:this.offset<0&&(this.offset=0),{x:t,y:this.offset+Math.random()*this.options.dataMax}},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var f=function(t){function n(n){var i=t.call(this,n)||this;i.previousPoint={x:0,y:0};var r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n={x:t,y:this.previousPoint.y+2*(Math.random()-.5)};return this.previousPoint=n,n},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var a=function(t){function n(n){var i=t.call(this,n)||this;i.x=i.options.start;var r={samplingFunction:n.samplingFunction,start:n.start,end:n.end,step:n.step};return i.options=Object.freeze(r),i.numberOfPoints=Math.ceil(Math.abs(r.end-r.start)/r.step),i}return i(n,t),n.prototype.setSamplingFunction=function(t){return new n(r(r({},this.options),{samplingFunction:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setEnd=function(t){return new n(r(r({},this.options),{end:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.x,y:this.options.samplingFunction(this.x)};return this.x=this.x+this.options.step,t},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length*(n[n.length-1].x-n[n.length-2].x),y:t.y}},n}(h);var c=function(t){function n(n){var i=t.call(this,n)||this;i.previous={x:0,y:0};var r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.previous.x+2*(Math.random()-.5),y:this.previous.y+2*(Math.random()-.5)};return this.previous=t,t},n.prototype.infiniteReset=function(t,n){return{x:t.x+n[n.length-1].x,y:t.y+n[n.length-1].y}},n}(h);var v=function(t){function n(n){var i=t.call(this,n)||this;return i.prevPoint=[i.options.startTimestamp,i.options.start,i.options.start,i.options.start,i.options.start],i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setStartTimestamp=function(t){return new n(r(r({},this.options),{startTimestamp:t}))},n.prototype.setDataFrequency=function(t){return new n(r(r({},this.options),{dataFreq:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setVolatility=function(t){return new n(r(r({},this.options),{volatility:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n,i=this,r=this.options.startTimestamp+this.options.dataFreq*t,e=Math.random()>.5?1:-1,s=Array.from(Array(4)).map(function(t){var n=Math.random()*i.options.volatility*e;return i.prevPoint[4]+n<0&&(n*=-1),i.prevPoint[4]+n}).sort(function(t,n){return t-n});return-1===e&&(s=[s[0],s[2],s[1],s[3]]),n=[r,s[1],s[3],s[0],s[2]],this.prevPoint=n,n},n.prototype.infiniteReset=function(t,n){return[t[0]+n.length*(n[n.length-1][0]-n[n.length-2][0]),t[1],t[2],t[3],t[4]]},n}(h);var w=function(t){function n(n){var i=t.call(this,n)||this;i.lastSpike=0;var r={numberOfPoints:n.numberOfPoints,minGap:n.minGap,maxGap:n.maxGap,minAmplitude:n.minAmplitude,maxAmplitude:n.maxAmplitude,probability:n.probability};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setMinGap=function(t){return new n(r(r({},this.options),{minGap:t}))},n.prototype.setMaxGap=function(t){return new n(r(r({},this.options),{maxGap:t}))},n.prototype.setMinAmplitude=function(t){return new n(r(r({},this.options),{minAmplitude:t}))},n.prototype.setMaxAmplitude=function(t){return new n(r(r({},this.options),{maxAmplitude:t}))},n.prototype.setProbability=function(t){return new n(r(r({},this.options),{probability:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n=t-this.lastSpike,i={x:t,y:0};(n>this.options.minGap||-1===this.options.minGap)&&(n<this.options.maxGap||-1===this.options.maxGap?Math.random()>1-this.options.probability&&(i.y=Math.random()*(this.options.maxAmplitude-this.options.minAmplitude)+this.options.minAmplitude,this.lastSpike=t):n>=this.options.maxGap&&(i.y=Math.random()*(this.options.maxAmplitude-this.options.minAmplitude)+this.options.minAmplitude,this.lastSpike=t));return i},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var m=function(t){function n(n){var i=t.call(this,n)||this,r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(this.options?r(r({},this.options),{numberOfPoints:t}):{numberOfPoints:t})},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){return{x:t,y:2*(Math.random()-.5)}},n.prototype.infiniteReset=function(t,n){return{x:t.x+n[n.length-1].x,y:t.y+n[n.length-1].y}},n}(h);var p=function(t){function n(n){var i=t.call(this,n)||this;i.interval=1/(i.options.samplingFrequency||10);var r={inputData:n.inputData,samplingFrequency:n.samplingFrequency,step:n.step};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setInputData=function(t){return new n(r(r({},this.options),{inputData:t}))},n.prototype.setSamplingFrequency=function(t){return new n(r(r({},this.options),{samplingFrequency:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.options.inputData.length},n.prototype.generateDataPoint=function(t){return{timestamp:t*this.interval+t*this.options.step,data:this.options.inputData[t]}},n.prototype.infiniteReset=function(t,n){return{timestamp:t.timestamp+n[n.length-1].timestamp,data:t.data}},n}(h);var b=function(t){function n(n){var i=t.call(this,n)||this;i.t=i.options.start;var r={xFunction:n.xFunction,yFunction:n.yFunction,start:n.start,end:n.end,step:n.step};return i.options=Object.freeze(r),i.numberOfPoints=Math.ceil(Math.abs(r.end-r.start)/r.step),i}return i(n,t),n.prototype.setXFunction=function(t){return new n(r(r({},this.options),{xFunction:t}))},n.prototype.setYFunction=function(t){return new n(r(r({},this.options),{yFunction:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setEnd=function(t){return new n(r(r({},this.options),{end:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.options.xFunction(this.t),y:this.options.yFunction(this.t)};return this.t=this.t+this.options.step,t},n.prototype.infiniteReset=function(t,n){return{x:t.x,y:t.y}},n}(h);return t.DataGenerator=h,t.DataHost=u,t.Stream=s,t.createDeltaFunctionGenerator=function(){return new w({numberOfPoints:1e3,minGap:1,maxGap:-1,minAmplitude:.1,maxAmplitude:1,probability:.02})},t.createOHLCGenerator=function(){return new v({numberOfPoints:1e3,startTimestamp:0,dataFreq:1,start:100,volatility:.1})},t.createParametricFunctionGenerator=function(){return new b({xFunction:function(t){return 3*Math.cos(3*t)},yFunction:function(t){return 3*Math.sin(4*t)},start:0,end:1e3,step:.5})},t.createProgressiveFunctionGenerator=function(){return new a({samplingFunction:function(t){return t*t},start:0,end:100,step:1})},t.createProgressiveRandomGenerator=function(){return new o({numberOfPoints:1e3,offsetStep:10,offsetDeltaMax:.3,offsetDeltaMin:.1,dataMax:.5})},t.createProgressiveTraceGenerator=function(){return new f({numberOfPoints:1e3})},t.createSampledDataGenerator=function(){return new p({inputData:[],samplingFrequency:50,step:0})},t.createTraceGenerator=function(){return new c({numberOfPoints:1e3})},t.createWhiteNoiseGenerator=function(){return new m({numberOfPoints:1e3})},t}({}); | ||
var xydata=function(t){"use strict"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i])})(t,i)};function i(t,i){function r(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var n,i=1,r=arguments.length;i<r;i++)for(var e in n=arguments[i])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t}).apply(this,arguments)};var e,s=function(){function t(t,n){this.options=t,this.streamActive=!1,this.data=[],this.interval=this.options.interval||1e3,this.batchSize=this.options.batchSize||1,this.batchesLeft=-2,this.runStream=this.runStream.bind(this),this.infiniteReset=n,void 0!==t.repeat&&("boolean"==typeof t.repeat?this.batchesLeft=t.repeat?-1:-2:"number"==typeof t.repeat?this.batchesLeft=t.repeat+1:"function"==typeof t.repeat&&(this.continueHandler=t.repeat))}return t.prototype.consume=function(){var t=this,n=this.batchSize;this.data.length<this.batchSize&&(n=this.data.length);var i=this.data.splice(0,n);if((this.batchesLeft>0||-1===this.batchesLeft)&&i.length>0&&(this.data=this.data.concat(i.map((function(n){return t.infiniteReset(n)}))),i.length<this.batchSize))for(;i.length<this.batchSize;){var r=this.data.splice(0,1)[0];this.data=this.data.concat(this.infiniteReset(r)),i.push(r)}return i},t.prototype.checkStreamContinue=function(){var t=this.batchesLeft>0||-1===this.batchesLeft||-2===this.batchesLeft&&this.data.length>0;return this.continueHandler&&(t=!0===this.continueHandler()),t},t.prototype.runStream=function(){var t=this.checkStreamContinue();if(this.data&&this.data.length>0&&t){if(this.streamHandler){var n=this.consume();this.streamHandler(n)}setTimeout(this.runStream,this.interval)}else this.streamActive=!1;this.batchesLeft>0&&this.batchesLeft--},t.prototype.activateStream=function(){this.streamActive||(this.streamActive=!0,this.runStream())},t.prototype.push=function(t){Array.isArray(t)?this.data=this.data.concat(t):this.data.push(t),this.activateStream()},t.prototype.map=function(n){return this.outputStream=new t(r(r({},this.options),{repeat:!1}),this.infiniteReset),this.mapHandler=n,this.streamHandler=this.i,this.activateStream(),this.outputStream},t.prototype.i=function(t){if(this.mapHandler&&this.outputStream){var n=t.map(this.mapHandler);this.outputStream.push(n)}},t.prototype.forEach=function(t){this.forEachHandler=t,this.streamHandler=this.u,this.activateStream()},t.prototype.u=function(t){this.forEachHandler&&t.forEach(this.forEachHandler)},t}(),u=function(){function t(t,n){this.data=[],this.derivativeDataHosts=[],this.promisesToResolve=[],this.streamsToPush=[],this.infiniteReset=this.infiniteReset.bind(this),this.infiniteResetHandler=t;var i={interval:n.interval,batchSize:n.batchSize,repeat:void 0!==n.repeat&&n.repeat};this.streamOptions=Object.freeze(i)}return t.prototype.toStream=function(){var t=new s(this.streamOptions,this.infiniteReset);return this.frozenData?t.push(this.frozenData):this.streamsToPush.push(t),t},t.prototype.toPromise=function(){var t=this;return this.frozenData?Promise.resolve(this.frozenData):new Promise((function(n){t.promisesToResolve.push(n)}))},t.prototype.infiniteReset=function(t){return this.infiniteResetHandler(t,this.frozenData?this.frozenData:[])},t.prototype.push=function(t){var n,i;if(!this.frozenData)if(Array.isArray(t))try{for(var r=function(t){var n="function"==typeof Symbol&&Symbol.iterator,i=n&&t[n],r=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),e=r.next();!e.done;e=r.next()){var s=e.value;this.data.push(s)}}catch(t){n={error:t}}finally{try{e&&!e.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}else this.data.push(t)},t.prototype.setData=function(t){this.data=t},t.prototype.freeze=function(){var t=this;this.frozenData||(this.frozenData=this.data,setTimeout((function(){t.promisesToResolve.forEach((function(n){return n(t.frozenData)})),t.promisesToResolve=[]}),0),setTimeout((function(){t.streamsToPush.forEach((function(n){return n.push(t.frozenData||[])})),t.streamsToPush=[]}),0),setTimeout((function(){t.handleDerivativeDataHosts()}),0),this.data=[])},t.prototype.getPointCount=function(){return this.frozenData?this.frozenData.length:0},t.prototype.handleDerivativeDataHosts=function(){var t=this;this.frozenData&&this.derivativeDataHosts.length>0&&(this.derivativeDataHosts.forEach((function(n){t.frozenData&&n.setData(t.frozenData),n.freeze()})),this.derivativeDataHosts=[])},t.prototype.setStreamInterval=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{interval:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t.prototype.setStreamBatchSize=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{batchSize:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t.prototype.setStreamRepeat=function(n){var i=new t(this.infiniteResetHandler,r(r({},this.streamOptions),{repeat:n}));return this.derivativeDataHosts.push(i),this.handleDerivativeDataHosts(),i},t}();if("undefined"!=typeof window&&window.performance&&window.performance.now)e=window.performance.now.bind(window.performance);else try{if("undefined"==typeof require)throw new Error;e=require("perf_hooks").performance.now}catch(t){throw new Error('Failed to detect "performance.now" API')}var h=function(){function t(t){this.options=t}return t.prototype.generate=function(){var t=new u(this.infiniteReset,{interval:500,batchSize:10,repeat:!1}),n=this.getPointCount(),i=this.generateChunks.bind(this,0,n,t);return setTimeout(i,0),t},t.prototype.generateChunks=function(t,n,i){for(var r=e(),s=[],u=0;e()-r<15&&t<n;u++){var h=this.generateDataPoint(t);t++,s.push(h)}if(i.push(s),t<n){var o=this.generateChunks.bind(this,t,n,i);setTimeout(o,0)}else i.freeze()},t}();var o=function(t){function n(n){var i=t.call(this,n)||this;i.offset=.5;var r={numberOfPoints:n.numberOfPoints,offsetStep:0===n.offsetStep?0:n.offsetStep,offsetDeltaMax:Math.min(n.offsetDeltaMax,1),offsetDeltaMin:Math.max(0===n.offsetDeltaMin?0:n.offsetDeltaMin,0),dataMax:Math.min(n.dataMax,1)};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setOffsetStep=function(t){return new n(r(r({},this.options),{offsetStep:t}))},n.prototype.setOffsetDeltaMax=function(t){return new n(r(r({},this.options),{offsetDeltaMax:t}))},n.prototype.setOffsetDeltaMin=function(t){return new n(r(r({},this.options),{offsetDeltaMin:t}))},n.prototype.setDataMax=function(t){return new n(r(r({},this.options),{dataMax:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){if(t%this.options.offsetStep==0||0===t){var n=Math.random()*(this.options.offsetDeltaMax-this.options.offsetDeltaMin)+this.options.offsetDeltaMin;this.offset=Math.random()>.5?this.offset+n:this.offset-n}return this.offset+this.options.dataMax>1?this.offset=1-this.options.dataMax:this.offset<0&&(this.offset=0),{x:t,y:this.offset+Math.random()*this.options.dataMax}},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var f=function(t){function n(n){var i=t.call(this,n)||this;i.previousPoint={x:0,y:0};var r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n={x:t,y:this.previousPoint.y+2*(Math.random()-.5)};return this.previousPoint=n,n},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var a=function(t){function n(n){var i=t.call(this,n)||this;i.x=i.options.start;var r={samplingFunction:n.samplingFunction,start:n.start,end:n.end,step:n.step};return i.options=Object.freeze(r),i.numberOfPoints=Math.ceil(Math.abs(r.end-r.start)/r.step),i}return i(n,t),n.prototype.setSamplingFunction=function(t){return new n(r(r({},this.options),{samplingFunction:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setEnd=function(t){return new n(r(r({},this.options),{end:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.x,y:this.options.samplingFunction(this.x)};return this.x=this.x+this.options.step,t},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length*(n[n.length-1].x-n[n.length-2].x),y:t.y}},n}(h);var c=function(t){function n(n){var i=t.call(this,n)||this;i.previous={x:0,y:0};var r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.previous.x+2*(Math.random()-.5),y:this.previous.y+2*(Math.random()-.5)};return this.previous=t,t},n.prototype.infiniteReset=function(t,n){return{x:t.x+n[n.length-1].x,y:t.y+n[n.length-1].y}},n}(h);var v=function(t){function n(n){var i=t.call(this,n)||this;return i.prevPoint=[i.options.startTimestamp,i.options.start,i.options.start,i.options.start,i.options.start],i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setStartTimestamp=function(t){return new n(r(r({},this.options),{startTimestamp:t}))},n.prototype.setDataFrequency=function(t){return new n(r(r({},this.options),{dataFreq:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setVolatility=function(t){return new n(r(r({},this.options),{volatility:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n,i=this,r=this.options.startTimestamp+this.options.dataFreq*t,e=Math.random()>.5?1:-1,s=Array.from(Array(4)).map((function(t){var n=Math.random()*i.options.volatility*e;return i.prevPoint[4]+n<0&&(n*=-1),i.prevPoint[4]+n})).sort((function(t,n){return t-n}));return-1===e&&(s=[s[0],s[2],s[1],s[3]]),n=[r,s[1],s[3],s[0],s[2]],this.prevPoint=n,n},n.prototype.infiniteReset=function(t,n){return[t[0]+n.length*(n[n.length-1][0]-n[n.length-2][0]),t[1],t[2],t[3],t[4]]},n}(h);var w=function(t){function n(n){var i=t.call(this,n)||this;i.lastSpike=0;var r={numberOfPoints:n.numberOfPoints,minGap:n.minGap,maxGap:n.maxGap,minAmplitude:n.minAmplitude,maxAmplitude:n.maxAmplitude,probability:n.probability};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(r(r({},this.options),{numberOfPoints:t}))},n.prototype.setMinGap=function(t){return new n(r(r({},this.options),{minGap:t}))},n.prototype.setMaxGap=function(t){return new n(r(r({},this.options),{maxGap:t}))},n.prototype.setMinAmplitude=function(t){return new n(r(r({},this.options),{minAmplitude:t}))},n.prototype.setMaxAmplitude=function(t){return new n(r(r({},this.options),{maxAmplitude:t}))},n.prototype.setProbability=function(t){return new n(r(r({},this.options),{probability:t}))},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){var n=t-this.lastSpike,i={x:t,y:0};(n>this.options.minGap||-1===this.options.minGap)&&(n<this.options.maxGap||-1===this.options.maxGap?Math.random()>1-this.options.probability&&(i.y=Math.random()*(this.options.maxAmplitude-this.options.minAmplitude)+this.options.minAmplitude,this.lastSpike=t):n>=this.options.maxGap&&(i.y=Math.random()*(this.options.maxAmplitude-this.options.minAmplitude)+this.options.minAmplitude,this.lastSpike=t));return i},n.prototype.infiniteReset=function(t,n){return{x:t.x+n.length,y:t.y}},n}(h);var m=function(t){function n(n){var i=t.call(this,n)||this,r={numberOfPoints:n.numberOfPoints};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfPoints=function(t){return new n(this.options?r(r({},this.options),{numberOfPoints:t}):{numberOfPoints:t})},n.prototype.getPointCount=function(){return this.options.numberOfPoints},n.prototype.generateDataPoint=function(t){return{x:t,y:2*(Math.random()-.5)}},n.prototype.infiniteReset=function(t,n){return{x:t.x+n[n.length-1].x,y:t.y+n[n.length-1].y}},n}(h);var p=function(t){function n(n){var i=t.call(this,n)||this;i.interval=1/(i.options.samplingFrequency||10);var r={inputData:n.inputData,samplingFrequency:n.samplingFrequency,step:n.step};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setInputData=function(t){return new n(r(r({},this.options),{inputData:t}))},n.prototype.setSamplingFrequency=function(t){return new n(r(r({},this.options),{samplingFrequency:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.options.inputData.length},n.prototype.generateDataPoint=function(t){return{timestamp:t*this.interval+t*this.options.step,data:this.options.inputData[t]}},n.prototype.infiniteReset=function(t,n){return{timestamp:t.timestamp+n[n.length-1].timestamp,data:t.data}},n}(h);var b=function(t){function n(n){var i=t.call(this,n)||this;i.t=i.options.start;var r={xFunction:n.xFunction,yFunction:n.yFunction,start:n.start,end:n.end,step:n.step};return i.options=Object.freeze(r),i.numberOfPoints=Math.ceil(Math.abs(r.end-r.start)/r.step),i}return i(n,t),n.prototype.setXFunction=function(t){return new n(r(r({},this.options),{xFunction:t}))},n.prototype.setYFunction=function(t){return new n(r(r({},this.options),{yFunction:t}))},n.prototype.setStart=function(t){return new n(r(r({},this.options),{start:t}))},n.prototype.setEnd=function(t){return new n(r(r({},this.options),{end:t}))},n.prototype.setStep=function(t){return new n(r(r({},this.options),{step:t}))},n.prototype.getPointCount=function(){return this.numberOfPoints},n.prototype.generateDataPoint=function(){var t={x:this.options.xFunction(this.t),y:this.options.yFunction(this.t)};return this.t=this.t+this.options.step,t},n.prototype.infiniteReset=function(t,n){return{x:t.x,y:t.y}},n}(h),l={numberOfSamples:1e3,sampleSize:10,variation:10,frequencyStability:1,narrowFactor1:8,narrowFactor2:24};var y=function(t){function n(n){var i=t.call(this,n)||this,r={sampleSize:void 0!==n.sampleSize?n.sampleSize:l.sampleSize,numberOfSamples:void 0!==n.numberOfSamples?n.numberOfSamples:l.numberOfSamples,variation:void 0!==n.variation?n.variation:l.variation,frequencyStability:void 0!==n.frequencyStability?n.frequencyStability:l.frequencyStability,narrowFactor1:void 0!==n.narrowFactor1?n.narrowFactor1:l.narrowFactor1,narrowFactor2:void 0!==n.narrowFactor2?n.narrowFactor2:l.narrowFactor2};return i.options=Object.freeze(r),i}return i(n,t),n.prototype.setNumberOfSamples=function(t){return new n(r(r({},this.options),{numberOfSamples:t}))},n.prototype.setSampleSize=function(t){return new n(r(r({},this.options),{sampleSize:t}))},n.prototype.setVariation=function(t){return new n(r(r({},this.options),{variation:t}))},n.prototype.setFrequencyStability=function(t){return new n(r(r({},this.options),{frequencyStability:t}))},n.prototype.setNarrowFactor1=function(t){return new n(r(r({},this.options),{narrowFactor1:t}))},n.prototype.setNarrowFactor2=function(t){return new n(r(r({},this.options),{narrowFactor2:t}))},n.prototype.getPointCount=function(){return this.options.numberOfSamples},n.prototype.generateDataPoint=function(t){for(var n=100,i=this.options.variation,r=this.options.sampleSize,e=this.options.frequencyStability,s=r/8,u=r/2,h=new Array(r),o=0;o<r;o++)h[o]=10;var f,a,c,v,w=r/2;(s+=(Math.random()-.5)*i/e/100*r/2)<0&&(s=0),s>r&&(s=r),(u+=(Math.random()-.5)*i/e/100*r)<0&&(u=0),u>r&&(u=r);var m,p=n/3*2,b=p/(w*w)*this.options.narrowFactor1,l=50/(w*w)*this.options.narrowFactor2;for(o=0;o<r;o++)(f=p-(c=.8*o-s)*c*b)<0&&(f=0),f>n&&(f=n),(a=50-(v=.8*o-u)*v*l)<0&&(a=0),a>n&&(a=n),m=f+a,m+=m*(Math.random()-.5)*i/10,h[o]=(h[o]+m)/2,h[o]<0&&(h[o]=0),h[o]>n&&(h[o]=n),h[o]=.02*h[o];return h},n.prototype.infiniteReset=function(t,n){return t.slice()},n}(h);return t.DataGenerator=h,t.DataHost=u,t.Stream=s,t.createDeltaFunctionGenerator=function(){return new w({numberOfPoints:1e3,minGap:1,maxGap:-1,minAmplitude:.1,maxAmplitude:1,probability:.02})},t.createOHLCGenerator=function(){return new v({numberOfPoints:1e3,startTimestamp:0,dataFreq:1,start:100,volatility:.1})},t.createParametricFunctionGenerator=function(){return new b({xFunction:function(t){return 3*Math.cos(3*t)},yFunction:function(t){return 3*Math.sin(4*t)},start:0,end:1e3,step:.5})},t.createProgressiveFunctionGenerator=function(){return new a({samplingFunction:function(t){return t*t},start:0,end:100,step:1})},t.createProgressiveRandomGenerator=function(){return new o({numberOfPoints:1e3,offsetStep:10,offsetDeltaMax:.3,offsetDeltaMin:.1,dataMax:.5})},t.createProgressiveTraceGenerator=function(){return new f({numberOfPoints:1e3})},t.createSampledDataGenerator=function(){return new p({inputData:[],samplingFrequency:50,step:0})},t.createSpectrumDataGenerator=function(){return new y(l)},t.createTraceGenerator=function(){return new c({numberOfPoints:1e3})},t.createWhiteNoiseGenerator=function(){return new m({numberOfPoints:1e3})},Object.defineProperty(t,"h",{value:!0}),t}({}); |
@@ -795,2 +795,113 @@ 'use strict'; | ||
var defaultOptions = { | ||
numberOfSamples: 1000, | ||
sampleSize: 10, | ||
variation: 10.0, | ||
frequencyStability: 1.0, | ||
narrowFactor1: 8.0, | ||
narrowFactor2: 24.0 | ||
}; | ||
function createSpectrumDataGenerator() { | ||
return new SpectrumDataGenerator(defaultOptions); | ||
} | ||
var SpectrumDataGenerator = (function (_super) { | ||
__extends(SpectrumDataGenerator, _super); | ||
function SpectrumDataGenerator(args) { | ||
var _this = _super.call(this, args) || this; | ||
var opts = { | ||
sampleSize: args.sampleSize !== undefined ? args.sampleSize : defaultOptions.sampleSize, | ||
numberOfSamples: args.numberOfSamples !== undefined ? args.numberOfSamples : defaultOptions.numberOfSamples, | ||
variation: args.variation !== undefined ? args.variation : defaultOptions.variation, | ||
frequencyStability: args.frequencyStability !== undefined ? args.frequencyStability : defaultOptions.frequencyStability, | ||
narrowFactor1: args.narrowFactor1 !== undefined ? args.narrowFactor1 : defaultOptions.narrowFactor1, | ||
narrowFactor2: args.narrowFactor2 !== undefined ? args.narrowFactor2 : defaultOptions.narrowFactor2 | ||
}; | ||
_this.options = Object.freeze(opts); | ||
return _this; | ||
} | ||
SpectrumDataGenerator.prototype.setNumberOfSamples = function (numberOfSamples) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { numberOfSamples: numberOfSamples })); | ||
}; | ||
SpectrumDataGenerator.prototype.setSampleSize = function (sampleSize) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { sampleSize: sampleSize })); | ||
}; | ||
SpectrumDataGenerator.prototype.setVariation = function (variation) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { variation: variation })); | ||
}; | ||
SpectrumDataGenerator.prototype.setFrequencyStability = function (frequencyStability) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { frequencyStability: frequencyStability })); | ||
}; | ||
SpectrumDataGenerator.prototype.setNarrowFactor1 = function (narrowFactor1) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { narrowFactor1: narrowFactor1 })); | ||
}; | ||
SpectrumDataGenerator.prototype.setNarrowFactor2 = function (narrowFactor2) { | ||
return new SpectrumDataGenerator(__assign(__assign({}, this.options), { narrowFactor2: narrowFactor2 })); | ||
}; | ||
SpectrumDataGenerator.prototype.getPointCount = function () { | ||
return this.options.numberOfSamples; | ||
}; | ||
SpectrumDataGenerator.prototype.generateDataPoint = function (iPoint) { | ||
var m_dInitialValue = 10.0; | ||
var m_dMax = 100; | ||
var m_dMin = 0; | ||
var m_dVariation = this.options.variation; | ||
var m_iRowLength = this.options.sampleSize; | ||
var m_dFrequencyStability = this.options.frequencyStability; | ||
var m_dPeak1X = m_iRowLength / 8.0; | ||
var m_dPeak2X = m_iRowLength / 2.0; | ||
var aNewData = new Array(m_iRowLength); | ||
for (var i = 0; i < m_iRowLength; i++) | ||
aNewData[i] = m_dInitialValue; | ||
var dHalf = m_iRowLength / 2.0; | ||
m_dPeak1X += (Math.random() - 0.5) * m_dVariation / m_dFrequencyStability / 100.0 * m_iRowLength / 2.0; | ||
m_dPeak2X += (Math.random() - 0.5) * m_dVariation / m_dFrequencyStability / 100.0 * m_iRowLength; | ||
if (m_dPeak1X < 0) | ||
m_dPeak1X = 0; | ||
if (m_dPeak1X > m_iRowLength) | ||
m_dPeak1X = m_iRowLength; | ||
if (m_dPeak2X < 0) | ||
m_dPeak2X = 0; | ||
if (m_dPeak2X > m_iRowLength) | ||
m_dPeak2X = m_iRowLength; | ||
var dNewValue1; | ||
var dNewValue2; | ||
var dX1; | ||
var dX2; | ||
var dPeakY1 = m_dMax / 3.0 * 2.0; | ||
var dPeakY2 = m_dMax / 2.0; | ||
var dNarrowFactor1 = this.options.narrowFactor1; | ||
var dNarrowFactor2 = this.options.narrowFactor2; | ||
var dA1 = dPeakY1 / (dHalf * dHalf) * dNarrowFactor1; | ||
var dA2 = dPeakY2 / (dHalf * dHalf) * dNarrowFactor2; | ||
var dSum12; | ||
for (var i = 0; i < m_iRowLength; i++) { | ||
dX1 = 0.8 * i - m_dPeak1X; | ||
dX2 = 0.8 * i - m_dPeak2X; | ||
dNewValue1 = dPeakY1 - dX1 * dX1 * dA1; | ||
if (dNewValue1 < m_dMin) | ||
dNewValue1 = m_dMin; | ||
if (dNewValue1 > m_dMax) | ||
dNewValue1 = m_dMax; | ||
dNewValue2 = dPeakY2 - dX2 * dX2 * dA2; | ||
if (dNewValue2 < m_dMin) | ||
dNewValue2 = m_dMin; | ||
if (dNewValue2 > m_dMax) | ||
dNewValue2 = m_dMax; | ||
dSum12 = dNewValue1 + dNewValue2; | ||
dSum12 = dSum12 + dSum12 * (Math.random() - 0.5) * m_dVariation / 10.0; | ||
aNewData[i] = (aNewData[i] + dSum12) / 2.0; | ||
if (aNewData[i] < m_dMin) | ||
aNewData[i] = m_dMin; | ||
if (aNewData[i] > m_dMax) | ||
aNewData[i] = m_dMax; | ||
aNewData[i] = aNewData[i] * 0.02; | ||
} | ||
return aNewData; | ||
}; | ||
SpectrumDataGenerator.prototype.infiniteReset = function (dataToReset, data) { | ||
return dataToReset.slice(); | ||
}; | ||
return SpectrumDataGenerator; | ||
}(DataGenerator)); | ||
exports.DataGenerator = DataGenerator; | ||
@@ -806,4 +917,5 @@ exports.DataHost = DataHost; | ||
exports.createSampledDataGenerator = createSampledDataGenerator; | ||
exports.createSpectrumDataGenerator = createSpectrumDataGenerator; | ||
exports.createTraceGenerator = createTraceGenerator; | ||
exports.createWhiteNoiseGenerator = createWhiteNoiseGenerator; | ||
//# sourceMappingURL=xydata.js.map |
{ | ||
"name": "@arction/xydata", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "A random data generation library.", | ||
@@ -44,21 +44,21 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/chai": "^4.2.11", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^13.9.8", | ||
"@wessberg/rollup-plugin-ts": "^1.2.23", | ||
"@types/chai": "^4.2.14", | ||
"@types/mocha": "^8.0.4", | ||
"@types/node": "^14.14.10", | ||
"@wessberg/rollup-plugin-ts": "^1.3.8", | ||
"chai": "^4.2.0", | ||
"del": "^5.1.0", | ||
"del": "^6.0.0", | ||
"gulp": "^4.0.2", | ||
"gulp-mocha": "^7.0.2", | ||
"gulp-sourcemaps": "^2.6.5", | ||
"gulp-terser": "^1.2.0", | ||
"gulp-sourcemaps": "^3.0.0", | ||
"gulp-terser": "^2.0.0", | ||
"gulp-tslint": "^8.1.4", | ||
"mocha": "^7.1.1", | ||
"rollup": "^2.3.2", | ||
"mocha": "^8.2.1", | ||
"rollup": "^2.34.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-sourcemaps": "^0.5.0", | ||
"ts-node": "^8.8.1", | ||
"tslint": "^6.1.1", | ||
"typedoc": "^0.17.3", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"ts-node": "^9.0.0", | ||
"tslint": "^6.1.3", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^3.8.3" | ||
@@ -65,0 +65,0 @@ }, |
@@ -115,2 +115,3 @@ # XYData generator library | ||
| White Noise | Generate white noise. | | ||
| Spectrum Data | Generate spectrum data. | | ||
@@ -117,0 +118,0 @@ ## Development instructions |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
440238
2594
135