如何在d3plus / javascript中将路径传递给open.window()onclick事件?

时间:2016-12-14 22:29:59

标签: javascript d3plus

我正在尝试通过d3plus.js构建一个小应用程序。目的是使用网络可视化来显示表示pdf文件的一系列节点。单击节点时,应显示一个显示pdf的窗口。

我想出了如何使用window.open()函数,如果我将路径直接写入window.open()函数(fx“docs / somepdf.pdf”),它就可以工作。

我现在的问题是将路径字符串从sample_data传递给window.open函数。

任何人都可以请求告诉我这里的错误吗?

    

<script src="//d3plus.org/js/d3.js"></script>
<script src="//d3plus.org/js/d3plus.js"></script>

<div id="viz"></div>

<script>
  // create list of node positions
  var sample_data = [
    {"name": "alpha", "size": 10, "path": "docs/Tan - 1999 - Text mining The state of the art and the challeng.pdf"},
    {"name": "beta", "size": 12, "path": ""},
    {"name": "gamma", "size": 30, "path": ""},
    {"name": "delta", "size": 26, "path": ""},
    {"name": "epsilon", "size": 12, "path": ""},
    {"name": "zeta", "size": 26, "path": ""},
    {"name": "theta", "size": 11, "path": ""},
    {"name": "eta", "size": 24, "path": ""}
  ]
  var connections = [
    {"source": "alpha", "target": "beta"},
    {"source": "alpha", "target": "gamma"},
    {"source": "beta", "target": "delta"},
    {"source": "beta", "target": "epsilon"},
    {"source": "zeta", "target": "gamma"},
    {"source": "theta", "target": "gamma"},
    {"source": "eta", "target": "gamma"}
  ]
  // instantiate d3plus
  var visualization = d3plus.viz()
    .container("#viz")
    .type("network")
    .edges(connections)
    .size("size")
    .id("name")
    .tooltip(["name", "size"]).mouse({                
      "move": false,                        // key will also take custom function
      "click": function(){window.open("path", '_blank', 'fullscreen=yes')}    
    })
    .draw()
</script>

1 个答案:

答案 0 :(得分:2)

问题在于您将“path”作为字符串提供,而不是作为节点的属性。

尝试将mouse方法更改为:

.mouse({                
  "move": false,
  "click": function(node){window.open(node.path, '_blank', 'fullscreen=yes')}    
})

看看类似的工作示例: http://jsfiddle.net/v1fvhpvx/14/