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

hyper-venn

v0.0.34

Published

Renders 3-, 5-, and 7-set pseudo-Venn diagrams

Downloads

1

Readme

hyper-venn

A D3 plugin for rendering 3-, 5-, and 7-set Venn diagrams[^todo-setcounts]. Though, using this plug-in for 3-set diagrams is a bit unnecessary - this was included as a baseline for development purposes. I wrote this package because I was looking for a 5-set Venn diagram in D3 and came across this repo. I thought the main drawing component could be done a little more thoroughly. (Perhaps ironically, I haven't fully fleshed that functionality out in this plugin, but the objects are all there.)

The base obloids are sourced from this waaaaaaaay more powerful R package and the objects used to render the intersection paths can be found in the /test/var/ directory.

And, finally, the package was structured following the guidance outlined here.

Note: throughout this document I will use the term "obloid" to refer to concave / non-elliptical shapes.

Examples

3-set diagrams (by intersection on the left, by non-overlapping area on the right)

5-set diagrams (by intersection on the left, by non-overlapping area on the right)

5-set diagrams rendered with ellipses (by intersection on the left, by non-overlapping area on the right)

7-set diagrams (by intersection on the left, by non-overlapping area on the right)

Installing

If you use NPM, npm install hyper-venn. Otherwise, download the latest release.

API Reference

hyperVenn(data, [options])

The main function hyperVenn.hyperVenn(data, [options]) returns a method that will draw the SVG elements it renders. This function has one required input and one optional input.

data

Array of arrays or object of arrays representing sets to use in defining the intersections for the Venn diagram.

    ExampleDataAsObject = {
        "Purple": ["001", "002", "003", "004", "005"],
        "Blue": ["001", "002", "005", "007", "008"],
        "Green": ["001", "002", "003", "004", "0012"],
        "Orange": ["001", "002", "003", "006", "004"],
        "Red": ["001", "002", "003", "007", "008"],
        "Yellow": ["001", "002", "003", "005", "004"],
        "Cyan": ["001", "002", "003", "006", "008"],
        "Other": "Non-array properties will be ignored."
    };

or

    ExampleDataAsArray = [
        ["001", "002", "003", "004", "005"],
        ["001", "002", "005", "007", "008"],
        ["001", "002", "003", "004", "0012"],
        ["001", "002", "003", "006", "004"],
        ["001", "002", "003", "007", "008"],
        ["001", "002", "003", "005", "004"],
        ["001", "002", "003", "006", "008"]
    ];

options (optional)

Customizes behavior of hyperVenn(). The default options are:

    {
        width: 500,
        height: 500,
        tooltip: true,
        tooltipCallbackRenderer: _defaultTooltipCallbackRenderer /* Renders simple tooltip showing intersection label and contents. */,
        click: true,
        clickCallbackRenderer: _defaultClickCallbackRenderer /* Prints the intersection's label and contents to the console. */,
        hover: true,
        hoverCallbackRenderer: _defaultHoverCallbackRenderer /* Sets fill-opacity to 0.6, stroke-opacity to 1, and stroke-width to 4. */ ,
        useEllipses: false,
        useDistinctAreas: false,
        showLabels: true,
        labelStyle: "stroke:#ffffff;fill:#000000;stroke-width:0.25px;",
        labels: ["A", "B", "C", "D", "E", "F", "G"],
        colors: ["#6600ff", "#0099ff", "#00cc00", "#cc9900", "#ff0000", "#999999", "#009933"],
        style: "fill-opacity:0.05;stroke-width:1;stroke-opacity:1;stroke:#ffffff"
    }

| Option | Property Type | Description | | --- | --- | --- | | width | integer | If the D3 selection passed to the rendering function, returned from hyperVenn(), does not have a child svg selement, the renderer will add an svg element with this width.[^todo-width] | | height | integer | If the D3 selection passed to the rendering function, returned from hyperVenn(), does not have a child svg selement, the renderer will add an svg element with this height.[^todo-height] | | tooltip | boolean | If false, the tooltip callback function will not be added to the rendered paths. | | tooltipCallbackRenderer[^todo-callbacks] | (string, object) => {} | May render callback functions for mouseover, mouseout, and mousemove events (the event type is passed in the first parameter). The object passed in will be the relevant hyperVenn.intersections() object. This must return a function of the form () => {}. | | click | boolean | If false, the click callback function will not be added to the rendered paths. | | clickCallbackRenderer | (object) => {} | The object passed in will be the relevant hyperVenn.intersections() object. This must return a function of the form () => {}. | | hover | boolean | If false, the hover callback function will not be added to the rendered paths. | | hoverCallbackRenderer | (string, object) => {} | May render callback functions for mouseover, mouseout events (the event type is passed in the first parameter). The object passed in will be the relevant hyperVenn.intersections() object. This must return a function of the form () => {}. | | useEllipses | boolean | For 5-set data arrays. Set to true to use ellipses instead of obloids. | | useDistinctAreas | boolean | Set to true to render diagram as a collection of non-overlapping elements. By default, the paths will draw out the whole region of intersection. Consider the 3-set diagram. 1 or 2 or 3 middle "triangle" is part of the 1 or 2 set. Thus, by default, the rendered path for 1 or 2 includes that middle area. Setting this to true will render the path for 1 or 2 as 1 or 2 and not 3 (this only effects how the path is rendered; it does not effect calculations). | | showLabels | boolean | Set to false to hide the labels from the diagram. | | labelStyle | string | Allows for embedding specific CSS on the label elements. It is recommended to set this to '' and use CSS styling to style the elements. (Details on id and class attributes can be found in the hyperVenn.labels() documentation below.) | | labels | string[] | Allows for setting the data labels for array-type data. If a data object is used, it is recommended to set this to an empty array which will trigger the use of the object's properties as data labels. (Not following this recommendation will result in indeterminant behavior since the ordering of an object's keys is not guaranteed.[^todo-labels]) | | colors | string[] | Fill colors for the data sets themselves. (It is not possible to set the fill colors of intersection areas using this array.[^todo-colors]) | | style | string | Allows for embedding specific CSS on the path elements. It is recommended to set this to '' and use CSS styling to style the elements. (Details on id and class attributes can be found in the hyperVenn.paths() documentation below.) |

