我设法让它工作。首先,您需要创建两个新类:
class NodeStyleImpl implements NodeStyle
class RelationshipStyleImpl implements RelationshipStyle
在这里,您可以定义节点和关系应如何以点表示法编写。示例实现如下所示:
public class NodeStyleImpl implements NodeStyle {
public void emitNodeStart(Appendable apndbl, Node node) throws IOException {
apndbl.append(" N" + node.getId() + " [\n label = \"");
}
public void emitEnd(Appendable apndbl) throws IOException {
apndbl.append("\"\n]\n");
}
public void emitProperty(Appendable apndbl, String propkey, Object propvalue) throws IOException {
if(propkey.equals("propkeyone") || propkey.equals("propkeytwo"){
apndbl.append(propvalue.toString());
}
}
}
以模拟方式,您可以编写RelationshipStyleImpl。如果您正在寻找更高级的配置,您还可以编写一个 StyleConfiguration 实现。您可以查看 Neo4j 代码中的默认实现作为示例。
然后是 GraphStyle 类的问题。GraphStyle 类有一个受保护的构造函数,因此只能从包内访问。我提出了一个将其更改为公开的请求请求,但目前,这里有一个小“黑客”,它提供了一种解决方法。
package org.neo4j.visualization.graphviz
public class GraphStyleImpl extends GraphStyle {
private GraphStyleImpl (NodeStyleImpl nstyle, RelationshipStyleImpl rstyle) {
super(nstyle, rstyle);
}
}
注意包声明。因为 GraphStyle 构造函数是受保护的,所以 super(nstyle, rstyle) 方法只能从同一个包中访问。通过使用新的公共构造函数扩展类,您现在可以执行以下操作:
GraphStyle graphstyle = new GraphStyleImpl(new NodeStyleImpl(), new RelationshipStyleImpl());
GraphvizWriter writer = new GraphvizWriter(graphstyle);
如果我的拉取请求被接受,则不再需要使用 GraphStyleImpl 类。