admin管理员组文章数量:1302403
I'm creating a map using the modules system. I'm more or less used to D3.js v3 but I am still getting used to v4.
I am trying to add a dispatch but I don't know how to rebind the exports in V4, as this function is not available now.
So for my dispatch (_dis) and my particular event ("changetype"), the rebind in d3 v3 would be right before returning the exports, for example:
d3.mapDots = function (districts){
var _dis = d3.dispatch('changetype');
(...)
exports.color = function(_c){
if(!arguments.length) return color;
color = _c;
return this;
};
d3.rebind(exports,_dis,"on");
return exports
};
Does anyone know how to do this in v4? I've been trying dispatch.apply but it doesn't work.
Thanks!
I'm creating a map using the modules system. I'm more or less used to D3.js v3 but I am still getting used to v4.
I am trying to add a dispatch but I don't know how to rebind the exports in V4, as this function is not available now.
So for my dispatch (_dis) and my particular event ("changetype"), the rebind in d3 v3 would be right before returning the exports, for example:
d3.mapDots = function (districts){
var _dis = d3.dispatch('changetype');
(...)
exports.color = function(_c){
if(!arguments.length) return color;
color = _c;
return this;
};
d3.rebind(exports,_dis,"on");
return exports
};
Does anyone know how to do this in v4? I've been trying dispatch.apply but it doesn't work.
Thanks!
Share asked Jul 12, 2016 at 15:48 IreneIrene 1251 silver badge7 bronze badges1 Answer
Reset to default 10Good question. Looks like the dispatch object has somewhat changed, and that d3.rebind
no longer exists. Because the latter is gone, it appears that there's no way to "copy" (via d3.rebind
) the .on()
method. Instead you must implement your own. See here how bostock implemented d3-brush
.
I put together this jsFiddle to demonstrate how to achieve with D3 v4 what you're asking.
The important bit is implementing the .on
method:
instance.on = function() {
var value = dispatcher.on.apply(dispatcher, arguments);
return value === dispatcher ? instance : value;
}
And, dispatching is like this
dispatcher.call("was_clicked", this, "Hello, Foo!");
本文标签: javascriptRebinding exports in d3js v4Stack Overflow
版权声明:本文标题:javascript - Rebinding exports in d3.js v4 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741674610a2391806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论