import React from 'react' import ReactECharts from 'echarts-for-react' import * as echarts from 'echarts' import { get } from 'lodash' import s from './index.less' import { Descriptions, Divider } from 'antd' const Page = props => { const [data, setData] = React.useState({}) React.useEffect(() => { const { data = {} } = props setData(data) }, []) const { // saveAsImage = { // icon: // 'image://https://cdn.weipaitang.com/static/public/20210824acf87486-499f-7486499f-1d32-40d793b1fd05.svg' // } saveAsImage = false, showTitle = true, showLine = false } = props function getOptions (title, xData = [], yData = [], { yFormat = '{value}', tooltipFormat, yMax, showAreaStyle } = {}) { return { tooltip: { trigger: 'axis', position: function (pt) { return [pt[0], '10%'] }, formatter: function (params) { let rez = `
${params[0].axisValue}
` params.forEach(item => { const strItem = `
${item.marker} ${item.seriesName}
${tooltipFormat ? tooltipFormat(item.value) : item.value}
` rez += strItem }) return rez } }, grid: { left: '60px', right: '28px', containLabel: true }, title: { left: 'center', text: title, textStyle: { fontSize: 16, fontWeight: 'normal', color: '#666' } }, toolbox: { feature: { saveAsImage: saveAsImage } }, xAxis: { type: 'category', boundaryGap: false, data: xData }, yAxis: { type: 'value', boundaryGap: [0, '100%'], axisLabel: { show: true, interval: 'auto', formatter: yFormat }, max: yMax }, dataZoom: [ { type: 'inside', start: 0, end: 100 }, { start: 0, end: 100 } ], series: yData.map((yItem, index) => { const h = ((yData.length - index) * (255 / yData.length)) >> 0 return { name: yItem.name, type: 'line', symbol: 'none', sampling: 'lttb', itemStyle: { color: yData.length === 1 ? 'rgb(255, 70, 131)' : `hsl(${h}, 100%, 64%)` }, ...( showAreaStyle ? { areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgb(255, 158, 68)' }, { offset: 1, color: 'rgb(255, 70, 131)' } ]) } } : {} ), data: yItem.data } }) } } function getSeriesYData (data, format) { const _data = data return Object.keys(_data).map(key => { return { name: key, data: _data[key].vertical.map(item => { if (format) { return format(item) } else { return item } }) } }) } function getSeriesXData (data) { return Object.keys(data).reduce((acc, key) => { return data[key].cross }, {}) } return (
{ showLine && ( ) } { showTitle && (
{data.taskName}-压测报告
) }
-t {data.threads} -c {data.connects} -d {data.duration} -timeout {data.timeout} {get(data, 'monitor.infoResult')} {get(data, 'monitor.deployType')} {get(data, 'report.summary_req_sec')} {get(data, 'report.latency_mean')} {get(data, 'report.latency_p99')}
(value / 1024).toFixed(2)), { yFormat: function (value) { return value + 'kb/s' }, tooltipFormat: function (value) { return value + 'kb/s' } } )} />
(value / 1024).toFixed(2)), { yFormat: function (value) { return value + 'kb/s' }, tooltipFormat: function (value) { return value + 'kb/s' } } )} />
) } export default Page