@@ -12,6 +12,7 @@ const props = defineProps({
1212 },
1313})
1414
15+ const wrapperEl = ref ()
1516const chartEl = ref ()
1617const tooltipEl = ref ()
1718const tooltip = ref ({
@@ -20,11 +21,11 @@ const tooltip = ref({
2021})
2122
2223const buildChart = (chart ) => {
23- const { width , height } = chart .getBoundingClientRect ()
24+ const { width } = chart .getBoundingClientRect ()
2425
2526 const radialScale = d3 .scaleLinear ()
2627 .domain ([0 , 100 ])
27- .range ([0 , (width - 150 ) / 2 ])
28+ .range ([0 , (width - 160 ) / 2 ])
2829
2930 const maxRadius = radialScale (100 )
3031 const ticks = [25 , 50 , 75 , 100 ]
@@ -160,8 +161,8 @@ const buildChart = (chart) => {
160161 const svg = d3
161162 .create (" svg" )
162163 .attr (" width" , width)
163- .attr (" height" , height )
164- .attr (" viewBox" , [- width / 2 , - height / 2 + 20 , width, height ])
164+ .attr (" height" , width )
165+ .attr (" viewBox" , [- width / 2 , - width / 2 + 20 , width, width ])
165166 .attr (" preserveAspectRatio" , " none" )
166167 .attr (" style" , " max-width: 100%;" )
167168 .attr (" id" , " chart" )
@@ -185,17 +186,25 @@ const buildChart = (chart) => {
185186 for (let i = 0 ; i < features .length ; i++ ) {
186187 const angle = (- Math .PI / 2 ) + (2 * Math .PI * i / features .length )
187188 const lineCoordinate = angleToCoordinate (angle, 100 )
188- const labelCoordinate = angleToCoordinate (angle, 130 )
189+ const labelCoordinate = angleToCoordinate (angle, 116 )
190+ let labelAnchor = " start"
191+
189192 if (angle < 0 && angle > - Math .PI / 4 ) {
190- labelCoordinate .x += 4
193+ labelCoordinate .x -= width > 400 ? 16 : 4
191194 }
192195 if (angle < 0 && angle < - Math .PI / 3 ) {
193- labelCoordinate .y += 4
196+ labelCoordinate .y -= 12
197+ }
198+
199+ if (angle > Math .PI / 2 ) {
200+ labelAnchor = " end"
201+ } else if (angle < - Math .PI / 3 ) {
202+ labelAnchor = " middle"
194203 }
195204
196205 // Draw axis labels and values
197206 const label = svg .append (" text" )
198- .attr (" text-anchor" , " middle " )
207+ .attr (" text-anchor" , labelAnchor )
199208 .attr (" x" , labelCoordinate .x )
200209 .attr (" y" , labelCoordinate .y )
201210 .attr (" font-size" , " 12px" )
@@ -291,7 +300,7 @@ const buildChart = (chart) => {
291300 const legendSpacing = 22
292301 const legendGroup = svg .append (" g" )
293302 .attr (" class" , " legend-group" )
294- .attr (" transform" , ` translate(${ - width / 2 + 20 } , ${ height / 2 - 20 } )` )
303+ .attr (" transform" , ` translate(${ - width / 2 + 20 } , ${ width / 2 - 20 } )` )
295304
296305 legendItems .forEach ((item , i ) => {
297306 const y = i * legendSpacing
@@ -334,7 +343,7 @@ onMounted(() => {
334343< / script>
335344
336345< template>
337- < Flex direction= " column" wide : class = " $style.wrapper" >
346+ < Flex ref = " wrapperEl " direction= " column" wide : class = " $style.wrapper" >
338347 < Flex : class = " $style.chart_wrapper" >
339348 < Transition name= " fastfade" >
340349 < div v- if = " tooltip.show" : class = " $style.tooltip_wrapper" >
@@ -378,21 +387,22 @@ onMounted(() => {
378387
379388< style module lang= " scss" >
380389.wrapper {
381- height: 800px ;
390+ flex: 1 ;
391+
392+ aspect- ratio: 1 / 1 ;
382393
383394 border- radius: 12px ;
384395}
385396
386397.chart_wrapper {
387- position : relative ;
398+ flex : 1 ;
388399
389- height : 800px ;
400+ position : relative ;
390401}
391402
392403.chart {
393- height: 100 % ;
394404 position: absolute;
395-
405+
396406 overflow: hidden;
397407
398408 & svg {
@@ -436,11 +446,4 @@ onMounted(() => {
436446 background: var (-- op- 5 );
437447 }
438448}
439-
440- @media (max - width : 1000px ) {
441- .wrapper {
442- max- width: initial;
443- width: 100 % ;
444- }
445- }
446449< / style>
0 commit comments