Skip to content

Commit

Permalink
[#1362] Chart > ev-chart-group 내 ev-chart, ev-chart-brush를 element로 감…
Browse files Browse the repository at this point in the history
…쌀 시 에러 발생 (#1363)
  • Loading branch information
Mun94 authored Mar 3, 2023
1 parent 0497531 commit d55bb2c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evui",
"version": "3.3.51",
"version": "3.3.52",
"description": "A EXEM Library project",
"author": "exem <dev_client@ex-em.com>",
"license": "MIT",
Expand Down
16 changes: 13 additions & 3 deletions src/components/chart/Chart.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
v-if="zoomOptions.toolbar.show && !injectIsChartGroup"
v-if="zoomOptions.toolbar?.show && !injectIsChartGroup"
ref="evChartToolbarRef"
>
<ev-chart-toolbar
Expand Down Expand Up @@ -79,6 +79,7 @@
const injectBrushSeries = inject('brushSeries', { list: [], chartIdx: null });
const injectGroupSelectedLabel = inject('groupSelectedLabel', null);
const injectBrushIdx = inject('brushIdx', { start: 0, end: -1 });
const injectEvChartPropsInGroup = inject('evChartPropsInGroup', []);
const {
eventListeners,
Expand Down Expand Up @@ -110,10 +111,11 @@
setDataForUseZoom,
controlZoomIdx,
onClickToolbar,
} = useZoomModel(
} = injectIsChartGroup ? {} : useZoomModel(
normalizedOptions,
{ wrapper, evChartGroupRef: null },
props.selectedLabel ? selectedLabel : selectedItem,
injectEvChartPropsInGroup,
);
const createChart = () => {
Expand Down Expand Up @@ -227,6 +229,10 @@
}
onMounted(async () => {
if (injectEvChartPropsInGroup?.value) {
injectEvChartPropsInGroup.value.push(props);
}
await createChart();
await drawChart();
});
Expand All @@ -235,6 +241,10 @@
if (evChart && 'destroy' in evChart) {
evChart.destroy();
}
if (injectEvChartPropsInGroup?.value?.length) {
injectEvChartPropsInGroup.value.length = 0;
}
});
onDeactivated(() => {
Expand Down Expand Up @@ -268,7 +278,7 @@
injectIsChartGroup,
onClickToolbar,
normalizedOptions,
zoomOptions: toRef(evChartZoomOptions, 'zoom'),
zoomOptions: toRef(evChartZoomOptions ?? { zoom: {} }, 'zoom'),
};
},
};
Expand Down
31 changes: 17 additions & 14 deletions src/components/chart/uses.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ref, computed, getCurrentInstance, nextTick, reactive, onUpdated, watch } from 'vue';
import {
ref,
reactive,
computed,
watch,
getCurrentInstance,
nextTick,
onUpdated,
} from 'vue';
import { cloneDeep, defaultsDeep, isEqual } from 'lodash-es';
import { getQuantity } from '@/common/utils';
import EvChartZoom from '@/components/chart/chartZoom.core';
Expand Down Expand Up @@ -357,8 +365,9 @@ export const useZoomModel = (
evChartNormalizedOptions,
{ wrapper: evChartWrapper, evChartGroupRef },
selectedLabelOrItem,
evChartPropsInGroup,
) => {
const { props, slots, emit } = getCurrentInstance();
const { props, emit } = getCurrentInstance();

const isExecuteZoom = ref(false);
const isUseZoomMode = ref(false);
Expand Down Expand Up @@ -418,23 +427,17 @@ export const useZoomModel = (
};

const createEvChartZoom = () => {
if (evChartGroupRef) {
if (evChartGroupRef?.value) {
evChartInfo.dom = evChartGroupRef.value.querySelectorAll('.ev-chart-container');

let chartIdx = 0;
if (evChartInfo.dom.length) {
slots.default(evChartInfo.dom).forEach(({ type, props: evChartProps }) => {
if (type?.name === 'EvChart') {
const { options, data } = evChartProps;
evChartPropsInGroup.value.forEach(({ data, options }, idx) => {
data.chartIdx = idx;

data.chartIdx = chartIdx;
chartIdx++;
evChartInfo.props.data.push(data);
evChartInfo.props.options.push(options);

evChartInfo.props.data.push(data);
evChartInfo.props.options.push(options);
} else if (type?.name === 'EvChartBrush') {
brushChartIdx.value.push(evChartProps?.options?.chartIdx ?? 0);
}
brushChartIdx.value.push(idx);
});
}
} else {
Expand Down
30 changes: 16 additions & 14 deletions src/components/chartBrush/chartBrush.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,28 @@ export default class EvChartBrush {
return;
}

const existedBrushCanvas = this.evChartBrushRef.value.querySelector('.brush-canvas');
if (this.evChartBrushRef?.value) {
const existedBrushCanvas = this.evChartBrushRef.value.querySelector('.brush-canvas');

if (!existedBrushCanvas) {
const brushCanvas = document.createElement('canvas');
if (!existedBrushCanvas) {
const brushCanvas = document.createElement('canvas');

brushCanvas.setAttribute('class', 'brush-canvas');
brushCanvas.setAttribute('style', 'display: block; z-index: 1;');
brushCanvas.setAttribute('class', 'brush-canvas');
brushCanvas.setAttribute('style', 'display: block; z-index: 1;');

const evChartBrushContainer = this.evChartBrushRef.value.querySelector('.ev-chart-brush-container');
const evChartBrushContainer = this.evChartBrushRef.value.querySelector('.ev-chart-brush-container');

if (evChartBrushContainer) {
this.brushCanvas = brushCanvas;
evChartBrushContainer.appendChild(brushCanvas);
this.evChartBrushContainer = evChartBrushContainer;
if (evChartBrushContainer) {
this.brushCanvas = brushCanvas;
evChartBrushContainer.appendChild(brushCanvas);
this.evChartBrushContainer = evChartBrushContainer;

this.drawBrushRect({ brushCanvas });
this.addEvent(brushCanvas);
this.drawBrushRect({ brushCanvas });
this.addEvent(brushCanvas);
}
} else {
this.drawBrushRect({ brushCanvas: existedBrushCanvas, isResize });
}
} else {
this.drawBrushRect({ brushCanvas: existedBrushCanvas, isResize });
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/chartGroup/ChartGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ export default {
isExecuteZoom,
brushSeries,
evChartGroupRef,
evChartPropsInGroup,
} = useGroupModel();
const normalizedOptions = getNormalizedOptions(props.options);
provide('isExecuteZoom', isExecuteZoom);
provide('isChartGroup', true);
provide('brushSeries', brushSeries);
provide('evChartPropsInGroup', evChartPropsInGroup);
const groupSelectedLabel = computed({
get: () => props.groupSelectedLabel,
set: val => emit('update:groupSelectedLabel', val),
Expand All @@ -85,6 +87,7 @@ export default {
normalizedOptions,
{ wrapper: null, evChartGroupRef },
groupSelectedLabel,
evChartPropsInGroup,
);
provide('evChartClone', evChartClone);
Expand Down
2 changes: 2 additions & 0 deletions src/components/chartGroup/uses.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const DEFAULT_OPTIONS = {
export const useGroupModel = () => {
const isExecuteZoom = ref(false);
const evChartGroupRef = ref();
const evChartPropsInGroup = ref([]);
const brushSeries = reactive({ list: [], chartIdx: null });
const getNormalizedOptions = options => defaultsDeep({}, options, DEFAULT_OPTIONS);

Expand All @@ -45,5 +46,6 @@ export const useGroupModel = () => {
isExecuteZoom,
brushSeries,
evChartGroupRef,
evChartPropsInGroup,
};
};

0 comments on commit d55bb2c

Please sign in to comment.