Commit 4be9d1c4 authored by 崔佳豪's avatar 崔佳豪

perf: 优化基础图表默认配置

parent f4b77868
import React, { useMemo } from 'react'; import React, { memo, useMemo } from 'react';
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import ReactEcharts from 'echarts-for-react'; import ReactEcharts from 'echarts-for-react';
import { omit } from 'lodash'; import { omit } from 'lodash';
import buildOption from './utils'; import buildOption from './utils';
const ECharts = React.forwardRef((props, ref) => { const ECharts = memo(
React.forwardRef((props, ref) => {
const { getPrefixCls } = React.useContext(ConfigProvider.ConfigContext); const { getPrefixCls } = React.useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('basic-chart'); const prefixCls = getPrefixCls('basic-chart');
...@@ -16,6 +17,8 @@ const ECharts = React.forwardRef((props, ref) => { ...@@ -16,6 +17,8 @@ const ECharts = React.forwardRef((props, ref) => {
// const chartProps = pick(props, ['option', 'notMerge', 'lazyUpdate', 'style', 'className', 'theme', 'onChartReady', 'loadingOption', 'showLoading', 'onEvents', 'opts']); // const chartProps = pick(props, ['option', 'notMerge', 'lazyUpdate', 'style', 'className', 'theme', 'onChartReady', 'loadingOption', 'showLoading', 'onEvents', 'opts']);
console.log('update ');
return ( return (
<ReactEcharts <ReactEcharts
ref={ref} ref={ref}
...@@ -24,6 +27,7 @@ const ECharts = React.forwardRef((props, ref) => { ...@@ -24,6 +27,7 @@ const ECharts = React.forwardRef((props, ref) => {
{...chartProps} {...chartProps}
/> />
); );
}); }),
);
export default ECharts; export default ECharts;
...@@ -13,6 +13,8 @@ export const buildDefaultTitle = (option) => { ...@@ -13,6 +13,8 @@ export const buildDefaultTitle = (option) => {
const { show, text } = title ?? {}; const { show, text } = title ?? {};
if (show && text) { if (show && text) {
return { return {
left: 12,
top: 12,
textStyle: { textStyle: {
rich: { rich: {
prefix: { prefix: {
...@@ -25,7 +27,6 @@ export const buildDefaultTitle = (option) => { ...@@ -25,7 +27,6 @@ export const buildDefaultTitle = (option) => {
fontFamily: 'Microsoft YaHei', fontFamily: 'Microsoft YaHei',
fontWeight: 'bold', fontWeight: 'bold',
color: '#333333', color: '#333333',
lineHeight: 28,
padding: [0, 0, 0, 10], padding: [0, 0, 0, 10],
}, },
suffix: { suffix: {
...@@ -53,16 +54,18 @@ export const buildDefaultGrid = (option) => { ...@@ -53,16 +54,18 @@ export const buildDefaultGrid = (option) => {
const hasName = axisArr.some((d) => !!d.name) || seriesArr.some((d) => !!d.unit); const hasName = axisArr.some((d) => !!d.name) || seriesArr.some((d) => !!d.unit);
const hasTitle = !!title && title.show; const hasTitle = !!title && title.show;
const top = hasTitle && hasName ? 70 : 50; const top = hasTitle && hasName ? 70 : 50;
return { right: 40, left: 60, top }; return { right: 40, left: 60, top, bottom: 40 };
}; };
export const defaultLegend = { export const defaultLegend = {
show: true, show: true,
right: 40, right: 20,
top: 20,
icon: 'react', icon: 'react',
itemWidth: 14, itemWidth: 14,
itemHeight: 8, itemHeight: 8,
itemGap: 20, itemGap: 20,
padding: [0, 0, 0, 80], // 给标题留够空间
textStyle: { textStyle: {
padding: [0, 0, 0, 4], padding: [0, 0, 0, 4],
color: '#2d2d2d', color: '#2d2d2d',
......
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment';
const isArray = (arr) => Array.isArray(arr); const isArray = (arr) => Array.isArray(arr);
...@@ -130,10 +131,12 @@ const colorAccessor = (param) => { ...@@ -130,10 +131,12 @@ const colorAccessor = (param) => {
*/ */
const headTemplate = (option, param) => { const headTemplate = (option, param) => {
if (!param) return ''; if (!param) return '';
const { name, axisValueLabel } = param; const { name, axisValueLabel, axisType, axisValue } = param;
return `<div style="border-bottom: 1px solid #F0F0F0; color: #808080; margin-bottom: 5px; padding-bottom: 5px;">${ const { tooltip } = option;
name || axisValueLabel const { timeFormat = 'YYYY-MM-DD HH:mm:ss' } = tooltip ?? {};
}</div>`; const text =
axisType === 'xAxis.time' ? moment(axisValue).format(timeFormat) : name || axisValueLabel;
return `<div style="border-bottom: 1px solid #F0F0F0; color: #808080; margin-bottom: 5px; padding-bottom: 5px;">${text}</div>`;
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment