Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1256] chart > 객체 참조 에러 로그 발생 #1257

Merged
merged 2 commits into from
Aug 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions src/components/chart/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { onMounted, onBeforeUnmount, watch, onDeactivated } from 'vue';
'update:selectedSeries',
],
setup(props) {
let evChart = {};
let evChart = null;
let isInit = false;

const {
Expand Down Expand Up @@ -98,8 +98,11 @@ import { onMounted, onBeforeUnmount, watch, onDeactivated } from 'vue';
};

watch(() => props.options, (chartOpt) => {
const newOpt = getNormalizedOptions(chartOpt);
if (!isInit) {
return;
}
kdeun1 marked this conversation as resolved.
Show resolved Hide resolved

const newOpt = getNormalizedOptions(chartOpt);
const isUpdateLegendType = !isEqual(newOpt.legend.table, evChart.options.legend.table);

evChart.options = cloneDeep(newOpt);
Expand All @@ -112,8 +115,11 @@ import { onMounted, onBeforeUnmount, watch, onDeactivated } from 'vue';
}, { deep: true });

watch(() => props.data, (chartData) => {
const newData = getNormalizedData(chartData);
if (!isInit) {
return;
}

const newData = getNormalizedData(chartData);
const isUpdateSeries = !isEqual(newData.series, evChart.data.series)
|| !isEqual(newData.groups, evChart.data.groups)
|| props.options.type === 'heatMap';
Expand All @@ -130,18 +136,29 @@ import { onMounted, onBeforeUnmount, watch, onDeactivated } from 'vue';
}, { deep: true });

watch(() => props.selectedItem, (newValue) => {
const chartType = props.options?.type;
if (!isInit) {
return;
}

const chartType = props.options.type;
evChart.selectItemByData(newValue, chartType);
}, { deep: true });

watch(() => props.selectedLabel, (newValue) => {
if (!isInit) {
return;
}

if (newValue.dataIndex) {
evChart.renderWithSelected(newValue.dataIndex);
}
}, { deep: true });

watch(() => props.selectedSeries, (newValue) => {
if (!isInit) {
return;
}

if (newValue.seriesId) {
evChart.renderWithSelected(newValue.seriesId);
}
Expand All @@ -153,28 +170,38 @@ import { onMounted, onBeforeUnmount, watch, onDeactivated } from 'vue';
});

onBeforeUnmount(() => {
if (!isInit) {
return;
}

evChart.destroy();
});

onDeactivated(() => {
if (evChart && 'hideTooltip' in evChart) {
evChart.hideTooltip();
if (!isInit) {
return;
}

evChart.hideTooltip();
});

const redraw = () => {
if (evChart && isInit) {
evChart.update({
updateSeries: true,
updateSelTip: { update: true, keepDomain: false },
});
if (!isInit) {
return;
}

evChart.update({
updateSeries: true,
updateSelTip: { update: true, keepDomain: false },
});
};

const onResize = debounce(() => {
if (evChart && 'resize' in evChart && isInit) {
evChart.resize();
if (!isInit) {
return;
}

evChart.resize();
}, props.resizeTimeout);

return {
Expand Down