Vis.js network node customization: cards as nodes

只愿长相守 提交于 2019-12-01 08:18:10

Unfortunately, no. As of Jan 2018, node labels don't support html in general (they are a part of canvas so it's not easy to incorporate arbitrary html pieces into it). There's only a limited markup (both html-emulating and markdown) which allows several font sizes/colors/families in the same label (up to 4, afaik, = plain and inside <b>, <i> and <code> "tags") + you may use an image as the node's shape (shape: 'icon' or 'image' or 'circularImage').

Here you may find an example of usage of the multifont approach: they define

var options = {
  nodes: {
    font: {
      multi: true,
      bold: {
        mod: '',
        color: '#ff0000'
      }
    }
  }
}

in options and such label for a node:

label: '<b>3306</b>\n3307\n3308'

Considering the particular "cards case" (desribed in comments)

You can create a multi-line textarea indeed, but creating buttons is only possible in a hacky way. You can try the following workaround:

  • add buttons as new network nodes hovering above the card itself with custom click handlers;
  • if you need to move such cards as a whole via drag&drop, you have also to select all "button nodes" corresponding to the card when the card gets selected and make selection of those buttons indistinguishable from the non-selected state.

This may have some side-effects/involve an amount of additional coding, but at least will work like you have described.

PS: html inside SVG technique

In this question the author uses an interesting technique of injecting html into a vis.js graph using SVGs. I'm not aware of limits of that technique (aside that only non-interactive html can be inserted) so may be it deserves a try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!