|
|
(21 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| == Glioblastoma Treatments ==
| | {{#ask: [[Has Usefulness Rating::+]] |
| | | |?Has treatment name=Treatment Name |
| <div id="categories"></div>
| | |?Has Usefulness Rating=Usefulness Rating |
| <div id="plot"></div>
| | |?Has Toxicity Level=Toxicity Level |
| | | |?Category=Category |
| <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
| | | mainlabel=- |
| <script>
| | | format=json |
| // Fetch the JSON data from the query result
| | }} |
| fetch('/index.php?title=Special:Ask&format=json&q=[[Category:Treatments]]|%3FHas+treatment+name=Treatment|%3FHas+Effectiveness=Effectiveness|%3FHas+Toxicity=Toxicity|%3FHas+Category=Category|format=json|link=none|headers=hide|mainlabel=-')
| |
| .then(response => response.json())
| |
| .then(data => {
| |
| const treatments = data.results.map(item => ({
| |
| treatment: item.printouts['Treatment'][0],
| |
| effectiveness: parseInt(item.printouts['Effectiveness'][0]),
| |
| toxicity: parseInt(item.printouts['Toxicity'][0]),
| |
| category: item.printouts['Category'][0]
| |
| }));
| |
| | |
| const categories = [...new Set(treatments.map(t => t.category))];
| |
| | |
| // Create checkboxes for categories
| |
| const categoriesDiv = document.getElementById('categories');
| |
| categories.forEach(category => {
| |
| const label = document.createElement('label');
| |
| const checkbox = document.createElement('input');
| |
| checkbox.type = 'checkbox';
| |
| checkbox.value = category;
| |
| checkbox.checked = true;
| |
| checkbox.addEventListener('change', updatePlot);
| |
| label.appendChild(checkbox);
| |
| label.appendChild(document.createTextNode(category));
| |
| categoriesDiv.appendChild(label);
| |
| });
| |
| | |
| // Initial plot
| |
| updatePlot();
| |
| | |
| function updatePlot() {
| |
| const selectedCategories = Array.from(document.querySelectorAll('#categories input[type="checkbox"]:checked')).map(cb => cb.value);
| |
| | |
| const filteredTreatments = treatments.filter(t => selectedCategories.includes(t.category));
| |
| | |
| const trace = {
| |
| x: filteredTreatments.map(t => t.effectiveness),
| |
| y: filteredTreatments.map(t => t.toxicity),
| |
| mode: 'markers',
| |
| type: 'scatter',
| |
| text: filteredTreatments.map(t => t.treatment),
| |
| marker: { color: filteredTreatments.map(t => categories.indexOf(t.category)) }
| |
| };
| |
| | |
| const layout = {
| |
| title: 'Glioblastoma Treatments',
| |
| xaxis: { title: 'Effectiveness' },
| |
| yaxis: { title: 'Toxicity', autorange: 'reversed' }
| |
| };
| |
| | |
| Plotly.newPlot('plot', [trace], layout);
| |
| }
| |
| });
| |
| </script>
| |