Skip to content

Commit 42f7a96

Browse files
committed
push
1 parent b6f9bdd commit 42f7a96

49 files changed

Lines changed: 127 additions & 336 deletions

Some content is hidden

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

fix_dpi_final_correct.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Apply the EXACT structure from exemplar: ctx first, then DPI fix without redefining ctx.
4+
"""
5+
6+
import re
7+
from pathlib import Path
8+
9+
def fix_dpi_correct(file_path):
10+
"""Fix DPI with correct structure from exemplar."""
11+
12+
with open(file_path, 'r', encoding='utf-8') as f:
13+
content = f.read()
14+
15+
# The correct pattern from exemplar:
16+
# 1. const ctx = getContext
17+
# 2. medianValuesPlugin
18+
# 3. DPI fix (that uses ctx, doesn't redefine it)
19+
20+
# Remove the broken DPI fix that redefines ctx
21+
content = re.sub(
22+
r'// Fix blurry canvas on high-DPI displays\s*const ctx = document\.getElementById.*?ctx\.scale\(dpr, dpr\);',
23+
'',
24+
content,
25+
flags=re.DOTALL
26+
)
27+
28+
# Now find where medianValuesPlugin ends (look for the closing };)
29+
# and insert the DPI fix RIGHT AFTER it
30+
31+
dpi_fix_correct = '''
32+
// Fix blurry canvas on high-DPI displays
33+
const dpr = window.devicePixelRatio || 1;
34+
const canvas = document.getElementById('severityChart');
35+
const rect = canvas.getBoundingClientRect();
36+
canvas.width = rect.width * dpr;
37+
canvas.height = rect.height * dpr;
38+
ctx.scale(dpr, dpr);
39+
'''
40+
41+
# Find the end of medianValuesPlugin and insert DPI fix after it
42+
# Pattern: closing of medianValuesPlugin followed by whitespace then either // Track hover or something else
43+
pattern = r'(const medianValuesPlugin = \{[^}]+afterDatasetsDraw:[^}]+\}\s*\};)\s*\n'
44+
45+
replacement = r'\1' + dpi_fix_correct + '\n'
46+
47+
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
48+
49+
# Write back
50+
with open(file_path, 'w', encoding='utf-8') as f:
51+
f.write(content)
52+
53+
print(f"Updated: {file_path.name}")
54+
55+
56+
def main():
57+
"""Process all severity chart files."""
58+
59+
# Find all BAU and PM severity charts
60+
bau_charts = sorted(Path('.').glob('risk*_bau_chart.html'))
61+
pm_charts = sorted(Path('.').glob('risk*_pm_chart.html'))
62+
63+
all_charts = bau_charts + pm_charts
64+
65+
if not all_charts:
66+
print("No severity charts found!")
67+
return
68+
69+
print(f"Found {len(all_charts)} severity charts")
70+
print(f"Applying correct DPI fix structure from exemplar...\n")
71+
72+
for chart_file in all_charts:
73+
fix_dpi_correct(chart_file)
74+
75+
print(f"\nCompleted! Updated {len(all_charts)} files.")
76+
77+
78+
if __name__ == '__main__':
79+
main()

risk10_bau_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,13 +1687,7 @@
16871687

16881688
// Create chart with custom plugin for colored squares
16891689
const canvas = document.getElementById('severityChart');
1690-
// Fix blurry canvas on high-DPI displays
1691-
const ctx = document.getElementById('severityChart').getContext('2d');
1692-
const dpr = window.devicePixelRatio || 1;
1693-
const rect = canvas.getBoundingClientRect();
1694-
canvas.width = rect.width * dpr;
1695-
canvas.height = rect.height * dpr;
1696-
ctx.scale(dpr, dpr);
1690+
16971691

16981692

16991693
let hoveredExpertIndex = null;

risk10_pm_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,13 +1687,7 @@
16871687

16881688
// Create chart with custom plugin for colored squares
16891689
const canvas = document.getElementById('severityChart');
1690-
// Fix blurry canvas on high-DPI displays
1691-
const ctx = document.getElementById('severityChart').getContext('2d');
1692-
const dpr = window.devicePixelRatio || 1;
1693-
const rect = canvas.getBoundingClientRect();
1694-
canvas.width = rect.width * dpr;
1695-
canvas.height = rect.height * dpr;
1696-
ctx.scale(dpr, dpr);
1690+
16971691

16981692

16991693
let hoveredExpertIndex = null;

risk11_bau_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,13 +2712,7 @@
27122712

27132713
// Create chart with custom plugin for colored squares
27142714
const canvas = document.getElementById('severityChart');
2715-
// Fix blurry canvas on high-DPI displays
2716-
const ctx = document.getElementById('severityChart').getContext('2d');
2717-
const dpr = window.devicePixelRatio || 1;
2718-
const rect = canvas.getBoundingClientRect();
2719-
canvas.width = rect.width * dpr;
2720-
canvas.height = rect.height * dpr;
2721-
ctx.scale(dpr, dpr);
2715+
27222716

27232717

27242718
let hoveredExpertIndex = null;

risk11_pm_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,13 +2712,7 @@
27122712

27132713
// Create chart with custom plugin for colored squares
27142714
const canvas = document.getElementById('severityChart');
2715-
// Fix blurry canvas on high-DPI displays
2716-
const ctx = document.getElementById('severityChart').getContext('2d');
2717-
const dpr = window.devicePixelRatio || 1;
2718-
const rect = canvas.getBoundingClientRect();
2719-
canvas.width = rect.width * dpr;
2720-
canvas.height = rect.height * dpr;
2721-
ctx.scale(dpr, dpr);
2715+
27222716

27232717

27242718
let hoveredExpertIndex = null;

risk12_bau_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,13 +2862,7 @@
28622862

28632863
// Create chart with custom plugin for colored squares
28642864
const canvas = document.getElementById('severityChart');
2865-
// Fix blurry canvas on high-DPI displays
2866-
const ctx = document.getElementById('severityChart').getContext('2d');
2867-
const dpr = window.devicePixelRatio || 1;
2868-
const rect = canvas.getBoundingClientRect();
2869-
canvas.width = rect.width * dpr;
2870-
canvas.height = rect.height * dpr;
2871-
ctx.scale(dpr, dpr);
2865+
28722866

28732867

28742868
let hoveredExpertIndex = null;

risk12_pm_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,13 +2862,7 @@
28622862

28632863
// Create chart with custom plugin for colored squares
28642864
const canvas = document.getElementById('severityChart');
2865-
// Fix blurry canvas on high-DPI displays
2866-
const ctx = document.getElementById('severityChart').getContext('2d');
2867-
const dpr = window.devicePixelRatio || 1;
2868-
const rect = canvas.getBoundingClientRect();
2869-
canvas.width = rect.width * dpr;
2870-
canvas.height = rect.height * dpr;
2871-
ctx.scale(dpr, dpr);
2865+
28722866

28732867

28742868
let hoveredExpertIndex = null;

risk13_bau_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,13 +1962,7 @@
19621962

19631963
// Create chart with custom plugin for colored squares
19641964
const canvas = document.getElementById('severityChart');
1965-
// Fix blurry canvas on high-DPI displays
1966-
const ctx = document.getElementById('severityChart').getContext('2d');
1967-
const dpr = window.devicePixelRatio || 1;
1968-
const rect = canvas.getBoundingClientRect();
1969-
canvas.width = rect.width * dpr;
1970-
canvas.height = rect.height * dpr;
1971-
ctx.scale(dpr, dpr);
1965+
19721966

19731967

19741968
let hoveredExpertIndex = null;

risk13_pm_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,13 +1962,7 @@
19621962

19631963
// Create chart with custom plugin for colored squares
19641964
const canvas = document.getElementById('severityChart');
1965-
// Fix blurry canvas on high-DPI displays
1966-
const ctx = document.getElementById('severityChart').getContext('2d');
1967-
const dpr = window.devicePixelRatio || 1;
1968-
const rect = canvas.getBoundingClientRect();
1969-
canvas.width = rect.width * dpr;
1970-
canvas.height = rect.height * dpr;
1971-
ctx.scale(dpr, dpr);
1965+
19721966

19731967

19741968
let hoveredExpertIndex = null;

risk14_bau_chart.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,13 +1637,7 @@
16371637

16381638
// Create chart with custom plugin for colored squares
16391639
const canvas = document.getElementById('severityChart');
1640-
// Fix blurry canvas on high-DPI displays
1641-
const ctx = document.getElementById('severityChart').getContext('2d');
1642-
const dpr = window.devicePixelRatio || 1;
1643-
const rect = canvas.getBoundingClientRect();
1644-
canvas.width = rect.width * dpr;
1645-
canvas.height = rect.height * dpr;
1646-
ctx.scale(dpr, dpr);
1640+
16471641

16481642

16491643
let hoveredExpertIndex = null;

0 commit comments

Comments
 (0)