如何使用Cytoscape将文本包装在形状中?

Nun*_*ira 5 cytoscape cytoscape.js

我正在尝试使用Cytoscape构建磁贴.基本上,每个矩形(平铺)都有一个标题,我希望它在该矩形的范围内写入.

我的代码是:

var cy = cytoscape({
  container: document.getElementById('cy'),

  style: [
    {
      selector: 'node',
      css: {
        'shape': 'rectangle',
        'width': '200',
        'height': '150',
        'content': 'data(name)',
        'text-wrap': 'wrap',
        'text-valign': 'center',
        'text-halign': 'center',
        'text-transform': 'uppercase'
      }
    }, ///
Run Code Online (Sandbox Code Playgroud)

和:

elements: {
    nodes: [
      { data: { id: 'F1', name: 'This is my very long text long text long text long text long text long text long text'} },
      { data: { id: 'F2' } },
      { data: { id: 'c', parent: 'b' } },
      { data: { id: 'd' } },
      { data: { id: 'e' } },
      { data: { id: 'f', parent: 'e' } }
    ],///
Run Code Online (Sandbox Code Playgroud)

但似乎没有读取文本换行值.我明白了:

有人能帮忙吗?

提前致谢!

页

max*_*anz 5

您已设置text-wrap: wrap为启用文本环绕。您还没有指定任何规则如何包装文本的。选项:

(1)使用手动换行符(即'\n'

(2)text-max-width根据需要设置为最大行长