How can I select :last-child in d3.js?

后端 未结 6 2157
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 08:55

I need to manipulate the text elements of the first and last tick of an axis to bring them more towards the center.

I am trying to select them, one at t

6条回答
  •  情书的邮戳
    2020-12-31 09:39

    It's for D3.js v4

    d3.selection.prototype.first = function() {
        return d3.select(
            this.nodes()[0]
        );
    };
    d3.selection.prototype.last = function() {
        return d3.select(
            this.nodes()[this.size() - 1]
        );
    };
    

    Example:

    var lines = svg.selectAll('line');
       lines.first()
          .attr('transform','translate(4,0)');
       lines.last()
          .attr('transform','translate(-4,0)');
    

提交回复
热议问题