|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Fix duplicate canvas declaration in DPI fix. |
| 4 | +Change 'const canvas' to just use the existing canvas variable. |
| 5 | +""" |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +def fix_duplicate_canvas(file_path): |
| 10 | + """Fix duplicate canvas declaration.""" |
| 11 | + |
| 12 | + with open(file_path, 'r', encoding='utf-8') as f: |
| 13 | + content = f.read() |
| 14 | + |
| 15 | + # Replace the duplicate canvas declaration in DPI fix |
| 16 | + old_dpi_fix = ''' // Fix blurry canvas on high-DPI displays |
| 17 | + const dpr = window.devicePixelRatio || 1; |
| 18 | + const canvas = document.getElementById('severityChart'); |
| 19 | + const rect = canvas.getBoundingClientRect();''' |
| 20 | + |
| 21 | + new_dpi_fix = ''' // Fix blurry canvas on high-DPI displays |
| 22 | + const dpr = window.devicePixelRatio || 1; |
| 23 | + const rect = canvas.getBoundingClientRect();''' |
| 24 | + |
| 25 | + if old_dpi_fix in content: |
| 26 | + content = content.replace(old_dpi_fix, new_dpi_fix) |
| 27 | + |
| 28 | + with open(file_path, 'w', encoding='utf-8') as f: |
| 29 | + f.write(content) |
| 30 | + |
| 31 | + print(f"Fixed: {file_path.name}") |
| 32 | + else: |
| 33 | + print(f"Skipped (pattern not found): {file_path.name}") |
| 34 | + |
| 35 | + |
| 36 | +def main(): |
| 37 | + """Process all severity chart files.""" |
| 38 | + |
| 39 | + # Find all BAU and PM severity charts |
| 40 | + bau_charts = sorted(Path('.').glob('risk*_bau_chart.html')) |
| 41 | + pm_charts = sorted(Path('.').glob('risk*_pm_chart.html')) |
| 42 | + |
| 43 | + all_charts = bau_charts + pm_charts |
| 44 | + |
| 45 | + if not all_charts: |
| 46 | + print("No severity charts found!") |
| 47 | + return |
| 48 | + |
| 49 | + print(f"Found {len(all_charts)} severity charts") |
| 50 | + print(f"Fixing duplicate canvas declarations...\n") |
| 51 | + |
| 52 | + for chart_file in all_charts: |
| 53 | + fix_duplicate_canvas(chart_file) |
| 54 | + |
| 55 | + print(f"\nCompleted!") |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + main() |
0 commit comments