0.1.0 • Published 3 years ago

d3-exporter v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

d3-exporter

A D3.js plugin for exporting animations.

Installation

npm install d3-exporter

Getting Started

import * as d3 from 'd3';
import Exporter from 'd3-exporter';

(async function() {
    const width = window.innerWidth;
    const height = window.innerHeight;
    const radius = 50;

    const svg = d3.create('svg')
        .attr('viewBox', [0, 0, width, height])
        .style('height', '100%')
        .style('width', '100%')

    svg.append('circle')
        .attr('cx', width / 2 - radius / 2)
        .attr('cy', height / 2 - radius / 2)
        .style('fill', '#000')
        .transition()
            .duration(1000)
            .ease(d3.easeCubicOut)
            .attrTween('r', () => d3.interpolate(0, radius))

    document.body.appendChild(svg.node());
    await Exporter.sequence(svg);
})();

API

Exporter.render(element, options: RenderOptions) : []Blob

Renders a frame sequence and returns an array of image blobs.

RenderOptions

An object of options to pass into Exporter.render.

FieldTypeDefault ValueDescription
frameCountNumber60The number of frames to run the exporter for.
frameRateNumber60The frame rate of the exporter.
backgroundColorString#FFFA background color for the exported image.

Exporter.sequence(element, options: SequenceOptions)

Exports a frame sequence from a D3 animation.

SequenceOptions

An object of options to pass into Exporter.sequence.

FieldTypeDefault ValueDescription
imageTypeStringjpegA file format for the image output.
frameCountNumber60The number of frames to run the exporter for.
frameRateNumber60The frame rate of the exporter.
backgroundColorString#FFFA background color for the exported image.

Exporter.frame(element, options: FrameOptions)

Exports a frame from a D3 animation.

FrameOptions

An object of options to pass into Exporter.frame.

FieldTypeDefault ValueDescription
imageTypeStringjpegA file format for the image output.
frameIndexNumber0The frame index to export.
frameCountNumberframeIndex + 1The number of frames to run the exporter for.
frameRateNumber60The frame rate of the exporter.
backgroundColorString#FFFA background color for the exported image.

Author

Kazi Jawad

Acknowledgements

html-to-image

0.1.0

3 years ago

0.0.1

4 years ago