Home > Mobile >  D3 js bbox not forming in v7
D3 js bbox not forming in v7

Time:07-21

Im attempting to create a bbox in d3 js so it can encapsulate my text but it doesn't appear to be forming.

function jobsCreation()
{
        let enteringText = dataJobs
            .enter()
            .append("text")
            .attr("x",function(d){return d.posX})
            .attr("y",function(d){return d.posY})
            .text(function(d){return d.name});

            let bbox = text.nodes().getBBox();

            let rect = svg.append("rect")
            .attr("x", bbox.x)
            .attr("y", bbox.y)
            .attr("width".bbox.width)
            .attr("height",bbox.height)
            .style("fill","#ccc")
            .style("stroke", "black")
            .style("stroke-width", "1.5px");
    }

CodePudding user response:

sorry about that guys i was not getting the appropriate data and their was a few issues with my code i got it working now.

fixed code:

function jobsCreation(){
        let enteringText = dataJobs
            .enter()
            .append("text")
            .attr("x",function(d){return d.posX})
            .attr("y",function(d){return d.posY})
            .text(function(d){return d.name});

            let bbox = enteringText.node().getBBox();

            let rect = svg.append("rect")
            .attr("x", bbox.x)
            .attr("y", bbox.y)
            .attr("width",bbox.width)
            .attr("height",bbox.height)
            .style("fill","white")
            .style("stroke", "black")
            .style("stroke-width", "1.5px");

    }
  • Related