-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_layout_optimization.py
More file actions
152 lines (127 loc) · 4.13 KB
/
fix_layout_optimization.py
File metadata and controls
152 lines (127 loc) · 4.13 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
"""
Script to fix label positioning, optimize white space, and make legends more compact.
"""
import re
from pathlib import Path
def fix_layout(file_path):
"""Optimize the layout with better label positioning and compact legends."""
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Fix severity labels positioning - align them better with chart columns
# Remove the previous positioning and replace with better values
severity_label_positions = r''' .severity-label:nth-child(1) { left: 10%; transform: translateX(-50%); }
.severity-label:nth-child(2) { left: 30%; transform: translateX(-50%); }
.severity-label:nth-child(3) { left: 50%; transform: translateX(-50%); }
.severity-label:nth-child(4) { left: 70%; transform: translateX(-50%); }
.severity-label:nth-child(5) { left: 90%; transform: translateX(-50%); }'''
# Replace all severity-label:nth-child positioning
content = re.sub(
r'\.severity-label:nth-child\(1\)[^}]*\}',
'',
content
)
content = re.sub(
r'\.severity-label:nth-child\(2\)[^}]*\}',
'',
content
)
content = re.sub(
r'\.severity-label:nth-child\(3\)[^}]*\}',
'',
content
)
content = re.sub(
r'\.severity-label:nth-child\(4\)[^}]*\}',
'',
content
)
content = re.sub(
r'\.severity-label:nth-child\(5\)[^}]*\}',
'',
content
)
# Add the new positioning before the media query
media_query_pos = content.find('@media (max-width: 600px)')
if media_query_pos != -1:
content = content[:media_query_pos] + severity_label_positions + '\n ' + content[media_query_pos:]
# Update severity-label CSS to reduce max-width and adjust size
severity_label_css = r''' .severity-label {
font-size: 13px;
font-weight: bold;
white-space: normal;
position: absolute;
max-width: 16%;
text-align: center;
line-height: 1.1;
word-wrap: break-word;
hyphens: auto;
}'''
content = re.sub(
r'\.severity-label\s*\{[^}]*\}',
severity_label_css,
content,
flags=re.DOTALL
)
# Make the legend more compact
legend_css = r''' .legend {
margin-top: 15px;
padding: 8px 10px;
background: #f9f9f9;
border-radius: 4px;
display: flex;
justify-content: center;
gap: 15px;
flex-wrap: wrap;
}'''
content = re.sub(
r'\.legend\s*\{[^}]*\}',
legend_css,
content,
flags=re.DOTALL
)
# Make legend items more compact
legend_item_css = r''' .legend-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 12px;
font-weight: 500;
}'''
content = re.sub(
r'\.legend-item\s*\{[^}]*\}',
legend_item_css,
content,
flags=re.DOTALL
)
# Reduce severity-labels margin
content = re.sub(
r'(\.severity-labels\s*\{[^}]*margin-top:\s*)-?\d+px;',
r'\g<1>-5px;',
content
)
content = re.sub(
r'(\.severity-labels\s*\{[^}]*margin-bottom:\s*)\d+px;',
r'\g<1>8px;',
content
)
# Write back
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)
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"Optimizing layout and positioning...\n")
for chart_file in all_charts:
fix_layout(chart_file)
print(f"\nCompleted! Updated {len(all_charts)} files.")
if __name__ == '__main__':
main()