如何将附加参数传递给 graffle.js
How to pass an additional parameter to graffle.js
我正在尝试将一个附加参数传递给 graffle 的连接函数,以便我可以根据该新参数绘制一个连接with/without行尾的箭头。
为了建立联系,我通常会这样做:
connections.push(paper.connection(obj1, obj2, "#000"));
现在我想以这种方式添加这个新参数:
connections.push(paper.connection(condCol, ret, "#000",true));
但是参数总是undefined
这就是我更改连接功能的方式:
Raphael.fn.connection = function (obj1, obj2, line, bg, addArrow) {
//...
if (line && line.line) {
//...
} else {
// based on the 'addArrow' parameter I can figure out
// whether I should put an arrow at the end of the line or not
var settings;
if (addArrow) {
//If addArrow was true, draw a arrow at the end of the line
settings = { "stroke": color, fill: "none", 'stroke-width': 2, 'arrow-end': 'block-midium-midium' };
}
else {
//If addArrow was false, just draw a line
settings = { "stroke": color, fill: "none", 'stroke-width': 2 };
}
return {
bg: bg && bg.split && this.path(path).attr({ stroke: bg.split("|")[0], fill: "none", "stroke-width": bg.split("|")[1] || 3 }),
line: this.path(path).attr(settings), //use the settings
from: obj1,
to: obj2
};
}
}
你知道为什么这不起作用吗?
提前致谢。
您的新 connection()
函数有五个参数。你只通过了四次。这就是 addArray
未定义的原因。您传递的 true
值将进入 bg
参数。尝试这样调用:
connections.push(paper.connection(condCol, ret, "#000", null, true));
抱歉,我没有注意到这些是可选参数。
解决方案很简单。
我只是像这样更改方法的定义:
Raphael.fn.connection = function (obj1, obj2, line, bg, addArrow) {
}
并调用该函数,省略第四个参数:
connections.push(paper.connection(condCol, ret, "#000","",true));
就是这样。
我正在尝试将一个附加参数传递给 graffle 的连接函数,以便我可以根据该新参数绘制一个连接with/without行尾的箭头。
为了建立联系,我通常会这样做:
connections.push(paper.connection(obj1, obj2, "#000"));
现在我想以这种方式添加这个新参数:
connections.push(paper.connection(condCol, ret, "#000",true));
但是参数总是undefined
这就是我更改连接功能的方式:
Raphael.fn.connection = function (obj1, obj2, line, bg, addArrow) {
//...
if (line && line.line) {
//...
} else {
// based on the 'addArrow' parameter I can figure out
// whether I should put an arrow at the end of the line or not
var settings;
if (addArrow) {
//If addArrow was true, draw a arrow at the end of the line
settings = { "stroke": color, fill: "none", 'stroke-width': 2, 'arrow-end': 'block-midium-midium' };
}
else {
//If addArrow was false, just draw a line
settings = { "stroke": color, fill: "none", 'stroke-width': 2 };
}
return {
bg: bg && bg.split && this.path(path).attr({ stroke: bg.split("|")[0], fill: "none", "stroke-width": bg.split("|")[1] || 3 }),
line: this.path(path).attr(settings), //use the settings
from: obj1,
to: obj2
};
}
}
你知道为什么这不起作用吗?
提前致谢。
您的新 connection()
函数有五个参数。你只通过了四次。这就是 addArray
未定义的原因。您传递的 true
值将进入 bg
参数。尝试这样调用:
connections.push(paper.connection(condCol, ret, "#000", null, true));
抱歉,我没有注意到这些是可选参数。 解决方案很简单。 我只是像这样更改方法的定义:
Raphael.fn.connection = function (obj1, obj2, line, bg, addArrow) {
}
并调用该函数,省略第四个参数:
connections.push(paper.connection(condCol, ret, "#000","",true));
就是这样。