Javascript 如何在draw2d.js中创建组合图形

Javascript 如何在draw2d.js中创建组合图形,javascript,draw2d-js,Javascript,Draw2d Js,我已经浏览了随库提供的示例集合,但不幸的是,所有用于合成图形的示例都基于解析json文件 reader.unmarshal(canvas, jsonDocument); 然而,我想看到的是如何从基本图形创建合成图形,例如: var figure_1 = new draw2d.shape.basic.Rectangle(....); var figure_1 = new draw2d.shape.basic.Diamond(....); ... then do something, so tha

我已经浏览了随库提供的示例集合,但不幸的是,所有用于合成图形的示例都基于解析json文件

reader.unmarshal(canvas, jsonDocument);
然而,我想看到的是如何从基本图形创建合成图形,例如:

var figure_1 = new draw2d.shape.basic.Rectangle(....);
var figure_1 = new draw2d.shape.basic.Diamond(....);
... then do something, so that figure_1 and figure_2 are now part of
... a composite figure
我想我需要的是,但我不知道如何使用它。希望有人能帮忙

编辑

这就是我所尝试的:

var baseRectangle =  new draw2d.shape.composite.StrongComposite({width: 200, height: 200, x: conf.x, y: conf.y});
var top = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y});
var bottom = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y + 60});
baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);
canvas.add(baseRectangle);
但它不起作用。我只看到一个灰色的盒子。我也试过:

var baseRectangle =  new draw2d.shape.composite.StrongComposite({width: 200, height: 200, x: conf.x, y: conf.y});
var top = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y});
var bottom = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y + 60});
baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);
canvas.add(top);
canvas.add(bottom);

但结果是,我得到了绝对独立的椭圆。

您还必须向画布添加
baseRectangle

var baseRectangle = new draw2d.shape.composite.StrongComposite({
    width: 200,
    height: 200,
    x: conf.x,
    y: conf.y
});
canvas.add(baseRectangle);

var top = new draw2d.shape.basic.Oval({
    width: 120,
    height: 40,
    x: conf.x,
    y: conf.y
});
var bottom = new draw2d.shape.basic.Oval({
    width: 120,
    height: 40,
    x: conf.x,
    y: conf.y + 60
});

baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);

canvas.add(top);
canvas.add(bottom);

您还必须将
baseRectangle
添加到画布

var baseRectangle = new draw2d.shape.composite.StrongComposite({
    width: 200,
    height: 200,
    x: conf.x,
    y: conf.y
});
canvas.add(baseRectangle);

var top = new draw2d.shape.basic.Oval({
    width: 120,
    height: 40,
    x: conf.x,
    y: conf.y
});
var bottom = new draw2d.shape.basic.Oval({
    width: 120,
    height: 40,
    x: conf.x,
    y: conf.y + 60
});

baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);

canvas.add(top);
canvas.add(bottom);