LoginSignup
5
4

More than 5 years have passed since last update.

selection.callはどういうときに使うのか

Posted at

同じ設定を複数のセレクションに対して行いたいとき。
同じ設定をfunctionにして呼び出せば使いまわせるので。

// 同じ設定
function common(){
  this.attr(...)
  .on('click',function(d){...});
}

// idが違うだけで他は同じ設定
d3.select('body').append('div')
.attr('id','div1')
.call(common);

d3.select('body').append('div')
.attr('id','div2')
.call(common);

d3.select('body').append('div')
.attr('id','div3')
.call(common);

selection.callの使い道はほかにもあると思うが、使っているうちに「そうだ!!こういうときに使うんだ!!」という気づきがあり、うれしくて書き込んだ。

以上

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4