Kevin Wenger presents

D3Bubbles, Bubble Chart using D3

Bubble charts encode data in the area of circles. Although less perceptually-accurate than bar charts, they can pack hundreds of values into a small space.

Usage

how to include D3Bubbles into your projects

1. Add libraries and dependencies


<!-- jQuery 1.11.0 -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- D3.js v3 -->
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<!-- D3Bubbles libraries -->
<script src="lib/d3bubbles.js"></script>
<!-- D3Bubbles stylesheet -->
<link rel="stylesheet" href="lib/d3bubbles.css">
                        

2. Generate Markup


<div id="sample-1">
    <div class="plot"></div>
</div>
                        

3. Initilize your plot and choose your options


var bubbles = new D3Bubbles({
    width: 'auto',
    height: 300,
    wrapper: '#bubbles',
    container: '#bubbles .plot',
    bubbles: {
        bubbles_per_px: 0.02,
        bubbles_max: 'auto',
    },
    radius: {
        min:28,
        max:65
    },
    colors: {
        bubbles:['#c9ad7d'],
        texts:['#FFF'],
    },
    features: {
        dragmove: true,
        overflow: false,
        fit_texts: true,
    },
});
                        

4. Get Data on correct format


var data = [
    {name: "love", radius: 186, label: "186 posts", type: "hashtag"},
    {name: "code", radius: 67, label: "67 posts", type: "keyword"},
    {name: "sudei", radius: 53, label: "53 posts", type: "hashtag"},
];
                        

5. Bring data to life using HTML, SVG and CSS


bubbles.init();
bubbles.visualize();
                        

(bonus). Add Event Listener


var container = document.querySelector('#d3bubbles');
container.addEventListener('complete', function (e) {
    // do stuff ...
}, false);
                        

Options

Object options, callback and events

options

width: 'auto'
here you can type pixels (for instance '300' whitout suffix px),or auto. 'auto' will generate a bubbles chart on 100% of wrapper width.
height: 'auto'
here you can type pixels (for instance '300' whitout suffix px),or auto. 'auto' will generate a bubbles chart on 100% of wrapper height.
wrapper: '#plot-wrapper'
wrapper of our plot. Must be an valid selectquery.
container: '#plot-wrapper .plot'
Drawing area. Must be an valid selectquery.
bubbles: { bubbles_max: 'auto' }
'auto' will calculate a number of bubbles depending on container.width and bubbles_per_px.
bubbles: { bubbles_per_px: 0.02 }
increase the value to generate more bubbles per px.
NB: set bubbles_max to any number to choose number of bubble display - could cause issue on responsive design.
radius: { min: 1 }
radius: { max: 100 }
size of the lowest/biggest bubble. this value must be smaller than width/height of your container.
colors: {bubbles: ['#c9ad7d', '#e0c18c'] }
colors: {texts: ['#FFF'] }
set an array of colors for a gradiant between lowest and biggets bubbles.
NB: set only on value to force one color
features: { 'dragmove': true }
true, false. Allow user to interract with the chart.
features: { 'overflow': false }
true, false. Allow bubbles to overflow them container.
NB: fixing overflow to false and forcing bubbles_max could result of bad rendering.
features: { 'fit_texts': true }
true, false. Fit font-size, inside bubble, to it size.
features: { 'responsive': false }
true, false. Allow bubble chart to be responsive.
NB: development and draft in progress

events

complete()
this event is invoked when all bubbles has been draw.
dragstart( bubble_ref, bubble_data )
this event is invoked when a bubble is drag.
drag( bubble_ref, bubble_data )
this event is invoked when a bubble is dragged.
dragend( bubble_ref, bubble_data )
this event is invoked when a bubble is drop.
enter( bubble_ref, bubble_data )
this event is invoked when mouse enter in a bubble.
leave( bubble_ref, bubble_data )
this event is invoked when mouse enter in a bubble.

Examples

Play with me ! Change my properties and click on redraw to see the result
Events
complete
enter
leave
dragstart
drag
dragend

Roadmap

Changelogs and futur updates

next changes

v.1.0.6 - aaaa.mm.dd
Add feature : Responsive - true,false
Add feature : Fit texts - true,false
v.1.1 - aaaa.mm.dd
Add method : add - add new bubble
Add method : remove - remove bubble by id
v.1.1.5 - aaaa.mm.dd
Remove jQuery dependency

changelog

v.1.0.0 - 2015.02.02
First release.
v.1.0.5 - 2015.02.22
Add event : dragstart - fired at the start of the drag (bubble)
Add event : drag - during the drag (bubble)
Add event : dragend - fired when dragging stops (bubble)
Add event : enter - fired when enter hover a bubble
Add event : leave - fired when leave a bubble
v.1.0.6 - 2015.02.24
Add feature : Responsive - true,false
Add feature : Fit texts - true,false