npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-venn

v0.2.3

Published

Small package to create two-ring, area-proportional Venn diagrams.

Downloads

2

Readme

simple-venn

View the examples

simple-venn is a tiny JavaScript library for area-proportional, two-ringed Venn diagrams. A lot of the math in this library is pulled from benfred's Venn.js library - a great library for Venn diagrams with 3+ sets, but overkill for what I needed.

simple-venn was created with the end goal of giving developers access to the underlying dimensions of the Venn diagram. In the /examples directory, you'll see that simple-venn can be used with canvas or regular divs. I personally made it to be used with regl. It should give you all the math to position the sets as you see fit.

However I wanted simple-venn to be...simple. So it has some built-in drawing functionality using canvas. This way it's super easy to get drawing Venn diagrams:

<!DOCTYPE html>
<html>
<head>
  <title>SimpleVenn</title>
</head>
<body></body>

<script src="simple-venn.dist.js"></script>
<script>
  var aSet = 120000;
  var bSet = 120000;
  var uSet = 60000;
  var scale = 0.5;
  // Appends canvas element to body and draws Venn
  new SimpleVenn(aSet, bSet, uSet, scale).draw();
</script>

</html>

API

Constructor

new SimpleVenn(aSetCount, bSetCount, uSetCount, scale)

| parameter | type | details | | --- | --- | --- | | aSetCount | Number | Value for set A | | bSetCount | Number | Value for set B | | uSetCount | Number | Value for set intersection | | scale (optional) | Number | Set area is determined by count and scaled up or down by this scale factor (default: 1) |

Each parameter can be accessed and updated directly from the returned SimpleVenn object.

let venn = new SimpleVenn(4, 4, 2);
console.log(venn.scale); // 1
venn.scale = 2;
console.log(venn.scale); // 2

Computed Properties

Besides the four initial properties, all other properties are computed when accessed.

| property | description | | --- | --- | | aSetArea | The area of set A | | bSetArea | The area of set B | | uSetArea | The area of set intersection | | aSetRadius | The radius of set A | | bSetRadius | The radius of set B | | aSetDiameter | The diameter of set A | | bSetDiameter | The diameter of set B | | setDistance | The approximate distance between the center of set A and the center of set B so the overlap area is proportional to the overlap value | | aSetIntersectDist | The distance from the center of set A to the point of intersection between the two sets | | bSetIntersectDist | The distance from the center of set B to the point of intersection between the two sets |

Methods

SimpleVenn.draw(selector, options);

While this library is more about the math of Venn diagrams (so you can do what you want with the results), this is a method that will just draw it for you.

| parameter | type | details | | --- | --- | --- | | selector (optional) | String | Selector for the element the Venn diagram will be appended to or the canvas object the diagram will be drawn on | | options (optional) | Object | An object specifying styles for the Venn diagram |

If a selector is not provided, simple-venn will append a canvas element to the body of the document, sized to the full viewport size. If the selected element is a canvas element, simple-venn will draw the diagram on the canvas element. Otherwise simple-venn will append a canvas element to the selected element that is the full size of the element. Under the hood, simple-venn uses querySelectorAll and will try to draw to all matches.

The options object will look for these properties:

| property | Type | description | | --- | --- | --- | | aSetColor (optional) | String | The color of set A (default: '#00F') | | bSetColor (optional) | String | The color of set B (default: '#0F0') | | opacity (optional) | Number | The opacity of each set (default: 0.5) |

Recommended use:

<div id="venn" style="width: 500px; height: 500px;"></div>

<script>
const venn = new SimpleVenn(60000, 60000, 30000);
venn.draw('#venn');
</script>

Contributing

Please do! As long as you're cool about it (no jerks). Feel free to file an issue for bugs and feature requests. Before working on a PR, it might be good to check if it's needed in the library. It could certainly use some math review, optimizations, and testing.

License

MIT