Skip to content

Commit

Permalink
fix: legend order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jsers committed Jun 1, 2023
1 parent bd474bd commit a70a1cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/pages/dashboard/Renderer/Renderer/Timeseries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default function index(props: IProps) {
title: 'Max',
dataIndex: 'max',
width: 100,
sorter: (a, b) => a.max.value - b.max.value,
sorter: (a, b) => a.max.stat - b.max.stat,
render: (text) => {
return text.text;
},
Expand All @@ -313,7 +313,7 @@ export default function index(props: IProps) {
title: 'Min',
dataIndex: 'min',
width: 100,
sorter: (a, b) => a.min.value - b.min.value,
sorter: (a, b) => a.min.stat - b.min.stat,
render: (text) => {
return text.text;
},
Expand All @@ -322,7 +322,7 @@ export default function index(props: IProps) {
title: 'Avg',
dataIndex: 'avg',
width: 100,
sorter: (a, b) => a.avg.value - b.avg.value,
sorter: (a, b) => a.avg.stat - b.avg.stat,
render: (text) => {
return text.text;
},
Expand All @@ -331,7 +331,7 @@ export default function index(props: IProps) {
title: 'Sum',
dataIndex: 'sum',
width: 100,
sorter: (a, b) => a.sum.value - b.sum.value,
sorter: (a, b) => a.sum.stat - b.sum.stat,
render: (text) => {
return text.text;
},
Expand All @@ -340,7 +340,7 @@ export default function index(props: IProps) {
title: 'Last',
dataIndex: 'last',
width: 100,
sorter: (a, b) => a.last.value - b.last.value,
sorter: (a, b) => a.last.stat - b.last.stat,
render: (text) => {
return text.text;
},
Expand Down
7 changes: 6 additions & 1 deletion src/pages/dashboard/Renderer/utils/byteConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ export function format(value: number, options = defaultOptions) {
value: '',
unit: '',
text: '',
stat: '',
};
const baseUtil = options.base ? baseUtilMap[options.base] : ''; // 支持
if ((options.type === 'si' && Math.abs(value) < 1000) || (options.type === 'iec' && Math.abs(value) < 1024)) {
return {
value: _.round(value, options.decimals),
unit: baseUtil,
text: _.round(value, options.decimals) + baseUtil,
stat: value,
};
}

Expand All @@ -95,14 +97,15 @@ export function format(value: number, options = defaultOptions) {
const expArray = autoDetect.match(autoDetectRegex);

if (expArray) {
const expVal = Math.floor(parseInt(_.get(expArray, '[2]')) / 3) * 3;
const expVal = Math.floor(parseInt(_.get(expArray, '[2]')! as string) / 3) * 3;
const map = _.find(valueMap, { exp: expVal });

if (!map) {
return {
value: NaN,
unit: '',
text: NaN,
stat: NaN,
};
}
const unit = _.get(map, options.type);
Expand All @@ -114,12 +117,14 @@ export function format(value: number, options = defaultOptions) {
value: newValue,
unit: unit + baseUtil,
text: newValue + unit + baseUtil,
stat: value,
};
}
return {
value: _.round(value, options.decimals),
unit: '',
text: _.round(value, options.decimals),
stat: value,
};
}

Expand Down
16 changes: 14 additions & 2 deletions src/pages/dashboard/Renderer/utils/valueFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import moment from 'moment';
import { utilValMap } from '../config';
import * as byteConverter from './byteConverter';

function timeFormatter(val, type: 'seconds' | 'milliseconds', decimals) {
export function timeFormatter(val, type: 'seconds' | 'milliseconds', decimals) {
if (typeof val !== 'number')
return {
value: val,
unit: '',
text: val,
stat: val,
};
const timeMap = [
{
Expand Down Expand Up @@ -76,7 +77,8 @@ function timeFormatter(val, type: 'seconds' | 'milliseconds', decimals) {
return {
value: _.round(newVal, decimals),
unit,
text: _.round(newVal, decimals) + unit,
text: _.round(newVal, decimals) + ' ' + unit,
stat: val,
};
}

Expand All @@ -86,8 +88,10 @@ const valueFormatter = ({ unit, decimals = 3, dateFormat = 'YYYY-MM-DD HH:mm:ss'
value: '',
unit: '',
text: '',
stat: '',
};
}
if (decimals === null) decimals = 3;
if (typeof val !== 'number') {
val = _.toNumber(val);
}
Expand All @@ -106,34 +110,39 @@ const valueFormatter = ({ unit, decimals = 3, dateFormat = 'YYYY-MM-DD HH:mm:ss'
value: _.round(val, decimals),
unit: '',
text: _.round(val, decimals),
stat: val,
};
}
if (unit === 'percent') {
return {
value: _.round(val, decimals),
unit: '%',
text: _.round(val, decimals) + '%',
stat: val,
};
}
if (unit === 'percentUnit') {
return {
value: _.round(val * 100, decimals),
unit: '%',
text: _.round(val * 100, decimals) + '%',
stat: val,
};
}
if (unit === 'humantimeSeconds') {
return {
value: moment.duration(val, 'seconds').humanize(),
unit: '',
text: moment.duration(val, 'seconds').humanize(),
stat: val,
};
}
if (unit === 'humantimeMilliseconds') {
return {
value: moment.duration(val, 'milliseconds').humanize(),
unit: '',
text: moment.duration(val, 'milliseconds').humanize(),
stat: val,
};
}
if (unit === 'seconds') {
Expand All @@ -147,19 +156,22 @@ const valueFormatter = ({ unit, decimals = 3, dateFormat = 'YYYY-MM-DD HH:mm:ss'
value: moment.unix(val).format(dateFormat),
unit: '',
text: moment.unix(val).format(dateFormat),
stat: val,
};
}
if (unit === 'datetimeMilliseconds') {
return {
value: moment(val).format(dateFormat),
unit: '',
text: moment(val).format(dateFormat),
stat: val,
};
}
return {
value: _.round(val, decimals),
unit: '',
text: _.round(val, decimals),
stat: val,
};
}
// 默认返回 SI 不带基础单位
Expand Down

0 comments on commit a70a1cd

Please sign in to comment.