码迷,mamicode.com
首页 > 移动开发 > 详细

d3 tspan append

时间:2020-07-29 10:27:04      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:foo   box   keyword   ring   tag   etc   ref   comm   ext   

http://bl.ocks.org/enjalot/1829187

index.html#

<html>
    <meta charset=‘utf-8‘ />
<head>
</head>
<body>
    <svg>
    <text id=‘text_node‘ y="20px" text-anchor="start" opacity="1">
        <tspan>You</tspan>
        <tspan dx=‘.5em‘>shall</tspan>
        <tspan dx=‘.5em‘ dy=‘.9em‘>not</tspan>
        <tspan dx=‘.4em‘ dy=‘.9em‘>pass</tspan>

    </text>
</svg>
<script src="https://mbostock.github.com/d3/d3.js"></script>
<script>
    var node = document.getElementById(‘text_node‘);
    var bbox = node.getBBox();
    var computed_text_length = node.getComputedTextLength();

    //Does not work
    text_node = d3.select(‘#text_node‘)
    text_node.append(‘tspan‘)
        .text(‘Fly‘)
        .attr(‘dx‘, ‘.2em‘)
    text_node.append(‘tspan‘)
        .text(‘you‘)
        .attr(‘dx‘, ‘.2em‘)
        .attr(‘dy‘, ‘.9em‘)
    text_node.append(‘tspan‘)
        .text(‘fools‘)
        .attr(‘dx‘, ‘.2em‘)
        .attr(‘dy‘, ‘.9em‘)

    /*
    d3.select(‘#text_node‘).append(‘tspan‘)
        .text(‘Fly‘)
        .attr(‘dx‘, ‘.2em‘)
        .attr(‘dy‘, ‘.9em‘)

    d3.select(‘#text_node‘).append(‘tspan‘)
        .text(‘you‘)
        .attr(‘dx‘, ‘.2em‘)
        .attr(‘dy‘, ‘.9em‘)
    */

    console.log(‘BBOX width: ‘, bbox.width);
    console.log(‘Computed text length: ‘, computed_text_length);
</script>
</body>
</html>

LICENSE

d3 tspan append

标签:foo   box   keyword   ring   tag   etc   ref   comm   ext   

原文地址:https://www.cnblogs.com/kungfupanda/p/13395016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!