utils.js 2.9 KB

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