utils.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { presetPrimaryColors } from '@ant-design/colors';
  2. import devWarning from '../vc-util/devWarning';
  3. export function validProgress(progress) {
  4. if (!progress || progress < 0) {
  5. return 0;
  6. }
  7. if (progress > 100) {
  8. return 100;
  9. }
  10. return progress;
  11. }
  12. export function getSuccessPercent(_ref) {
  13. let {
  14. success,
  15. successPercent
  16. } = _ref;
  17. let percent = successPercent;
  18. /** @deprecated Use `percent` instead */
  19. if (success && 'progress' in success) {
  20. devWarning(false, 'Progress', '`success.progress` is deprecated. Please use `success.percent` instead.');
  21. percent = success.progress;
  22. }
  23. if (success && 'percent' in success) {
  24. percent = success.percent;
  25. }
  26. return percent;
  27. }
  28. export function getPercentage(_ref2) {
  29. let {
  30. percent,
  31. success,
  32. successPercent
  33. } = _ref2;
  34. const realSuccessPercent = validProgress(getSuccessPercent({
  35. success,
  36. successPercent
  37. }));
  38. return [realSuccessPercent, validProgress(validProgress(percent) - realSuccessPercent)];
  39. }
  40. export function getStrokeColor(_ref3) {
  41. let {
  42. success = {},
  43. strokeColor
  44. } = _ref3;
  45. const {
  46. strokeColor: successColor
  47. } = success;
  48. return [successColor || presetPrimaryColors.green, strokeColor || null];
  49. }
  50. export const getSize = (size, type, extra) => {
  51. var _a, _b, _c, _d;
  52. let width = -1;
  53. let height = -1;
  54. if (type === 'step') {
  55. const steps = extra.steps;
  56. const strokeWidth = extra.strokeWidth;
  57. if (typeof size === 'string' || typeof size === 'undefined') {
  58. width = size === 'small' ? 2 : 14;
  59. height = strokeWidth !== null && strokeWidth !== void 0 ? strokeWidth : 8;
  60. } else if (typeof size === 'number') {
  61. [width, height] = [size, size];
  62. } else {
  63. [width = 14, height = 8] = size;
  64. }
  65. width *= steps;
  66. } else if (type === 'line') {
  67. const strokeWidth = extra === null || extra === void 0 ? void 0 : extra.strokeWidth;
  68. if (typeof size === 'string' || typeof size === 'undefined') {
  69. height = strokeWidth || (size === 'small' ? 6 : 8);
  70. } else if (typeof size === 'number') {
  71. [width, height] = [size, size];
  72. } else {
  73. [width = -1, height = 8] = size;
  74. }
  75. } else if (type === 'circle' || type === 'dashboard') {
  76. if (typeof size === 'string' || typeof size === 'undefined') {
  77. [width, height] = size === 'small' ? [60, 60] : [120, 120];
  78. } else if (typeof size === 'number') {
  79. [width, height] = [size, size];
  80. } else {
  81. if (process.env.NODE_ENV !== 'production') {
  82. devWarning(false, 'Progress', 'Type "circle" and "dashboard" do not accept array as `size`, please use number or preset size instead.');
  83. }
  84. width = (_b = (_a = size[0]) !== null && _a !== void 0 ? _a : size[1]) !== null && _b !== void 0 ? _b : 120;
  85. height = (_d = (_c = size[0]) !== null && _c !== void 0 ? _c : size[1]) !== null && _d !== void 0 ? _d : 120;
  86. }
  87. }
  88. return {
  89. width,
  90. height
  91. };
  92. };