File size: 3,990 Bytes
a4af9c5 | 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 | <!DOCTYPE html>
<html>
<head>
<title>Spiral Visualization with Flask</title>
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
.controls {
margin: 20px 0;
padding: 20px;
background-color: #f8f9fa;
border-radius: 5px;
}
.slider-container {
margin: 15px 0;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="range"] {
width: 100%;
}
.value-display {
display: inline-block;
width: 50px;
text-align: right;
}
#vis {
width: 700px;
height: 700px;
margin: 20px auto;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to Flask Spiral Visualization!</h1>
<div class="controls">
<div class="slider-container">
<label for="points">Number of points in spiral: <span id="points-value" class="value-display">1100</span></label>
<input type="range" id="points" name="points" min="1" max="10000" value="1100">
</div>
<div class="slider-container">
<label for="turns">Number of turns in spiral: <span id="turns-value" class="value-display">31</span></label>
<input type="range" id="turns" name="turns" min="1" max="300" value="31">
</div>
<button onclick="updateChart()">Update Chart</button>
</div>
<div id="vis"></div>
</div>
<script>
// Initialize slider value displays
document.getElementById('points').addEventListener('input', function() {
document.getElementById('points-value').textContent = this.value;
});
document.getElementById('turns').addEventListener('input', function() {
document.getElementById('turns-value').textContent = this.value;
});
// Function to update the chart
function updateChart() {
const numPoints = document.getElementById('points').value;
const numTurns = document.getElementById('turns').value;
fetch('/generate_chart', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
num_points: parseInt(numPoints),
num_turns: parseInt(numTurns)
})
})
.then(response => response.json())
.then(data => {
vegaEmbed('#vis', JSON.parse(data.chart));
})
.catch(error => {
console.error('Error:', error);
});
}
// Load initial chart
document.addEventListener('DOMContentLoaded', function() {
updateChart();
});
</script>
</body>
</html> |