微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将图像添加到 Mxgraph mxGeometry

如何解决如何将图像添加到 Mxgraph mxGeometry

我目前正在使用 MxGraph 进行一个项目,并且我想要渲染的组件已使用 mxGeometry 方法创建。我在 stackoverflow 上看到许多答案,建议将图像属性添加到 insertVertex 或 addVertex 方法。但是我没有使用过这样的方法。 这是我的代码片段:

  class HyComp extends Component {
  constructor() {
    var w = 50;
    var h = 50;

    super(new mxGeometry(0,w,h));
    this.style += "strokeColor=black;fillColor=white;";
  }

  createChildren(name) {
    let w = this.geometry.width;
    let h = this.geometry.height;

    this.createLabel(name);

    var c_in = new mxCell("",new mxGeometry(-10,5,10,10));
    c_in.vertex = true;
    c_in.connectable = true;
    c_in.connectionType = "hydro";
    c_in.style =
      "editable=0;movable=0;strokeColor=blue;fillColor=white;portConstraint=west;perimeter=none;";
    this.insert(c_in);

    var c_out = new mxCell("",h - 10 - 5,10));
    c_out.vertex = true;
    c_out.connectable = true;
    c_out.connectionType = "hydro";
    c_out.style =
      "editable=0;movable=0;strokeColor=blue;fillColor=white;portConstraint=west;perimeter=none;";
    this.insert(c_out);

    this.setDimensions(10,w + c_in.geometry.width,h);
  }
}

这就是 Component 类的样子:

class Component extends mxCell {
  constructor(geometry) {
    super("",geometry);

    this.vertex = true;
    this.connectable = false;
    this.isComponent = true;
    this.componentName = this.constructor.name;
    this.userName = "";
    this.setNewId();
    this.style = "editable=0;movable=1;";

    this.setDimensions(0,0);
  }

几天来,我一直在尝试插入图像作为这些单元格的背景,但没有成功。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。