Other public functions

The other functions are used to access the internal data structures used by this drawing method to support implementing your own rendering method.

hyperVenn.intersections()

Returns the object representing all set intersections and original sets. The object is keyed using the name field described below. It includes an areas property that counts the number of areas in the diagram:

`intersections.areas = Object.keys(intersections).length - 1`

| Field | Field Type | Description | | --- | --- | --- | | name | string | Intersection naming convention. Example: S0n1n2 is the name for the intersection of the first three sets of data. Note: S0, S1, etc. are the original data sets and are included in this object. | | index | integer[] | Array representing the sets in the intersection. Example: [0,1,2] is the index for the intersection of the first three sets of data. Note: [0], [1], etc. are the original data sets and are included in this object. | | label | string | A pretty-print label defined by the data labels in options or the keys from the data object (as described in options.labels). Example: Green Blue is the intersection of sets Green and Blue. Note: The original data sets will have their respective labels (e.g. Green). | | array | variant[] | Array of elements in the intersection of relevant data sets. This array will contain elements of whatever type were in the data (integers, floats, strings, etc.). |

hyperVenn.paths()

Returns an array of objects used to render the paths (note: this includes circle and ellipse elements). Each object in the array will have the following fields:

| Field | Field Type | Description | | --- | --- | --- | | tag | string | HTML element type (path, circle, ellipse) | | attrs | object | Each property of attrs is described in the rest of this table. | | attrs.id | string | HTML element ID. This will be equivalent to the Name of the rendered intersection. | | attrs.index | string | Index of the rendered intersection. | | attrs.style | string | Style string as computed from options.style and options.colors. | | attrs.class | string | If the path represents a data set, the class is set. Otherwise, it is intersection. |

hyperVenn.labels()

Returns an array of objects used to render the labels (note: this includes data labels outside of the diagram). Each object in the array will have the following fields:

| Field | Field Type | Description | | --- | --- | --- | | tag | string | This will always be text. | | text | string | The text contained in the label. This will be the data sets's label or the intersection's size. | | attrs | object | Each property of attrs is described in the rest of this table. | | attrs.id | string | HTML element ID. This will be equivalent to the Name of the rendered intersection appended with Label (e.g. S0n1Label). | | attrs.index | string | Index of the rendered intersection. | | attrs.style | string | Style string as computed from options.labelStyle and options.colors. | | attrs.class | string | If the path represents a data set, the class is set-label. Otherwise, it is intersection-label. | | attrs.x | integer | The X-coordinate of the center of the text element. The renderer returned from hyperVenn(data, [options]) will offset the text element accordingly. | | attrs.y | integer | The Y-coordinate of the center of the text element. The renderer returned from hyperVenn(data, [options]) will offset the text element accordingly. |

hyperVenn.data()

This is either the passed-in 2D array of data, or the 2D array resulting by parsing the data object.

hyperVenn.options()

The amalgamation of default options and passed in options.

[^todo-setcounts]: TODO: Add paths for 4- and 6-set diagrams [^todo-width]: TODO: Apply transforms to rendered paths and texts to fit into non-default SVG sizes. [^todo-height]: TODO: Apply transforms to rendered paths and texts to fit into non-default SVG sizes. [^todo-callbacks]: TODO: Apply callbacks to labels as well. [^todo-labels]: TODO: Update options.labels to support callback function for calculating the label. [^todo-colors]: TODO: Update options.colors to support callback function for calculating the fill color. [^todo-style]: TODO: Update options.style to support callback function for calculating the style.