How to change a circle into a square with d3.js

前端 未结 1 1766
一向
一向 2020-12-05 15:54

After appending 25 circles to the page, I run the following function:

var transitionPage = function () {
  startThePage();
  var height = $(document).height(         


        
相关标签:
1条回答
  • 2020-12-05 16:32

    In the svg recomendation there are no transformation possible for the circle shape to become a square. What you can try to do, and if you have control over this part, is to draw squares instead of circles and apply a border radius on it. Something like this:

    d3.select("body").select("svg").append("rect")
        .attr("rx",100)
        .attr("ry",100)
        .attr("x",100)
        .attr("y",100)
        .attr("width",100)
        .attr("height",100)
        .attr("stroke","black")
        .attr("fill","white");
    

    Then the transition from a circle to a square could be done as:

    d3.select("rect")
        .transition()
        .duration(1000)
        .attr("rx",0)
        .attr("ry",0);
    
    0 讨论(0)
提交回复
热议问题