Socket
Socket
Sign inDemoInstall

d3

Package Overview
Dependencies
3
Maintainers
1
Versions
273
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    d3

A small, free JavaScript library for manipulating documents based on data.


Version published
Weekly downloads
3.1M
increased by4.86%
Maintainers
1
Install size
48.3 MB
Created
Weekly downloads
 

Package description

What is d3?

D3.js (or just D3 for Data-Driven Documents) is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It helps in manipulating documents based on data and uses HTML, SVG, and CSS to bring data to life. D3's emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework.

What are d3's main functionalities?

Data Binding

D3 allows you to bind data to the DOM (Document Object Model), and then apply data-driven transformations to the document. In this code sample, we select paragraph elements and bind them to an array of numbers, setting their text content to the bound data.

const data = [1, 2, 3, 4];
const p = d3.select('body').selectAll('p').data(data).text(d => d);

Creating and Manipulating SVG

D3 can create and manipulate SVG elements for complex visualizations. This code sample creates an SVG element and appends a blue circle to it.

const svg = d3.select('body').append('svg').attr('width', 100).attr('height', 100);
svg.append('circle').attr('cx', 50).attr('cy', 50).attr('r', 40).style('fill', 'blue');

Dynamic Properties and Transitions

D3 makes it easy to apply dynamic styles and transitions to elements. Here, all circles in the document are transitioned to a red fill color over 750 milliseconds.

d3.selectAll('circle').transition().duration(750).style('fill', 'red');

Data-Driven Document Transformations

D3 can load external data sources like CSV files and use them to drive document transformations. In this example, data from a CSV file is used to create and append paragraph elements to the body of the document.

d3.csv('data.csv').then(data => {
  d3.select('body').selectAll('p').data(data).enter().append('p').text(d => d.value);
});

Interactivity and Event Handling

D3 provides powerful event handling for interactive visualizations. This code sample adds a click event listener to all paragraph elements, changing their background color to yellow when clicked.

d3.select('body').selectAll('p').on('click', function(event, d) {
  d3.select(this).style('background-color', 'yellow');
});

Other packages similar to d3

Readme

Source

D3

D3 is a small, free JavaScript library for manipulating HTML documents based on data. D3 can help you quickly visualize your data as HTML or SVG, handle interactivity, and incorporate smooth transitions and staged animations into your pages. You can use D3 as a visualization framework (like Protovis), or you can use it to build dynamic pages (like jQuery).

Browser Support

D3 should work on any browser, with minimal requirements such as JavaScript and the W3C DOM API. By default D3 requires the Selectors API Level 1, but you can preload Sizzle for compatibility with older browsers. Some of the included D3 examples use additional browser features, such as SVG and CSS3 Transitions. These features are not required to use D3, but are useful for visualization! D3 is not a compatibility layer. The examples should work on Firefox, Chrome (Chromium), Safari (WebKit), Opera and IE9.

Note: Chrome has strict permissions for reading files out of the local file system. Some examples use AJAX which works differently via HTTP instead of local files. For the best experience, load the D3 examples from your own machine via HTTP. Any static file web server will work; for example you can run Python's built-in server:

python -m SimpleHTTPServer 8888

Once this is running, go to: http://localhost:8888/examples/

Development Setup

This repository should work out of the box if you just want to create new visualizations using D3. On the other hand, if you want to extend D3 with new features, fix bugs, or run tests, you'll need to install a few more things.

D3's test framework uses Vows, which depends on Node.js and NPM. If you are developing on Mac OS X, an easy way to install Node and NPM is using Homebrew:

brew install node
brew install npm

Next, from the root directory of this repository, install D3's dependencies:

npm install

You can see the list of dependencies in package.json. The packages will be installed in the node_modules directory.

Keywords

FAQs

Last updated on 12 Sep 2011

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc