我正在寻找一种仅使用mxGraph Javascript而不使用SVG画布来呈现HTML图形的方法。用户手册说:
mxGraph还包括完全使用html呈现的功能,这限制了可用功能的范围,但适用于更简单的图表。”
但是,我尝试了以下操作但未成功:
var editor = new mxEditor();
var graph = new mxGraph(graphContElem, new mxGraphModel(), 'fastest'); // fastest maps to stricthtml
graph.setHtmlLabels(true);
graph.dialect = mxConstants.DIALECT_STRICTHTML;
editor.graph = graph;
editor.createGraph();
Run Code Online (Sandbox Code Playgroud)
添加此单元格:
var prototype = new mxCell('<input type="text" value="test" />', new mxGeometry(0, 0, w, h), style);
prototype.setVertex(true);
... import cells ...
Run Code Online (Sandbox Code Playgroud)
导致此:
<svg style="width: 100%; height: 100%; display: block; min-width: 1px; min-height: 1px;">
...
<g transform="translate(104,61)">
<foreignObject style="overflow:visible;" pointer-events="all" width="173" height="19">
<div style="display:inline-block;font-size:11px;font-family:Arial,Helvetica;color:#774400;line-height:1.2;vertical-align:top;white-space:nowrap;text-align:center;">
<div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;">
<input type="text" value="test">
</div>
</div> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Java将XML转换为SVG,但看起来形状信息在这个过程中会丢失.
给出一个简单的draw.io图表:
运行XmlToSvg.java后,我得到:
我将其保存为未压缩的XML.我使用的是mxgraph-all.jar从mxGraph回购
你知道是否有隐藏的设置来保存形状和颜色?
我正在使用Angular 4,并且希望将mxGraph集成到我的项目中。我已经用谷歌搜索了,但是没有得到完整的示例。
我已经尝试过以下方法,但对我也不起作用。
我遵循的步骤:
安装的mxgraph: npm install mxgraph --save
用于mxgraph的npm软件包:https ://www.npmjs.com/package/mxgraph
安装的mxgraph-typings: npm install lgleim/mxgraph-typings --save
Github回购mxgraph-typings- https://github.com/lgleim/mxgraph-typings
现在,我已将其导入到组件中: import {mxgraph} from 'mxgraph';
在.angular-cli.json资产数组中添加了以下行,以使mxGraph资产可用。
{"glob":"**/*", "input":"node_modules/mxgraph/javascript/src", "output": "./mxgraph"}
Run Code Online (Sandbox Code Playgroud)如果我尝试像这样使用它: const graph: mxgraph.mxGraph = new mxgraph.mxGraph(document.getElementById('graphContainer'));
当我跑步时 ng serve
然后我遇到问题/错误:
Module not found: Error: Can't resolve 'mxgraph' in 'path to my file where I have imported and used mxgraph'
现在,如果我尝试设置mxBasePath:
const mx = require('mxgraph')({
mxImageBasePath: 'mxgraph/images',
mxBasePath: 'mxgraph'
});
Run Code Online (Sandbox Code Playgroud)
像这样使用:
const graph: mxgraph.mxGraph = mx.mxGraph(document.getElementById('graphContainer'));
当我跑步时 ng serve
这次我也遇到同样的问题/错误:
Module …
我试图以编程方式为我的图形中的每个单元格关闭格式化文本,这样我就可以避免mxgraph编辑器中的查看器不支持(类似于Draw.io)
这是我的尝试:
graph.stopEditing();
graph.getModel().beginUpdate();
try
{
var cells = graph.getChildCells(graph.getDefaultParent());
cells.forEach(function (cell)
{
var state = graph.getView().getState(cell);
if (state == null)
{
return;
}
if (state.style['html'] != '1') {
return;
}
var label = graph.convertValueToString(state.cell);
if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
{
label = label.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
}
// Removes HTML tags
var temp = document.createElement('div');
temp.innerHTML = label;
label = mxUtils.extractTextWithWhitespace(temp.childNodes);
graph.cellLabelChanged(state.cell, label);
graph.setCellStyles('html', null);
});
ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['html'],
'values', ['0'], 'cells', cells));
} …Run Code Online (Sandbox Code Playgroud) 我想拖动每个表行,因为rectangle它必须具有与相同的功能rectangle。
运行代码后,您可以看到表格矩形下方的表格将位于左上方,我想为表格行复制相同的功能 drag
问题:当我将drag 表格行移至下方graph区域时,应将其视为矩形拖动。类似于旁边 graph区域左上角的矩形drag。
我正在使用(文档):https : //jgraph.github.io/mxgraph/docs/manual.html
有关完整视图,请参阅codepen: https ://codepen.io/eabangalore/pen/vMvdmZ
视频将向您显示我的问题:https : //drive.google.com/file/d/1DR3qMxX8JViSwMbA5vWYhMeMgRlQ0Krs/view
// Program starts here. Creates a sample graph in the
// DOM node with the specified ID. This function is invoked
// from the onLoad event handler of the document (see below).
function main() {
// Checks …Run Code Online (Sandbox Code Playgroud)嗨,我在边缘验证方面遇到了问题
注意:任何方法都是最受欢迎的,但应该解决问题
下面是我的要求
源 -> Action_1 -> Action_2
来源 -> Action_1 <- Action_2
下面的 Gif 显示了我的要求
在上面的 gif 中,出现的文字是我想避免的文字
这是我尝试过的
graph.multiplicities.push(new mxMultiplicity(
true, 'Source', null, null, 1, 1, ['Action_1','Action_2'],
'Source can have 1 Action and from there it can be multiple',
null));
graph.multiplicities.push(new mxMultiplicity(
false, 'Source', null, null, 0, 0, null,
'Source Must Have No Incoming Edge',
null)); // Type does not matter
Run Code Online (Sandbox Code Playgroud)
这是我提到的演示https://jgraph.github.io/mxgraph/javascript/examples/validation.html ,这里是它的代码 https://github.com/jgraph/mxgraph/blob/master/javascript/examples /validation.html
这是Multiplicity …
我是在 javascript 中使用 mxgraph 的新手,并且对如何使用图表中的事件有一些具体问题。我有兴趣使用并更好地理解两个基本场景:
1)我有兴趣使用示例中的拖放机制(即使用 mxgraph 工具栏)添加顶点。为此,我希望在将节点添加到图形之前接收一个事件,以便在“添加单元格”事件被触发之前能够做两件事:
a) 使用逻辑合并顶点数据(即时间戳)
b) 能够为每个顶点分配一个自定义 id
你能帮我理解如何处理这个案子吗?我一直在查看在线文档,但看不到对事件从“A 到 B”的实际工作方式的非常直接的描述。
非常感谢
I have an mxGraph, and my edges use an OrthoConnect style so that the arrows of the edges correctly point to the vertex. I found with other styles, they remained horizontal even when connecting to the top and bottom of a vertex. The OrthoConnect lets arrows point correctly.
Anyway, I have two edges coming out of one vertex, going to two different vertices. However, one edge goes right through a vertex:
Ideally, this would would branch down around where the …
我正在研究mxgraph的javascript https://github.com/jgraph/mxgraph/tree/master/javascript/examples/grapheditor下的grapheditor示例
但是,我注意到有两个部分。www文件夹中有一个javascript / HTML部分。还有一个Java部分。
我对Java有点生锈,所以我不确定Java代码负责什么。
Javascript和HTML部分是否完全负责GraphEditor示例的UI / UX显示?
意思是说诸如显示操作菜单和拖放等操作是由javascript和html部分处理的?
那么到底是什么负责Java代码?
我想在无镶边模式下突出显示draw.io图中的一系列单元格。目的是说明一条包含顶点和边的路径:
使用辅助类mxCellHighlight,我基本上尝试以下操作:
var highlight = new mxCellHighlight(graph, '#ff0000', 2);
highlight.highlight(graph.view.getState(cell1)));
highlight.highlight(graph.view.getState(cell2)));
...
Run Code Online (Sandbox Code Playgroud)
这不起作用,一次只能突出显示一个单元格。我知道当单元格的当前根发生更改时, resetHandler会隐藏突出显示标记,但不幸的是我无法正确覆盖它以防止这种效果。
非常感谢任何帮助,谢谢。