dc.js - 监听图表组渲染 [英] dc.js - Listening for chart group render
问题描述
我试图重构一些自定义d3代码,我写了通过引入dc.js渲染一系列交叉过滤器驱动的图表。
I'm trying to refactor some custom d3 code that I wrote to render a series of crossfilter-driven charts by bringing in dc.js.
我的主要问题是我有一些不支持dc.js的图表类型(例如 Sunburst Partition ),我想弄清楚如何结合使用dc.js图表组。
My main problem is that I have some chart types that are not supported by dc.js (e.g. a Sunburst Partition) and I'm trying to figure out how to render them in conjunction with a dc.js chart group.
过滤单个dc.js图表将自动呈现/重绘属于同一 chartGroup 。是否可能以某种方式挂钩到全局重新渲染事件中,以便我可以同时重新绘制非直方图?
Filtering a single dc.js chart will automatically render / redraw all other charts belonging to the same chartGroup. Is it possible to somehow hook into that global re-render event, so that I can re-draw the non-dc charts at the same time?
我知道是每个图表上的监听器,例如 chart.on(postRender,function(chart){...})
但似乎没有办法钩到重新渲染一组图表。
I understand that there are listeners on each individual chart, e.g. chart.on("postRender", function(chart){...})
but there doesn't seem to be a way to hook into re-rendering a group of charts. Is there a good pattern by which this could be accomplished?
推荐答案
正确的方法是注册你的图表在dc注册表中与 dc.registerChart
The "right" way to do this is to register your chart in the dc registry with dc.registerChart
https://github.com/dc-js/dc.js/blob/master/src/core.js #L91
不幸的是,这些东西目前没有记录,但实际上有很轻的耦合。你只需要在某个对象(图表或包装器)上实现 .redraw()
和 .render()
,并将其作为第一个参数传递。
Unfortunately this stuff is not currently documented, but there is actually pretty light coupling here. You just need to implement .redraw()
and .render()
on some object (your chart or a wrapper), and pass it in as the first arg.
将其放入与应该响应的图表相同的组(第二个参数)。
Put it in the same group (second arg) as the charts it should respond to.
render()从头开始创建dom元素, redraw()在数据更改时更新它们。
render() creates the dom elements from scratch, and redraw() updates them when the data changes.
看起来您可能还需要实现一个<
Looks like you may also need to implement a dummy .filterAll()
but that's an oversight.
我添加了一个问题来记录这些东西:
I added an issue to document this stuff:
https://github.com/dc- js / dc.js / issues / 676
如果遇到麻烦,请在那里评论。
Please comment there or here if you run into trouble.
编辑:现在记录,感谢Jasmine Hegman。请参见 chartRegistry文档< a>。
this is now documented, thanks to Jasmine Hegman. See chartRegistry documentation.
这篇关于dc.js - 监听图表组渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!