-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-visualization.js
43 lines (35 loc) · 1.35 KB
/
data-visualization.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
function showContent(contentId) {
var contents = document.querySelectorAll('.content-datavis');
contents.forEach(function(content) {
content.style.display = 'none';
});
document.getElementById(contentId).style.display = 'block';
}
document.addEventListener('DOMContentLoaded', function() {
function switchPlotlyTheme(theme) {
var newLayout = {
paper_bgcolor: theme === 'dark' ? '#2c2c2c' : 'white',
plot_bgcolor: theme === 'dark' ? '#2c2c2c' : 'white',
font: { color: theme === 'dark' ? 'white' : 'black' }
};
Plotly.relayout('plot2', newLayout);
Plotly.relayout('plot4', newLayout);
}
// Expose switchPlotTheme to the global scope
window.switchPlotlyTheme = switchPlotlyTheme;
});
function extractNumericalData(data) {
// TODO Adjust based on JSON structure
return data.map(item => ({ label: item.label, value: item.value }));
}
//** Extract (id, fieldname) as tuple from json data*/
function extractNumericalDataFromJSON(jsonData, fieldName) {
const dataPoints = JSON.parse(jsonData);
// Sort
dataPoints.sort((a,b) => a.data[fieldName] - b.data[fieldName]);
// Extract labels + num values by fieldName
const formattedData = dataPoints.map(point => {
return {x: point.label, y: point.data[fieldName]};
});
return formattedData;
}