首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Graphiti中,如何将编辑器放在附加到图形的标签上

在Graphiti中,如何将编辑器放在附加到图形的标签上
EN

Stack Overflow用户
提问于 2012-07-16 02:00:25
回答 1查看 163关注 0票数 1

我正在尝试创建一个可编辑的标签,类似于示例connection_labeledit_inplace中的标签。

我遇到的问题是,我希望将标签附加到自定义VectorFigure,而不是连接。这样做时,标签只是图的一部分,不要启动编辑器。

代码语言:javascript
复制
ivr.shape.menu.MenuItem = graphiti.VectorFigure.extend({

NAME:"ivr.shape.menu.MenuItem",

MyOutputPortLocator : graphiti.layout.locator.Locator.extend({
    init: function(parent)
    {
        this._super(parent);
    },
    relocate:function(index, figure){
        var w = figure.getParent().getWidth();
        var h = figure.getParent().getHeight();

        figure.setPosition(w, h/2);
    }
}),

/**
 * @constructor
 * Creates a new figure element which are not assigned to any canvas.
 *
 */
init: function( width, height) {
    this._super();
    this.setBackgroundColor( new graphiti.util.Color(200,200,200));
    this.setColor(new graphiti.util.Color(50,50,50));

    // set some good defaults
    //
    if(typeof width === "undefined"){
        this.setDimension(100, 15);
    }
    else{
        this.setDimension(width, height);
    }

    // add port
    var outputLocator = new this.MyOutputPortLocator(this);
    this.createPort("output",outputLocator);

    this.label = new graphiti.shape.basic.Label("I'm a Label");
    this.label.setColor("#0d0d0d");
    this.label.setFontColor("#0d0d0d");
    this.addFigure(this.label, new graphiti.layout.locator.LeftLocator(this));

    this.label.installEditor(new graphiti.ui.LabelInplaceEditor());
},


repaint : function(attributes)
{
    if(this.repaintBlocked===true || this.shape===null){
        return;
    }

    if (typeof attributes === "undefined") {
        attributes = {};
    }

    var box = this.getBoundingBox();
    var center = box.getCenter();
    var path = ["M",box.x,",",box.y];
    path.push("l", box.w-10, ",0");
    path.push("l10,", box.h/2);
    path.push("l-10,", box.h/2);
    path.push("L",box.x,",", box.getBottomLeft().y);
    path.push("Z");
    var strPath = path.join("");
    attributes.path = strPath;

    this._super(attributes);
},


/**
 * @method
 * Called by the framework. Don't call them manually.
 *
 * @private
 **/
createShapeElement:function()
{
    // create dummy line
    return this.canvas.paper.path("M0 0L1 1");
}

});

对于本例,我将标签放在图的左侧,但显然我将创建一个将标签放在图上的定位器(以防它改变了什么)

在我看来,问题出在“graphiti.Canvas.getBestFigure()”的工作方式上。该函数仅检查直接附加到“graphity.Canvas”的元素。此外,该函数缺少一些递归来在子级上传播事件。

EN

回答 1

Stack Overflow用户

发布于 2012-07-21 05:41:43

Graphiti提供了一个CenterLocator。所有像dblClick这样的事件都可以被这个数字捕捉到。

....did你用的是最新版本吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11494297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档