Skip to content

Instantly share code, notes, and snippets.

@owendall
Forked from mbostock/.block
Last active April 21, 2017 17:59
Show Gist options
  • Select an option

  • Save owendall/4f6af21223b17ca4abae0fdd8318ee97 to your computer and use it in GitHub Desktop.

Select an option

Save owendall/4f6af21223b17ca4abae0fdd8318ee97 to your computer and use it in GitHub Desktop.

Revisions

  1. owendall renamed this gist Apr 21, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @mbostock mbostock revised this gist Feb 9, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions .block
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    license: gpl-3.0
  3. @mbostock mbostock revised this gist Oct 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@

    </style>
    <body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
    <script src="//d3js.org/d3.v3.min.js"></script>
    <script>

    var width = 960,
  4. @mbostock mbostock revised this gist Jun 11, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@

    </style>
    <body>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
    <script>

    var width = 960,
    @@ -43,6 +43,8 @@
    node = svg.selectAll(".node");

    d3.json("graph.json", function(error, graph) {
    if (error) throw error;

    force
    .nodes(graph.nodes)
    .links(graph.links)
  5. @mbostock mbostock revised this gist Dec 18, 2013. 2 changed files with 7 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the _fixed_ property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the _fixed_ property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces). Double-click to release a node.

    Internally, the force layout uses three bits to control whether a node is fixed. The first bit can be set externally, as in this example. The second and third bits are set on mouseover and mousedown, respectively, so that nodes are fixed temporarily during dragging. Although the second and third bits are automatically cleared when dragging ends, the first bit stays true in this example, and thus nodes remain fixed after dragging.

    8 changes: 6 additions & 2 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -56,6 +56,7 @@
    .enter().append("circle")
    .attr("class", "node")
    .attr("r", 12)
    .on("dblclick", dblclick)
    .call(drag);
    });

    @@ -69,9 +70,12 @@
    .attr("cy", function(d) { return d.y; });
    }

    function dblclick(d) {
    d3.select(this).classed("fixed", d.fixed = false);
    }

    function dragstart(d) {
    d.fixed = true;
    d3.select(this).classed("fixed", true);
    d3.select(this).classed("fixed", d.fixed = true);
    }

    </script>
  6. @mbostock mbostock revised this gist Aug 4, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the `fixed` property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the _fixed_ property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).

    Internally, the force layout uses three bits to control whether a node is fixed. The first bit can be set externally, as in this example. The second and third bits are set on mouseover and mousedown, respectively, so that nodes are fixed temporarily during dragging. Although the second and third bits are automatically cleared when dragging ends, the first bit stays true in this example, and thus nodes remain fixed after dragging.

  7. @mbostock mbostock revised this gist Aug 4, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the `fixed` property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).

    Internally, the force layout uses three bits to control whether a node is fixed. The first bit can be set externally, as in this example. The second and third bits are set on mouseover and mousedown, respectively, so that nodes are fixed temporarily during dragging. Although the second and third bits are automatically cleared when dragging ends, the first bit stays true in this example, and thus nodes remain fixed after dragging.

    Also note that the force layout [resumes](https://github.com/mbostock/d3/wiki/Force-Layout#wiki-resume) automatically on _dragmove_. This ensures that other nodes in the graph respond naturally to the dragged node’s movement.
  8. @mbostock mbostock revised this gist Aug 4, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    This example demonstrates how to prevent the force layout from moving nodes that have been dragged by the user. When the force layout’s drag behavior dispatches a _dragstart_ event, the `fixed` property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).
    This example demonstrates how to prevent D3’s [force layout](https://github.com/mbostock/d3/wiki/Force-Layout) from moving nodes that have been repositioned by the user. When the force layout’s [drag behavior](https://github.com/mbostock/d3/wiki/Drag-Behavior) dispatches a _dragstart_ event, the `fixed` property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).

    Internally, the force layout uses three bits to control whether a node is fixed. The first bit can be set externally, as in this example. The second and third bits are set on mouseover and mousedown, respectively, so that nodes are fixed temporarily during dragging. Although the second and third bits are automatically cleared when dragging ends, the first bit stays true in this example, and thus nodes remain fixed after dragging.
  9. @mbostock mbostock revised this gist Aug 4, 2013. 2 changed files with 40 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    This example demonstrates how to prevent the force layout from moving nodes that have been dragged by the user. When the force layout’s drag behavior dispatches a _dragstart_ event, the `fixed` property of the dragged node is set to true. This prevents the force layout from subsequently changing the position of the node (due to forces).

    Internally, the force layout uses three bits to control whether a node is fixed. The first bit can be set externally, as in this example. The second and third bits are set on mouseover and mousedown, respectively, so that nodes are fixed temporarily during dragging. Although the second and third bits are automatically cleared when dragging ends, the first bit stays true in this example, and thus nodes remain fixed after dragging.
    37 changes: 37 additions & 0 deletions graph.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    {
    "nodes": [
    {"x": 469, "y": 410},
    {"x": 493, "y": 364},
    {"x": 442, "y": 365},
    {"x": 467, "y": 314},
    {"x": 477, "y": 248},
    {"x": 425, "y": 207},
    {"x": 402, "y": 155},
    {"x": 369, "y": 196},
    {"x": 350, "y": 148},
    {"x": 539, "y": 222},
    {"x": 594, "y": 235},
    {"x": 582, "y": 185},
    {"x": 633, "y": 200}
    ],
    "links": [
    {"source": 0, "target": 1},
    {"source": 1, "target": 2},
    {"source": 2, "target": 0},
    {"source": 1, "target": 3},
    {"source": 3, "target": 2},
    {"source": 3, "target": 4},
    {"source": 4, "target": 5},
    {"source": 5, "target": 6},
    {"source": 5, "target": 7},
    {"source": 6, "target": 7},
    {"source": 6, "target": 8},
    {"source": 7, "target": 8},
    {"source": 9, "target": 4},
    {"source": 9, "target": 11},
    {"source": 9, "target": 10},
    {"source": 10, "target": 11},
    {"source": 11, "target": 12},
    {"source": 12, "target": 10}
    ]
    }
  10. @mbostock mbostock revised this gist Aug 4, 2013. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@

    var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("weight", height);
    .attr("height", height);

    var link = svg.selectAll(".link"),
    node = svg.selectAll(".node");
    Binary file modified thumbnail.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  11. @mbostock mbostock revised this gist Aug 4, 2013. 1 changed file with 38 additions and 48 deletions.
    86 changes: 38 additions & 48 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -4,75 +4,60 @@

    .link {
    stroke: #000;
    stroke-width: 1.5px;
    }

    .node {
    cursor: move;
    fill: #ccc;
    stroke: #000;
    stroke-width: 1.5px;
    }

    .node.sticky {
    .node.fixed {
    fill: #f00;
    }

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

    var graph = {
    nodes: d3.range(13).map(Object),
    links: [
    {source: 0, target: 1},
    {source: 1, target: 2},
    {source: 2, target: 0},
    {source: 1, target: 3},
    {source: 3, target: 2},
    {source: 3, target: 4},
    {source: 4, target: 5},
    {source: 5, target: 6},
    {source: 5, target: 7},
    {source: 6, target: 7},
    {source: 6, target: 8},
    {source: 7, target: 8},
    {source: 9, target: 4},
    {source: 9, target: 11},
    {source: 9, target: 10},
    {source: 10, target: 11},
    {source: 11, target: 12},
    {source: 12, target: 10}
    ]
    };

    var width = 960,
    height = 500;

    var force = d3.layout.force()
    .size([width, height])
    .charge(-400)
    .linkDistance(40)
    .on("tick", tick);

    var drag = force.drag()
    .on("dragstart", dragstart);

    var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("weight", height);

    var force = d3.layout.force()
    .nodes(graph.nodes)
    .links(graph.links)
    .size([width, height])
    .on("tick", tick)
    .start();

    var link = svg.selectAll(".link")
    .data(graph.links)
    .enter().append("line")
    .attr("class", "link");

    var node = svg.selectAll(".node")
    .data(graph.nodes)
    .enter().append("circle")
    .attr("class", "node")
    .attr("r", 4.5)
    .call(force.drag)
    .on("mousedown", function(d) {
    d.fixed = true;
    d3.select(this).classed("sticky", true);
    });
    var link = svg.selectAll(".link"),
    node = svg.selectAll(".node");

    d3.json("graph.json", function(error, graph) {
    force
    .nodes(graph.nodes)
    .links(graph.links)
    .start();

    link = link.data(graph.links)
    .enter().append("line")
    .attr("class", "link");

    node = node.data(graph.nodes)
    .enter().append("circle")
    .attr("class", "node")
    .attr("r", 12)
    .call(drag);
    });

    function tick() {
    link.attr("x1", function(d) { return d.source.x; })
    @@ -84,4 +69,9 @@
    .attr("cy", function(d) { return d.y; });
    }

    function dragstart(d) {
    d.fixed = true;
    d3.select(this).classed("fixed", true);
    }

    </script>
  12. @mbostock mbostock revised this gist Oct 12, 2012. 1 changed file with 0 additions and 0 deletions.
    Binary file added thumbnail.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  13. @mbostock mbostock revised this gist Sep 19, 2012. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,10 @@
    stroke: #000;
    }

    .node.sticky {
    fill: #f00;
    }

    </style>
    <body>
    <script src="http://d3js.org/d3.v2.min.js?2.10.1"></script>
    @@ -51,7 +55,6 @@
    .nodes(graph.nodes)
    .links(graph.links)
    .size([width, height])
    .charge(-200)
    .on("tick", tick)
    .start();

    @@ -66,7 +69,10 @@
    .attr("class", "node")
    .attr("r", 4.5)
    .call(force.drag)
    .on("mousedown", function(d) { d.fixed = true; });
    .on("mousedown", function(d) {
    d.fixed = true;
    d3.select(this).classed("sticky", true);
    });

    function tick() {
    link.attr("x1", function(d) { return d.source.x; })
  14. @mbostock mbostock revised this gist Sep 19, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@

    </style>
    <body>
    <script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
    <script src="http://d3js.org/d3.v2.min.js?2.10.1"></script>
    <script>

    var graph = {
    @@ -64,7 +64,9 @@
    .data(graph.nodes)
    .enter().append("circle")
    .attr("class", "node")
    .attr("r", 4.5);
    .attr("r", 4.5)
    .call(force.drag)
    .on("mousedown", function(d) { d.fixed = true; });

    function tick() {
    link.attr("x1", function(d) { return d.source.x; })
  15. @mbostock mbostock created this gist Aug 10, 2012.
    79 changes: 79 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    <!DOCTYPE html>
    <meta charset="utf-8">
    <style>

    .link {
    stroke: #000;
    }

    .node {
    fill: #ccc;
    stroke: #000;
    }

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

    var graph = {
    nodes: d3.range(13).map(Object),
    links: [
    {source: 0, target: 1},
    {source: 1, target: 2},
    {source: 2, target: 0},
    {source: 1, target: 3},
    {source: 3, target: 2},
    {source: 3, target: 4},
    {source: 4, target: 5},
    {source: 5, target: 6},
    {source: 5, target: 7},
    {source: 6, target: 7},
    {source: 6, target: 8},
    {source: 7, target: 8},
    {source: 9, target: 4},
    {source: 9, target: 11},
    {source: 9, target: 10},
    {source: 10, target: 11},
    {source: 11, target: 12},
    {source: 12, target: 10}
    ]
    };

    var width = 960,
    height = 500;

    var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("weight", height);

    var force = d3.layout.force()
    .nodes(graph.nodes)
    .links(graph.links)
    .size([width, height])
    .charge(-200)
    .on("tick", tick)
    .start();

    var link = svg.selectAll(".link")
    .data(graph.links)
    .enter().append("line")
    .attr("class", "link");

    var node = svg.selectAll(".node")
    .data(graph.nodes)
    .enter().append("circle")
    .attr("class", "node")
    .attr("r", 4.5);

    function tick() {
    link.attr("x1", function(d) { return d.source.x; })
    .attr("y1", function(d) { return d.source.y; })
    .attr("x2", function(d) { return d.target.x; })
    .attr("y2", function(d) { return d.target.y; });

    node.attr("cx", function(d) { return d.x; })
    .attr("cy", function(d) { return d.y; });
    }

    </script>