UNPKG

4.33 kBJavaScriptView Raw
1import { createVNode as _createVNode } from "vue";
2
3function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
5function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
7function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
9var __rest = this && this.__rest || function (s, e) {
10 var t = {};
11
12 for (var p in s) {
13 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
14 }
15
16 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
18 }
19 return t;
20};
21
22import { defineComponent } from 'vue';
23import { initDefaultProps } from '../../_util/props-util';
24import enhancer from './enhancer';
25import { propTypes, defaultProps } from './types';
26var Line = defineComponent({
27 name: 'Line',
28 props: initDefaultProps(propTypes, defaultProps),
29 created: function created() {
30 this.paths = {};
31 },
32 render: function render() {
33 var _this = this;
34
35 var _a = this.$props,
36 percent = _a.percent,
37 prefixCls = _a.prefixCls,
38 strokeColor = _a.strokeColor,
39 strokeLinecap = _a.strokeLinecap,
40 strokeWidth = _a.strokeWidth,
41 trailColor = _a.trailColor,
42 trailWidth = _a.trailWidth,
43 transition = _a.transition,
44 restProps = __rest(_a, ["percent", "prefixCls", "strokeColor", "strokeLinecap", "strokeWidth", "trailColor", "trailWidth", "transition"]);
45
46 delete restProps.gapPosition;
47 var percentList = Array.isArray(percent) ? percent : [percent];
48 var strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
49 var center = strokeWidth / 2;
50 var right = 100 - strokeWidth / 2;
51 var pathString = "M ".concat(strokeLinecap === 'round' ? center : 0, ",").concat(center, "\n L ").concat(strokeLinecap === 'round' ? right : 100, ",").concat(center);
52 var viewBoxString = "0 0 100 ".concat(strokeWidth);
53 var stackPtg = 0;
54 var pathFirst = {
55 d: pathString,
56 'stroke-linecap': strokeLinecap,
57 stroke: trailColor,
58 'stroke-width': trailWidth || strokeWidth,
59 'fill-opacity': '0',
60 class: "".concat(prefixCls, "-line-trail")
61 };
62 return _createVNode("svg", _objectSpread({
63 "class": "".concat(prefixCls, "-line"),
64 "viewBox": viewBoxString,
65 "preserveAspectRatio": "none"
66 }, restProps), [_createVNode("path", pathFirst, null), percentList.map(function (ptg, index) {
67 var pathStyle = {
68 strokeDasharray: "".concat(ptg, "px, 100px"),
69 strokeDashoffset: "-".concat(stackPtg, "px"),
70 transition: transition || 'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear'
71 };
72 var color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
73 stackPtg += ptg;
74 var pathProps = {
75 key: index,
76 d: pathString,
77 'stroke-linecap': strokeLinecap,
78 stroke: color,
79 'stroke-width': strokeWidth,
80 'fill-opacity': '0',
81 class: "".concat(prefixCls, "-line-path"),
82 style: pathStyle
83 };
84 return _createVNode("path", _objectSpread({
85 "ref": function ref(c) {
86 return _this.paths[index] = c;
87 }
88 }, pathProps), null);
89 })]);
90 }
91});
92export default enhancer(Line);
\No newline at end of file