d3#interval TypeScript Examples
The following examples show how to use
d3#interval.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Stage.ts From anichart.js with MIT License | 5 votes |
private doPlay() {
if (!this.alreadySetup) this.setup();
if (this.interval) {
this.interval.stop();
this.interval = null;
} else if (typeof window === "undefined") {
// node
let f = 0;
const fs = require("fs");
while (f < this.totalFrames) {
this.render(f / this.options.fps);
const data = this.canvas.toBuffer("image/png");
const outDir = `out`;
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir);
}
const p = `${outDir}/${this.outputOptions.fileName}-${f}.png`;
fs.writeFileSync(p, data);
console.log(p);
f++;
}
} else if (this.output) {
let ffmpeg = createFFmpeg({
log: true,
corePath: "/ffmpeg-core.js",
});
loadffmpeg(ffmpeg).then(() => {
const partCount =
Math.floor(this.options.sec / this.outputOptions.splitSec) + 1;
let part = 0;
const parts: number[] = [];
while (part++ < partCount) {
parts.push(part);
}
eachSeries(parts, (p, callback) => {
const frames: number[] = [];
const picNameList: string[] = [];
while (
this.cFrame < this.totalFrames &&
this.cFrame < p * this.outputOptions.splitSec * this.options.fps
) {
this.cFrame++;
frames.push(this.cFrame);
}
eachLimit(frames, this.outputConcurrency, (f, cb) => {
this.cFrame = f;
this.render();
const no =
f - (p - 1) * this.outputOptions.splitSec * this.options.fps;
picNameList.push(`output-${no}.png`);
const imageData = this.renderer.getImageData();
addFrameToFFmpeg(ffmpeg, imageData, no).then(() => cb());
}).then(() => {
outputMP4(ffmpeg, this.options.fps).then(() => {
removePNG(ffmpeg, picNameList);
callback();
});
});
})
// tslint:disable-next-line:no-console
.then(() => console.log("finished!"));
});
} else {
this.interval = interval((elapsed) => {
if (this.output || this.mode === "output") {
this.cFrame++;
} else {
this.cFrame = Math.floor((elapsed / 1000) * this.options.fps);
}
this.render();
if (this.cFrame >= this.totalFrames) {
if (this.interval) {
this.interval.stop();
this.interval = null;
}
}
}, (1 / this.options.fps) * 1000);
}
}
Example #2
Source File: Stage.ts From anichart.js with MIT License | 5 votes |
interval: Timer | null;