Skip to content

Commit

Permalink
fix: fix resize bug in heatmap table
Browse files Browse the repository at this point in the history
Signed-off-by: yuda <[email protected]>
  • Loading branch information
yuda110 committed Jan 3, 2025
1 parent 00c23cd commit f86398c
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const state = reactive({
boxHeight: 0,
scrollHeight: 0,
xAxisData: computed<string[]>(() => {
if (isDateField(state.xAxisField)) {
if (isDateField(widgetOptionsState.xAxisInfo?.data)) {
const _isSeparatedDate = widgetOptionsState.xAxisInfo?.data !== DATE_FIELD.DATE;
return getWidgetDateFields(widgetOptionsState.granularityInfo?.granularity, state.widgetDateRange.start, state.widgetDateRange.end, _isSeparatedDate);
}
Expand Down Expand Up @@ -177,6 +177,31 @@ const getColor = (val: string|number): string => {
});
return _color;
};
const resizeWidget = () => {
const _containerWidth = colorCodedTableRef.value?.clientWidth;
const _containerHeight = colorCodedTableRef.value?.clientHeight;
if (!_containerWidth || !_containerHeight) return;
// width
const boxWidth = (_containerWidth - Y_AXIS_FIELD_WIDTH) / widgetOptionsState.xAxisCount;
if (boxWidth < BOX_MIN_WIDTH) state.boxWidth = BOX_MIN_WIDTH - 2;
else state.boxWidth = boxWidth - 2;
// height
const yAxisCount = state.yAxisData.length || 1;
const boxHeight = (_containerHeight - 16) / yAxisCount;
const padding = 20 / yAxisCount;
if (boxHeight < 32) state.boxHeight = 32 - padding;
else state.boxHeight = boxHeight - padding;
if (props.mode === 'overlay') {
state.scrollHeight = '100%';
} else {
const _scrollHeight = scrollViewRef.value?.scrollHeight || 0;
if (_containerHeight < _scrollHeight) state.scrollHeight = `${_scrollHeight}px`;
else state.scrollHeight = '100%';
}
};
/* Watcher */
watch(() => widgetOptionsState.formatRulesInfo?.rules, async () => {
Expand All @@ -193,6 +218,9 @@ const { widgetFrameProps, widgetFrameEventHandlers } = useWidgetFrame(props, emi
widgetLoading: widgetLoading.value,
noData: computed(() => (state.data ? !state.data?.results?.length : false)),
});
watch(() => widgetOptionsState, () => {
resizeWidget();
}, { deep: true });
/* Lifecycle */
useWidgetInitAndRefresh({ props, emit, loadWidget });
Expand All @@ -204,29 +232,7 @@ defineExpose<WidgetExpose>({
loadWidget,
});
useResizeObserver(colorCodedTableRef, throttle(() => {
const _containerWidth = colorCodedTableRef.value?.clientWidth;
const _containerHeight = colorCodedTableRef.value?.clientHeight;
if (!_containerWidth || !_containerHeight) return;
// width
const boxWidth = (_containerWidth - Y_AXIS_FIELD_WIDTH) / widgetOptionsState.xAxisCount;
if (boxWidth < BOX_MIN_WIDTH) state.boxWidth = BOX_MIN_WIDTH - 2;
else state.boxWidth = boxWidth - 2;
// height
const yAxisCount = state.yAxisData.length || 1;
const boxHeight = (_containerHeight - 16) / yAxisCount;
const padding = 20 / yAxisCount;
if (boxHeight < 32) state.boxHeight = 32 - padding;
else state.boxHeight = boxHeight - padding;
if (props.mode === 'overlay') {
state.scrollHeight = '100%';
} else {
const _scrollHeight = scrollViewRef.value?.scrollHeight || 0;
if (_containerHeight < _scrollHeight) state.scrollHeight = `${_scrollHeight}px`;
else state.scrollHeight = '100%';
}
resizeWidget();
}, 500));
</script>

Expand Down Expand Up @@ -273,7 +279,7 @@ useResizeObserver(colorCodedTableRef, throttle(() => {
position="bottom"
class="tooltip-wrapper"
>
{{ targetValue(xField, yField, 'table') }}
<span>{{ targetValue(xField, yField, 'table') }}</span>
</p-tooltip>
</div>
<div class="x-field-text">
Expand Down

0 comments on commit f86398c

Please sign in to comment.