eaglelandsonce
commited on
Commit
•
48c1006
1
Parent(s):
e03a28f
Rename pages/Base6Example.py to pages/5_Base6Example.py
Browse files- pages/5_Base6Example.py +107 -0
- pages/Base6Example.py +0 -59
pages/5_Base6Example.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
|
4 |
+
# HTML content
|
5 |
+
html_content = """
|
6 |
+
<!DOCTYPE html>
|
7 |
+
<html lang="en">
|
8 |
+
<head>
|
9 |
+
<meta charset="UTF-8">
|
10 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
11 |
+
<title>2D Canvas Base 6 with Hidden State in Red</title>
|
12 |
+
<style>
|
13 |
+
body { font-family: Arial, sans-serif; }
|
14 |
+
#coordinate-display {
|
15 |
+
position: absolute;
|
16 |
+
top: 10px;
|
17 |
+
left: 10px;
|
18 |
+
background-color: rgba(255, 255, 255, 0.7);
|
19 |
+
padding: 5px;
|
20 |
+
border-radius: 5px;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<h1>2D Interactive Graph Base 6 With Hidden State in Red</h1>
|
26 |
+
<div style="position: relative;">
|
27 |
+
<canvas id="graphCanvas" width="500" height="400" style="border: 1px solid #000;"></canvas>
|
28 |
+
<div id="coordinate-display"></div>
|
29 |
+
</div>
|
30 |
+
|
31 |
+
<script>
|
32 |
+
const canvas = document.getElementById('graphCanvas');
|
33 |
+
const ctx = canvas.getContext('2d');
|
34 |
+
const coordinateDisplay = document.getElementById('coordinate-display');
|
35 |
+
|
36 |
+
function shouldHighlightCoordinate(num) {
|
37 |
+
return ['6', '7', '8', '9'].some(digit => num.toString().includes(digit));
|
38 |
+
}
|
39 |
+
|
40 |
+
function drawGraph() {
|
41 |
+
// Clear canvas
|
42 |
+
ctx.fillStyle = '#f0f0f0';
|
43 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
44 |
+
|
45 |
+
// Draw grid
|
46 |
+
ctx.strokeStyle = '#999';
|
47 |
+
ctx.lineWidth = 0.5;
|
48 |
+
for (let i = 0; i <= 55; i += 5) {
|
49 |
+
let x = i / 55 * canvas.width;
|
50 |
+
let y = canvas.height - (i / 55 * canvas.height);
|
51 |
+
|
52 |
+
ctx.beginPath();
|
53 |
+
ctx.moveTo(x, 0);
|
54 |
+
ctx.lineTo(x, canvas.height);
|
55 |
+
ctx.stroke();
|
56 |
+
|
57 |
+
ctx.beginPath();
|
58 |
+
ctx.moveTo(0, y);
|
59 |
+
ctx.lineTo(canvas.width, y);
|
60 |
+
ctx.stroke();
|
61 |
+
|
62 |
+
// Draw labels
|
63 |
+
ctx.fillStyle = 'black';
|
64 |
+
ctx.font = '12px Arial';
|
65 |
+
ctx.fillText(i.toString(), x, canvas.height - 5);
|
66 |
+
ctx.fillText(i.toString(), 5, y);
|
67 |
+
}
|
68 |
+
|
69 |
+
// Draw highlighted areas
|
70 |
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
|
71 |
+
for (let i = 0; i <= 55; i++) {
|
72 |
+
if (shouldHighlightCoordinate(i)) {
|
73 |
+
ctx.fillRect(i / 55 * canvas.width, 0, canvas.width / 55, canvas.height);
|
74 |
+
ctx.fillRect(0, canvas.height - ((i + 1) / 55 * canvas.height), canvas.width, canvas.height / 55);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
function updateCoordinateDisplay(event) {
|
80 |
+
const rect = canvas.getBoundingClientRect();
|
81 |
+
const x = Math.min(55, Math.round((event.clientX - rect.left) / canvas.width * 55));
|
82 |
+
const y = Math.round((1 - (event.clientY - rect.top) / canvas.height) * 55);
|
83 |
+
const combined = x * 100 + y;
|
84 |
+
|
85 |
+
coordinateDisplay.textContent = `Coordinate: ${combined}`;
|
86 |
+
coordinateDisplay.style.color = shouldHighlightCoordinate(combined) ? 'red' : 'black';
|
87 |
+
}
|
88 |
+
|
89 |
+
canvas.addEventListener('mousemove', updateCoordinateDisplay);
|
90 |
+
|
91 |
+
drawGraph();
|
92 |
+
</script>
|
93 |
+
</body>
|
94 |
+
</html>
|
95 |
+
"""
|
96 |
+
|
97 |
+
# Streamlit app
|
98 |
+
def main():
|
99 |
+
st.set_page_config(page_title="Interactive 2D Graph", layout="wide")
|
100 |
+
|
101 |
+
st.title("2D Interactive Graph Base 6 With Hidden State in Red")
|
102 |
+
|
103 |
+
# Embed the HTML content
|
104 |
+
components.html(html_content, height=600)
|
105 |
+
|
106 |
+
if __name__ == "__main__":
|
107 |
+
main()
|
pages/Base6Example.py
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import plotly.graph_objects as go
|
4 |
-
|
5 |
-
def should_highlight_coordinate(num):
|
6 |
-
return any(digit in str(num) for digit in ['6', '7', '8', '9'])
|
7 |
-
|
8 |
-
def create_interactive_graph():
|
9 |
-
# Create a DataFrame for the grid
|
10 |
-
df = pd.DataFrame([(x, y) for x in range(56) for y in range(56)], columns=['x', 'y'])
|
11 |
-
df['combined'] = df['x'] * 100 + df['y']
|
12 |
-
df['highlight'] = df['combined'].apply(should_highlight_coordinate)
|
13 |
-
|
14 |
-
# Create the Plotly figure
|
15 |
-
fig = go.Figure()
|
16 |
-
|
17 |
-
# Add highlighted areas
|
18 |
-
highlighted_points = df[df['highlight']]
|
19 |
-
fig.add_trace(go.Scatter(
|
20 |
-
x=highlighted_points['x'],
|
21 |
-
y=highlighted_points['y'],
|
22 |
-
mode='markers',
|
23 |
-
marker=dict(color='rgba(0, 0, 0, 0.2)', size=5),
|
24 |
-
showlegend=False
|
25 |
-
))
|
26 |
-
|
27 |
-
# Add grid lines
|
28 |
-
for i in range(0, 56, 5):
|
29 |
-
fig.add_shape(type="line", x0=i, y0=0, x1=i, y1=55, line=dict(color="gray", width=0.5))
|
30 |
-
fig.add_shape(type="line", x0=0, y0=i, x1=55, y1=i, line=dict(color="gray", width=0.5))
|
31 |
-
|
32 |
-
# Customize the layout
|
33 |
-
fig.update_layout(
|
34 |
-
xaxis=dict(range=[0, 55], dtick=5, title="X"),
|
35 |
-
yaxis=dict(range=[0, 55], dtick=5, title="Y"),
|
36 |
-
width=700,
|
37 |
-
height=600,
|
38 |
-
title="2D Interactive Graph Base 6 With Hidden State in Red"
|
39 |
-
)
|
40 |
-
|
41 |
-
return fig
|
42 |
-
|
43 |
-
def main():
|
44 |
-
st.set_page_config(page_title="Interactive 2D Graph", layout="wide")
|
45 |
-
|
46 |
-
st.title("2D Interactive Graph Base 6 With Hidden State in Red")
|
47 |
-
|
48 |
-
fig = create_interactive_graph()
|
49 |
-
|
50 |
-
# Display the graph
|
51 |
-
st.plotly_chart(fig, use_container_width=True)
|
52 |
-
|
53 |
-
# Display coordinate information
|
54 |
-
st.markdown("### Coordinate Information")
|
55 |
-
st.markdown("Hover over the graph to see coordinate information.")
|
56 |
-
st.markdown("Coordinates containing 6, 7, 8, or 9 are highlighted.")
|
57 |
-
|
58 |
-
if __name__ == "__main__":
|
59 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|