1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import Decimal from 'decimal.js';
- /**
- * 将查询结果的表头信息格式化
- * */
- export const formatColumns=(props)=>{
- let columns = [];
- try {
- if (props && props.length>0){
- columns = props.map(item=> (
- {
- title: item.name||item.nameEn,
- dataIndex: item.nameEn,
- key: item.nameEn,
- width: 100,
- }
- ))
- }
- }catch(e){}
- return columns
- }
- /**
- * 查询结果的维度信息格式化
- * */
- export const formatDimensions=(props)=>{
- let dimensions = [];
- try {
- if (props && props.length>0){
- dimensions = props.map(item=> (
- {
- title: item.name,
- value: item.nameEn,
- }
- ))
- }
- }catch (e) {}
- return dimensions
- }
- /**
- * 查询结果的维度信息格式化
- * */
- export const formatMetrics=(props)=>{
- let metrics = [];
- if (props && props.length>0){
- metrics = props.map(item=> (
- {
- title: item.name,
- value: item.nameEn,
- dataType: item.dataFormatType
- }
- ))
- }
- return metrics
- }
- /**
- * 格式化索引
- * */
- export const formatIndex=(props)=> ( props && props.length>0 && props.map(item=> item.nameEn) ) || []
- /**
- * 数据格式化
- * */
- export const formatData=(data, dim, mtc, cat)=>(
- data && data.length>0 && mtc &&
- data.map(item=> {
- const mtcType = mtc.dataType;
- const mtcData = item[mtc?.value];
- const metric = mtcType==="PERCENT" && mtcData
- ? new Decimal(parseFloat(mtcData.replace('%', '')) / 100).toDP(4).toNumber()
- : new Decimal(mtcData||'0').toNumber()
- return {
- dimension:item[dim?.value],
- category:item[cat?.value],
- metric,
- }
- })
- ) || []
|