UNPKG

2.9 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var util_1 = require("@antv/util");
5var base_1 = require("../base");
6var get_path_points_1 = require("../util/get-path-points");
7var get_style_1 = require("../util/get-style");
8var util_2 = require("./util");
9var interpolateCallback = function (point, nextPoint, shapeType) {
10 var x = point.x;
11 var y = point.y;
12 var nextX = nextPoint.x;
13 var nextY = nextPoint.y;
14 var result;
15 switch (shapeType) {
16 case 'hv':
17 result = [{ x: nextX, y: y }];
18 break;
19 case 'vh':
20 result = [{ x: x, y: nextY }];
21 break;
22 case 'hvh':
23 var middleX = (nextX + x) / 2;
24 result = [
25 { x: middleX, y: y },
26 { x: middleX, y: nextY },
27 ];
28 break;
29 case 'vhv':
30 var middleY = (y + nextY) / 2;
31 result = [
32 { x: x, y: middleY },
33 { x: nextX, y: middleY },
34 ];
35 break;
36 default:
37 break;
38 }
39 return result;
40};
41function getInterpolatePoints(points, shapeType) {
42 var result = [];
43 util_1.each(points, function (point, index) {
44 var nextPoint = points[index + 1];
45 result.push(point);
46 if (nextPoint) {
47 var interpolatePoint = interpolateCallback(point, nextPoint, shapeType);
48 result = result.concat(interpolatePoint);
49 }
50 });
51 return result;
52}
53// 插值的图形path,不考虑null
54function getInterpolatePath(points) {
55 return points.map(function (point, index) {
56 return index === 0 ? ['M', point.x, point.y] : ['L', point.x, point.y];
57 });
58}
59// 插值的图形
60function getInterpolateShapeAttrs(cfg, shapeType) {
61 var points = get_path_points_1.getPathPoints(cfg.points, cfg.connectNulls, cfg.showSinglePoint); // 根据 connectNulls 值处理 points
62 var path = [];
63 util_1.each(points, function (eachLinePoints) {
64 var interpolatePoints = getInterpolatePoints(eachLinePoints, shapeType);
65 path = path.concat(getInterpolatePath(interpolatePoints));
66 });
67 return tslib_1.__assign(tslib_1.__assign({}, get_style_1.getStyle(cfg, true, false, 'lineWidth')), { path: path });
68}
69// step line
70util_1.each(['hv', 'vh', 'hvh', 'vhv'], function (shapeType) {
71 base_1.registerShape('line', shapeType, {
72 draw: function (cfg, container) {
73 var attrs = getInterpolateShapeAttrs(cfg, shapeType);
74 var shape = container.addShape({
75 type: 'path',
76 attrs: attrs,
77 name: 'line',
78 });
79 return shape;
80 },
81 getMarker: function (markerCfg) {
82 return util_2.getLineMarker(markerCfg, shapeType);
83 },
84 });
85});
86//# sourceMappingURL=step.js.map
\No newline at end of file