WorksMathematics
Eunoia: Area-Proportional Euler and Venn Diagrams in Rust, Julia, Python, R, and JavaScript
Abstract
Area-proportional Euler diagrams visualize sets and their intersections through regions whose areas represent their sizes. Because many set specifications have no exact geometric representation, constructing these diagrams requires numerical optimization and diagnostics that quantify the remaining discrepancies. Eunoia is a Rust library for fitting area-proportional Euler diagrams and constructing canonical Venn diagrams. It supports circles, ellipses, squares, and rectangles, computes region areas analytically, and provides exact analytical gradients for several shape families. Its fitting pipeline combines multidimensional scaling initialization with local refinement, global optimization when needed, and seeded restarts. Fitted layouts include residuals and goodness-of-fit statistics that help users assess how faithfully a diagram represents the data. Shared plotting routines extract region polygons, place labels, and pack unit glyphs and member names within regions. The same core implementation powers packages for R, Python, Julia, and JavaScript, a C interface, and a web application that fits diagrams entirely in the browser through WebAssembly. By centralizing fitting, geometry, diagnostics, and annotation in an independent library, Eunoia provides consistent set visualization across programming languages and interactive applications.
Statement of Need
Euler diagrams [3] depict relationships between sets, and area-proportional Euler diagrams do so quantitatively: the area of each region is proportional to the size of the corresponding set intersection. They are common in the life sciences, for instance, where researchers use them to compare gene and protein lists across conditions or studies. For most specifications involving three or more sets, however, no exact area-proportional diagram exists [14], and the diagram must instead be constructed numerically [1]. Fitting a diagram is therefore an optimization problem: choosing the shapes’ positions and parameters to minimize the discrepancy between fitted and requested intersection areas.
Existing alternatives offer different compromises. venneuler introduced multidimensional scaling (MDS) initialization followed by overlap-aware refinement (Wilkinson, [14]). venn.js improved that initialization and added exact area calculations (Frederickson, [4]). eulerAPE introduced ellipses for three-set diagrams (Micallef & Rodgers, [10]), and eulerr generalized them to any number of sets (Larsson & Gustafsson, [8]).
Eunoia extends eulerr by
replacing its fitting algorithm with a multistage method that combines local and global optimization,
supporting squares and rectangles, and
providing analytical gradients.
Eunoia serves researchers and others who need trustworthy proportional set visualizations in R, Python, Julia, JavaScript, Rust, or C. Developers can also embed its diagram fitter and visualizer in their own tools, including interactive web visualizations.
State of the Field
Table 1 compares Eunoia with representative area-proportional diagram fitters: venneuler (Wilkinson, [14]), eulerAPE (Micallef & Rodgers, [10]), venn.js (Frederickson, [4]), matplotlib-venn (Tretyakov, [13]), nVenn (Pérez-Silva et al., [11]), Edeap (Wybrow et al., [15]), and eulerr (Larsson & Gustafsson, [8]).
| Package | Algorithm | Shapes | Sets | Language |
| venneuler | Stress minimization | Circles | Any | Java, R |
| eulerAPE | Hill climbing | Ellipses | 3 | Java |
| venn.js | MDS + final layout | Circles | Any | JavaScript |
| matplotlib-venn | Analytic placement | Circles | 3 | Python |
| nVenn | Physics-based simulation | Polygons | Any | C++, R |
| Edeap | Hill climbing | Ellipses | Any | JavaScript |
| Eunoia | MDS + final layout | Circles, ellipses, squares, rectangles | Any | Rust, R, Julia, Python, C, JS |
Table 1. Related software for area-proportional Euler and Venn diagrams: fitting algorithm, supported shapes, maximum number of sets, and implementation language.
Eunoia is a separate library because eulerr’s C++ implementation was coupled to R and could not directly support WebAssembly and the other bindings. Centralizing fitting, diagnostics, and geometry in an independent Rust crate keeps the interfaces consistent and avoids duplicating this work across bindings.
Example
A diagram specification names the sets and their intersections and gives the size of each region. For example, in Rust:
use eunoia::geometry::shapes::Ellipse;
use eunoia::{DiagramSpecBuilder, Fitter, InputType};
let spec = DiagramSpecBuilder::new()
.set("SE", 13.0)
.set("Treat", 28.0)
.set("Anti-CCP", 101.0)
.set("DAS28", 91.0)
.intersection(&["SE", "Treat"], 1.0)
.intersection(&["SE", "DAS28"], 14.0)
.intersection(&["Treat", "Anti-CCP"], 6.0)
.intersection(&["SE", "Anti-CCP", "DAS28"], 1.0)
.input_type(InputType::Exclusive)
.build()
.unwrap();
let layout = Fitter::<Ellipse>::new(&spec).seed(1).fit().unwrap();
The four sets—SE, Treat, Anti-CCP, and DAS28—correspond to clinical variables in the rheumatoid arthritis data from Junta et al. [6]. The fitted layout is shown in Figure 1. Its diagError of indicates that the diagram reproduces the data essentially exactly. The figure also shows Eunoia’s automatic label placement: set labels and region quantities are positioned at poles of inaccessibility of the region polygons, with labels placed outside the diagram when they do not fit inside their regions.
Figure 1. A four-set Euler diagram fitted with ellipses, with region quantities shown. Eunoia fits it to a diagError of , an essentially exact diagram.
The bindings mirror this interface; the equivalent call in Python is:
import eunoia as eu
diagram = eu.euler(
{
"SE": 13,
"Treat": 28,
"Anti-CCP": 101,
"DAS28": 91,
"SE&Treat": 1,
"SE&DAS28": 14,
"Treat&Anti-CCP": 6,
"SE&Anti-CCP&DAS28": 1,
},
shape="ellipse",
)
The JavaScript, Julia, and R packages follow the same pattern.
Eunoia also constructs Venn diagrams, in which every intersection is drawn regardless of whether it is empty (Figure 2).
Figure 2. A canonical five-set Venn diagram drawn with ellipses.
Software Design
The library uses a trait-based design, with shapes selected at compile time. A given specification can be fitted with circles, ellipses, squares, or rectangles, as illustrated in Figure 3.
Figure 3. A three-set specification fitted with circles, ellipses, squares, and rectangles. Not every shape family can represent the input exactly: the diagError is for circles, for squares, and for rectangles, compared to for ellipses.
Fitting proceeds in two phases, roughly following the approach of venneuler (Wilkinson, [14]), venn.js (Frederickson, [4]), and the original eulerr package (Larsson & Gustafsson, [8]). The first phase uses multidimensional
scaling to place shapes of fixed size so that their pairwise distances approximate those required by the pairwise intersections. For disjoint and contained set pairs, it uses the relaxed loss suggested by Frederickson [4]. The second phase refines all shape parameters to minimize a loss computed from the differences between the fitted and requested region areas1. Eunoia computes region areas analytically for every shape. It finds ellipse intersections through a projective-conic construction [12] and computes the resulting overlaps from circular and elliptical segments in closed form [2]. For several shape families, the smooth losses have exact analytical gradients.
For shapes with analytical gradients, refinement begins with Levenberg-Marquardt least squares, with a bounded Levenberg-Marquardt retry if the loss remains above a threshold. If both local fits remain above the threshold, a bounded variant of CMA-ES [5] searches for another basin, which bounded Levenberg-Marquardt then polishes. Eunoia keeps the solution with the lowest loss. The pipeline uses several seeded restarts, which can run in parallel when the optional parallel feature is enabled (but remain serial in WebAssembly). For small set counts, one restart begins from a canonical Venn layout. Non-smooth losses—such as the maximum absolute region error—use derivative-free methods (Nelder–Mead or mesh-adaptive direct search) or can be replaced by a smooth surrogate.
Eunoia returns the fitted layout with its residuals, loss, and two goodness-of-fit statistics: stress, a venneuler-style normalized least-squares measure, and diagError, the maximum absolute difference between requested and fitted region shares. These diagnostics allow users to assess the diagram’s quality numerically. A plotting module extracts the region polygons through polygon clipping and computes label positions. The R, Python, Julia, and JavaScript packages use this output for rendering. The core has no dependency on any host language’s runtime and compiles to WebAssembly. The {link text}(https://eunoia) web app therefore fits diagrams entirely in the browser without a server.
Annotation and Interactivity
Area-proportional Euler diagrams encode the size of each set intersection as the area of a region. Eunoia adds three complementary features: unit glyphs show how many elements a region contains, member labels identify those elements, and interactive output reveals information about regions too small to annotate Figure 4.
Figure 4. A three-set Euler diagram fitted with ellipses, shown with glyphs (left) and member labels (right). Callouts identify members in regions too narrow for their names.
Glyphs
Glyphs are circular marks, one per data unit, packed inside their regions following the eulerGlyphs approach of Micallef et al. [9]. They can also be added to Venn diagrams. All glyphs in a diagram are the same size, so counts can be compared across regions. By default, Eunoia searches for the largest size that fits all the glyphs in every region. The placement routines also accept a fixed size and report any glyphs that do not fit. Glyphs can be kept clear of the diagram’s labels where space allows.
The shared placement routines offer four arrangements: a hexagonal grid (the default), a rectangular grid, an even, deterministic scatter, and a random scatter.
Member Labels
Member labels show the names of the elements in each region. The shared packing routine places each name individually inside its region and reduces all font sizes by the same factor when space is limited, down to a minimum size. Names that still do not fit are reported as unplaced.
Interactivity
The Python package provides an interactive Plotly backend through fit.plot_plotly(). Each region has a hover tooltip showing its intersection label, sample size, and members. These tooltips are primarily useful for dense multi-set diagrams, in which small regions cannot hold any text. The JavaScript SVG serializer similarly supports native tooltips and data attributes on each region, so host pages can add their own interaction. The web app provides controls for glyph mode, spacing, and styling.
Research Impact Statement
Eunoia descends from eulerr, which has been distributed on CRAN since 2016 and has been cited in over 700 academic publications2, predominantly in the life sciences. Since version 8.0, eulerr has used Eunoia in place of its C++ backend, so all current eulerr users also use Eunoia. Other packages depend on eulerr, and therefore on Eunoia, to draw area-proportional diagrams in their analyses. These include three Bioconductor genomics packages—cola, hicVennDiagram, and seqsetvis—and the CRAN package RulesTools. Six more packages—DOTSeq, highdir, IlluminaHumanMethylationEPICv2manifest, IS-Analytics, overviewR, and pcutils—use eulerr optionally and can therefore also invoke Eunoia.
The Python, Julia, and JavaScript packages and the web app extend the same underlying library to communities that previously had no access to ellipse-based area-proportional diagrams.
AI Usage Disclosure
JL wrote Eunoia’s predecessor, eulerr, entirely without AI. For Eunoia, JL used generative AI tools including Claude Code Opus (versions 4.5, 4.8, and 5.0), Claude Code Fable 5, GitHub Copilot GPT 5.1 and 5.4, and Codex GPT 5.6-sol and GPT 6.1-sol. NML used Claude Code Opus 5.5. The authors used these tools to help write code, parts of the documentation, and unit tests and to review and edit the manuscript. NML performed user testing and detected bugs independently of AI. JL and NML reviewed, modified, and validated all AI-assisted content and made the final design and implementation decisions.
Acknowledgements
Eunoia builds on a decade of feedback from users of eulerr, whose bug reports and feature requests have shaped the fitting engine, and on Peter Gustafsson’s contributions to the original eulerr package.
References
References
- [1]Chow, S. C. (2007). Generating and drawing area-proportional Euler and Venn diagrams [PhD thesis]. University of Victoria.
- [2]Eberly, D. (2016, November). The area of intersecting ellipses. Geometric Tools. https://www.geometrictools.com/Documentation/AreaIntersectingEllipses.pdf
- [3]Euler, L. (1802). Letters of Euler to a German princess, on different subjects in physics and philosophy. Murray; Highley.
- [4]Frederickson, B. (2015, June 29). A better algorithm for area proportional Venn and Euler diagrams. https://www.benfrederickson.com/better-venn-diagrams/
- [5]Hansen, N., & Ostermeier, A. (1996). Adapting arbitrary normal mutation distributions in evolution strategies: The covariance matrix adaptation. Proceedings of IEEE International Conference on Evolutionary Computation, 312–317. https://doi.org/10.1109/ICEC.1996.542381
- [6]Junta, C. M., Sandrin-Garcia, P., Fachin-Saltoratto, A. L., Mello, S. S., Oliveira, R. D. R., Rassi, D. M., Giuliatti, S., Sakamoto-Hojo, E. T., Louzada-Junior, P., Donadi, E. A., & Passos, G. A. S. (2009). Differential gene expression of peripheral blood mononuclear cells from rheumatoid arthritis patients may discriminate immunogenetic, pathogenic and treatment features. Immunology, 127(3), 365–372. https://doi.org/10.1111/j.1365-2567.2008.03005.x
- [8]Larsson, J., & Gustafsson, P. (2018). A case study in fitting area-proportional Euler diagrams with ellipses using eulerr. Proceedings of International Workshop on Set Visualization and Reasoning, 2116, 84–91. https://ceur-ws.org/Vol-2116/paper7.pdf
- [9]Micallef, L., Dragicevic, P., & Fekete, J.-D. (2012). Assessing the effect of visualizations on Bayesian reasoning through crowdsourcing. IEEE Transactions on Visualization and Computer Graphics, 18(12), 2536–2545. https://doi.org/10.1109/TVCG.2012.199
- [10]Micallef, L., & Rodgers, P. (2014). eulerAPE: Drawing area-proportional 3-Venn diagrams using ellipses. PLOS ONE, 9(7), e101717. https://doi.org/10.1371/journal.pone.0101717
- [11]Pérez-Silva, J. G., Araujo-Voces, M., & Quesada, V. (2018). NVenn: Generalized, quasi-proportional Venn and Euler diagrams. Bioinformatics, 34(13), 2322–2324. https://doi.org/10.1093/bioinformatics/bty109
- [12]Richter-Gebert, J. (2011). Perspectives on projective geometry: A guided tour through real and complex geometry. Springer. https://doi.org/10.1007/978-3-642-17286-1
- [13]Tretyakov, K. (2024). Matplotlib-venn: Area-weighted Venn diagrams for Python/matplotlib. https://github.com/konstantint/matplotlib-venn
- [14]Wilkinson, L. (2012). Exact and approximate area-proportional circular Venn and Euler diagrams. IEEE Transactions on Visualization and Computer Graphics, 18(2), 321–331. https://doi.org/10.1109/TVCG.2011.56
- [15]Wybrow, M., Rodgers, P., & Dib, F. K. (2021). Euler diagrams drawn with ellipses area-proportionally (Edeap). BMC Bioinformatics, 22(1), 214. https://doi.org/10.1186/s12859-021-04121-8



