Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@redsift/d3-rs-svg

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redsift/d3-rs-svg

Creates a SVG element using D3v4.

  • 0.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
613
decreased by-24.79%
Maintainers
1
Weekly downloads
 
Created
Source

d3-rs-svg

d3-rs-svg is a component for creating a SVG 1.1 root element that is compatable with the D3 margin convention. This component is dependent on D3 v4 (Alpha).

Builds

Circle CI

UMD from //static.redsift.io/reusable/d3-rs-svg/latest/d3-rs-svg.umd-es2015.min.js

Usage

Browser

<script src="//static.redsift.io/reusable/d3-rs-svg/latest/d3-rs-svg.umd-es2015.min.js"></script>
<script>
	var svg = d3_rs_svg.html();
	...
</script>

ES6

import * as svg from "@redsift/d3-rs-svg";
let eml = svg.html();
...

If using rollup.js for a browser target, ensure d3-rs-svg is part of the global map.

Require

var svg = require("@redsift/d3-rs-svg");
var eml = svg.html();
...

By convention, the SVG element is meant to be hosted in a HTML node, hence svg.html()

Parameters

NameDescriptionTransition
width,heightSVG viewport size, pxY
scaleSVG scaling factor, floating pointY
marginmargin convention, Object or integer pxY
classedSVG custom classN
styleSVG CSS embedN
backgroundRect background colorY
titleN
rolehttps://www.w3.org/TR/wai-aria/roles#imgN

Parameters that support transition can be animated and chained.

d3.select('#elm')
	.call(svg)					// draw the SVG at default (1x) scale
.transition().duration(1000)
	.call(svg.scale(2.0))		// scale the SVG by 2x
.transition().duration(333)
	.call(svg.scale(1.0))		// bounce back after 333ms

Note, this form of chaining does not work for parameters that do not support transition. Use the on('end', ... event for them.

var el = d3.select('#elm')
	.call(svg.style('rect{fill: yellow;}'));

el.select(svg.self()).select(svg.child())
  	.append('rect')				// add a rect to the SVG we can paint with CSS
    	.attr('width', svg.childWidth())
    	.attr('height', svg.childHeight());

el.transition().delay(1000).duration(0).on('end', function() {
	 el.transition().duration(1000).delay(500)
      	.call(svg.scale(2.0).style('rect{fill: green;}'));	// this green is applied after 1s of delay but 500ms before the scale changes
});

Accessible features

This module implements some of the features described here.

Keywords

FAQs

Package last updated on 11 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc