venn.js: Area Proportional Venn and Euler Diagrams in JavaScript

venn.js: Area Proportional Venn and Euler Diagrams in JavaScript

Summary

venn.js is a JavaScript library designed for creating area-proportional Venn and Euler diagrams. It offers both a managed D3-based rendering approach and a flexible layout function for custom implementations. This library is a maintained fork, providing robust tools for visualizing set intersections.

Repository Info

Updated on March 10, 2026
View on GitHub

Tags

Click on any tag to explore related repositories

Introduction

venn.js is a powerful JavaScript library for generating area-proportional Venn and Euler diagrams. Maintained by upsetjs, it builds upon the original venn.js project, offering a robust solution for visualizing relationships and overlaps between sets. This library is ideal for data visualization tasks requiring clear and accurate representation of set theory concepts.

Installation

To integrate venn.js into your project, you can easily install it via npm:

npm install --save @upsetjs/venn.js

Examples

venn.js provides two primary modes of operation: managed usage with D3.js for direct rendering, and manual usage as a layout library for custom rendering.

Managed Usage with D3.js

For quick integration, the VennDiagram function handles the rendering using D3.js. You define your sets and their intersection sizes, and the library calculates and displays the diagram.

const sets = [
  { sets: ['A'], size: 12 },
  { sets: ['B'], size: 12 },
  { sets: ['A', 'B'], size: 2 },
];
const chart = venn.VennDiagram();
d3.select('#venn').datum(sets).call(chart);

You can explore various examples, including simple layouts, custom styling, dynamic diagrams, and interactive elements with tooltips.

Manual Usage for Custom Rendering

For greater control, venn.js can be used purely as a layout engine. The venn.layout method computes the necessary data, which you can then render using D3.js, HTML Canvas, or any other visualization library.

const sets = [
  { sets: ['A'], size: 12 },
  { sets: ['B'], size: 12 },
  { sets: ['A', 'B'], size: 2 },
];
const data = venn.layout(sets);
// ... custom D3 or Canvas rendering logic ...

This approach offers maximum flexibility for advanced use cases.

Why Use

venn.js stands out for its ability to generate accurate area-proportional Venn and Euler diagrams, which are crucial for clear data representation. Its integration with D3.js simplifies rendering, while the manual layout option provides extensive customization possibilities. The library is well-documented and actively maintained, making it a reliable choice for developers needing sophisticated set visualization tools.

Links