circle.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  2. import { Circle as VCCircle } from '../vc-progress';
  3. import { validProgress } from './utils';
  4. var statusColorMap = {
  5. normal: '#108ee9',
  6. exception: '#ff5500',
  7. success: '#87d068'
  8. };
  9. function getPercentage(_ref) {
  10. var percent = _ref.percent,
  11. successPercent = _ref.successPercent;
  12. var ptg = validProgress(percent);
  13. if (!successPercent) return ptg;
  14. var successPtg = validProgress(successPercent);
  15. return [successPercent, validProgress(ptg - successPtg)];
  16. }
  17. function getStrokeColor(_ref2) {
  18. var progressStatus = _ref2.progressStatus,
  19. successPercent = _ref2.successPercent,
  20. strokeColor = _ref2.strokeColor;
  21. var color = strokeColor || statusColorMap[progressStatus];
  22. if (!successPercent) return color;
  23. return [statusColorMap.success, color];
  24. }
  25. var Circle = {
  26. functional: true,
  27. render: function render(h, context) {
  28. var _wrapperClassName;
  29. var props = context.props,
  30. children = context.children;
  31. var prefixCls = props.prefixCls,
  32. width = props.width,
  33. strokeWidth = props.strokeWidth,
  34. trailColor = props.trailColor,
  35. strokeLinecap = props.strokeLinecap,
  36. gapPosition = props.gapPosition,
  37. gapDegree = props.gapDegree,
  38. type = props.type;
  39. var circleSize = width || 120;
  40. var circleStyle = {
  41. width: typeof circleSize === 'number' ? circleSize + 'px' : circleSize,
  42. height: typeof circleSize === 'number' ? circleSize + 'px' : circleSize,
  43. fontSize: circleSize * 0.15 + 6
  44. };
  45. var circleWidth = strokeWidth || 6;
  46. var gapPos = gapPosition || type === 'dashboard' && 'bottom' || 'top';
  47. var gapDeg = gapDegree || type === 'dashboard' && 75;
  48. var strokeColor = getStrokeColor(props);
  49. var isGradient = Object.prototype.toString.call(strokeColor) === '[object Object]';
  50. var wrapperClassName = (_wrapperClassName = {}, _defineProperty(_wrapperClassName, prefixCls + '-inner', true), _defineProperty(_wrapperClassName, prefixCls + '-circle-gradient', isGradient), _wrapperClassName);
  51. return h(
  52. 'div',
  53. { 'class': wrapperClassName, style: circleStyle },
  54. [h(VCCircle, {
  55. attrs: {
  56. percent: getPercentage(props),
  57. strokeWidth: circleWidth,
  58. trailWidth: circleWidth,
  59. strokeColor: strokeColor,
  60. strokeLinecap: strokeLinecap,
  61. trailColor: trailColor,
  62. prefixCls: prefixCls,
  63. gapDegree: gapDeg,
  64. gapPosition: gapPos
  65. }
  66. }), children]
  67. );
  68. }
  69. };
  70. export default Circle;