utils.js 3.3 KB

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