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

[#846] [3.0] chart- props.data / props.option update 로직 이슈 #847

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/components/chart/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
import { onMounted, onBeforeUnmount, watch } from 'vue';
import { cloneDeep, defaultsDeep, isEqual, debounce } from 'lodash-es';
import { cloneDeep, isEqual, debounce } from 'lodash-es';
import EvChart from './chart.core';
import { useModel, useWrapper } from './uses';

Expand Down Expand Up @@ -40,10 +40,13 @@

const {
eventListeners,
normalizedData,
normalizedOptions,
getNormalizedData,
getNormalizedOptions,
} = useModel();

const normalizedData = getNormalizedData(props.data);
const normalizedOptions = getNormalizedOptions(props.options);

const {
wrapper,
wrapperStyle,
Expand Down Expand Up @@ -71,17 +74,17 @@
await createChart();
await drawChart();

await watch(() => props.options, (curr) => {
const newOpt = defaultsDeep({}, curr, normalizedOptions);
await watch(() => props.options, (chartOpt) => {
const newOpt = getNormalizedOptions(chartOpt);
evChart.options = cloneDeep(newOpt);
evChart.update({
updateSeries: false,
updateSelTip: { update: false, keepDomain: false },
});
}, { deep: true });

await watch(() => props.data, (curr) => {
const newData = defaultsDeep({}, curr, normalizedData);
await watch(() => props.data, (chartData) => {
const newData = getNormalizedData(chartData);
const isUpdateSeries = !isEqual(newData.series, evChart.data.series);
evChart.data = cloneDeep(newData);
evChart.update({
Expand Down
10 changes: 5 additions & 5 deletions src/components/chart/uses.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ const DEFAULT_DATA = {
};

export const useModel = () => {
const { props, emit } = getCurrentInstance();
const { emit } = getCurrentInstance();

const normalizedOptions = defaultsDeep({}, props.options, DEFAULT_OPTIONS);
const normalizedData = defaultsDeep(props.data, DEFAULT_DATA);
const getNormalizedOptions = options => defaultsDeep({}, options, DEFAULT_OPTIONS);
const getNormalizedData = data => defaultsDeep(data, DEFAULT_DATA);

const eventListeners = {
click: async (e) => {
Expand All @@ -115,8 +115,8 @@ export const useModel = () => {

return {
eventListeners,
normalizedData,
normalizedOptions,
getNormalizedData,
getNormalizedOptions,
};
};

Expand Down