@byai/topology
Advanced tools
Comparing version 1.6.0-beta-2 to 1.6.0-beta-3
@@ -6,2 +6,6 @@ import React, { HTMLAttributes } from 'react'; | ||
import './index.less'; | ||
export interface AutoLayoutOptions { | ||
preprocess?: (data: ITopologyData) => ITopologyData; | ||
resultProcess?: (data: ITopologyData) => ITopologyData; | ||
} | ||
export interface ITopologyProps { | ||
@@ -68,2 +72,3 @@ data: ITopologyData; | ||
renderMinimapChild?: (params: any) => React.ReactNode; | ||
autoLayoutOption?: AutoLayoutOptions; | ||
} | ||
@@ -124,3 +129,3 @@ export interface ITopologyState { | ||
clearSelectData: (updated?: boolean) => void; | ||
autoLayout: () => void; | ||
autoLayout: (options?: AutoLayoutOptions) => void; | ||
initDomEvents: () => void; | ||
@@ -127,0 +132,0 @@ removeDomEvents: () => void; |
@@ -12,54 +12,29 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
/* eslint-disable no-debugger */ | ||
/* eslint-disable no-param-reassign */ | ||
import dagre from 'dagre'; | ||
import { getNodeSize } from '.'; | ||
import config from '../config'; | ||
import Graph from './Graph'; | ||
function computeLayout(data, options) { | ||
console.log(options); | ||
var g = new dagre.graphlib.Graph({}); | ||
g.setGraph({ ranksep: config.autoLayout.verticalSpacing, nodesep: config.autoLayout.horizontalSpacing }); | ||
g.setDefaultEdgeLabel(function () { return ({}); }); | ||
data.nodes.forEach(function (node) { | ||
var layoutGraph = new Graph(); | ||
layoutGraph.setNodeList(data.nodes.map(function (node) { | ||
var nodeSize = getNodeSize(node.id); | ||
g.setNode(node.id, { | ||
label: node.id, | ||
width: nodeSize.width, | ||
height: nodeSize.height, | ||
}); | ||
}); | ||
data.lines.forEach(function (line) { | ||
var _a; | ||
g.setEdge((_a = line.start.split('-')) === null || _a === void 0 ? void 0 : _a[0], line.end); | ||
}); | ||
dagre.layout(g); | ||
return [node.id, { | ||
label: node.id, | ||
width: nodeSize.width, | ||
height: nodeSize.height, | ||
}]; | ||
})); | ||
layoutGraph.setEdgeList(data.lines.map(function (line) { var _a; return [(_a = line.start.split('-')) === null || _a === void 0 ? void 0 : _a[0], line.end]; })); | ||
layoutGraph.layout(); | ||
var boundary = layoutGraph.getBoundary(); | ||
var nodeMap = new Map(); | ||
var bar = g.nodes().reduce(function (prev, curr) { | ||
// x, y 坐标是中心点坐标 | ||
var _a = g.node(curr), width = _a.width, height = _a.height, x = _a.x, y = _a.y; | ||
var halfWidth = width / 2; | ||
var halfHeight = height / 2; | ||
nodeMap.set(curr, { x: x - halfWidth, y: y - halfHeight }); | ||
var top = Math.min(prev.top, y - halfHeight); | ||
var left = Math.min(prev.left, x - halfWidth); | ||
var bottom = Math.max(prev.bottom, y + halfHeight); | ||
var right = Math.max(prev.right, x + halfWidth); | ||
return { | ||
top: top, | ||
left: left, | ||
bottom: bottom, | ||
right: right, | ||
}; | ||
}, { | ||
top: Infinity, | ||
left: Infinity, | ||
bottom: -Infinity, | ||
right: -Infinity | ||
layoutGraph.getNodes().forEach(function (node) { | ||
nodeMap.set(node.label, node); | ||
}); | ||
var containerSize = { | ||
width: bar.right - bar.left, | ||
height: bar.bottom - bar.top | ||
width: boundary.width, | ||
height: boundary.height | ||
}; | ||
var leftOffset = bar.left + containerSize.width / 2; | ||
var topOffset = bar.top + containerSize.height / 2; | ||
var leftOffset = containerSize.width / 2; | ||
var topOffset = containerSize.height / 2; | ||
return data.nodes.map(function (node) { | ||
@@ -66,0 +41,0 @@ var infoPos = nodeMap.get(node.id); |
import dagre from 'dagre'; | ||
export declare enum Direction { | ||
TB = "TB", | ||
BT = "BT", | ||
LR = "LR", | ||
RL = "RL" | ||
} | ||
export declare class Graph { | ||
import { DagreDirection } from '.'; | ||
export default class Graph { | ||
private graphObj; | ||
@@ -13,3 +8,3 @@ constructor(opt?: { | ||
nodeSep?: number; | ||
rankDir?: Direction; | ||
rankDir?: DagreDirection; | ||
}); | ||
@@ -16,0 +11,0 @@ setNode: (name: string, label: string | dagre.Label) => void; |
@@ -24,10 +24,4 @@ var __assign = (this && this.__assign) || function () { | ||
import dagre from 'dagre'; | ||
import { DagreDirection } from '.'; | ||
import config from '../config'; | ||
export var Direction; | ||
(function (Direction) { | ||
Direction["TB"] = "TB"; | ||
Direction["BT"] = "BT"; | ||
Direction["LR"] = "LR"; | ||
Direction["RL"] = "RL"; | ||
})(Direction || (Direction = {})); | ||
var Graph = /** @class */ (function () { | ||
@@ -98,3 +92,3 @@ function Graph(opt) { | ||
}; | ||
var _a = opt !== null && opt !== void 0 ? opt : {}, _b = _a.rankSep, rankSep = _b === void 0 ? config.autoLayout.verticalSpacing : _b, _c = _a.nodeSep, nodeSep = _c === void 0 ? config.autoLayout.horizontalSpacing : _c, _d = _a.rankDir, rankDir = _d === void 0 ? Direction.TB : _d; | ||
var _a = opt !== null && opt !== void 0 ? opt : {}, _b = _a.rankSep, rankSep = _b === void 0 ? config.autoLayout.verticalSpacing : _b, _c = _a.nodeSep, nodeSep = _c === void 0 ? config.autoLayout.horizontalSpacing : _c, _d = _a.rankDir, rankDir = _d === void 0 ? DagreDirection.TB : _d; | ||
var g = new dagre.graphlib.Graph({}); | ||
@@ -107,3 +101,3 @@ g.setGraph({ ranksep: rankSep, nodesep: nodeSep, rankdir: rankDir }); | ||
}()); | ||
export { Graph }; | ||
export default Graph; | ||
//# sourceMappingURL=Graph.js.map |
import { IPosition, ITopologyNode } from '../declare'; | ||
export declare enum DagreDirection { | ||
TB = "TB", | ||
BT = "BT", | ||
LR = "LR", | ||
RL = "RL" | ||
} | ||
export declare const shouldAutoLayout: (nodes: ITopologyNode[]) => boolean; | ||
@@ -3,0 +9,0 @@ /** |
@@ -12,2 +12,9 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
export var DagreDirection; | ||
(function (DagreDirection) { | ||
DagreDirection["TB"] = "TB"; | ||
DagreDirection["BT"] = "BT"; | ||
DagreDirection["LR"] = "LR"; | ||
DagreDirection["RL"] = "RL"; | ||
})(DagreDirection || (DagreDirection = {})); | ||
export var shouldAutoLayout = function (nodes) { | ||
@@ -14,0 +21,0 @@ if (nodes.length === 0) { |
{ | ||
"name": "@byai/topology", | ||
"version": "1.6.0-beta-2", | ||
"version": "1.6.0-beta-3", | ||
"description": "拓扑图组件", | ||
@@ -5,0 +5,0 @@ "bugs": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
412028
5433