mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-24 10:20:16 +08:00
feat: 新增饼图轮播功能
This commit is contained in:
parent
0c87b9ecac
commit
d8faf22714
@ -18,7 +18,14 @@ export const PieTypeObject = {
|
|||||||
[PieTypeEnum.ROSE]: 'rose'
|
[PieTypeEnum.ROSE]: 'rose'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 其它配置
|
||||||
|
const otherConfig = {
|
||||||
|
// 轮播动画
|
||||||
|
isCarousel: false,
|
||||||
|
}
|
||||||
|
|
||||||
const option = {
|
const option = {
|
||||||
|
...otherConfig,
|
||||||
type: 'ring',
|
type: 'ring',
|
||||||
tooltip: {
|
tooltip: {
|
||||||
show: true,
|
show: true,
|
||||||
|
@ -7,6 +7,17 @@
|
|||||||
<n-select v-model:value="optionData.type" size="small" :options="fontWeightOptions" />
|
<n-select v-model:value="optionData.type" size="small" :options="fontWeightOptions" />
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingItemBox>
|
</SettingItemBox>
|
||||||
|
<SettingItemBox name="动画" :alone="true">
|
||||||
|
<SettingItem>
|
||||||
|
<n-space>
|
||||||
|
<n-switch v-model:value="optionData.isCarousel" size="small"></n-switch>
|
||||||
|
<n-text>开启<n-text :depth="3">(将自动隐藏图例)</n-text></n-text>
|
||||||
|
</n-space>
|
||||||
|
</SettingItem>
|
||||||
|
<SettingItem>
|
||||||
|
<n-text :depth="3">无鼠标点击图例场景时,可强行打开图例</n-text>
|
||||||
|
</SettingItem>
|
||||||
|
</SettingItemBox>
|
||||||
<SettingItemBox name="标签">
|
<SettingItemBox name="标签">
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<n-space>
|
<n-space>
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-chart ref="vChartRef" :init-options="initOptions" :theme="themeColor" :option="option" :manual-update="isPreview()" autoresize></v-chart>
|
<v-chart
|
||||||
|
ref="vChartRef"
|
||||||
|
autoresize
|
||||||
|
:init-options="initOptions"
|
||||||
|
:theme="themeColor"
|
||||||
|
:option="option"
|
||||||
|
:manual-update="isPreview()"
|
||||||
|
@mouseover="handleHighlight"
|
||||||
|
@mouseout="handleDownplay"
|
||||||
|
></v-chart>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, PropType, reactive, watch } from 'vue'
|
import { computed, PropType, onMounted, watch } from 'vue'
|
||||||
import VChart from 'vue-echarts'
|
import VChart from 'vue-echarts'
|
||||||
import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
|
import { useCanvasInitOptions } from '@/hooks/useCanvasInitOptions.hook'
|
||||||
import { use } from 'echarts/core'
|
import { use } from 'echarts/core'
|
||||||
@ -15,6 +24,7 @@ import { useChartDataFetch } from '@/hooks'
|
|||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { isPreview } from '@/utils'
|
import { isPreview } from '@/utils'
|
||||||
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
import { DatasetComponent, GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
||||||
|
import dataJson from './data.json'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
themeSetting: {
|
themeSetting: {
|
||||||
@ -30,8 +40,10 @@ const props = defineProps({
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const initOptions = useCanvasInitOptions(props.chartConfig.option, props.themeSetting)
|
const initOptions = useCanvasInitOptions(props.chartConfig.option, props.themeSetting)
|
||||||
|
let seriesDataNum = -1
|
||||||
|
let seriesDataMaxLength = 0
|
||||||
|
let intervalInstance: any = null
|
||||||
|
|
||||||
use([DatasetComponent, CanvasRenderer, PieChart, GridComponent, TooltipComponent, LegendComponent])
|
use([DatasetComponent, CanvasRenderer, PieChart, GridComponent, TooltipComponent, LegendComponent])
|
||||||
|
|
||||||
@ -39,6 +51,54 @@ const option = computed(() => {
|
|||||||
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
return mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 会重新选择需要选中和展示的数据
|
||||||
|
const handleSeriesData = () => {
|
||||||
|
if (seriesDataNum > -1) {
|
||||||
|
vChartRef.value?.dispatchAction({
|
||||||
|
type: 'downplay',
|
||||||
|
dataIndex: seriesDataNum
|
||||||
|
})
|
||||||
|
}
|
||||||
|
seriesDataNum = seriesDataNum >= seriesDataMaxLength - 1 ? 0 : seriesDataNum + 1
|
||||||
|
vChartRef.value?.dispatchAction({
|
||||||
|
type: 'highlight',
|
||||||
|
dataIndex: seriesDataNum
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增轮播
|
||||||
|
const addPieInterval = (newData?: typeof dataJson, skipPre = false) => {
|
||||||
|
if (!skipPre && !Array.isArray(newData?.source)) return
|
||||||
|
if (!skipPre) seriesDataMaxLength = newData?.source.length || 0
|
||||||
|
clearInterval(intervalInstance)
|
||||||
|
intervalInstance = setInterval(() => {
|
||||||
|
handleSeriesData()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消轮播
|
||||||
|
const clearPieInterval = () => {
|
||||||
|
vChartRef.value?.dispatchAction({
|
||||||
|
type: 'downplay',
|
||||||
|
dataIndex: seriesDataNum
|
||||||
|
})
|
||||||
|
clearInterval(intervalInstance)
|
||||||
|
intervalInstance = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理鼠标聚焦高亮内容
|
||||||
|
const handleHighlight = () => {
|
||||||
|
clearPieInterval()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理鼠标取消悬浮
|
||||||
|
const handleDownplay = () => {
|
||||||
|
if (props.chartConfig.option.isCarousel && !intervalInstance) {
|
||||||
|
// 恢复轮播
|
||||||
|
addPieInterval(undefined, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.chartConfig.option.type,
|
() => props.chartConfig.option.type,
|
||||||
newData => {
|
newData => {
|
||||||
@ -60,5 +120,27 @@ watch(
|
|||||||
{ deep: false, immediate: true }
|
{ deep: false, immediate: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore)
|
watch(
|
||||||
|
() => props.chartConfig.option.isCarousel,
|
||||||
|
newData => {
|
||||||
|
if (newData) {
|
||||||
|
addPieInterval(undefined, true)
|
||||||
|
props.chartConfig.option.legend.show = false
|
||||||
|
} else {
|
||||||
|
props.chartConfig.option.legend.show = true
|
||||||
|
clearPieInterval()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, (newData: typeof dataJson) => {
|
||||||
|
addPieInterval(newData)
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
seriesDataMaxLength = dataJson.source.length
|
||||||
|
if (props.chartConfig.option.isCarousel) {
|
||||||
|
addPieInterval(undefined, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user