74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
import { presetPrimaryColors } from '@ant-design/colors';
|
|
import { isNumber } from '../_util/is';
|
|
export function validProgress(progress) {
|
|
if (!progress || progress < 0) {
|
|
return 0;
|
|
}
|
|
if (progress > 100) {
|
|
return 100;
|
|
}
|
|
return progress;
|
|
}
|
|
export function getSuccessPercent({
|
|
success
|
|
}) {
|
|
let percent;
|
|
if (success && 'percent' in success) {
|
|
percent = success.percent;
|
|
}
|
|
return percent;
|
|
}
|
|
export const getPercentage = ({
|
|
percent,
|
|
success
|
|
}) => {
|
|
const realSuccessPercent = validProgress(getSuccessPercent({
|
|
success
|
|
}));
|
|
return [realSuccessPercent, validProgress(validProgress(percent) - realSuccessPercent)];
|
|
};
|
|
export const getStrokeColor = ({
|
|
success = {},
|
|
strokeColor
|
|
}) => {
|
|
const {
|
|
strokeColor: successColor
|
|
} = success;
|
|
return [successColor || presetPrimaryColors.green, strokeColor || null];
|
|
};
|
|
export const getSize = (size, type, extra) => {
|
|
let width = -1;
|
|
let height = -1;
|
|
if (type === 'step') {
|
|
const steps = extra.steps;
|
|
const strokeWidth = extra.strokeWidth;
|
|
if (typeof size === 'string' || typeof size === 'undefined') {
|
|
width = size === 'small' ? 2 : 14;
|
|
height = strokeWidth ?? 8;
|
|
} else if (isNumber(size)) {
|
|
[width, height] = [size, size];
|
|
} else {
|
|
[width = 14, height = 8] = Array.isArray(size) ? size : [size.width, size.height];
|
|
}
|
|
width *= steps;
|
|
} else if (type === 'line') {
|
|
const strokeWidth = extra?.strokeWidth;
|
|
if (typeof size === 'string' || typeof size === 'undefined') {
|
|
height = strokeWidth || (size === 'small' ? 6 : 8);
|
|
} else if (isNumber(size)) {
|
|
[width, height] = [size, size];
|
|
} else {
|
|
[width = -1, height = 8] = Array.isArray(size) ? size : [size.width, size.height];
|
|
}
|
|
} else if (type === 'circle' || type === 'dashboard') {
|
|
if (typeof size === 'string' || typeof size === 'undefined') {
|
|
[width, height] = size === 'small' ? [60, 60] : [120, 120];
|
|
} else if (isNumber(size)) {
|
|
[width, height] = [size, size];
|
|
} else if (Array.isArray(size)) {
|
|
width = size[0] ?? size[1] ?? 120;
|
|
height = size[0] ?? size[1] ?? 120;
|
|
}
|
|
}
|
|
return [width, height];
|
|
}; |