0

D3 PhylogramのライブラリFigueからの戻り配列を変換したいと思います。この関数をビルドしましたが、うまくいきません:

function convert(input, rootName) {
        // top level
        if (Array.isArray(input)) {
            return {
                "name": rootName,
                "branchset": input.map(convert)
            };
        }
        // node
        else {
            ['left', 'right'].forEach(function(side) {
                if (input[side]) {
                    input.branchset = input.branchset || [];
                    input.branchset.push(convert(input[side]));
                    delete input[side];
                }
            });
            return input;
        }
    }

以下に、 D3のデータの例を示します。

{
        "branchset": [
          {
            "name": "", "length": 0.05,
            "branchset": [
              {
                "name": "", "length": 0.05,
                "branchset": [ { "name": "A", "length": 0.05 }, { "name": "B", "length": 0.05 } ]
              },
              {
                "name": "", "length": 0.05,
                "branchset": [ { "name": "C", "length": 0.05 }, { "name": "D", "length": 0.05 } ]
              }
            ]      
          },
          {
            "name": "", "length": 0.1, 
            "branchset": [ { "name": "E", "length": 0.05 }, { "name": "F", "length": 0.05 }
            ]
          },
          {
            "name": "", "length": 0.05,
            "branchset": [
              {
                "name": "", "length": 0.05,
                "branchset": [ { "name": "G", "length": 0.05 }, { "name": "H", "length": 0.05 } ]         
              },
              { "name": "I", "length": 0.1 }
            ]
          }
        ],
        "name": ""
      } 

そしてここで、図から返された配列のピース(上記の関数を使用):

{"label":-1,"dist":2.0373900000000003,"centroid":[0.0000027272727272704085,-0.0000018181818181937295],"size":11,"depth":6,"branchset":[{"label":-1,"dist":2.0373900000000003,"centroid":[-0.10734300000000001,-0.18521900000000002],"size":10,"depth":5,"branchset":[{"label":-1,"dist":1.38918,"centroid":[-0.00701333333333334,-0.4115955555555556],"size":9,"depth":4,"branchset":[{"label":-1,"dist":0,"centroid":[-1.01031,-0.18522],"size":4,"depth":3,"branchset":[{"label":-1,"dist":0,"centroid":[-1.01031,-0.18522000000000002],"size":3,"depth":2, ....
4

0 に答える 0