在d3线生成器上的重复方法上获得更好的性能 [英] Getting a better performance on repeatedly method on d3 line generator

查看:80
本文介绍了在d3线生成器上的重复方法上获得更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几天,我一直在努力优化D3的性能.我在SVG上使用了行生成器,并且只想计算一次xy中使用的函数. 例如:

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

我想保存Math.sqrt(d)的结果并只计算一次.

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

有人有什么建议吗?

推荐答案

您可以将结果存储在第一个函数中,然后在第二个函数中使用

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

例如

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

这篇关于在d3线生成器上的重复方法上获得更好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