-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_d3.js
58 lines (48 loc) · 1.89 KB
/
app_d3.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
var svgSettings = {
width: 1140,
height: 705
};
//d3 append svg on username submission
var svgAppend = function(topArtistsArray){
var xRandom = function(){
var x = Math.random() * 1000;
return x;
};
var yRandom = function(){
var y = Math.random() * 500;
return y;
};
var svg = d3.select('.d3-data').append('svg')
.attr('width', svgSettings.width)
.attr('height', svgSettings.height);
var circles = svg.selectAll('circle')
.data(topArtistsArray)
.enter()
.append('circle');
var circleAttributes = circles
.attr('cx', function(d){return xRandom();})
.attr('cy', function(d){return yRandom();})
.attr('r', function(d){return (d.playcount/40);})
.style('opacity', .5)
.style('fill', '#e31b23')
.on('mouseenter', function(d){
var artistName = d.name;
d3.select(this).append('artistName')
.attr('class', 'addArtistName')
.text(artistName);
$('svg circle').tipsy({
gravity: 'w',
html: true,
title: function(artistName) {
var showName = $(this).find('.addArtistName').text();
return showName;
}
});
})
.on('mouseout', function(d){
// d3.select('.text').remove();
d3.select(this)
.select('.addArtistName')
.remove();
});
};