fix(workbench): replay profile radar animation
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
width="min(1040px, calc(100vw - 48px))"
|
||||
:show-close="false"
|
||||
:lock-scroll="true"
|
||||
:destroy-on-close="false"
|
||||
destroy-on-close
|
||||
class="expense-profile-dialog"
|
||||
modal-class="expense-profile-dialog-overlay"
|
||||
body-class="expense-profile-dialog-body"
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'
|
||||
import { computed, shallowRef } from 'vue'
|
||||
import { RadarChart as EChartsRadarChart } from 'echarts/charts'
|
||||
import { RadarComponent, TooltipComponent } from 'echarts/components'
|
||||
import { init, use } from 'echarts/core'
|
||||
import { use } from 'echarts/core'
|
||||
import { CanvasRenderer } from 'echarts/renderers'
|
||||
|
||||
import { useEcharts } from '../../composables/useEcharts.js'
|
||||
import { useThemeColors } from '../../composables/useThemeColors.js'
|
||||
|
||||
use([RadarComponent, EChartsRadarChart, TooltipComponent, CanvasRenderer])
|
||||
@@ -32,8 +33,6 @@ const props = defineProps({
|
||||
|
||||
const themeColors = useThemeColors()
|
||||
const chartElement = shallowRef(null)
|
||||
let chartInstance = null
|
||||
let resizeObserver = null
|
||||
|
||||
const normalizedItems = computed(() =>
|
||||
props.items.map((item, index) => ({
|
||||
@@ -62,8 +61,11 @@ const chartOptions = computed(() => {
|
||||
|
||||
return {
|
||||
backgroundColor: 'transparent',
|
||||
animationDuration: 760,
|
||||
animation: true,
|
||||
animationDuration: 980,
|
||||
animationDurationUpdate: 760,
|
||||
animationEasing: 'cubicOut',
|
||||
animationEasingUpdate: 'cubicOut',
|
||||
color: [primary],
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
@@ -123,6 +125,11 @@ const chartOptions = computed(() => {
|
||||
{
|
||||
name: props.label,
|
||||
type: 'radar',
|
||||
animation: true,
|
||||
animationDuration: 980,
|
||||
animationDurationUpdate: 760,
|
||||
animationEasing: 'cubicOut',
|
||||
animationEasingUpdate: 'cubicOut',
|
||||
symbol: 'circle',
|
||||
symbolSize: 7,
|
||||
data: [
|
||||
@@ -169,56 +176,7 @@ const chartOptions = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
renderChart()
|
||||
bindResize()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
unbindResize()
|
||||
if (chartInstance) {
|
||||
chartInstance.dispose()
|
||||
chartInstance = null
|
||||
}
|
||||
})
|
||||
|
||||
watch(chartOptions, () => {
|
||||
nextTick(renderChart)
|
||||
}, { deep: true })
|
||||
|
||||
function renderChart() {
|
||||
if (!chartElement.value) {
|
||||
return
|
||||
}
|
||||
if (!chartInstance) {
|
||||
chartInstance = init(chartElement.value, null, { renderer: 'canvas' })
|
||||
}
|
||||
chartInstance.setOption(chartOptions.value, true)
|
||||
chartInstance.resize()
|
||||
}
|
||||
|
||||
function bindResize() {
|
||||
if (!chartElement.value) {
|
||||
return
|
||||
}
|
||||
if (typeof ResizeObserver !== 'undefined') {
|
||||
resizeObserver = new ResizeObserver(() => {
|
||||
chartInstance?.resize()
|
||||
})
|
||||
resizeObserver.observe(chartElement.value)
|
||||
}
|
||||
window.addEventListener('resize', handleResize)
|
||||
}
|
||||
|
||||
function unbindResize() {
|
||||
resizeObserver?.disconnect()
|
||||
resizeObserver = null
|
||||
window.removeEventListener('resize', handleResize)
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
chartInstance?.resize()
|
||||
}
|
||||
useEcharts(chartElement, chartOptions)
|
||||
|
||||
function formatTooltip() {
|
||||
const rows = normalizedItems.value.map((item) => (
|
||||
|
||||
Reference in New Issue
Block a user