-
Notifications
You must be signed in to change notification settings - Fork 9
/
bins.js
67 lines (53 loc) · 2.13 KB
/
bins.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import scatterplot_component from './scatterplot_component';
import * as d3_hexbin from "d3-hexbin";
function bins(configObject) {
scatterplot_component.call(this, configObject);
// TODO: dirty hack to make bin size reasonable if set to 3 (scatterplot default)
if (this.ptSize == 3)
this.ptSize = 15;
}
bins.prototype = Object.create(scatterplot_component.prototype);
bins.prototype.draw = function(container, skipTransition) {
var that = this;
var hexbin = d3_hexbin.hexbin()
.x(function(d) { return that.scale.x(that.xValue(d)); })
.y(function(d) { return that.scale.y(that.yValue(d)); })
.extent([this.scale.x.range(), this.scale.x.range()])
.radius(this.ptSize);
var hexbins = hexbin(this.data);
var attenuation = this.attenuation || d3.scale.log().range([0,1]);
attenuation.domain([.1, d3.max(hexbins.map(function(d) { return d.length; }))]);
container.selectAll('g.hexes')
.data([1]).enter().append('g')
.attr('class', 'hexes');
container.selectAll('path.hex').remove();
var hex = container.select('g.hexes').selectAll('path.hex')
.data(hexbins);
hex.exit().remove();
hex.enter().append('path')
.attr('class', 'hex')
.attr('d', hexbin.hexagon(this.ptSize - 0.5))
.attr('transform', function(d) { return "translate(" + d.x + "," + d.y + ")"; });
hex.style('fill', function(d) {
var counts = Array(that.foundGroups.length).fill(0);
d.forEach(function(p) {
counts[that.foundGroups.indexOf(that.grpValue(p))]++;
});
return counts.reduce(function(p,c,i) {
return d3.interpolateLab(p, that.colorScale.range()[i])(c / d.length);
}, "white");
})
.style('fill-opacity', function(d) { return attenuation(d.length); });
this.attenuation = attenuation;
}
bins.prototype.update = function(container, skipTransition) {
this.draw(container, skipTransition);
}
bins.prototype.highlight = function(container, selector) {
console.warn("no highlight method implemented for bins");
return;
}
bins.prototype.visualEncSelector = function() {
return "path.hex";
}
export default bins;