npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

d3-layout-circle-graph

v1.1.0

Published

A d3 layout generator for visualizing a graph using a circle of nodes and chords connecting them

Downloads

5

Readme

d3.layout.circleGraph

A d3 layout generator for visualizing a graph using a circle of nodes and chords connecting them. Kind of like this block by sjengle.

bower install d3-layout-circle-graph

Demo

The demo that the above screenshot is taken from is located in demo.html.

Usage

First, include circleGraph.js in your project, either manually or with bower.

var myRadius = 100;
var myNodes = [
  { name: 'node1' },
  { name: 'node2' },
  { name: 'node3' }
];
var myEdges = [
  { source: 'node1', target: 'node2' },
  { source: 'node1', target: 'node3' }
];

var layout = d3.layout.circleGraph()
  .radius(myRadius)
  .tension(0.3)
  .nodes(myNodes)
  .edges(myEdges);

The node objects will be endowed with x, y, radians, radianRange, and degrees properties. These can be used to visualize the graph as a circle. Note that 0° is assumed to be 12 o'clock, and increases going clockwise.

node.x, node.y

The x and y coordinates for the center of the node.

node.radians, node.degrees

The radians and degrees around the circle that the node resides.

node.radianRange

An array of two radian values that give the "range" of a particular node (good for visualizing bands, etc).

The edge objects will be endowed with a coords property, which is an array of three coordinates: the source node point, the center of the circle (as a control point), and the target node point.

API

d3.layout.circleGraph()

Creates the layout object.

circleGraph.radius([Number])

Sets the radius of the circle.

circleGraph.line

Line function that can be used for drawing chords.

circleGraph.tension([Number])

Sets the tension of the bundle line function that is available at circleGraph.line. Should be a number between 0 and 1.

circleGraph.nodes([nodes])

Runs the layout on the provided nodes, adding the x, y, radians and degrees properties. By default, assumes that there is an identifying property called name on each node. To change this behavior, use the circleGraph.key function.

circleGraph.edges([edges])

Runs the layout on the provided edges, adding a coords array to each edge. By default, this assumes that there are two properties on each edge object: a source property and a target property. This can be changed with the circleGraph.edgeSource and circleGraph.edgeTarget methods, respectively.

circleGraph.key([fn])

Sets the accessor function used to identify a node. By default, this function is:

function key(node) {
  return node.name;
}

circleGraph.edgeSource([fn])

Sets the accessor function used to find the source node's identity from an edge object. By default, this function is:

function edgeSourceAccessor(edge) {
  return edge.source;
}

circleGraph.edgeTarget([fn])

Same as edgeSource, but for the target. Default is:

function edgeTargetAccessor(edge) {
  return edge.target;
}

circleGraph.nodeMap()

Returns an object that maps identities to nodes. Sometimes useful in client code.

circleGraph.range([number])

Sets or gets the "range" in radians of a complete circle within which the nodes should be evenly distributed. Default is Math.PI * 2 (which represents the complete circle).

For example, calling circleGraph.range(Math.PI * 3/2) on the demo will result in this:

WARNING: This must be called before .nodes() gets called.