chartformers

Zoomable Circle Pack
Copy component without data

Test tooltip

Test tooltip

To use the zoomable circle packs, import these on top:

import { CirclePacks } from 'chartformers';
import 'chartformers/dist/chartformers.css';

Minimum call:

The chart must be called in a container with width and height set. It will then fill the available space of this container.

<div className="w-full h-60 md:h-96">
 <CirclePacks data={[]} />
</div>

the data is an array of objects with a mandatory 'name' string property, an optional number 'value' property, and an optional 'children' property, which is an array of the same data shape. If the 'children' property is not presents then the 'value' property is mandatory and must be given a number value which is greater than 0, so the system will be able to calculate and render the chart properly.

Sample data :

const sample1 = [
    { name: "USA", value: 1250000}
]

const sample2 = [
    {
        name: "USA", 
        children: [
            { name: "New York Main Branch", value: 800000 },
            { name: "Houston Branch", value: 450000 }
        ]
    }
]

const sample3 = [
    {
        name: "USA", 
        children: [
            { name: "New York Main Branch",value: 800000 },
            { name: "Houston Branch", value: 450000 }
        ]
    },
    {
        name: "United Kingdom",
        children: [
            { name: "London Main Branch", value: 900000 },
            { name: "Liverpool Branch", value: 675000 },
            { name: "Bristol Branch", value: 527000 }
        ]
    }
]

#Property Table

propertydescriptionmandatorydefault value
dataAn array of objects with a mandatory 'name' string property, an optional number 'value' property, and an optional 'children' property, which is an array of objects of the same data shape. If the 'children' property is not presents then the 'value' property becomes mandatory and must be given a number value which is greater than 0.Yes[]
tooltipFormatSee belowNo{}
About tooltipFormat prop

For most chart types you can pass the optional tooltipFormat prop. This prop has 3 properties: formatType, prefix and suffix, all are optional.

formatTypeprefixsuffix
either 'long' or 'short', default is 'long'. If given a number value of 1500, 'long' will format the value into '1,500', while 'short' will format into '1,5k'. Optional property.prefix for the given number value, optional property. eg: 'US$'suffix for the given number value, optional property. eg: 'KWh'

Example use:

if given number value of 1500:

  • <CirclePacks data={[...]} tooltipFormat={{ prefix:"US$ " }} />

    with default 'formatType' as 'long', will render 'US$ 1,500' at the tooltip component.

    Hint: In this example the US$ prefix has a single space at the end. If you want to put space between prefix and the value, do so by manually typing the space at the end of the prefix.

  • <CirclePacks data={[...]} tooltipFormat={{ formatType: "short", suffix:" KWh" }} />

    with the 'formatType' as 'short', will render '1,5k KWh' at the tooltip component.

    Hint: In this example the KWh suffix has a single space at the start. If you want to put space between suffix and the value, do so by manually typing the space at the start of the suffix.