-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancer.html
220 lines (214 loc) · 9.92 KB
/
cancer.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
<html>
<head>
<!-- Use CDN -->
<script src="https://unpkg.com/deckly@1.0.14/umd/deckly.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/deckly@1.0.14/umd/deckly.css">
<!-- or
<script src="../umd/deckly.min.js"></script>
<link rel="stylesheet" href="../umd/deckly.css">
-->
</head>
<body>
<script>
// Example app
const IMD_DOMAINS = ["IMD18_mean", "Employment_mean", "Income_mean", "Crime_mean", "Housing_mean", "Health_mean", "Education_mean", "Access_mean"]
const YEAR_BRACKETS = ["2010-2012", "2013-2015", "2016-2018"]
Deckly({
title: "Cancer distribution in NZ",
data: "https://uoa-eresearch.github.io/cancermap/data/TALB_2018.geojson",
//colorBy: d => d.properties.cancer["total 18+ all cancertotal2016-2018"] / d.properties.smoking["total_15+"] * 100,
//colorScale: "Blues",
colorBy: {
"Bivariate Cancer 2016-2018 + IMD18": d => [
d.properties.cancer["total 18+ all cancertotal2016-2018"] / d.properties.smoking["total_15+"] * 100,
d.properties.IMD18_mean
],
"Cancer 2010-2012": d => d.properties.cancer["total 18+ all cancertotal2010-2012"] / d.properties.smoking["total_15+"] * 100,
"Cancer 2013-2015": d => d.properties.cancer["total 18+ all cancertotal2013-2015"] / d.properties.smoking["total_15+"] * 100,
"Cancer 2016-2018": d => d.properties.cancer["total 18+ all cancertotal2016-2018"] / d.properties.smoking["total_15+"] * 100,
},
colorScale: ["Blues", "Reds"],
hoverMessage: d => d.properties.TALB2018_1,
perText: "Display cancer/smoking values as per 100K people",
perFunc: d => {
const RATE_PER = 1E5;
var f = JSON.parse(JSON.stringify(d))
//console.log(f);
for (var subkey of ["cancer", "smoking"]) {
for (var k in f[subkey]) {
if (k.includes("total")) {
f[subkey][k] = f[subkey][k] / f.age.Total.Total * RATE_PER
} else if (k.includes("non-maori")) {
f[subkey][k] = f[subkey][k] / f.age["Non-maori"].Total * RATE_PER
} else {
f[subkey][k] = f[subkey][k] / f.age["Maori"].Total * RATE_PER
}
}
}
return f
},
legendTitle: {
"Bivariate Cancer 2016-2018 + IMD18": "Cancer registrations from 2016-2018 divided by 2018 adult population (percentage) vs deprivation",
"Cancer 2010-2012": "Cancer registrations from 2013-2015 divided by 2018 adult population (percentage)",
"Cancer 2013-2015": "Cancer registrations from 2013-2015 divided by 2018 adult population (percentage)",
"Cancer 2016-2018": "Cancer registrations from 2016-2018 divided by 2018 adult population (percentage)",
},
legendLabels: ["Cancer", "Deprivation"],
//limits: [1,3],
extraPlotData: ["https://raw.githubusercontent.com/UoA-eResearch/cancermap/master/data/DHB/NZ_cancer.csv"],
plots: [{
id: "cancertypes",
style: {
width: "50%",
},
data: ({ cancer }) => [
{
name: "Māori",
vars: ["breastmaori2016-2018", "prostatemaori2016-2018", "lungmaori2016-2018"],
x: ["Breast cancer", "Prostate cancer", "Lung cancer"],
y: [cancer["breastmaori2016-2018"], cancer["prostatemaori2016-2018"], cancer["lungmaori2016-2018"]],
type: 'bar',
},
{
name: "Non-māori",
vars: ["breastnon-maori2016-2018", "prostatenon-maori2016-2018", "lungnon-maori2016-2018"],
x: ["Breast cancer", "Prostate cancer", "Lung cancer"],
y: [cancer["breastnon-maori2016-2018"], cancer["prostatenon-maori2016-2018"], cancer["lungnon-maori2016-2018"]],
type: 'bar',
}
],
layout: {
title: d => `Cancer types in ${d ? d.properties.TALB2018_1 : "NZ"} from 2016-2018`,
barmode: 'stack',
}
},
{
id: "smoking",
style: {
width: "50%",
},
data: ({ smoking }) => [
{
name: "Māori",
x: ["Male smoker", "Male non-smoker", "Female smoker", "Female non-smoker"],
y: [smoking["maori_male_smoker"], smoking["maori_male_non-smoker"], smoking["maori_female_smoker"], smoking["maori_female_non-smoker"]],
type: 'bar',
},
{
name: "Non-māori",
x: ["Male smoker", "Male non-smoker", "Female smoker", "Female non-smoker"],
y: [smoking["non-maori_male_smoker"], smoking["non-maori_male_non-smoker"], smoking["non-maori_female_smoker"], smoking["non-maori_female_non-smoker"]],
type: 'bar',
}
],
layout: {
title: d => `Smoking in ${d ? d.properties.TALB2018_1 : "NZ"} as per the 2018 census`,
barmode: 'stack',
}
},
{
id: "age_distribution",
data: ({ age }) => [
{
name: "Māori",
x: Object.keys(age.Maori).filter(k => k != "Total"),
y: Object.keys(age.Maori).filter(k => k != "Total").map(k => age.Maori[k]),
type: 'bar',
},
{
name: "Non-māori",
x: Object.keys(age["Non-maori"]).filter(k => k != "Total"),
y: Object.keys(age["Non-maori"]).filter(k => k != "Total").map(k => age["Non-maori"][k]),
type: 'bar',
}
],
layout: {
title: d => `Age distribution in ${d ? d.properties.TALB2018_1 : "NZ"} as per the 2018 census`,
barmode: 'stack',
}
},
{
id: "deprivation",
data: data => {
// NZ wide context
if (data.aggregate) {
return [{
x: IMD_DOMAINS.map(k => k.replace("_mean", "")),
y: IMD_DOMAINS.map(k => data[k] / 86),
type: 'line',
name: "NZ"
}];
} else {
// This TALB
return [
{
x: IMD_DOMAINS.map(k => k.replace("_mean", "")),
y: IMD_DOMAINS.map(k => data.aggregateData[k] / 86),
type: 'line',
name: "NZ"
},
{
x: IMD_DOMAINS.map(k => k.replace("_mean", "")),
y: IMD_DOMAINS.map(k => data[k]),
type: 'line',
name: data.TALB2018_1
}
];
}
},
layout: {
title: d => `Deprivation in ${d ? d.properties.TALB2018_1 + " vs NZ" : "NZ"}`,
yaxis: {
range: [0, 6000]
}
}
},
{
id: "cancer_over_time",
data: ({ cancer }) => [
{
name: "Māori",
type: 'bar',
x: YEAR_BRACKETS,
y: YEAR_BRACKETS.map(y => cancer["total 18+ all cancermaori" + y]),
},
{
name: "Non-māori",
type: 'bar',
x: YEAR_BRACKETS,
y: YEAR_BRACKETS.map(y => cancer["total 18+ all cancernon-maori" + y]),
}
],
layout: {
title: d => `Cancer over time in ${d ? d.properties.TALB2018_1 : "NZ"}`,
barmode: 'stack'
}
},
{
id: "DHB_level",
data: ({ extraData }) => {
if (!extraData) return;
var cancer = extraData[0];
var years = [2012, 2013, 2014, 2015, 2016, 2017];
return [{
x: years,
y: years.map(year => cancer.filter(r => r.Year == year && r.Cases && r.Sex == "Male").reduce((sum, r) => sum + parseInt(r.Cases), 0)),
name: "Male",
type: 'bar',
}, {
x: years,
y: years.map(year => cancer.filter(r => r.Year == year && r.Cases && r.Sex == "Female").reduce((sum, r) => sum + parseInt(r.Cases), 0)),
name: "Female",
type: 'bar',
}];
},
layout: {
title: d => `DHB-level cancer over time in NZ`,
barmode: 'stack'
}
}
]
})
</script>
</body>
</html>