Skip to content

Commit 67e54f0

Browse files
committed
push
1 parent b6c913a commit 67e54f0

51 files changed

Lines changed: 5590 additions & 5280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

final_fix.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Final fix: Apply the working structure from exemplar.
4+
1. Only ctx at the start (no canvas)
5+
2. medianValuesPlugin
6+
3. DPI fix (which defines canvas)
7+
4. Chart creation
8+
5. Event handlers AFTER chart
9+
"""
10+
11+
from pathlib import Path
12+
import re
13+
14+
def fix_chart_file(file_path):
15+
"""Fix a single chart file."""
16+
17+
with open(file_path, 'r', encoding='utf-8') as f:
18+
content = f.read()
19+
20+
# Step 1: Remove any existing "const canvas = " line that comes before the DPI fix
21+
# This is the line that comes right before "const ctx"
22+
content = re.sub(
23+
r' const canvas = document\.getElementById\(\'severityChart\'\);\n const ctx = document\.getElementById\(\'severityChart\'\)\.getContext\(\'2d\'\);',
24+
r' const ctx = document.getElementById(\'severityChart\').getContext(\'2d\');',
25+
content
26+
)
27+
28+
# Step 2: Ensure the DPI fix is in the right place and defines canvas
29+
# Remove any existing DPI fix
30+
content = re.sub(
31+
r'\n // Fix blurry canvas on high-DPI displays\n const dpr = window\.devicePixelRatio \|\| 1;\n const (rect|canvas) = .*?\n .*?\n .*?\n ctx\.scale\(dpr, dpr\);',
32+
'',
33+
content,
34+
flags=re.DOTALL
35+
)
36+
37+
# Add DPI fix right before chart creation
38+
dpi_fix = '''
39+
// Fix blurry canvas on high-DPI displays
40+
const dpr = window.devicePixelRatio || 1;
41+
const canvas = document.getElementById('severityChart');
42+
const rect = canvas.getBoundingClientRect();
43+
canvas.width = rect.width * dpr;
44+
canvas.height = rect.height * dpr;
45+
ctx.scale(dpr, dpr);
46+
47+
'''
48+
49+
# Insert before "const chart = new Chart"
50+
content = re.sub(
51+
r'( const chart = new Chart\(ctx,)',
52+
dpi_fix + r'\1',
53+
content
54+
)
55+
56+
# Step 3: Move mouse event handlers after chart creation
57+
# First, extract the handlers
58+
mouse_handler_pattern = r'(\n // Add mouse move handler for hover interaction\n const chartCanvas = document\.getElementById\(\'severityChart\'\);\n const tooltip = document\.getElementById\(\'expertTooltip\'\);.*?chartCanvas\.addEventListener\(\'mouseleave\'.*?\n \}\);\n)'
59+
60+
match = re.search(mouse_handler_pattern, content, re.DOTALL)
61+
62+
if match:
63+
handlers = match.group(1)
64+
# Remove from current location
65+
content = content.replace(handlers, '')
66+
67+
# Insert right before "// UI Controls"
68+
content = re.sub(
69+
r'(\n // UI Controls)',
70+
handlers + r'\1',
71+
content
72+
)
73+
74+
# Write back
75+
with open(file_path, 'w', encoding='utf-8') as f:
76+
f.write(content)
77+
78+
print(f"Fixed: {file_path.name}")
79+
80+
81+
def main():
82+
"""Process all severity chart files."""
83+
84+
# Find all BAU and PM severity charts
85+
bau_charts = sorted(Path('.').glob('risk*_bau_chart.html'))
86+
pm_charts = sorted(Path('.').glob('risk*_pm_chart.html'))
87+
88+
all_charts = bau_charts + pm_charts
89+
90+
if not all_charts:
91+
print("No severity charts found!")
92+
return
93+
94+
print(f"Found {len(all_charts)} severity charts")
95+
print(f"Applying final fix...\n")
96+
97+
for chart_file in all_charts:
98+
fix_chart_file(chart_file)
99+
100+
print(f"\nCompleted!")
101+
102+
103+
if __name__ == '__main__':
104+
main()

fix_event_handler_order.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Move mouse event handlers to AFTER chart creation.
4+
The handlers reference 'chart' so they must come after it's created.
5+
"""
6+
7+
from pathlib import Path
8+
import re
9+
10+
def fix_event_handler_order(file_path):
11+
"""Move event handlers after chart creation."""
12+
13+
with open(file_path, 'r', encoding='utf-8') as f:
14+
content = f.read()
15+
16+
# Pattern to match the mouse event handlers section
17+
# From "// Add mouse move handler" to the closing of the mouseleave handler
18+
event_handlers_pattern = r'( // Add mouse move handler for hover interaction\n const chartCanvas = document\.getElementById\(\'severityChart\'\);\n const tooltip = document\.getElementById\(\'expertTooltip\'\);\n\n chartCanvas\.addEventListener\(\'mousemove\',.*?chartCanvas\.addEventListener\(\'mouseleave\',.*?\n \}\);\n\n)'
19+
20+
match = re.search(event_handlers_pattern, content, re.DOTALL)
21+
22+
if not match:
23+
print(f"ERROR: Could not find event handlers in {file_path.name}")
24+
return
25+
26+
event_handlers = match.group(1)
27+
28+
# Remove the event handlers from their current location
29+
content = content.replace(event_handlers, '')
30+
31+
# Find the end of chart creation (closing of Chart constructor)
32+
# Look for the pattern where Chart(...) ends with }); followed by update button handlers
33+
# We want to insert BEFORE the button handlers
34+
35+
# Find "// Update mode buttons" or first button event listener
36+
insert_pattern = r'( // Update mode buttons| document\.getElementById\(\'exactBtn\'\)\.addEventListener)'
37+
38+
match = re.search(insert_pattern, content)
39+
if match:
40+
insert_pos = match.start()
41+
content = content[:insert_pos] + event_handlers + content[insert_pos:]
42+
43+
with open(file_path, 'w', encoding='utf-8') as f:
44+
f.write(content)
45+
46+
print(f"Fixed: {file_path.name}")
47+
else:
48+
print(f"ERROR: Could not find insertion point in {file_path.name}")
49+
50+
51+
def main():
52+
"""Process all severity chart files."""
53+
54+
# Find all BAU and PM severity charts
55+
bau_charts = sorted(Path('.').glob('risk*_bau_chart.html'))
56+
pm_charts = sorted(Path('.').glob('risk*_pm_chart.html'))
57+
58+
all_charts = bau_charts + pm_charts
59+
60+
if not all_charts:
61+
print("No severity charts found!")
62+
return
63+
64+
print(f"Found {len(all_charts)} severity charts")
65+
print(f"Moving event handlers after chart creation...\n")
66+
67+
for chart_file in all_charts:
68+
fix_event_handler_order(chart_file)
69+
70+
print(f"\nCompleted!")
71+
72+
73+
if __name__ == '__main__':
74+
main()

