export polyline config

This commit is contained in:
TomHuangCN 2018-08-10 11:26:56 +08:00
parent 953f225130
commit fee48f03ae
3 changed files with 9 additions and 11 deletions

View File

@ -72,6 +72,9 @@
[0.5, 1] [0.5, 1]
] ]
}); });
G6.registerEdge('polyline', {
offset: 20
});
const data = { const data = {
roots: [{ roots: [{
main: '主指标一', main: '主指标一',

View File

@ -6,11 +6,6 @@
const G6 = require('@antv/g6'); const G6 = require('@antv/g6');
const Util = G6.Util; const Util = G6.Util;
const DEFAULT_STYLE = {
offset: 10,
borderRadius: 10
};
function isHorizontalPort(port, bbox) { function isHorizontalPort(port, bbox) {
const dx = Math.abs(port.x - bbox.centerX); const dx = Math.abs(port.x - bbox.centerX);
const dy = Math.abs(port.y - bbox.centerY); const dy = Math.abs(port.y - bbox.centerY);
@ -416,6 +411,7 @@ function getPathWithBorderRadiusByPolyline(points, borderRadius) {
} }
G6.registerEdge('polyline', { G6.registerEdge('polyline', {
offset: 10,
getPath(item) { getPath(item) {
const points = item.getPoints(); const points = item.getPoints();
const source = item.getSource(); const source = item.getSource();
@ -423,21 +419,20 @@ G6.registerEdge('polyline', {
return this.getPathByPoints(points, source, target); return this.getPathByPoints(points, source, target);
}, },
getPathByPoints(points, source, target) { getPathByPoints(points, source, target) {
const { offset } = Util.merge({}, DEFAULT_STYLE); const polylinePoints = getPolylinePoints(points[0], points[points.length - 1], source, target, this.offset);
const polylinePoints = getPolylinePoints(points[0], points[points.length - 1], source, target, offset);
// FIXME default // FIXME default
return Util.pointsToPolygon(polylinePoints); return Util.pointsToPolygon(polylinePoints);
} }
}); });
G6.registerEdge('polyline-round', { G6.registerEdge('polyline-round', {
borderRadius: 10,
getPathByPoints(points, source, target) { getPathByPoints(points, source, target) {
const { offset, borderRadius } = Util.merge({}, DEFAULT_STYLE);
const polylinePoints = simplifyPolyline( const polylinePoints = simplifyPolyline(
getPolylinePoints(points[0], points[points.length - 1], source, target, offset) getPolylinePoints(points[0], points[points.length - 1], source, target, this.offset)
); );
// FIXME default // FIXME default
return getPathWithBorderRadiusByPolyline(polylinePoints, borderRadius); return getPathWithBorderRadiusByPolyline(polylinePoints, this.borderRadius);
} }
}, 'polyline'); }, 'polyline');

View File

@ -91,7 +91,7 @@ class Graph extends Base {
* renderer canvas or svg * renderer canvas or svg
* @type {string} * @type {string}
*/ */
renderer: 'canvas', renderer: 'svg',
_controllers: {}, _controllers: {},
_timers: {}, _timers: {},