@@ -19,12 +19,22 @@ export async function drawSkills() {
19
19
] ;
20
20
21
21
function drawSkillChart ( svgId , chartData , shapeSides ) {
22
- const radius = 200 ;
23
- const centerX = 250 ;
24
- const centerY = 250 ;
22
+ const svg = document . getElementById ( svgId ) ;
23
+ const width = svg . clientWidth ;
24
+ const height = svg . clientHeight ;
25
+ const centerX = width / 2 ;
26
+ const centerY = height / 2 ;
27
+ const radius = Math . min ( centerX , centerY ) * 0.8 ;
25
28
const angleIncrement = 360 / shapeSides ;
26
29
27
- const svg = document . getElementById ( svgId ) ;
30
+ // Clear previous contents
31
+ while ( svg . firstChild ) {
32
+ svg . removeChild ( svg . firstChild ) ;
33
+ }
34
+
35
+ // Set the viewBox attribute for responsiveness
36
+ svg . setAttribute ( 'viewBox' , `0 0 ${ width } ${ height } ` ) ;
37
+ svg . setAttribute ( 'preserveAspectRatio' , 'xMidYMid meet' ) ;
28
38
29
39
// Draw the 100% radius circle
30
40
const outerCircle = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'circle' ) ;
@@ -89,6 +99,14 @@ export async function drawSkills() {
89
99
} ) ;
90
100
}
91
101
92
- drawSkillChart ( 'techChart' , techData , techData . length ) ;
93
- drawSkillChart ( 'skillChart' , techSkills , techSkills . length ) ;
102
+ function resizeCharts ( ) {
103
+ drawSkillChart ( 'techChart' , techData , techData . length ) ;
104
+ drawSkillChart ( 'skillChart' , techSkills , techSkills . length ) ;
105
+ }
106
+
107
+ // Initial draw
108
+ resizeCharts ( ) ;
109
+
110
+ // Redraw charts on window resize
111
+ window . addEventListener ( 'resize' , resizeCharts ) ;
94
112
}
0 commit comments