import React, { useRef, useEffect, useState, useCallback } from 'react' import ReactEChartsCore from 'echarts-for-react/lib/core' import { echarts } from '../echarts' import { PieChart } from 'echarts/charts' import { TitleComponent, TooltipComponent, LegendComponent, LegendScrollComponent, } from 'echarts/components' import { CanvasRenderer } from 'echarts/renderers' import merge from 'lodash/merge' import { pieSeriesMapping } from '../preset' import { defineConfig } from '@/utils/common' import { genPercentObject } from '@/utils/echarts' import type { EChartsOption } from 'echarts' import type { MyEChartProps } from '../types' // const isSmallScreen = !!(window.screen.width < 576) // 注册 echarts 组件 echarts.use([ // charts PieChart, // components TitleComponent, TooltipComponent, LegendComponent, LegendScrollComponent, // render CanvasRenderer, ]) function genDefaultOptions(series: []): EChartsOption { const mapping = genPercentObject(series, 'name', 'value') const options: EChartsOption = { title: { show: false, }, legend: { type: 'scroll', top: 10, orient: 'vertical', left: 'left', textStyle: { fontSize: 10, }, formatter: (name: string) => { const mapObj = mapping[name] if (!mapObj) { return name } return `${name} | ${mapObj.percent}% | ${mapObj.value}` }, }, tooltip: { show: true, trigger: 'item', padding: [8, 12], appendToBody: true, textStyle: { fontSize: 12, lineHeight: 18, fontFamily: `'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif`, }, formatter: (params) => { const { name, seriesName, marker, value, percent } = params as any return `