- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 JointJS 与端口功能一起使用:
(...)
var model = joint.shapes.devs.Model({
size: { width: width, height: height },
label: node.label,
inPorts: node.inputPorts,
outPorts: node.outputPorts,
attrs: {
'.label': { text: node.label, 'ref-x': .4, 'ref-y': .2 },
rect: { fill: '#2ECC71' },
'.inPorts circle': { fill: '#16A085' },
'.outPorts circle': { fill: '#E74C3C' }
}
(...)
但是输入端口出现在左边,输出端口出现在右边。我想要顶部的输入端口和底部的输出端口。
使用 joint.shapes.devs.Model 将端口位置更改为 Top-Bottom 的最佳方法是什么?
提前致谢。
最佳答案
端口的位置在 devs.Model.prototype.getPortAttrs
中计算。您可以做的只是交换 x
和 y
端口坐标,如下例所示。
joint.shapes.devs.Model = joint.shapes.basic.Generic.extend(_.extend({}, joint.shapes.basic.PortsModelInterface, {
markup: '<g class="rotatable"><g class="scalable"><rect class="body"/></g><text class="label"/><g class="inPorts"/><g class="outPorts"/></g>',
portMarkup: '<g class="port port<%= id %>"><circle class="port-body"/><text class="port-label"/></g>',
defaults: joint.util.deepSupplement({
type: 'devs.Model',
size: { width: 1, height: 1 },
inPorts: [],
outPorts: [],
attrs: {
'.': { magnet: false },
'.body': {
width: 150, height: 250,
stroke: 'black'
},
'.port-body': {
r: 10,
magnet: true,
stroke: 'black'
},
text: {
fill: 'black',
'pointer-events': 'none'
},
'.label': { text: 'Model', 'ref-x': 10, 'ref-y': .2, 'ref': '.body' },
// CHANGED: find better positions for port labels
'.inPorts .port-label': { dy:-30, x: 4 },
'.outPorts .port-label':{ dy: 15, x: 4 }
//
}
}, joint.shapes.basic.Generic.prototype.defaults),
getPortAttrs: function(portName, index, total, selector, type) {
var attrs = {};
var portClass = 'port' + index;
var portSelector = selector + '>.' + portClass;
var portLabelSelector = portSelector + '>.port-label';
var portBodySelector = portSelector + '>.port-body';
attrs[portLabelSelector] = { text: portName };
attrs[portBodySelector] = { port: { id: portName || _.uniqueId(type) , type: type } };
// CHANGED: swap x and y ports coordinates ('ref-y' => 'ref-x')
attrs[portSelector] = { ref: '.body', 'ref-x': (index + 0.5) * (1 / total) };
// ('ref-dx' => 'ref-dy')
if (selector === '.outPorts') { attrs[portSelector]['ref-dy'] = 0; }
//
return attrs;
}
}));
JS fiddle :http://jsfiddle.net/kumilingus/L2f73cbf/
更新:
这是一个如何使用 JointJS v1.0.1+
实现相同功能的示例。
不再需要使用 PortsModelInterface
扩展类。端口 API 现在由 joint.dia.Element
实现,即可以轻松地使用端口丰富任意元素。
var shape = new joint.shapes.devs.Model({
inPorts: ['in1', 'in2'],
outPorts: ['out1', 'out2'],
ports: {
groups: {
'in': { position: 'top'},
'out': { position: 'bottom' }
}
}
});
JSFiddle:http://jsfiddle.net/kumilingus/trk63agg/
有关更多信息,请参阅文档:
关于JointJs 顶部底部端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25001487/
我想知道JointJS提供了什么样的动画? 有没有我可以引用的文档或链接? 最佳答案 您可以阅读 JointJS 中可用的转换 here 关于jointjs - 我们在 JointJS 中可以做哪些动
我已经实现了纸张的缩放,效果很好。 我将它与鼠标滚轮的滚动联系起来,但我仍然遇到一个问题:在 API 中,缩放函数定义为 scale paper.scale(sx, sy, [ox, oy])我认为
如何使链接在 1 点内保持与单元或端口的连接? 如果端口是圆形,则当单元移动时,与其连接的链路端会移动穿过该圆形。 我希望能够使其保持在同一点 - 圆边缘的中心。 期望: 当我向下移动单元格时会发生什
JointJs 是否有启用/绘制图表网格线的选项? 如果没有,有没有办法自定义实现并绘制网格线? 最佳答案 根据jointjs changelog您现在可以通过 joint.dia.paper 的 d
我有一个使用 JointJs 生成的图形,它使用 jointjs 提供的 Dagre 布局。目前,图表从上到下对齐,这是正确的方式,但随后完整的图表将对齐到纸张的左侧。 我需要图表在纸的中间水平对齐。
你好我正在尝试使用 JointJS 库执行 Hello world 应用程序,如下所示: http://www.jointjs.com/tutorial#hello-world我已经下载了 joint
我想获得与元素关联的所有传出链接。在jointJs 中实现这一点的方法是什么。实际上我已经尝试过类似的方法,但它同时给出了传出和传入的结果。 paper.findViewByModel(start).
我想禁用 JointJS 图表中元素和链接的移动,同时保持其他功能,如元素的超链接和鼠标悬停时链接的突出显示。我引用了以下链接: https://groups.google.com/forum/#!s
想象一下,我有一个 Rect 元素,我希望在左上角用一个小的(比如 16x16)PNG 图像装饰它。我无法确定如何完成该任务。我已经研究了文档,但(到目前为止)无法找到有关如何实现该任务的示例或引用。
如果纸张对于显示的 div 来说太大,我想让纸张可拖动。 我尝试了空白:pointerdown 和pointerup 事件的论文,但不能只跟随鼠标移动。我还尝试通过 jquery 使纸张元素可拖动,但
我有一份带有图表的工作文件。我已向图表中添加了多个单元格,并且正在尝试监听 cell:highlight 事件,但我从未收到它。 我正在做: paper.on('cell:highlight', fu
我正在尝试将 JointJS 与端口功能一起使用: (...) var model = joint.shapes.devs.Model({ siz
当我将圆圈元素拖出组时,如何取消附加圆圈元素?目前我可以将它附加到组中,但无法在拖动时取消附加。如果任何人有想法,请提供帮助。我是 d3js 和 javascript 的新手 演示:http://js
我试图避免链接在空间中结束,我只想允许链接将一个元素与另一个元素连接起来。我当前的代码是: new joint.shapes.basic.Rect({ id: id, size: {
如何在联合js中的矩形内输入文本区域/文本输入? 我有几个矩形。我想首先将文本输入到矩形中。我必须为此创建自定义元素还是可以使用预定义的形状? 这是我的代码: var
我有一个只读图表来可视化一些数据。我的最终用户希望“过滤”数据,以便一次只能显示数据的一个子集。我意识到每次应用过滤器时都可以重新绘制整个图表,忽略不显示的元素,但我想知道是否有一种方法可以简单地动态
我正在研究 JointJS。我有各种带有文字的元素。然而,元素的宽度随着文本的增加而增加。我想动态设置元素的大小,以便框可以达到最大高度和宽度,并通过文本换行相应地扩展。如果文本操作系统无法适应最大高
我正在使用此解决方案 ( Joint.js Drag and Drop Element between two papers ) 拖放两篇论文,效果非常好。 我想知道是否存在一种方法可以知道您是否将幽
我正在使用joint.shapes.devs.js插件在我的jointJS文档上创建元素。我想创建一个在您单击某个元素时出现的菜单,以便显示和修改其所有数据以及删除该元素。 由于我不是 Backbon
我的应用程序中有一个可以滚动纸张的平移 Controller 。如何获取所显示内容的坐标以查看元素是否完全在屏幕上? 最佳答案 您需要知道纸张元素的坐标(x、y、宽度、高度)。 x、y 可以是 scr
我是一名优秀的程序员,十分优秀!