dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.83k stars 588 forks source link

custom shape insert picture #378

Closed JavaMrYang closed 4 years ago

JavaMrYang commented 4 years ago

I want to insert a picture in a custom shape

haexhub commented 4 years ago

Have you tried this?


function(parent, bbox, node, options) {

  let { width, height } = bbox

  let shapeSvg = parent
  .append("img")
  .attr('src', 'url_of_your_picture')
  .attr('width', width)
  .attr('height', height)

  node.intersect = point => {
    return dagreD3.intersect.rect(node, point)
  }

  return shapeSvg
}
haexhub commented 4 years ago

or you can add the image, after the node is rendered.

d3.select('id_node_where_image_goes').append('img').attr('src', 'url_of_image')
JavaMrYang commented 4 years ago

thank you,fixed