How to use the d3-hierarchy.stratify 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 DefinitelyTyped / DefinitelyTyped / types / d3-hierarchy / d3-hierarchy-tests.ts View on Github external
}

let tabularData: Array;
tabularData = [
    { name: 'n0', parentId: null, val: 10 },
    { name: 'n11', parentId: 'n0', val: 5 },
    { name: 'n12', parentId: 'n0', val: 4 },
    { name: 'n121', parentId: 'n12', val: 30 }
];

let idStringAccessor: (d: TabularHierarchyDatum, i?: number, data?: Array) => (string | null | '' | undefined);

// Create Stratify Operator  ---------------------------------------------

let stratificatorizer: d3Hierarchy.StratifyOperator;
stratificatorizer = d3Hierarchy.stratify();

// Configure Stratify Operator  ------------------------------------------

// id(...)

stratificatorizer = stratificatorizer.id(function (d, i, data) {
    console.log('Length of tabular array: ', data.length);
    console.log('Name of first entry in tabular array: ', data[0].name); // data of type Array
    return d.name; // d is of type TabularHierarchyDatum
});

idStringAccessor = stratificatorizer.id();

// parentId(...)

stratificatorizer = stratificatorizer.parentId(function (d, i, data) {
github onap / sdc / openecomp-ui / src / nfvo-components / tree / Tree.jsx View on Github external
(d.parent.y + offset) +
        ',' +
        d.parent.x +
        ' ' +
        d.parent.y +
        ',' +
        d.parent.x
    );
}

const nodeRadius = 8;
const verticalSpaceBetweenNodes = 70;
const NARROW_HORIZONTAL_SPACES = 47;
const WIDE_HORIZONTAL_SPACES = 65;

const stratifyFn = stratify()
    .id(d => d.id)
    .parentId(d => d.parent);

class Tree extends Component {
    // state = {
    // 	startingCoordinates: null,
    // 	isDown: false
    // }

    static propTypes = {
        name: PropTypes.string,
        width: PropTypes.number,
        allowScaleWidth: PropTypes.bool,
        nodes: PropTypes.arrayOf(
            PropTypes.shape({
                id: PropTypes.string,
github idekerlab / hiview / frontend / src / components / CirclePacking / index.jsx View on Github external
console.log(nodeMap)

    const csv = []
    csv.push({name: rootId, parent: ""})

    const edges = tree.elements.edges
    edges.forEach(edge => {
      const source = edge.data.source
      const target = edge.data.target

      csv.push({name: source, parent: target})
    })

    console.log('********** ROOT: ' + rootId)
    console.log(csv)
    const d3tree = d3Hierarchy.stratify().id(function(d) {
      return d.name;
    }).parentId(function(d) {
      return d.parent;
    })(csv);

    console.log(d3tree)
    return d3tree
  }
github idekerlab / hiview / backend / layout / api / cxToD3.js View on Github external
const getTree = edges => {

  return d3Hierarchy
    .stratify()
    .id(d => (d.id))
    .parentId(d => (d.parentId))(edges)
}
github swimlane / ngx-charts / src / tree-map / tree-map.component.ts View on Github external
width: this.width,
      height: this.height,
      margins: this.margin
    });

    this.domain = this.getDomain();

    this.treemap = treemap().size([this.dims.width, this.dims.height]);

    const rootNode = {
      name: 'root',
      value: 0,
      isRoot: true
    };

    const root = stratify()
      .id(d => {
        let label = d.name;

        if (label.constructor.name === 'Date') {
          label = label.toLocaleDateString();
        } else {
          label = label.toLocaleString();
        }
        return label;
      })
      .parentId(d => (d.isRoot ? null : 'root'))([rootNode, ...this.results])
      .sum(d => d.value);

    this.data = this.treemap(root);

    this.setColors();
github swimlane / ngx-charts / release / tree-map / tree-map.component.js View on Github external
TreeMapComponent.prototype.update = function () {
        _super.prototype.update.call(this);
        this.dims = calculateViewDimensions({
            width: this.width,
            height: this.height,
            margins: this.margin
        });
        this.domain = this.getDomain();
        this.treemap = treemap().size([this.dims.width, this.dims.height]);
        var rootNode = {
            name: 'root',
            value: 0,
            isRoot: true
        };
        var root = stratify()
            .id(function (d) {
            var label = d.name;
            if (label.constructor.name === 'Date') {
                label = label.toLocaleDateString();
            }
            else {
                label = label.toLocaleString();
            }
            return label;
        })
            .parentId(function (d) { return (d.isRoot ? null : 'root'); })([rootNode].concat(this.results))
            .sum(function (d) { return d.value; });
        this.data = this.treemap(root);
        this.setColors();
        this.transform = "translate(" + this.dims.xOffset + " , " + this.margin[0] + ")";
    };
github vega / vega-dataflow / src / hierarchy / Stratify.js View on Github external
prototype.transform = function(_, pulse) {
  if (!pulse.source) {
    error('Stratify transform requires an upstream data source.');
  }

  var run = !this.value
         || _.modified()
         || pulse.changed(pulse.ADD_REM)
         || pulse.modified(_.key.fields)
         || pulse.modified(_.parentKey.fields);

  if (run) {
    var tree = stratify().id(_.key).parentId(_.parentKey)(pulse.source),
        map = tree.lookup = {};
    tree.each(function(node) { map[node.data._id] = node; });
    this.value = tree;
  }

  pulse.source.root = this.value;
};