d3plus-export

Export methods for transforming and downloading SVG.

Usage no npm install needed!

<script type="module">
  import d3plusExport from 'https://cdn.skypack.dev/d3plus-export';
</script>

README

d3plus-export

NPM Release Build Status Dependency Status Gitter

Export methods for transforming and downloading SVG.

Installing

If you use NPM, npm install d3plus-export. Otherwise, download the latest release. You can also load d3plus-export as a standalone library or as part of D3plus. ES modules, AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3plus global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3plus-export@1"></script>
<script>
  console.log(d3plus);
</script>

API Reference

  • dom2canvas - Renders HTML/SVG elements to a shared canvas.
  • htmlPresets - Adds HTML default styles to a d3 selection in order to render it properly.
  • saveElement - Downloads an HTML Element as a bitmap PNG image.
  • svgPresets - Adds SVG default attributes to a d3 selection in order to render it properly.

d3plus.dom2canvas(elem, [options]) <>

Renders HTML/SVG elements to a shared canvas.

This is a global function.

Param Type Default Description
elem HTMLElement | Object | Array The element or array of elements to be rendered to a single canvas. Additionally, a complex object can be passed as an element which can contain specific other properties.
[elem.x] Number The x offset of the element within the rendered canvas.
[elem.y] Number The y offset of the element within the rendered canvas.
[options] Object Additional options to specify.
[options.background] String Background color of the rendered canvas.
[options.callback] function Callback function to be passed the canvas element after rendering.
[options.canvas] HTMLElement A canvas DOM element to draw onto. If no element is supplied, a canvas element will be created in memory and passed to the callback function when drawing is complete.
[options.excludes] Array An array of HTMLElement objects to be excluded from the render.
[options.height] Number Pixel height for the final output. If a height value has not been passed, it will be inferred from the sizing of the first DOM element passed.
[options.padding] Number 0 Outer padding for the final file.
[options.scale] Number 1 Scale for the final file.
[options.width] Number Pixel width for the final output. If a width value has not been passed, it will be inferred from the sizing of the first DOM element passed.

d3plus.htmlPresets(selection) <>

Adds HTML default styles to a d3 selection in order to render it properly.

This is a global function.


d3plus.saveElement(elem, [options], [renderOptions]) <>

Downloads an HTML Element as a bitmap PNG image.

This is a global function.

Param Type Default Description
elem HTMLElement | Array A single element or array of elements to be saved to one file.
[options] Object Additional options to specify.
[options.filename] String "download" Filename for the downloaded file, without the extension.
[options.type] String "png" File type of the saved document. Accepted values are "png" and "jpg".
[renderOptions] Object Custom options to be passed to the dom2canvas function.

d3plus.svgPresets(selection) <>

Adds SVG default attributes to a d3 selection in order to render it properly.

This is a global function.


Documentation generated on Wed, 18 Aug 2021 18:30:17 GMT