-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNorthernIrelandGPPrescriptionsCircleSpirals.html
223 lines (185 loc) · 6.57 KB
/
NorthernIrelandGPPrescriptionsCircleSpirals.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Northern Ireland GP Prescriptions by Amount of money spent
</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/site.css" />
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<button type="button" class="navbar-toggle"
data-toggle="collapse"
data-target=".navbar-collapse"
>
<span class="sr-only"> Toggle navigation</span>
<span class="icon-bar"> </span>
<span class="icon-bar"> </span>
<span class="icon-bar"> </span>
</button> <a class="navbar-brand" href="http://stiona.com" target="_blank">Stiona Software</a>
<a class="navbar-brand" href="index.html"><i class="fa fa-home"></i></a>
<a class="navbar-brand" href="https://github.com/shaydoc/NorthernIrelandGPData" target="_blank"><i class="fa fa-github"></i></a>
<a class="navbar-brand" href="https://twitter.com/shaydmusic" target="_blank"><i class="fa fa-twitter"></i></a>
<a class="navbar-brand" href="https://www.linkedin.com/pub/shay-doherty/7/45b/7bb" target="_blank"><i class="fa fa-linkedin"></i></a>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li> <a href="NorthernIrelandGPPrescriptionsCircleSpirals.html">BNF Chapter Chart</a> </li>
<li> <a href="practicespending.html">GP Surgery Chart</a> </li>
<li> <a href="NortherIrelandGPPrescriptionsBubbleChart.html">Drug Chart</a> </li>
<li> <a href="diabetes.html">Diabetes Map</a> </li>
<li> <a href="diabetestimeseries.html">Diabetes Time</a> </li>
</ul>
</div>
</div>
</nav>
<div id="body" class="container content-pad">
<div class="jumbotron">
<h2>
Northern Ireland GP Prescription Spending Overview
</h2>
<h3>
BNF Chapter and Drug Spending from April 2013 - May 2016
</h3>
</div>
<div class="chart">
</div>
</div>
<script>
d3.json("json/bnfchapterdrugspending.json",function(res) {
var flareMapped = _.chain(res).pluck('name').uniq().value();
var flareJSON = {
name: 'flare',
children: []
};
_.each(flareMapped, function(i, n) {
var filtered = _.chain(res).where({
name: i
}).pluck('drugName').value();
var rec = {
name: i,
children: _.chain(res).where({
name: i
}).filter(function(f) {
return f.drugName !== '-' && f.drugName !== 'NULL' && f.totalSpend > 100000;
}).map(function(d) {
return {
name: d.drugName,
size: d.totalSpend < 0 ? 100 : parseInt(d.totalSpend)
};
}).value()
}
flareJSON.children.push(rec);
});
var margin = 20,
diameter = 960;
var color = d3.scale.linear()
.domain([-1, 5])
.range(["hsl(152,80%,80%)", "hsl(228,30%,40%)"])
.interpolate(d3.interpolateHcl);
var pack = d3.layout.pack()
.padding(2)
.size([diameter - margin, diameter - margin])
.value(function(d) {
return d.size;
})
var svg = d3.select("#body").select('.chart').append("svg")
.attr("viewBox", "0 0 960 960")
.attr("preserveAspectRatio", "xMinYMin meet")
//.attr("width", diameter)
//.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");
function popUp(error, root) {
if (error) throw error;
var focus = root,
nodes = pack.nodes(root),
view;
var circle = svg.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("class", function(d) {
return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root";
})
.style("fill", function(d) {
return d.children ? color(d.depth) : null;
})
.on("click", function(d) {
if (focus !== d) zoom(d), d3.event.stopPropagation();
});
var text = svg.selectAll("text")
.data(nodes)
.enter().append("text")
.attr("class", "label")
.style("fill-opacity", function(d) {
return d.parent === root ? 1 : 0;
})
.style("display", function(d) {
return d.parent === root ? "inline" : "none";
})
.text(function(d) {
return d.name;
});
var node = svg.selectAll("circle,text");
d3.select("body")
.on("click", function() {
zoom(root);
});
zoomTo([root.x, root.y, root.r * 2 + margin]);
function zoom(d) {
var focus0 = focus;
focus = d;
var transition = d3.transition()
.duration(d3.event.altKey ? 7500 : 750)
.tween("zoom", function(d) {
var i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2 + margin]);
return function(t) {
zoomTo(i(t));
};
});
transition.selectAll("text")
.filter(function(d) {
return d.parent === focus || this.style.display === "inline";
})
.style("fill-opacity", function(d) {
return d.parent === focus ? 1 : 0;
})
.each("start", function(d) {
if (d.parent === focus) this.style.display = "inline";
})
.each("end", function(d) {
if (d.parent !== focus) this.style.display = "none";
});
}
function zoomTo(v) {
var k = diameter / v[2];
view = v;
node.attr("transform", function(d) {
return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")";
});
circle.attr("r", function(d) {
return d.r * k;
});
}
}
popUp(null, flareJSON);
d3.select(self.frameElement).style("height", diameter + "px");
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-84653625-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>