2019-02-19 14:35:03 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import ref from 'vue-ref';
|
2019-01-12 03:33:27 +00:00
|
|
|
import { initDefaultProps } from '../../_util/props-util';
|
|
|
|
import enhancer from './enhancer';
|
|
|
|
import { propTypes, defaultProps } from './types';
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-02-19 14:35:03 +00:00
|
|
|
Vue.use(ref, { name: 'ant-ref' });
|
|
|
|
|
2018-04-03 03:00:05 +00:00
|
|
|
const Line = {
|
|
|
|
props: initDefaultProps(propTypes, defaultProps),
|
2019-02-19 14:35:03 +00:00
|
|
|
data() {
|
|
|
|
this.paths = {};
|
|
|
|
return {};
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2018-04-03 03:00:05 +00:00
|
|
|
const {
|
|
|
|
percent,
|
|
|
|
prefixCls,
|
|
|
|
strokeColor,
|
|
|
|
strokeLinecap,
|
|
|
|
strokeWidth,
|
|
|
|
trailColor,
|
|
|
|
trailWidth,
|
|
|
|
...restProps
|
2019-01-12 03:33:27 +00:00
|
|
|
} = this.$props;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
delete restProps.gapPosition;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-02-19 14:35:03 +00:00
|
|
|
const percentList = Array.isArray(percent) ? percent : [percent];
|
|
|
|
const strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const center = strokeWidth / 2;
|
|
|
|
const right = 100 - strokeWidth / 2;
|
|
|
|
const pathString = `M ${strokeLinecap === 'round' ? center : 0},${center}
|
|
|
|
L ${strokeLinecap === 'round' ? right : 100},${center}`;
|
|
|
|
const viewBoxString = `0 0 100 ${strokeWidth}`;
|
2018-12-10 14:25:16 +00:00
|
|
|
|
2019-02-19 14:35:03 +00:00
|
|
|
let stackPtg = 0;
|
|
|
|
|
2018-04-03 03:00:05 +00:00
|
|
|
const pathFirst = {
|
|
|
|
attrs: {
|
2019-01-12 03:33:27 +00:00
|
|
|
d: pathString,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-linecap': strokeLinecap,
|
2019-01-12 03:33:27 +00:00
|
|
|
stroke: trailColor,
|
2018-04-03 03:00:05 +00:00
|
|
|
'stroke-width': trailWidth || strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
|
|
|
},
|
|
|
|
class: `${prefixCls}-line-trail`,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
return (
|
|
|
|
<svg
|
|
|
|
class={`${prefixCls}-line`}
|
|
|
|
viewBox={viewBoxString}
|
2019-01-12 03:33:27 +00:00
|
|
|
preserveAspectRatio="none"
|
2018-04-03 03:00:05 +00:00
|
|
|
{...restProps}
|
|
|
|
>
|
2019-01-12 03:33:27 +00:00
|
|
|
<path {...pathFirst} />
|
2019-02-19 14:35:03 +00:00
|
|
|
{percentList.map((ptg, index) => {
|
|
|
|
const pathStyle = {
|
|
|
|
strokeDasharray: `${ptg}px, 100px`,
|
|
|
|
strokeDashoffset: `-${stackPtg}px`,
|
|
|
|
transition:
|
|
|
|
'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear',
|
|
|
|
};
|
|
|
|
const color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
|
|
|
|
|
|
|
stackPtg += ptg;
|
|
|
|
|
|
|
|
const pathProps = {
|
|
|
|
attrs: {
|
|
|
|
d: pathString,
|
|
|
|
'stroke-linecap': strokeLinecap,
|
|
|
|
stroke: color,
|
|
|
|
'stroke-width': strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
|
|
|
},
|
|
|
|
class: `${prefixCls}-line-path`,
|
|
|
|
style: pathStyle,
|
|
|
|
directives: [
|
|
|
|
{
|
|
|
|
name: 'ant-ref',
|
|
|
|
value: c => {
|
|
|
|
this.paths[index] = c;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return <path {...pathProps} />;
|
|
|
|
})}
|
2018-04-03 03:00:05 +00:00
|
|
|
</svg>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-04-03 03:00:05 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default enhancer(Line);
|