d3-bubble-matrix
A bubble matrix, for representing any kind of bidimensional data.
Install
With npm:
npm install d3-bubble-matrix
With bower:
bower install d3-bubble-matrix
Dependencies:
npm install d3
npm install d3-tip
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/bubble-matrix.min.css">
</head>
<body>
<div id="bubble"></div>
<script src="js/bubble-matrix.min.js"></script>
</body>
</html>
let data = {
columns: ['2013', '2014', '2015', '2016', '2017'],
rows: [{ name: 'Hey men', values: [0.3, 0.54, 0.99, 0.3, 0.2]},
{ name: 'What?????', values: [0.5 ,0.6, 0.7, 0.8, 0.5]},
{ name: 'Whatever!!', values: [0.99 ,0.2, 0.3, 0.4, 0.7]},
{ name: 'Really?', values: [0.94 ,0.07, 0.27, 0.9, 0.5]}]
};
let config = {
selector: '#bubble',
onClick: val => alert(`Value ${val}`)
};
let matrix = new BubbleMatrix(config);
matrix.draw(data);
This will draw a bubble matrix. You can find this example in the app/index.html folder.
To play with the example npm install
, run npm start
and go to
localhost:8000.
Constructor
let config = {
root: d3.select('#bubble'),
selector: '#bubble',
width: 800,
height: 600,
onClick: val => alert(`Value ${val}`)
reverseColor: true,
hideTooltip: true,
tooltip: d3.tip().html(value => 'Value: ' + value),
hideLeftTitle: true,
hideRightTitle: true,
hideTopTitle: true,
hideBottomTitle: true,
duration: 5000,
maxRadius: 10,
maxColors: 6,
padding: { top: 20, right: 0, bottom: 20, left: 10 }
classNames: {
bubbleMatrix: 'bubble-matrix',
leftRows: 'left-rows',
rightRows: 'right-rows',
horizontalLines: 'horizontal-lines',
verticalLines: 'vertical-lines',
row: 'row',
column: 'column',
topColumns: 'top-columns',
bottomColumns: 'bottom-columns',
rects: 'rects',
bubbles: 'bubbles',
color: 'bubble-color-'
}
};
let matrix = new BubbleMatrix(config);
Add more colors
Change the value of maxColors.
maxColors: 3,
Add this classes to the css.
.bubble-color-1 {
fill: orangered;
}
.bubble-color-2 {
fill: gold;
}
.bubble-color-3 {
fill: forestgreen;
}
Ready!
Methods
chart.draw(data)
let data = {
columns: ['hello', 'world'],
rows: [
{ name: 'foo', values: [0.1, 0.3, 0.9] },
{ name: 'blob', values: [0.5, 0.8, 0.2] }
]
};
data
Object Data to represent.
Draw the chart.
Please feel free to open pull requests to make any change.