Jay Taylor's notes

back to listing index

Reingold–Tilford Tree

[web search]
Original source (bl.ocks.org)
Tags: javascript d3 reingold–tilford-tree visualization bl.ocks.org
Clipped on: 2014-05-16

mbostock’s block #4339184 December 19, 2012

Reingold–Tilford Tree

flareanalyticsclusterAgglomerativeClusterCommunityStructureHierarchicalClusterMergeEdgegraphBetweennessCentralityLinkDistanceMaxFlowMinCutShortestPathsSpanningTreeoptimizationAspectRatioBankeranimateEasingFunctionSequenceinterpolateArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolatorISchedulableParallelPauseSchedulerSequenceTransitionTransitionerTransitionEventTweendataconvertersConvertersDelimitedTextConverterGraphMLConverterIDataConverterJSONConverterDataFieldDataSchemaDataSetDataSourceDataTableDataUtildisplayDirtySpriteLineSpriteRectSpriteTextSpriteflexFlareVisphysicsDragForceGravityForceIForceNBodyForceParticleSimulationSpringSpringForcequeryAggregateExpressionAndArithmeticAverageBinaryExpressionComparisonCompositeExpressionCountDateUtilDistinctExpressionExpressionIteratorFnIfIsALiteralMatchMaximummethodsaddandaveragecountdistinctdiveqfngtgteiffisaltltemaxminmodmulneqnotororderbyrangeselectstddevsubsumupdatevariancewherexor_MinimumNotOrQueryRangeStringUtilSumVariableVarianceXorscaleIScaleMapLinearScaleLogScaleOrdinalScaleQuantileScaleQuantitativeScaleRootScaleScaleScaleTypeTimeScaleutilArraysColorsDatesDisplaysFilterGeometryheapFibonacciHeapHeapNodeIEvaluableIPredicateIValueProxymathDenseMatrixIMatrixSparseMatrixMathsOrientationpaletteColorPalettePaletteShapePaletteSizePalettePropertyShapesSortStatsStringsvisaxisAxesAxisAxisGridLineAxisLabelCartesianAxescontrolsAnchorControlClickControlControlControlListDragControlExpandControlHoverControlIControlPanZoomControlSelectionControlTooltipControldataDataDataListDataSpriteEdgeSpriteNodeSpriterenderArrowTypeEdgeRendererIRendererShapeRendererScaleBindingTreeTreeBuildereventsDataEventSelectionEventTooltipEventVisualizationEventlegendLegendLegendItemLegendRangeoperatordistortionBifocalDistortionDistortionFisheyeDistortionencoderColorEncoderEncoderPropertyEncoderShapeEncoderSizeEncoderfilterFisheyeTreeFilterGraphDistanceFilterVisibilityFilterIOperatorlabelLabelerRadialLabelerStackedAreaLabelerlayoutAxisLayoutBundledEdgeRouterCircleLayoutCirclePackingLayoutDendrogramLayoutForceDirectedLayoutIcicleTreeLayoutIndentedTreeLayoutLayoutNodeLinkTreeLayoutPieLayoutRadialTreeLayoutRandomLayoutStackedAreaLayoutTreeMapLayoutOperatorOperatorListOperatorSequenceOperatorSwitchSortOperatorVisualization

The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. The depth of nodes is computed by distance from the root, leading to a ragged appearance. Radial orientations are also supported. Implementation based on work by Jeff Heer and Jason Davies using Buchheim et al.'s linear-time variant of the Reingold-Tilford algorithm. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

Compare to this radial layout.

index.html#

<!DOCTYPE html>
<meta charset="utf-8">
<style>

.node circle {
  fill: #fff;
  stroke: steelblue;
  stroke-width: 1.5px;
}

.node {
  font: 10px sans-serif;
}

.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>

var width = 960,
    height = 2000;

var tree = d3.layout.tree()
    .size([height, width - 160]);

var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.y, d.x]; });

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", "translate(40,0)");

d3.json("/d/4063550/flare.json", function(error, json) {
  var nodes = tree.nodes(json),
      links = tree.links(nodes);

  var link = svg.selectAll("path.link")
      .data(links)
    .enter().append("path")
      .attr("class", "link")
      .attr("d", diagonal);

  var node = svg.selectAll("g.node")
      .data(nodes)
    .enter().append("g")
      .attr("class", "node")
      .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })

  node.append("circle")
      .attr("r", 4.5);

  node.append("text")
      .attr("dx", function(d) { return d.children ? -8 : 8; })
      .attr("dy", 3)
      .attr("text-anchor", function(d) { return d.children ? "end" : "start"; })
      .text(function(d) { return d.name; });
});

d3.select(self.frameElement).style("height", height + "px");

</script>
mbostock’s block #4339184 December 19, 2012