Controlling order of circles in D3 circle pack layout algorithm

Kaster

I was wondering if it's possible to slightly change packing algorithm in d3.layout. Namely, I'd like to know if instead of putting a child node with highest value at the position where it touches parent node one can put it in the middle of it. Right now it looks like all children go by spiral with smallest child deep inside of the parent.

I hope it's not too confusing. I'll gladly clarify whatever is unclear.

VividD

It is possible.

You only need to replace this code in d3.js:

  function d3_layout_packSort(a, b) {
    return a.value - b.value;
  }

with this code:

  function d3_layout_packSort(a, b) {
    return -(a.value - b.value);
  }

(just a change of sign)

Largest circles will not be at the very center of the parent, however they will tend to be close to the center. My understanding is that you don't need exact placement at the center, just approximate, so I hope this will satisfy your idea.

Following picture illustrates circular pack example obtained with regular and modified d3.js, side-by-side:

Regular and modified packing

I a kind of tend to like modified packing more. :) So I guess it was a good idea. Check how it looks with your data.

You can access these examples here: regular, modified.

My modified d3.js is here.

Let me know if you have additional questions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Controlling order of circles in D3 circle pack layout algorithm

From Dev

Text along circles in a D3 circle pack layout

From Dev

Tooltips for nested circles in D3 circle pack layout

From Dev

D3 Circle Pack Layout with a horizontal arrangement

From Dev

pack in small circles into a bigger circle

From Dev

d3.layout.pack stacks circles when sort is ascending

From Dev

Circle Pack Layout D3 - remove add nodes on new data

From Dev

Add circle to pack layout

From Dev

Algorithm for packing circles within a circle?

From Dev

D3 add zoom to circle pack

From Dev

Different colors for each circle - D3 circle pack

From Dev

same size circles in pack layout in d3.v4.js

From Dev

Realtime D3 bubble chart (circle pack)

From Dev

Keeping aspect ratio of D3 circle pack - responsive design

From Dev

Adding hyeperlinks to zoomable d3 circle pack

From Dev

stop d3 circle pack labels from overlapping

From Dev

Keeping aspect ratio of D3 circle pack - responsive design

From Dev

Undefined function when loading D3 circle pack

From Dev

Grouping Circles and Path as a node in D3 Force Layout?

From Dev

How to center root node circle in a d3.layout.pack graph?

From Dev

How to center root node circle in a d3.layout.pack graph?

From Dev

Circle pack layout using nest() and rollup

From Dev

Access scale factor in d3's pack layout

From Dev

D3 - How to convert circle-pack to ellipse-pack?

From Dev

Circle packs as nodes of a D3 force layout

From Dev

Circle packs as nodes of a D3 force layout

From Dev

Algorithm to check if a Circle is totally contained in the area of other circles

From Dev

'd3-circle-text' on zoomable circle-pack

From Dev

D3.js circles order

Related Related

HotTag

Archive