summaryrefslogtreecommitdiffstats
path: root/static/functions/artist_cloud.js
blob: 40d54d5b897347689e5978e2db6547720498d289 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(function() {

var LIMIT = 10;
var artistId, artistName;
var artistTags;
$(document).ready(function() {
	initArtistCloud();
});
function initArtistCloud() {
	$("#currentArtist").text();

	artistTags = $("#artistTags").find('ul');
	artistName = $("#content").find("h2:first").text();
	artistId = window.location.search.split("?id=")[1];
	addArtistMain(artistName);
	loadArtists();
}


function loadArtists() {
	$.getJSON('ajax.php?action=similar_artists&id='+artistId+'&limit='+LIMIT, function(data) {
		var first = true;
		var ratio;
		$.each(data, function(key, val) {
			if (first) {
				ratio = val['score'] / 300;
				first = false;
			}
			var score = val['score'] / ratio;
			score = score <= 150 ? 150 : score;
			addArtist(val['id'], val['name'], score);
		});

	createCloud();
	});

}

function addArtist(id, name, score) {
	var item = $('<li><a style="color:#007DC6;" data-weight="' + score + '">' + name + '</a></li>');

	$(item).click(function(e) {
		e.preventDefault();
		reinit(id, name);
	});

	artistTags.append(item);
}

function addArtistMain(name) {
	var item = $('<li><a style="color: #007DC6;" data-weight="350">' + name + '</a></li>');

	$("#currentArtist").attr('href', 'artist.php?id=' + artistId);
	$("#currentArtist").text(artistName);


	$(item).click(function(e) {
		e.preventDefault();
		reinit(artistId, name);
	});

	artistTags.append(item);
}

function reinit(id, name) {
	artistId = id;
	artistName = name;
	artistTags.empty();
	addArtistMain(artistName);
	loadArtists();
}

function createCloud() {
	if (!$('#similarArtistsCanvas').tagcanvas({

		// textFont: 'Impact,"Arial Black",sans-serif',
		wheelZoom: false,
		freezeActive: true,
		weightSize: 0.15,
		interval: 20,
		textFont: null,
		textColour: null,
		textHeight: 25,
		outlineColour: '#f96',
		outlineThickness: 4,
		maxSpeed: 0.04,
		minBrightness: 0.1,
		depth: 0.92,
		pulsateTo: 0.2,
		pulsateTime: 0.75,
		initial: [0.1,-0.1],
		decel: 0.98,
		reverse: true,
		shadow: '#ccf',
		shadowBlur: 3,
		weight : true,
		weightFrom: 'data-weight'
	},'artistTags')) {
		// something went wrong, hide the canvas container
		$('#flip_view_2').hide();
	}
}

})();