-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathheatmap.js
50 lines (45 loc) · 1.57 KB
/
heatmap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* globals d3, $ */
/* global $, _ */
(function(kcharts, $, _) {
'use strict';
kcharts.HeatMap = function() {
var radius = 0.05,
COLS = ['red', 'green', 'blue'],
heatmap = function(selection) {
selection.each(function(data) {
var cs, chartArea = d3.select(this).select('g.chart-area'),
hmap = chartArea.selectAll('.heatmap').data(data);
hmap.enter().append('g').attr('class', 'heatmap').attr('fill', heatmap.colors);
cs = hmap.selectAll('circle').data(function(d) {
return d;
});
cs.enter().append('circle');
cs.exit().remove();
cs.attr('cx', function(d) {
return parseInt(heatmap.x(d.x), 10);
})
.attr('cy', function(d) {
return parseInt(heatmap.y(d.y),10);
})
.attr('r', radius * parseInt(chartArea.attr('width'), 10))
;
});
};
heatmap.xScale = function(scale) {
heatmap.x = scale;
return heatmap;
};
heatmap.yScale = function(scale) {
heatmap.y = scale;
return heatmap;
};
heatmap.radius = function(r) {
radius = r;
return this;
};
heatmap.colors = function(d, i) {
return COLS[i%COLS.length];
};
return heatmap;
};
}(window.kcharts = window.kcharts || {}, $));