将函数传递给.attr('d')? [英] Passing a function to .attr('d')?

查看:397
本文介绍了将函数传递给.attr('d')?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个 .data()选择中使用两个不同的区域生成器,以便一组点可以具有从上到下呈现的区域,而第二组的区域可以从左到右渲染。我可以将胖箭头函数传递给除之外的每个 .attr(),它会产生以下错误:



错误:< path>属性d:预期的moveto path命令( M或 m),功能区域(da…)。



我需要访问选择索引以设置布尔数组的区域。



因此,您没有获取值,而是调用函数。



在返回值中添加(d)以便执行区域生成器函数:

  .attr('d',function(d,i){
if(horizo​​ntalNotVertical [i]){
return horizo​​ntalArea( d);
} else {
返回verticalArea(d);
}
})


I am attempting to use two different area generators inside one .data() selection, so that one set of points can have an area rendered from top to bottom while the second set's area can be rendered from left to right. I can pass fat arrow functions to every .attr() except 'd', which produces the following error:

Error: <path> attribute d: Expected moveto path command ('M' or 'm'), "function area(da…".

I need to access the selection index in order to set the area from an array of booleans. Please see the jsfiddle I've set up with the relevant code. I've commented two of my attempts to pass a function to the .attr('d').

解决方案

if you inspect your generated code, you'll see this:

So, you are not geting values. Instead call the function.

Add (d) to the return value so that the area generator function is executed:

  .attr('d', function(d, i){
    if (horizontalNotVertical[i]) {
        return horizontalArea(d);
    } else {
        return verticalArea(d);
    }
  })

这篇关于将函数传递给.attr('d')?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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