move_handlers_simple.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Move event handlers to after chart creation.
4+
"""
5+
6+
from pathlib import Path
7+
8+
def move_handlers(file_path):
9+
"""Move event handlers after chart creation."""
10+
11+
with open(file_path, 'r', encoding='utf-8') as f:
12+
lines = f.readlines()
13+
14+
# Find the event handler section
15+
handler_start = None
16+
handler_end = None
17+
18+
for i, line in enumerate(lines):
19+
if '// Add mouse move handler for hover interaction' in line:
20+
handler_start = i
21+
if handler_start is not None and 'chartCanvas.addEventListener(\'mouseleave\'' in line:
22+
# Find the closing }); of this addEventListener
23+
for j in range(i, min(i + 10, len(lines))):
24+
if '});' in lines[j]:
25+
handler_end = j + 1 # Include the line after });
26+
break
27+
break
28+
29+
if handler_start is None or handler_end is None:
30+
print(f"ERROR: Could not find event handlers in {file_path.name}")
31+
return
32+
33+
# Extract the event handler section (including blank line after)
34+
handler_lines = lines[handler_start:handler_end]
35+
36+
# Remove from current location
37+
del lines[handler_start:handler_end]
38+
39+
# Find where to insert: after the chart closing " });" and before " // UI Controls"
40+
insert_pos = None
41+
for i, line in enumerate(lines):
42+
if '// UI Controls' in line:
43+
insert_pos = i
44+
break
45+
46+
if insert_pos is None:
47+
print(f"ERROR: Could not find insertion point in {file_path.name}")
48+
return
49+
50+
# Insert the handlers before "// UI Controls"
51+
for j, handler_line in enumerate(handler_lines):
52+
lines.insert(insert_pos + j, handler_line)
53+
54+
# Write back
55+
with open(file_path, 'w', encoding='utf-8') as f:
56+
f.writelines(lines)
57+
58+
print(f"Fixed: {file_path.name}")
59+
60+
61+
def main():
62+
"""Process all severity chart files."""
63+
64+
# Find all BAU and PM severity charts
65+
bau_charts = sorted(Path('.').glob('risk*_bau_chart.html'))
66+
pm_charts = sorted(Path('.').glob('risk*_pm_chart.html'))
67+
68+
all_charts = bau_charts + pm_charts
69+
70+
if not all_charts:
71+
print("No severity charts found!")
72+
return
73+
74+
print(f"Found {len(all_charts)} severity charts")
75+
print(f"Moving event handlers...\n")
76+
77+
for chart_file in all_charts:
78+
move_handlers(chart_file)
79+
80+
print(f"\nCompleted!")
81+
82+
83+
if __name__ == '__main__':
84+
main()

0 commit comments

Comments
 (0)