| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- var __rest = (this && this.__rest) || function (s, e) {
- var t = {};
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
- t[p] = s[p];
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
- t[p[i]] = s[p[i]];
- }
- return t;
- };
- import { Path } from '@antv/g';
- import { arc, line } from 'd3-shape';
- import { isPolar } from '../../utils/coordinate';
- import { select } from '../../utils/selection';
- import { dist } from '../../utils/vector';
- import { subObject } from '../../utils/helper';
- import { applyStyle, getShapeTheme } from '../utils';
- function getArrowMarker(arrowSize, arrowStyle) {
- const arrowMarker = new Path({
- style: Object.assign({ path: `M ${arrowSize},${arrowSize} L -${arrowSize},0 L ${arrowSize},-${arrowSize} L 0,0 Z`, anchor: '0.5 0.5', transformOrigin: 'center' }, arrowStyle),
- });
- return arrowMarker;
- }
- function getPath(points, coordinate) {
- if (!isPolar(coordinate))
- return line()
- .x((d) => d[0])
- .y((d) => d[1])(points);
- const center = coordinate.getCenter();
- return arc()({
- startAngle: 0,
- endAngle: Math.PI * 2,
- outerRadius: dist(points[0], center),
- innerRadius: dist(points[1], center),
- });
- }
- function getTransform(coordinate, transform) {
- if (!isPolar(coordinate))
- return transform;
- const [cx, cy] = coordinate.getCenter();
- return `translate(${cx}, ${cy}) ${transform || ''}`;
- }
- export const Line = (options) => {
- const { arrow, arrowSize = 4 } = options, style = __rest(options, ["arrow", "arrowSize"]);
- return (points, value, coordinate, theme) => {
- const { mark, shape, defaultShape } = value;
- const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor, lineWidth } = _a, shapeTheme = __rest(_a, ["defaultColor", "lineWidth"]);
- const { color = defaultColor, size = lineWidth } = value;
- const arrowMarker = arrow
- ? getArrowMarker(arrowSize, Object.assign({ fill: style.stroke || color, stroke: style.stroke || color }, subObject(style, 'arrow')))
- : null;
- const path = getPath(points, coordinate);
- const transform = getTransform(coordinate, value.transform);
- return select(new Path({}))
- .call(applyStyle, shapeTheme)
- .style('d', path)
- .style('stroke', color)
- .style('lineWidth', size)
- .style('transform', transform)
- .style('markerEnd', arrowMarker)
- .call(applyStyle, style)
- .node();
- };
- };
- Line.props = {
- defaultMarker: 'line',
- defaultEnterAnimation: 'fadeIn',
- defaultUpdateAnimation: 'morphing',
- defaultExitAnimation: 'fadeOut',
- };
- //# sourceMappingURL=line.js.map
|