UNPKG

6.25 kBJavaScriptView Raw
1import { createVNode as _createVNode } from "vue";
2
3function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
5function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
7function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
9function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
11function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
13function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
14
15function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
17var __rest = this && this.__rest || function (s, e) {
18 var t = {};
19
20 for (var p in s) {
21 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
22 }
23
24 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
25 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
26 }
27 return t;
28};
29
30import { validProgress } from './utils';
31/**
32 * {
33 * '0%': '#afc163',
34 * '75%': '#009900',
35 * '50%': 'green', ====> '#afc163 0%, #66FF00 25%, #00CC00 50%, #009900 75%, #ffffff 100%'
36 * '25%': '#66FF00',
37 * '100%': '#ffffff'
38 * }
39 */
40
41export var sortGradient = function sortGradient(gradients) {
42 var tempArr = []; // eslint-disable-next-line no-restricted-syntax
43
44 for (var _i = 0, _Object$entries = Object.entries(gradients); _i < _Object$entries.length; _i++) {
45 var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
46 key = _Object$entries$_i[0],
47 value = _Object$entries$_i[1];
48
49 var formatKey = parseFloat(key.replace(/%/g, ''));
50
51 if (isNaN(formatKey)) {
52 return {};
53 }
54
55 tempArr.push({
56 key: formatKey,
57 value: value
58 });
59 }
60
61 tempArr = tempArr.sort(function (a, b) {
62 return a.key - b.key;
63 });
64 return tempArr.map(function (_ref) {
65 var key = _ref.key,
66 value = _ref.value;
67 return "".concat(value, " ").concat(key, "%");
68 }).join(', ');
69};
70/**
71 * {
72 * '0%': '#afc163',
73 * '25%': '#66FF00',
74 * '50%': '#00CC00', ====> linear-gradient(to right, #afc163 0%, #66FF00 25%,
75 * '75%': '#009900', #00CC00 50%, #009900 75%, #ffffff 100%)
76 * '100%': '#ffffff'
77 * }
78 *
79 * Then this man came to realize the truth:
80 * Besides six pence, there is the moon.
81 * Besides bread and butter, there is the bug.
82 * And...
83 * Besides women, there is the code.
84 */
85
86export var handleGradient = function handleGradient(strokeColor) {
87 var _strokeColor$from = strokeColor.from,
88 from = _strokeColor$from === void 0 ? '#1890ff' : _strokeColor$from,
89 _strokeColor$to = strokeColor.to,
90 to = _strokeColor$to === void 0 ? '#1890ff' : _strokeColor$to,
91 _strokeColor$directio = strokeColor.direction,
92 direction = _strokeColor$directio === void 0 ? 'to right' : _strokeColor$directio,
93 rest = __rest(strokeColor, ["from", "to", "direction"]);
94
95 if (Object.keys(rest).length !== 0) {
96 var sortedGradients = sortGradient(rest);
97 return {
98 backgroundImage: "linear-gradient(".concat(direction, ", ").concat(sortedGradients, ")")
99 };
100 }
101
102 return {
103 backgroundImage: "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")")
104 };
105};
106
107var Line = function Line(_, _ref2) {
108 var attrs = _ref2.attrs,
109 slots = _ref2.slots;
110 var prefixCls = attrs.prefixCls,
111 percent = attrs.percent,
112 successPercent = attrs.successPercent,
113 strokeWidth = attrs.strokeWidth,
114 size = attrs.size,
115 strokeColor = attrs.strokeColor,
116 strokeLinecap = attrs.strokeLinecap;
117 var backgroundProps;
118
119 if (strokeColor && typeof strokeColor !== 'string') {
120 backgroundProps = handleGradient(strokeColor);
121 } else {
122 backgroundProps = {
123 background: strokeColor
124 };
125 }
126
127 var percentStyle = _extends({
128 width: "".concat(validProgress(percent), "%"),
129 height: "".concat(strokeWidth || (size === 'small' ? 6 : 8), "px"),
130 background: strokeColor,
131 borderRadius: strokeLinecap === 'square' ? 0 : '100px'
132 }, backgroundProps);
133
134 var successPercentStyle = {
135 width: "".concat(validProgress(successPercent), "%"),
136 height: "".concat(strokeWidth || (size === 'small' ? 6 : 8), "px"),
137 borderRadius: strokeLinecap === 'square' ? 0 : ''
138 };
139 var successSegment = successPercent !== undefined ? _createVNode("div", {
140 "class": "".concat(prefixCls, "-success-bg"),
141 "style": successPercentStyle
142 }, null) : null;
143 return _createVNode("div", null, [_createVNode("div", {
144 "class": "".concat(prefixCls, "-outer")
145 }, [_createVNode("div", {
146 "class": "".concat(prefixCls, "-inner")
147 }, [_createVNode("div", {
148 "class": "".concat(prefixCls, "-bg"),
149 "style": percentStyle
150 }, null), successSegment])]), slots === null || slots === void 0 ? void 0 : slots.default()]);
151};
152
153export default Line;
\No newline at end of file