首页 > 解决方案 > d3从绑定数据中一一添加svg元素的速度

问题描述

我在 WASM C++ 代码中有一些需要显示的数据。显示是静态的,所以绑定不是很重要。我很好奇两种方法的运行时间(以及人们认为值得考虑的任何其他因素)。两个选项是:让 C++ 代码将数据放入 JavaScript 数组(调用它theData),然后调用类似

svg.selectAll("bars")
  .data(theData)
  .enter()
  .append("rect")
  .attr("x", ...)
  .attr("y", ...)
  .attr("width", ...)
  .attr("height", ...)

或者WASM 代码是否应该调用一个 JS 函数来生成每个元素:

function newRect(x, y, width, height) {
  svg.append("rect")
    .attr("x", x)
    .attr("y", y)
    .attr("width", width)
    .attr("height", height)
}

标签: d3.jswebassembly

解决方案


推荐阅读