Spaces:
Running
Running
File size: 5,597 Bytes
4bb817b |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ABC LoCs</title>
<!-- Include ECharts library -->
<script src="https://cdn.jsdelivr.net/npm/echarts@latest/dist/echarts.min.js"></script>
<!-- Include jQuery library -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<!-- Placeholder for the chart -->
<div id="main" style="width: 100%; height: fit-content; min-height: 800px;"></div>
<script>
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
myChart.showLoading();
$.getJSON('data/output_echart.json')
.done(function (graph) {
myChart.hideLoading();
var functionNodes = graph.nodes.filter(node => node.category !== 0);
var organizationNodes = graph.nodes.filter(node => node.category === 0);
// Define colors for the functions matching those in the JSON
var functionColors = {
// "Data curation and hosting": "#5470c6",
// "Access to computational resources": "#fc8452",
// "Education and capacity building": "#fac858",
// "Field Data Collection": "#ee6666",
// "Global Research Collaboration": "#73c0de",
// "Inclusive community building and engagement": "#3ba272",
// "Tech transfer and open-source tools development": "#9a60b4"
"Data curation and hosting": "#7f3c8d",
"Access to computational resources": "#11a579",
"Education and capacity building": "#3969ac",
"Field Data Collection": "#f2b701",
"Global Research Collaboration": "#e73f74",
"Inclusive community building and engagement": "#80ba5a",
"Tech transfer and open-source tools development": "#e68310"
};
functionNodes.forEach((node, index) => {
node.x = Math.cos(2 * Math.PI * index / functionNodes.length) * 400;
node.y = Math.sin(2 * Math.PI * index / functionNodes.length) * 400;
node.symbolSize = 125;
node.itemStyle = { color: functionColors[node.name] };
var verticalPadding = node.y / 2 ;
var paddingRight = node.y >= 0 ? node.symbolSize : 0-node.symbolSize;
node.symbol = node.value;
node.label = {
show: true,
rotate: false,
position: 'inside',
align: 'center',
verticalAlign: 'middle',
// backgroundColor: '#000',
rotate: false,
padding: [0, paddingRight, 0, 0],
fontweight: 'bold',
fontSize: 12,
color: '#fff',
formatter: function(params) {
var name = params.data.name;
return wrapText(name, 15); // Handle text wrapping
}
// formatter: '{b}'
};
});
organizationNodes.forEach((node, index) => {
node.x = Math.cos(2 * Math.PI * index / organizationNodes.length) * 500;
node.y = Math.sin(2 * Math.PI * index / organizationNodes.length) * 500;
node.symbolSize = 5;
node.itemStyle = { color: '#000' };
node.label = {
show: true,
fontSize: 10,
color: '#000',
formatter: function(params) {
var name = params.data.name;
return wrapText(name, 50);
}
};
});
function wrapText(text, maxLength) {
var words = text.split(' ');
var lines = [];
var currentLine = '';
words.forEach(function(word) {
if (currentLine.length + word.length <= maxLength) {
currentLine += (currentLine ? ' ' : '') + word;
} else {
lines.push(currentLine);
currentLine = word;
}
});
lines.push(currentLine);
return lines.join('\n');
}
var option = {
tooltip: {
trigger: 'item',
formatter: function (params) {
return params.name;
}
},
animationDuration: 1500,
animationEasingUpdate: 'quinticInOut',
series: [
{
name: 'ABC LoCs',
type: 'graph',
layout: 'circular',
data: functionNodes.concat(organizationNodes),
links: graph.links.map(link => ({
...link,
lineStyle: {
color: functionColors[link.target] || '#ccc',
width: 1,
curveness: 0.3
}
})),
circular: {
rotateLabel: true
},
roam: false,
draggable: true,
labelLayout: {
hideOverlap: true
},
lineStyle: {
curveness: 0.2,
width: 1
},
emphasis: {
focus: 'adjacency',
lineStyle: {
width: 2
}
}
}
]
};
// Apply the updated option to the chart
myChart.setOption(option);
})
.fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.log("Request Failed: " + err);
chartDom.innerHTML = "Failed to load data: " + err;
});
</script>
</body>
</html>
|