Mchristos / circlify

Circle packing similar to squarify for treemap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyPi version

Python compatibility

Build Status

Coverage

Codacy

circlify

Pure Python implementation of circle packing layout algorithm.

Circles are first arranged via a version of A1.0 by Huang et al (see https://home.mis.u-picardie.fr/~cli/Publis/circle.pdf for details) and then enclosed in a circle created around them using Matoušek-Sharir-Welzl algorithm used in d3js (see https://beta.observablehq.com/@mbostock/miniball, http://www.inf.ethz.ch/personal/emo/PublFiles/SubexLinProg_ALG16_96.pdf, and https://github.com/d3/d3-hierarchy/blob/master/src/pack/enclose.js)

Installation

Compatible with Python 2.7 and Python 3.2+.

Using pip:

pip install circlify

or using the source:

git clone git://github.com/elmotec/circlify.git
cd circlify
python setup.py install

The last step may require sudo if you don't have root access.

Usage

The main function circlify is supported by a small data class circlify.Circle and takes 3 parameters:

  • A list of positive values sorted from largest to smallest.
  • (optional) A target enclosure where the packed circles should fit. It defaults to the unit circle (0, 0, 1).
  • (optional) A boolean indicating if the target enclosure should be appended to the output.

The function returns a list of circlify.Circle objects, each one corresponding to the coordinates and radius of cirlces proportional to the corresponding input value.

Example

The variable circles contains (last one is the enclosure):

A simple matplotlib representation. See circlify.bubbles helper function (requires matplotlib):

About

Circle packing similar to squarify for treemap

License:MIT License


Languages

Language:Python 100.0%