-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRadar.js
107 lines (99 loc) · 3.48 KB
/
Radar.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
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
105
106
107
var radardata = []
var pokemons;
// d3.select('body').append('g').append('div').attr('id','radarchart')
function radarAdd(p){
if (p) {box.value=p}
var pokemon = pokemons
if (box.value){
for (var poke in pokemon){
if (pokemon[poke].Name == box.value){
//console.log('found poke')
radardata.push({
id: pokemon[poke]['#'],
name: pokemon[poke].Name,
color: typecolor[pokemon[poke]['Type 1']],
gen: pokemon[poke]['Generation'],
total: +pokemon[poke].Total,
axis: [
{'stat': 'HP' ,'value': +pokemon[poke]['HP']},
{'stat': 'Attack' ,'value': +pokemon[poke]['Attack']},
{'stat': 'Defense' ,'value': +pokemon[poke]['Defense']},
{'stat': 'Sp. Atk' ,'value': +pokemon[poke]['Sp. Atk']},
{'stat': 'Sp. Def' ,'value': +pokemon[poke]['Sp. Def']},
{'stat': 'Speed' ,'value': +pokemon[poke]['Speed']},
]
})
}
}
document.getElementById("radarform").reset()
if (radardata.length>0){
d3.select("#radarchart").selectAll("*").remove();
d3.select('#toolTip').remove();
RadarChart.draw("#radarchart", radardata, config);
}
}
}
d3.select("#Clear").on("click",function() {
radardata=[]
d3.select('#radarchart').selectAll('circle').remove()
d3.select('#radarchart').selectAll('polygon').remove()
d3.select('#radarlegend').remove()
})
d3.select("#Add").on("click",function(){
radarAdd()
})
var width = 300,
height = 300;
// Config for the Radar chart
var config = {
w: width,
h: height,
maxValue: 160,
levels: 5,
ExtraWidthX: 300,
TranslateX: 100
}
webshim.setOptions('forms', {
//replace the default datalist feature with a custom styleable datalist
customDatalist: true
});
webshim.setOptions('forms-ext', {
//replace all input type widgets with a custom styleable feature
replaceUI: true // 'auto' || true || false (default)
});
//load form polyfills
webshim.polyfill('forms forms-ext');
var typecolor = {'Bug':'#A8B820','Dark': '#705848','Dragon': '#7038F8','Electric':'#F8D030','Fairy':'#EE99AC','Fighting':'# C03028','Fire':'#F08030','Flying':'#A890F0','Ghost':'#705898','Grass':'#78C850','Ground':'#E0C068','Ice':'#98D8D8','Normal':'#A8A878','Poison':'#A040A0','Psychic':'#F85888','Rock':'#B8A038','Steel':'#B8B8D0','Water':'#6890F0'}
d3.csv("Pokemon.csv", function(pokemon) {
//console.log(pokemon)
pokemons = pokemon
radarAdd('Pikachu')
// for (var poke in pokemon.slice(0,2)){
// radardata.push({
// name: pokemon[poke].Name,
// color: typecolor[pokemon[poke]['Type 1']],
// total: +pokemon[poke].Total,
// axis: [
// {'stat': 'HP' ,'value': +pokemon[poke]['HP']},
// {'stat': 'Attack' ,'value': +pokemon[poke]['Attack']},
// {'stat': 'Defense' ,'value': +pokemon[poke]['Defense']},
// {'stat': 'Sp. Atk' ,'value': +pokemon[poke]['Sp. Atk']},
// {'stat': 'Sp. Def' ,'value': +pokemon[poke]['Sp. Def']},
// {'stat': 'Speed' ,'value': +pokemon[poke]['Speed']},
// ]
// })
// }
d3.select('#pokemons').append('select').selectAll('option').data(pokemon.sort(
function(a, b){
var nameA=a.Name.toLowerCase(), nameB=b.Name.toLowerCase();
if (nameA < nameB) //sort string ascending
return -1;
if (nameA > nameB)
return 1;
return 0; //default return value (no sorting)
}))
.enter()
.append('option')
.attr('val',function(d){return d})
.text(function(d){return d.Name})
})