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

Set stroke width for parent groups #8

Closed
spirtskhalava opened this issue Apr 2, 2019 · 2 comments
Closed

Set stroke width for parent groups #8

spirtskhalava opened this issue Apr 2, 2019 · 2 comments

Comments

@spirtskhalava
Copy link

Hello,
How is it possible to change stroke width for every groups?

@Kcnarf
Copy link
Owner

Kcnarf commented Apr 3, 2019

The d3-voronoi-treemap uses a d3-hierarchy as the main structure to handle parent/child relationships of your data. Thus, when drawing a cell, you can make the 'stroke-width' depending on the 'depth' or the 'height' of your node within the d3-hierarchy. Take a look d3-hierarchy to know what kind of property will fit your needs, and the last 3 loc of the below code:

var rootNode = d3.hierarchy(nestedData); // a d3-hierarchy of your nested data
rootNode.sum(weightAccessor); // assigns the adequate weight to each node of the d3-hierarchy

var voronoiTreemap = d3.voronoiTreemap().clip([[0, 0], [0, height], [width, height], [width, 0]]); // sets the clipping polygon
voronoiTreemap(rootNode); // computes the weighted Voronoi tessellation of the d3-hierarchy; assigns a 'polygon' property to each node of the hierarchy
var allNodes = rootNode.descendants();
d3.selectAll('path')
  .data(allNodes)
  .enter()
  .append('path')
  .attr('d', function(d) {
    // d is a node
    return d3.line()(d.polygon) + 'z'; // d.polygon is the computed Voronoï cell encoding the relative weight of your underlying original data
  })
  .style('stroke-width', function(d) {
    return 5*d.data.depth; // d.data is a node of the d3-hierarchy, with 'height', 'depth', and many more attributes
  });

@Kcnarf
Copy link
Owner

Kcnarf commented Apr 3, 2019

Closing because it's not an issue with d3-voronoi-treemap, but more on its usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants