-
Notifications
You must be signed in to change notification settings - Fork 6
/
plots.js
43 lines (38 loc) · 1.44 KB
/
plots.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
// Init function takes ID num and sets them as
// options of the dropdown menu
function init() {
var selector = d3.select("#selDataset");
d3.json("samples.json").then((data) => {
console.log(data);
var sampleNames = data.names;
sampleNames.forEach((sample) => {
selector
.append("option")
.text(sample)
.property("value", sample);
});
})}
init();
// optionChanged function is called in html
function optionChanged(newSample) {
console.log(newSample);
buildMetadata(newSample);
buildCharts(newSample);
}
// buildMetadata function called in optionChanged
function buildMetadata(sample) {
d3.json("samples.json").then((data) => {
var metadata = data.metadata;
var resultsArray = metadata.filter(sampleObj => sampleObj.id == sample);
var result = resultsArray[0]; //Because results are returned like an array =[0]
var PANEL = d3.select("#sample-metadata");
PANEL.html(""); //Clear content before other id gets called
PANEL.append("h6").text(`ID: ${result.id}`);
PANEL.append("h6").text(`Ethnicity: ${result.ethnicity}`);
PANEL.append("h6").text(`Gender: ${result.gender}`);
PANEL.append("h6").text(`Age: ${result.age}`);
PANEL.append("h6").text(`Location: ${result.location}`);
PANEL.append("h6").text(`BBtype: ${result.bbtype}`);
PANEL.append("h6").text(`Washing/week: ${result.wfreq}`);
});
}