feat: 支持渐变色全局变换

This commit is contained in:
MTrun
2022-03-11 10:22:54 +08:00
parent e6a7ad9776
commit ea75f161a7
7 changed files with 113 additions and 60 deletions
@@ -1,20 +1,18 @@
<template>
<VChart :theme="themeColor" :option="option" autoresize />
<VChart :theme="themeColor" :option="option.options" autoresize />
</template>
<script setup lang="ts">
import { computed, PropType } from 'vue'
import { reactive, watchEffect, watch, PropType } from 'vue'
import VChart from 'vue-echarts'
import { use, graphic } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { LineChart } from 'echarts/charts'
import config, { includes } from './config'
import { mergeTheme } from '@/packages/public/chart'
import {
GridComponent,
TooltipComponent,
LegendComponent,
} from 'echarts/components'
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
const props = defineProps({
themeSetting: {
@@ -38,8 +36,35 @@ use([
TooltipComponent,
LegendComponent,
])
const chartEditStore = useChartEditStore()
const option = computed(() => {
return mergeTheme( props.chartConfig.option, props.themeSetting, includes)
const option = reactive({
options: {}
})
watchEffect(()=> {
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
})
// 渐变色处理
watch(()=>chartEditStore.getEditCanvasConfig.chartThemeColor, (newColor: keyof typeof chartColorsSearch) => {
const themeColor = chartColorsSearch[newColor] || chartColorsSearch[defaultTheme]
props.chartConfig.option.series.forEach((value: any, index: number) => {
value.areaStyle.color = new graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: themeColor[3]
},
{
offset: 1,
color: 'rgba(0,0,0, 0)'
}
])
themeColor[index]
})
option.options = mergeTheme(props.chartConfig.option, props.themeSetting, includes)
},
{
immediate: true
})
</script>