* @function HeatMap.prototype.draw * @description 绘制热点图。 * @param {Array} data - convertToPixelPoints 方法计算出的点。 * @param {number} maxWeight -最大权重。 * @private
(data, maxWeight)
| 228 | * @private |
| 229 | */ |
| 230 | draw(data, maxWeight) { |
| 231 | if (this.maxHeight > 0 && this.maxWidth > 0) { |
| 232 | //清空 |
| 233 | var ctx = this.canvasContext; |
| 234 | this.canvasContext.clearRect(0, 0, this.maxWidth, this.maxHeight); |
| 235 | this.drawCircle(this.useRadius); |
| 236 | this.createGradient(); |
| 237 | |
| 238 | for (var i = 0; i < data.length; i++) { |
| 239 | var p = data[i]; |
| 240 | this.canvasContext.globalAlpha = Math.max(p[2] / maxWeight, 0.05); |
| 241 | this.canvasContext.drawImage(this.circle, p[0] - this.useRadius, p[1] - this.useRadius); |
| 242 | } |
| 243 | |
| 244 | var colored = ctx.getImageData(0, 0, this.maxWidth, this.maxHeight); |
| 245 | this.colorize(colored.data, this.grad); |
| 246 | ctx.putImageData(colored, 0, 0); |
| 247 | } else { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * @function HeatMap.prototype.colorize |
no test coverage detected