不幸的是,heatmap.js 似乎默认不提供这样的回调。您可以做的最好的事情是分叉项目并自己添加此功能。我会试着指出一些需要改变的地方。
首先,您需要提供添加回调的功能:
// heatmap object constructor
var heatmap = function heatmap(config){
// private variables
var _ = {
radius : 40,
element : {},
canvas : {},
acanvas: {},
ctx : {},
actx : {},
legend: null,
visible : true,
width : 0,
height : 0,
max : false,
gradient : false,
opacity: 180,
premultiplyAlpha: false,
bounds: {
l: 1000,
r: 0,
t: 1000,
b: 0
},
debug: false,
onRenderingStart: null,
onRenderingEnd: null
};
configure
方法:
me.set("onRenderingStart", config.onRenderingStart || null);
me.set("onRenderingEnd", config.onRenderingEnd || null);
最后一件事是调用这些回调(如果它们已附加)。我想最好的地方是一种setDataSet
方法:
setDataSet: function(obj, internal){
var me = this,
heatmap = me.get("heatmap"),
onRenderingStart = heatmap.get("onRenderingStart"),
onRenderingEnd= heatmap.get("onRenderingEnd"),
data = [],
d = obj.data,
dlen = d.length;
if(typeof onRenderingStart === "function") {
onRenderingStart(/* maybe it'd be a good idea to pass reference to heatmap or sth */);
}
// the rest of the code
heatmap.colorize();
this.set("data", d);
if(typeof onRenderingEnd === "function") {
onRenderingEnd(/* maybe it'd be a good idea to pass reference to heatmap or sth */);
}
}
请注意,我没有测试过这个解决方案,它可能需要一些修复和改进。希望它会帮助你。