@@ -131,6 +131,7 @@ const resizeObserver = ref(null)
131131const SIZE = ref ({ h: 10 , w: 10 })
132132const titleSize = ref (0 )
133133const boundValues = ref ([0 , 0 , 100 , 100 ])
134+ const PARENT_SIZE = ref ({ h: 0 , w: 0 })
134135
135136async function prepareChart () {
136137 if (objectIsEmpty (props .dataset )) {
@@ -143,6 +144,8 @@ async function prepareChart() {
143144 circles .value = await pack (formattedDataset .value )
144145 viewBox .value = bounds (circles .value , 1 ).join (' ' )
145146
147+ PARENT_SIZE .value = getParentDimensions (circlePackChart .value )
148+
146149 const handleResize = throttle (() => {
147150 const { width , height , heightTitle , heightNoTitle } = useResponsive ({
148151 chart: circlePackChart .value ,
@@ -163,6 +166,7 @@ async function prepareChart() {
163166 circles .value = await pack (freshDataset, SIZE .value .h , SIZE .value .w );
164167 boundValues .value = bounds (circles .value , 1 )
165168 viewBox .value = boundValues .value .join (' ' );
169+ PARENT_SIZE .value = getParentDimensions (circlePackChart .value )
166170 })
167171 })
168172 })
@@ -171,24 +175,32 @@ async function prepareChart() {
171175 resizeObserver .value .observe (circlePackChart .value .parentNode );
172176}
173177
174- function gcd (a , b ) {
175- return b === 0 ? a : gcd (b, a % b);
176- }
178+ onMounted (prepareChart);
177179
178- function getCssAspectRatio (width , height ) {
179- const divisor = gcd (width, height);
180- const aspectWidth = width / divisor;
181- const aspectHeight = height / divisor;
180+ function getParentDimensions (component ) {
181+ if (! component || ! component .parentElement ) {
182+ console .warn (" Component or parent element is missing." );
183+ return { w: 0 , h: 0 };
184+ }
182185
183- return ` ${ aspectWidth} /${ aspectHeight} ` ;
184- }
186+ const parent = component .parentElement ;
187+
188+ if (parent .offsetWidth > 0 && parent .offsetHeight > 0 ) {
189+ return { w: parent .offsetWidth , h: parent .offsetHeight };
190+ }
185191
186- const aspectRatio = computed (() => {
192+ const computedStyle = window .getComputedStyle (parent);
193+ const width = computedStyle .width ;
194+ const height = computedStyle .height ;
187195
188- return getCssAspectRatio (SIZE .value .w , (SIZE .value .h - titleSize .value ));
189- })
196+ if (width !== ' auto' && height !== ' auto' &&
197+ parseFloat (width) > 0 && parseFloat (height) > 0 ) {
198+ return { w: parseFloat (width), h: parseFloat (height) };
199+ }
200+
201+ return { w: 0 , h: 0 };
202+ }
190203
191- onMounted (prepareChart);
192204
193205watch (() => props .dataset , async (_ds ) => {
194206 await prepareChart ();
@@ -420,7 +432,7 @@ defineExpose({
420432<template >
421433 <div :id =" `vue-ui-circle-pack_${uid}`"
422434 :class =" `vue-ui-circle-pack ${isFullscreen ? 'vue-data-ui-wrapper-fullscreen' : ''}`" ref =" circlePackChart"
423- :style =" `font-family:${FINAL_CONFIG.style.fontFamily};text-align:center;background:${FINAL_CONFIG.style.chart.backgroundColor}`"
435+ :style =" `font-family:${FINAL_CONFIG.style.fontFamily};text-align:center;background:${FINAL_CONFIG.style.chart.backgroundColor}; height: ${PARENT_SIZE.h}px; width:${PARENT_SIZE.w}px `"
424436 @mouseenter =" () => setUserOptionsVisibility(true)" @mouseleave =" () => setUserOptionsVisibility(false)" >
425437 <PenAndPaper v-if =" FINAL_CONFIG.userOptions.buttons.annotator" :svgRef =" svgRef"
426438 :backgroundColor =" FINAL_CONFIG.style.chart.backgroundColor" :color =" FINAL_CONFIG.style.chart.color"
@@ -655,7 +667,6 @@ defineExpose({
655667 height : 100% ;
656668 min-height : 300px ;
657669 overflow : visible ;
658- aspect-ratio : v-bind(aspectRatio);
659670}
660671
661672@keyframes zoomCircle {
0 commit comments