我正在使用 yFiles 开发动态图形编辑器。这意味着用户可以从菜单中选择新节点并将它们拖到图形区域中。但是,我希望我的图表在 x 轴上的大小有限。也就是说,图形应该是可扩展的,垂直方向没有限制,但要保持最大宽度。我完全不知道这样做的方式,所以定义图形的最大宽度。
我想在这个演示中有一个像橙色矩形一样的最终效果。在那里,PositionHandler
使用了a,但我不知道如何集成它。
不知道它是否有任何帮助,但这是我定义图形交互部分的片段。
'createEditorMode': function() {
var /** yfiles.input.GraphSnapContext */ snapContext = new yfiles.input.GraphSnapContext();
snapContext.enabled = false;
snapContext.nodeGridConstraintProvider = new yfiles.input.SimpleGridConstraintProvider /** .<yfiles.graph.INode> */.FromGridInfo(this.gridInfo);
snapContext.bendGridConstraintProvider = new yfiles.input.SimpleGridConstraintProvider /** .<yfiles.graph.IBend> */.FromGridInfo(this.gridInfo);
snapContext.portGridConstraintProvider = new yfiles.input.SimpleGridConstraintProvider /** .<yfiles.graph.IPort> */.FromGridInfo(this.gridInfo);
var graph = this.graphControl.graph;
var /** yfiles.input.GraphEditorInputMode */ mode = new yfiles.input.GraphEditorInputMode();
mode.snapContext = snapContext;
mode.edgeCreationAllowed = false; //only one edge create
mode.marqueeSelectionInputMode.enabled = true; //block selection
mode.nodeCreator = null;
var /** yfiles.input.OrthogonalEdgeEditingContext */ newOrthogonalEdgeEditingContext = new yfiles.input.OrthogonalEdgeEditingContext();
newOrthogonalEdgeEditingContext.orthogonalEdgeEditing = true;
mode.createEdgeInputMode.orthogonalEdgeCreation = true; //Enable edges' creation in orthogonal mode
mode.orthogonalEdgeEditingContext = newOrthogonalEdgeEditingContext;
mode.createBendModePriority = mode.moveModePriority - 1;// add a context// menu
mode.clickSelectableItems = yfiles.graph.GraphItemTypes.NODE | yfiles.graph.GraphItemTypes.EDGE;
mode.labelAddingAllowed = false;
mode.labelEditingAllowed = false;
mode.clipboardOperationsAllowed = false;
mode.undoOperationsAllowed = true;
//mode.undoOperationsAllowed = false;
mode.addItemClickedListener(yfiles.lang.delegate(this.onItemClicked, this));
mode.addItemDoubleClickedListener(yfiles.lang.delegate(this.onItemDoubleClicked, this));
this.contextMenu = new demo.ContextMenu();
mode.contextMenuInputMode.menu = this.contextMenu;
this.contextMenu.install(this.graphControl.div);
this.contextMenu.addOpenedListener(function( /** Object */
sender, /** yfiles.system.EventArgs */
args) {
var /** yfiles.system.CancelEventArgs */ cancelEventArgs = new yfiles.system.CancelEventArgs();
mode.contextMenuInputMode.menuOpening(cancelEventArgs);
if (cancelEventArgs.cancel) {
(( /** @type {demo.ContextMenu} */ (sender))).visible = false;
}
}
);
this.contextMenu.addClosedListener(function( /** Object */ sender, /** yfiles.system.EventArgs */ args) {
mode.contextMenuInputMode.menuClosed();
});
mode.contextMenuInputMode.addCloseMenuListener((function( /** Object */ o, /** yfiles.system.EventArgs */ args) {
this.contextMenu.visible = false;
}).bind(this));
mode.contextMenuInputMode.addPopulateContextMenuListener(yfiles.lang.delegate(this.onPopulateContextMenu, this));
return mode;
},