乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      D3js畫圖 layout 布局,節(jié)點顯示到svg元素中央

       復雜網(wǎng)絡621 2017-04-13
      https:///questions/9901565/charge-based-on-size-d3-force-layout?answertab=oldest#tab-top

      D3js畫圖,force layout布局,得到的節(jié)點圖可以顯示在svg元素的中央,可是切換數(shù)據(jù)源之后,再次畫出的圖總是跑到屏幕外面去,于是,網(wǎng)上搜了一下,看到了這個帖子。按照回答中的操作,問題解決。


      I'm trying to make a force directed graph using d3.layout.force, and I need the container to be resizable - that is I'd like to be able calculate appropriate charge and linkDistance values based on the size, or have d3 do it for me in some magical way.

      I've made an attempt (link: http:///VHdUe/6/) which only uses nodes. I'm setting the charge to a value that's based on the number of nodes that would fit across the radius of the circle that it tends to be shaped like.

      The solution works for some middle-sized containers, but if you click resize a few times, you can see it doesn't really work for all sizes...

      The only way forward I can see is using an svg scale transform, which will mess up the size of my elements unfavorable. Any other options?

      PS: I have seen http://mbostock.github.com/d3/talk/20110921/bounding.html (the answer to D3 force directed layout with bounding box), but I'd rather have a gravity-based solution than a bounding box one.

      asked Mar 28 '12 at 5:20
      XwipeoutX
      1,92431636
      up vote 17 down vote accepted

      In addition to charge and linkDistance, you also have gravity. If you want the graph to maintain the same relative density to the layout size, then you'll want to scale both charge and gravity. These are the main two computing forces that determine the overall size of the blob. See my force layout talk for more details.

      I tried a few different versions, and this one seemed to work pretty well:

      var k = Math.sqrt(nodes.length / (width * height));
      
      layout
          .charge(-10 / k)
          .gravity(100 * k)

      Here nodes.length / (width * height) is linearly proportional to the graph density: the area of the nodes divided by the area of the layout. The charge force follows the inverse-square law, so that might explain why the square root works well. D3's "gravity" is a virtual spring that scales linearly with distance from the layout center, so this also increases the gravity as the graph becomes denser and discourages nodes from escaping the bounding box.

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多