简体   繁体   English

D3转换循环抛出Uncaught TypeError:t.call不是函数

[英]D3 transition looping throwing Uncaught TypeError: t.call is not a function

Very new to D3 and relatively new to JS in general. 这是D3的新手,也是JS的新手。 I am trying to create a circle on click, and that circle once created needs to repeatedly pulsate forever. 我试图在点击上创建一个圆圈,一旦创建该圆圈需要反复脉动。 Right now, it is being created properly and it does the transition one time, but then it sort of dies due to the error. 现在,它正在被正确创建并且它进行了一次转换,但是由于错误它会死掉。 Here is my code: 这是我的代码:

var shapesAtt = shapes
    // omitted: assigning fill, position, etc; working as intended
    .on("click", circleMouseClick);

function circleMouseClick(d, i)
{
    createPulse(this);
}

function createPulse(focusElement)
{
    // takes in "focal circle" element
    // some things here are hard coded for ease of reading 
    // (i.e. these variables aren't all useless)

    var focus = d3.select(focusElement);
    var origR = focus.attr("r");
    var origX = focus.attr("cx");
    var origY = focus.attr("cy");
    var origFill = focus.style("fill");

    var strokeColor = "black";

    var newG = svgContainer.append("g");
    var pulser = newG.append("circle").attr("id", "pulser")
        .style("fill", "none").style("stroke", strokeColor)
        .attr("cx", 150).attr("cy", 150)
        .attr("r", origR)
        .transition()
            .duration(2000)
            .each(pulsate);
}

function pulsate()
{
    var pulser = d3.select(this);
    pulser = pulser
        .transition().duration(2000)
            .attr("r", 25)
            .attr("stroke-width", 50)
        .transition().duration(2000)
            .attr("r", 90)
            .attr("stroke-width", 10)
        .each("end", pulsate);
}

The error I'm receiving when running in Chrome is: 我在Chrome中运行时收到的错误是:

Uncaught TypeError: t.call is not a function     d3.v4.min.js:4

The portion of my code I think it's taking issue with is: 我觉得它的问题部分是:

function pulsate()
{
    // ...   
    .each("end", pulsate);
}

This is because you are using d3 version4. 这是因为您使用的是d3 version4。 There has been a major change in the v4 API, so: v4 API发生了重大变化,因此:

Instead of using 而不是使用

// ...   
.each("end", pulsate);//in d3 version 3

do

// ...   
.on("end", pulsate);//in d3 version 4

refer: https://github.com/d3/d3-transition#transition_on 参考: https//github.com/d3/d3-transition#transition_on

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM