GithubHelp home page GithubHelp logo

micahstubbs / forceinabox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from john-guerra/forceinabox

0.0 1.0 0.0 1.79 MB

d3 force plugin that implements the GroupInABox algorithm that distributes nodes using a treemap to identify better clusters

License: MIT License

HTML 30.07% JavaScript 69.93%

forceinabox's Introduction

forceInABox.js

forceInABox demo gif

Updated for d3.v4

A d3.js v4 force that implements the Group-in-a-box layout algorithm to distribute nodes in a network according to their clusters. The algorithm uses a treemap or a force diagram to compute focis that are later used to distribute each cluster into it's own box.

To use it just add the forceInABox as another force in your simulation and make sure your other forces don't overpower it

<!-- Include d3.v4 or forceSimulation -->
<script type="text/javascript" src="forceInABox.js">   </script>
// Create the simulation with a small forceX and Y towards the center
var simulation = d3.forceSimulation()
	  .force("charge", d3.forceManyBody())
	  .force("x", d3.forceX(width/2).strength(0.05))
	  .force("y", d3.forceY(height/2).strength(0.05));

// Instantiate the forceInABox force
var groupingForce = forceInABox()
	  .strength(0.1) // Strength to foci
	  .template(template) // Either treemap or force
	  .groupBy("group") // Node attribute to group
	  .links(graph.links) // The graph links. Must be called after setting the grouping attribute
	  .size([width, height]) // Size of the chart

// Add your forceInABox to the simulation
simulation
    .nodes(graph.nodes)
    .force("group", groupingForce)
    .force("link", d3.forceLink(graph.links)
      .distance(50)
      .strength(groupingForce.getLinkStrength) // default link force will try to join nodes in the same group stronger than if they are in different groups
    );

Here is a forceInABox demo

forceinabox's People

Contributors

john-guerra avatar emeeks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.