|
|
@@ -1,26 +1,29 @@
|
|
|
<template>
|
|
|
- <v-chart
|
|
|
- ref="vChartRef"
|
|
|
- :theme="themeColor"
|
|
|
- :option="option.value"
|
|
|
- :manual-update="isPreview()"
|
|
|
- autoresize>
|
|
|
+ <v-chart
|
|
|
+ ref="vChartRef"
|
|
|
+ :theme="themeColor"
|
|
|
+ :option="option"
|
|
|
+ :manual-update="isPreview()"
|
|
|
+ :update-options="{
|
|
|
+ replaceMerge: replaceMergeArr
|
|
|
+ }"
|
|
|
+ autoresize
|
|
|
+ >
|
|
|
</v-chart>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { PropType, watch, reactive } from 'vue';
|
|
|
+import { PropType, computed, watch, ref, nextTick } from 'vue'
|
|
|
import VChart from 'vue-echarts'
|
|
|
import { use } from 'echarts/core'
|
|
|
import { CanvasRenderer } from 'echarts/renderers'
|
|
|
import { LineChart } from 'echarts/charts'
|
|
|
-import config, { includes } from './config'
|
|
|
+import config, { includes, seriesItem } from './config'
|
|
|
import { mergeTheme } from '@/packages/public/chart'
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
-import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
|
|
|
-import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
|
|
import { useChartDataFetch } from '@/hooks'
|
|
|
import { isPreview } from '@/utils'
|
|
|
+import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
|
|
|
|
|
const props = defineProps({
|
|
|
themeSetting: {
|
|
|
@@ -37,41 +40,34 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-use([
|
|
|
- DatasetComponent,
|
|
|
- CanvasRenderer,
|
|
|
- LineChart,
|
|
|
- GridComponent,
|
|
|
- TooltipComponent,
|
|
|
- LegendComponent
|
|
|
-])
|
|
|
+use([DatasetComponent, CanvasRenderer, LineChart, GridComponent, TooltipComponent, LegendComponent])
|
|
|
|
|
|
-const chartEditStore = useChartEditStore()
|
|
|
-const option = reactive({
|
|
|
- value: {}
|
|
|
+const replaceMergeArr = ref<string[]>()
|
|
|
+
|
|
|
+const option = computed(() => {
|
|
|
+ return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
})
|
|
|
|
|
|
-// 初始化与渐变色处理
|
|
|
-watch(() => chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => {
|
|
|
- if (!isPreview()) {
|
|
|
- const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
|
|
|
- props.chartConfig.option.series.forEach((value: any) => {
|
|
|
- value.lineStyle.shadowColor = themeColor[2]
|
|
|
- value.lineStyle.color.colorStops.forEach((v: { color: string }, i: number) => {
|
|
|
- v.color = themeColor[i]
|
|
|
+// dataset 无法变更条数的补丁
|
|
|
+watch(
|
|
|
+ () => props.chartConfig.option.dataset,
|
|
|
+ (newData, oldData) => {
|
|
|
+ if (newData?.dimensions.length !== oldData?.dimensions.length) {
|
|
|
+ const seriesArr = []
|
|
|
+ for (let i = 0; i < newData.dimensions.length - 1; i++) {
|
|
|
+ seriesArr.push(seriesItem)
|
|
|
+ }
|
|
|
+ replaceMergeArr.value = ['series']
|
|
|
+ props.chartConfig.option.series = seriesArr
|
|
|
+ nextTick(() => {
|
|
|
+ replaceMergeArr.value = []
|
|
|
})
|
|
|
- })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: false
|
|
|
}
|
|
|
- option.value = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
- props.chartConfig.option = option.value
|
|
|
-}, {
|
|
|
- immediate: true,
|
|
|
-})
|
|
|
-
|
|
|
-
|
|
|
-watch(() => props.chartConfig.option.dataset, () => {
|
|
|
- option.value = props.chartConfig.option
|
|
|
-})
|
|
|
+)
|
|
|
|
|
|
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
|
|
|
-</script>
|
|
|
+</script>
|