我想实现一个流程图编辑器,这将有一个图形组件和侧栏组件。侧边栏将有可重复使用的形状,如矩形,方形,月食,菱形,圆形等我应该能够拖放到图形容器中,以自动添加它们作为一个图形,我可以通过拖放各种shapes.Also在图形中添加其他顶点,我应该能够添加/在插入边或连接线之间的这些形状添加为顶点。
我在angular 10中为同样的代码写了下面的代码。
app.component.ts:
import {AfterViewInit, Component, ElementRef, ViewChild} from '@angular/core';
declare var mxClient: any;
declare var mxPerimeter: any;
declare var mxConstants: any;
declare var mxUtils: any;
declare var mxEvent: any;
declare var mxEventObject: any;
declare var mxEffects: any;
declare var mxDivResizer: any;
declare var mxGraphHandler: any;
declare var mxGuide: any;
declare var mxCodec: any;
declare var mxLog: any;
declare var mxConnectionHandler: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
@ViewChild('graphContainer') graphContainer: ElementRef;
@ViewChild('sidebarContainer') sidebar: ElementRef
ngAfterViewInit() {
const graph = new mxGraph(this.graphContainer.nativeElement);
try {
const parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
const vertex1 = graph.insertVertex(parent, '1', 'Vertex 1', 0, 0, 200, 80);
const vertex2 = graph.insertVertex(parent, '2', 'Vertex 2', 0, 0, 200, 80);
graph.insertEdge(parent, '', '', vertex1, vertex2);
} finally {
graph.getModel().endUpdate();
new mxHierarchicalLayout(graph).execute(graph.getDefaultParent());
this.addVertex(graph,'/assets/images/rectangle.gif', 100, 40, '');
this.addVertex(graph,'/assets/images/rounded.gif', 100, 40, 'shape=rounded');
this.addVertex(graph,'/assets/images/ellipse.png', 40, 40, 'shape=ellipse');
this.addVertex(graph,'/assets/images/rhombus.png', 40, 40, 'shape=rhombus');
this.addVertex(graph,'/assets/images/triangle.png', 40, 40, 'shape=triangle');
this.addVertex(graph,'/assets/images/cylinder.png', 40, 40, 'shape=cylinder');
this.addVertex(graph,'/assets/images/actor.png', 30, 40, 'shape=actor');
}
}
addVertex(graph,icon, w, h, style): void {
const vertex = new mxCell(null, new mxGeometry(0, 0, w, h), style);
vertex.setVertex(true);
this.addToolbarItem(graph, toolbar, vertex, icon);
}
addToolbarItem(graph, toolbar, prototype, image): void {
// Function that is executed when the image is dropped on
// the graph. The cell argument points to the cell under
// the mousepointer if there is one.
var funct = function(graph, evt, cell)
{
graph.stopEditing(false);
var pt = graph.getPointForEvent(evt);
var vertex = graph.getModel().cloneCell(prototype);
vertex.geometry.x = pt.x;
vertex.geometry.y = pt.y;
graph.setSelectionCells(graph.importCells([vertex], 0, 0, cell));
}
// Creates the image which is used as the drag icon (preview)
var img = toolbar.addMode(null, image, funct);
mxUtils.makeDraggable(img, graph, funct);
}
}app.component.html:
<div id="sidebarContainer"
style="position:absolute;overflow:hidden;top:36px;left:0px;bottom:36px;max-width:52px;width:56px;padding-top:10px;padding-left:4px;background-image:url('/assets/images/sidebar_bg.gif');">
</div>
<div #graphContainer id="graphContainer"
style="position:absolute;overflow:hidden;top:36px;left:60px;bottom:36px;right:0px;background-image:url('/assets/images/grid.gif');cursor:default;">
</div>>然而,我得到了错误,因为
src/app/APP.COMPOMENT.TS(62,20)中出错:错误TS2554:应为0个参数,但实际为3。src/app/APP.COMPOMENT.TS(62,41):错误TS2304:找不到名称'mxGeometry‘。
你能告诉我如何在angular 10中加入像mxGeometry、mxRectangle或mxCell这样的mxGraph模型来解决上面的错误吗?
另外,请让我知道上面的代码是否正确?
发布于 2020-08-20 18:35:31
请阅读StackOverflow same this文章中的答案。在这些来源中描述的远远不够。
发布于 2020-10-29 22:57:51
关于mxgraph typescript集成部分的问题,您可以避免使用any,并获得完整的类型支持(TS编译器检查、集成开发环境代码辅助、…。)通过使用https://github.com/hungtcs/mxgraph-type-definitions提供的类型(也可以使用https://github.com/typed-mxgraph/typed-mxgraph,这取决于您想要集成mxgraph的方式)。
对于完整的角度集成示例,您可以查看https://github.com/ivamax9/angular-mxgraph-demo或How to integrate mxGraph with Angular 4?。
https://stackoverflow.com/questions/63495464
复制相似问题