D3 Mechanics Diagram (Force layout) Update

Source: Internet
Author: User

D3 is a visual library of JavaScript, you can make a very beautiful table, which has a very interesting mechanics diagram, can be easily dragged, etc., but on the update of the operation of the online introduction of the few, the following describes the mechanics of the update, first look at an example (http:// example.codeboy.me/d3/force-layout.html, click the following image once to add directly to the ENTER key:

CSDN cannot insert an IFRAME, please click on the link above to view.

The way to draw a graph can basically be divided into SVG and canvas two, both have advantages and disadvantages, not for the future screen is larger, SVG more advantages, and SVG can be very convenient for event interaction.

Take a look at this mechanical diagram to achieve the specific: the overall code

 
Update Explanation 

The update is only updated with the update () function, which is divided into the following data update mechanics diagram reload data append corresponding edges and nodes (enter) remove unwanted elements (remove) perform force.start () operation

As long as in order, the new node can be well added. Example Description

There are a few examples that need to be explained.

Force.on ("tick", function (d) {...}) the calculated user draws a line between only two circles, and of course it makes it easier to add arrows and fewer overlapping operations.

The var nodes_labels = Svg.selectall ("text") is annotated only for the first point, which prompts for a click action, and can also be annotated for all points. Summary

D3 's GitHub (Https://github.com/mbostock/d3/wiki/Gallery) on a number of examples, you can find their favorite to learn, but also need to have a certain degree of SVG learning, to facilitate our own some improvements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.