@@ -131,6 +131,7 @@ const resizeObserver = ref(null)
131
131
const SIZE = ref ({ h: 10 , w: 10 })
132
132
const titleSize = ref (0 )
133
133
const boundValues = ref ([0 , 0 , 100 , 100 ])
134
+ const PARENT_SIZE = ref ({ h: 0 , w: 0 })
134
135
135
136
async function prepareChart () {
136
137
if (objectIsEmpty (props .dataset )) {
@@ -143,6 +144,8 @@ async function prepareChart() {
143
144
circles .value = await pack (formattedDataset .value )
144
145
viewBox .value = bounds (circles .value , 1 ).join (' ' )
145
146
147
+ PARENT_SIZE .value = getParentDimensions (circlePackChart .value )
148
+
146
149
const handleResize = throttle (() => {
147
150
const { width , height , heightTitle , heightNoTitle } = useResponsive ({
148
151
chart: circlePackChart .value ,
@@ -163,6 +166,7 @@ async function prepareChart() {
163
166
circles .value = await pack (freshDataset, SIZE .value .h , SIZE .value .w );
164
167
boundValues .value = bounds (circles .value , 1 )
165
168
viewBox .value = boundValues .value .join (' ' );
169
+ PARENT_SIZE .value = getParentDimensions (circlePackChart .value )
166
170
})
167
171
})
168
172
})
@@ -171,24 +175,32 @@ async function prepareChart() {
171
175
resizeObserver .value .observe (circlePackChart .value .parentNode );
172
176
}
173
177
174
- function gcd (a , b ) {
175
- return b === 0 ? a : gcd (b, a % b);
176
- }
178
+ onMounted (prepareChart);
177
179
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
+ }
182
185
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
+ }
185
191
186
- const aspectRatio = computed (() => {
192
+ const computedStyle = window .getComputedStyle (parent);
193
+ const width = computedStyle .width ;
194
+ const height = computedStyle .height ;
187
195
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
+ }
190
203
191
- onMounted (prepareChart);
192
204
193
205
watch (() => props .dataset , async (_ds ) => {
194
206
await prepareChart ();
@@ -420,7 +432,7 @@ defineExpose({
420
432
<template >
421
433
<div :id =" `vue-ui-circle-pack_${uid}`"
422
434
: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 `"
424
436
@mouseenter =" () => setUserOptionsVisibility(true)" @mouseleave =" () => setUserOptionsVisibility(false)" >
425
437
<PenAndPaper v-if =" FINAL_CONFIG.userOptions.buttons.annotator" :svgRef =" svgRef"
426
438
:backgroundColor =" FINAL_CONFIG.style.chart.backgroundColor" :color =" FINAL_CONFIG.style.chart.color"
@@ -655,7 +667,6 @@ defineExpose({
655
667
height : 100% ;
656
668
min-height : 300px ;
657
669
overflow : visible ;
658
- aspect-ratio : v-bind(aspectRatio);
659
670
}
660
671
661
672
@keyframes zoomCircle {
0 commit comments