-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_dpi_fix_simple.py
More file actions
83 lines (62 loc) · 2.56 KB
/
add_dpi_fix_simple.py
File metadata and controls
83 lines (62 loc) · 2.56 KB
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
#!/usr/bin/env python3
"""
Add DPI fix after medianValuesPlugin closing brace.
"""
from pathlib import Path
def add_dpi_fix(file_path):
"""Add DPI fix after medianValuesPlugin closes."""
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
# Check if already has DPI fix
for line in lines:
if '// Fix blurry canvas on high-DPI displays' in line:
print(f"Skipped (already has DPI fix): {file_path.name}")
return
dpi_fix_lines = [
'\n',
' // Fix blurry canvas on high-DPI displays\n',
' const dpr = window.devicePixelRatio || 1;\n',
' const canvas = document.getElementById(\'severityChart\');\n',
' const rect = canvas.getBoundingClientRect();\n',
' canvas.width = rect.width * dpr;\n',
' canvas.height = rect.height * dpr;\n',
' ctx.scale(dpr, dpr);\n'
]
# Find the line with " };" that closes medianValuesPlugin
# It should be after the plugin definition and before the chart creation
new_lines = []
found_plugin_close = False
for i, line in enumerate(lines):
new_lines.append(line)
# Look for the closing of medianValuesPlugin
if not found_plugin_close and line.strip() == '};':
# Check if this is after medianValues plugin definition
# Look back to see if we recently saw the plugin
lookback = ''.join(lines[max(0, i-200):i])
if 'medianValuesPlugin' in lookback and 'afterDatasetsDraw' in lookback:
# Add DPI fix after this line
new_lines.extend(dpi_fix_lines)
found_plugin_close = True
if not found_plugin_close:
print(f"ERROR: Could not find medianValuesPlugin closing in {file_path.name}")
return
# Write back
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(new_lines)
print(f"Updated: {file_path.name}")
def main():
"""Process all severity chart files."""
# Find all BAU and PM severity charts
bau_charts = sorted(Path('.').glob('risk*_bau_chart.html'))
pm_charts = sorted(Path('.').glob('risk*_pm_chart.html'))
all_charts = bau_charts + pm_charts
if not all_charts:
print("No severity charts found!")
return
print(f"Found {len(all_charts)} severity charts")
print(f"Adding DPI fix after medianValuesPlugin...\n")
for chart_file in all_charts:
add_dpi_fix(chart_file)
print(f"\nCompleted!")
if __name__ == '__main__':
main()