How to use the d3-hierarchy.pack function in d3-hierarchy

To help you get started, we’ve selected a few d3-hierarchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github finnfiddle / potion / src / Pack.js View on Github external
calculatePack(props) {
    let pack = d3Pack();
    [
      'radius',
      'size',
      'padding',
      // 'packSiblings',
      // 'packEnclose',
    ].forEach((key) => {
      if (itsSet(props[key])) pack = pack[key](props[key]);
    });
    return pack;
  }
github antvis / data-set / src / transform / hierarchy / pack.ts View on Github external
const as = options.as;
  if (!isArray(as) || as.length !== 3) {
    throw new TypeError('Invalid as: it must be an array with 3 strings (e.g. [ "x", "y", "r" ])!');
  }

  let field;
  try {
    field = getField(options);
  } catch (e) {
    console.warn(e);
  }
  if (field) {
    root.sum((d) => d[field]).sort((a, b) => b[field] - a[field]);
  }

  const packLayout = d3Hierarchy.pack();
  packLayout.size(options.size);

  if (options.padding) {
    packLayout.padding(options.padding);
  }
  packLayout(root);

  const x = as[0];
  const y = as[1];
  const r = as[2];
  root.each((node) => {
    node[x] = node.x;
    node[y] = node.y;
    node[r] = node.r;
  });
}
github ethantran / react-native-examples / src / components / AnimatedSvgD3HierarchyPack.js View on Github external
function createGenerator(
    props,
    generator?: Layout
): Layout {
    generator = generator || d3.pack();
    return args.reduce((acc: Layout, arg: string) => {
        const prop = props[arg];
        if (prop) {
            return acc[arg](prop);
        }
        return acc;
    }, generator);
}
github greenbone / gsa / gsa / src / web / components / chart / bubble.js View on Github external
const BubbleChart = ({data = [], width, height, svgRef, onDataClick}) => {
  const maxWidth = width - margin.left - margin.right;
  const maxHeight = height - margin.top - margin.bottom;

  const hasBubbles = data.length > 0;

  const bubbles = pack()
    .size([maxWidth, maxHeight])
    .padding(1.5);

  const root = hierarchy({children: data}).sum(d => d.value);

  const nodes = bubbles(root).leaves();
  return (
    <svg height="{height}" width="{width}">
      
        {hasBubbles ? (
          nodes.map((node, i) =&gt; {
            const {data: d, x, y, r} = node;
            return (
              
                {({targetRef, hide, show}) =&gt; {
                  const clippathId = 'clippath-' + i;</svg>
github edgarordonez / d3-stencil / src / components / bcg-matrix-chart / bcg-matrix-chart.tsx View on Github external
drawBubbles() {
    const bubble = pack()
      .size([
        this.width -
          (this.graphDataMerged.bcgMatrixChart.margin.left +
            this.graphDataMerged.bcgMatrixChart.margin.right) *
            2,
        this.height -
          (this.graphDataMerged.bcgMatrixChart.margin.top +
            this.graphDataMerged.bcgMatrixChart.margin.bottom) *
            2,
      ])
      .padding(1.5);

    const nodes = hierarchy(this.dataSet).sum(
      (data: BcgMatrix) =&gt; data.rel_size,
    );
github sghall / resonance / docs / src / routes / reduxExamples / packedByAge / module / index.js View on Github external
(rawData, sortKey, showTop) =&gt; {
      if (rawData.length === 0) {
        return {
          sortKey,
          data: rawData,
          xScale: () =&gt; 0,
          yScale: () =&gt; 0,
        };
      }

      const sort = getSortByKey(sortKey);
      const data = rawData.sort(sort).slice(0, showTop);

      const pack = packLayout()
        .padding(2)
        .size([Math.min(...dims), Math.min(...dims)]);

      const nodes = { name: 'root', children: [] };

      for (let i = 0; i &lt; data.length; i++) {
        const d = data[i];


        const state = { name: d.State, children: [] };
        nodes.children.push(state);

        for (let j = 0; j &lt; AGES.length; j++) {
          const group = AGES[j];
          const child = { name: `${d.State} - ${group}`, size: d[group] * d.Total };
          state.children.push(child);
github plouc / nivo / src / components / charts / bubble / BubblePlaceholders.js View on Github external
withPropsOnChange(['width', 'height', 'padding'], ({ width, height, padding }) => ({
        pack: pack()
            .size([width, height])
            .padding(padding),
    })),
    withStateHandlers(
github btd / rollup-plugin-visualizer / src / script-circlepacking.js View on Github external
const drawChart = (parentNode, { tree, nodes, links }, width, height) => {
  const size = Math.min(width, height);
  const layout = d3pack()
    .size([size, size])
    .padding(3);

  const chartNode = select(parentNode);

  const svg = chartNode
    .append("svg")
    .attr("viewBox", [0, 0, size, size])
    .attr("text-anchor", "middle");

  const tooltip = new Tooltip(chartNode);

  let root = d3hierarchy(tree)
    .eachAfter(node => {
      let sum = 0;
      const children = node.children;