Published
Edited
Apr 4, 2021
4 forks
Importers
46 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
example_duration = 3000 // Animation duration in milliseconds
Insert cell
Insert cell
{
// Fetch us our draw callback.
// This particular example function always reuses and updates the same SVG element.
const drawFrame = example_createAnimation();
while(true) {
// Use a duration of 2 seconds, loop back to 0 when t reaches 1.
const t = Date.now() / example_duration % 1;
// Yield the element returned by the draw callback.
yield drawFrame(t);
}
}
Insert cell
Insert cell
Insert cell
// Await button press.
example_start_render1,
// Actual cell content.
renderGif(invalidation, example_createAnimation(), example_duration)
Insert cell
Insert cell
Insert cell
{
// Await button press.
example_start_render2;
// This draw callback always returns the same element, allowing us to reuse it
// in the preview option.
const drawFrame = example_createAnimation();
return renderGif(
// Invalidation promise. Required.
invalidation,
// Render callback. Required.
drawFrame,
// Duration in milliseconds. Required.
example_duration,
// Additional options. None of these are required.
{
// Frames per seconds, defaults to 30.
fps: 40,
// Preview element, placeholder that gets displayed during rendering.
// Tip: Pass in an updating canvas or SVG element to get a "live" preview.
preview: drawFrame(0),
// Defaults to `observable-${timestamp}`;
filename: `example-gif-${+Date.now()}`,
// Update interval during rendering. Defaults to 500.
// Set to a lower value if your browser freezes.
interval: 200,
// Pause in milliseconds to add to the end of the gif. Defaults to 0.
pause: 0,
// Low-level options which get passed into GifConverter and gif.js.
// While these are gif.js options, it is recommended to only pass in
// the options listed below.
converterOptions: {
// Number of workers. GifConverter defaults this to the max. supported hardware concurrency.
workers: 1,
// Palette sampling interval in pixels. Defaults to 10.
// Lower is better, but also slower.
quality: 15,
// Palette dithering, defaults to false (no dithering).
dither: 'FalseFloydSteinberg',
}
}
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
await visibility();
const composer = new Composer(invalidation).fps(30);
const converter = new GifConverter(invalidation);
composer.frame(renderDemo({...renderPreset, width:620,height:320,updateInterval: 5, dpr: 1}));
composer.pause(750);
const data = await converter.convert(await composer.getFrames()).promise;
const url = URL.createObjectURL(data.blob);
return html`<img src="${url}">`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more