Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Variable node width #48

Closed
6br opened this issue Oct 30, 2017 · 1 comment
Closed

Request: Variable node width #48

6br opened this issue Oct 30, 2017 · 1 comment

Comments

@6br
Copy link

6br commented Oct 30, 2017

Hello, I would appreciate D3!

Request to d3-sankey:
Is there an API for changing the width of each node according to the information of each node?
Currently the width of all nodes is the same, but I would like to be able to change each node width according to node properties such as node.length or node.lengthProportion.

graph.nodes.forEach(function(node) {
        node.x1 = (node.x0 = x0 + Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x)))) * kx) + dx;
   // dx is the constant number, but could it be variable?
@callmewhy
Copy link

actually you can change each node width according to node properties.

take this code as an example: https://bl.ocks.org/mbostock/ca9a0bb7ba204d12974bca90acc507c0

just set width in data source:

{ name: 'A', color: '#000000', width: ANY_NUMBER, },

then you can set width when draw rect:

  node.append('rect')
      .attr('x', (d) => {
        return d.x0
      })
      .attr('y', (d) => {
        return d.y0
      })
      .attr('width', (d) => {
        return d.width ? d.width : d.x1 - d.x0
      })
      .attr('height', (d) => {
        return Math.max(d.y1 - d.y0, 1)
      })
      .attr('fill', (d) => {
        return d.color
      })

@6br 6br closed this as completed Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants