A random data generation library.
npm install @arction/xydatanpm install --save @arction/xydata
ts
import { createProgressiveRandomGenerator } from '@arction/xydata'
// create new instance of progressive random generator
createProgressiveRandomGenerator()
// define that 1000 points should be generated
.setNumberOfPoints(1000)
// generate those 1000 points
.generate()
// set stream to progress every 250 milliseconds
.setStreamInterval(250)
// set stream to output 10 points at a time
.setStreamBatchSize(10)
// make the stream infinite
.setStreamRepeat(true)
// create a new stream with previously defined stream settings
.toStream()
// every time the stream outputs data, run this function on each of the data points
.forEach(data=>{
console.log(data)
})
`
This creates a basic progressive random generator and uses the Stream API to output the data to console.
> Note: You should newer create a new instance of any generator using the new keyword. Generators should only be created with the create... functions.
When calling .generate() on any data generator a new instance of a 'DataHost' is returned. The .generate() function can be called multiple times to get a new set of data with same settings as before but different values each time.
$3
You can call .generate() function multiple times to get new sets of data.
`ts
import { createTraceGenerator } from '@arction/xydata'
const generator = createTraceGenerator()
const dataSet1 = generator.generate()
const dataSet2 = generator.generate()
`
This would give you two different data sets that have been generated based on same settings but which will have different values.
$3
When a data generator is created it has some default settings based on which generator it is. To change any of these settings call .set.... function that will create a new data generator with that setting changed. You can't change multiple settings with a single call or change settings of a generator that has been created previously. A change in settings will always result in a new generator.
`ts
import { createTraceGenerator } from '@arction/xydata'
const generator = createTraceGenerator()
.setNumberOfPoints( 10 )
const derivedGenerator = generator.setNumberOfPoints( 20 )
const dataSet1 = derivedGenerator.generate()
const dataSet2 = generator.generate()
`
This would create two data sets with different values and settings. dataSet1 would have 20 data points and dataSet2 would have 10.
$3
The data sets have possibility to output the data as a stream of data. These streams can be used to alter the data in multiple steps.
`ts
import { createTraceGenerator } from '@arction/xydata'
createTraceGenerator()
.setNumberOfPoints( 10 )
.generate()
.toStream()
.map( value => ( { x:value.x, y: value.y * 2 } ) )
.forEach( value => console.log(value) )
`
This code would create a data generator and then stream that data through two functions, map and forEach.
The map function alters the data by multiplying the y value by 2 and then streams it to the forEach function.
The forEach function would log each invidual point to console.
The settings for the stream are set by the Data Host that is returned from the .generate()` function. The stream settings can't be changed