Getting a better performance on repeatedly method on d3 line generator

天大地大妈咪最大 提交于 2019-12-25 10:31:02

问题


I've been struggling the past few days to optimize performance on a D3. I'm using a line generator on the SVG and would like to calculate only one time the function used in the x and y. For example:

d3.line().curve(d3.curveLinear) 
  .x(function(d){ return Math.sqrt(d) }
  .y(function(d){ return Math.sqrt(d) + 2) I

I would like to save the result of Math.sqrt(d) and compute only one time.

Does anyone have any suggestions?


回答1:


You could store the result in your first function, and use it in the second

eg

d3.line().curve(d3.curveLinear) 
  .x(function(d){ 
     d.sqrt = Math.sqrt(d.value);
     return d.sqrt
   })
  .y(function(d){
     return d.sqrt + 2
   })


来源:https://stackoverflow.com/questions/46185036/getting-a-better-performance-on-repeatedly-method-on-d3-line-generator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!