Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heatmap-ts

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heatmap-ts - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

dist/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.max=t.max,this.min=t.min||0,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min,a=this.max=t.max,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}(),r=function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}();module.exports=r;
"use strict";var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.min=t.min||0,this.max=t.max||100,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min||0,a=this.max=t.max||100,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}(),r=function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}();module.exports=r;

@@ -1,1 +0,1 @@

var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.max=t.max,this.min=t.min||0,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min,a=this.max=t.max,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}(),r=function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}();export default r;
var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.min=t.min||0,this.max=t.max||100,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min||0,a=this.max=t.max||100,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}(),r=function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}();export default r;

@@ -1,1 +0,1 @@

var HeatMap=function(){"use strict";var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.max=t.max,this.min=t.min||0,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min,a=this.max=t.max,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}();return function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}()}();
var HeatMap=function(){"use strict";var t={defaultRadius:40,defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}},i=function(){function t(){this.eStore={}}return t.prototype.on=function(t,i,a){this.eStore[t]||(this.eStore[t]=[]),this.eStore[t].push((function(t){return i.call(a,t)}))},t.prototype.emit=function(t,i){this.eStore[t]&&this.eStore[t].forEach((function(t){return t(i)}))},t}(),a=function(){function a(a){this.coordinator=new i,this.data=[],this.radi=[],this.min=10,this.max=1,this.xField=a.xField||t.defaultXField,this.yField=a.yField||t.defaultYField,this.valueField=a.valueField||t.defaultValueField,this.radius=a.radius||t.defaultRadius}return a.prototype._organiseData=function(t,i){var a=t[this.xField],e=t[this.yField],r=this.radi,n=this.data,s=this.max,h=this.min,o=t[this.valueField]||1,d=t.radius||this.radius;r[a]||(n[a]=[],r[a]=[]),r[a][e]?n[a][e]+=o:(n[a][e]=o,r[a][e]=d);var u=n[a][e];return u?u>s?(i?this.setDataMax(u):this.max=u,!1):u<h?(i?this.setDataMin(u):this.min=u,!1):void 0:{x:a,y:e,value:o,radius:d,min:h,max:s}},a.prototype._unOrganizeData=function(){for(var t=[],i=0;i<this.radi.length;i++)for(var a=0;a<this.radi[i].length;a++)t.push({x:i,y:a,radius:this.radi[i][a],value:this.radi[i][a]});return{min:this.min,max:this.max,data:t}},a.prototype._onExtremaChange=function(){this.coordinator.emit("extremachange",{min:this.min,max:this.max})},a.prototype.addData=function(t){var i=this._organiseData(t,!0);i&&(0===this.data.length&&(this.min=i.value,this.max=i.value),this.coordinator.emit("renderpartial",{min:this.min,max:this.max,data:[i]}))},a.prototype.setData=function(t){var i=t.data;this.data=[],this.radi=[];for(var a=0;a<i.length;a++)this._organiseData(i[a],!1);return this.min=t.min||0,this.max=t.max||100,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMax=function(t){return this.max=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype.setDataMin=function(t){return this.min=t,this._onExtremaChange(),this.coordinator.emit("renderall",this._getInternalData()),this},a.prototype._getInternalData=function(){return{max:this.max,min:this.min,data:this.data,radi:this.radi}},a.prototype.getData=function(){return this._unOrganizeData()},a}(),e=function(){function i(t){this.canvas=t.canvas||document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.shadowCanvas=t.shadowCanvas||document.createElement("canvas"),this.shadowCtx=this.shadowCanvas.getContext("2d"),this.width=t.width||512,this.height=t.height||512,this.max=100,this.min=1,this.blur=1,this.opacity=1,this.maxOpacity=1,this.minOpacity=0,this.useGradientOpacity=!1,this.canvas.style.cssText=this.shadowCanvas.style.cssText="position:absolute;left:0;top:0;",t.container&&(t.container.style.position="relative",t.container.appendChild(this.canvas)),this.renderBoundaries=[1e4,1e4,0,0],this.palette=this._getColorPalette(t),this.templates=[],this._setStyles(t)}return i.prototype.renderPartial=function(t){t.data.length>0&&(this._drawAlpha(t),this._colorize())},i.prototype.renderAll=function(t){this._clear(),t.data.length>0&&(this._drawAlpha(this._prepareData(t)),this._colorize())},i.prototype.updateConfig=function(t){t.gradient&&this._updateGradient(t),this._setStyles(t)},i.prototype.setDimensions=function(t,i){this.width=this.canvas.width=this.shadowCanvas.width=t,this.height=this.canvas.height=this.shadowCanvas.height=i},i.prototype.getValueAt=function(t){if(!this.shadowCtx)return 0;var i=this.shadowCtx.getImageData(t.x,t.y,1,1);return Math.abs(this.max-this.min)*(i.data[3]/255)>>0},i.prototype.getDataURL=function(){return this.canvas.toDataURL()},i.prototype._getColorPalette=function(i){var a=i.gradient||t.defaultGradient,e=document.createElement("canvas"),r=e.getContext("2d");if(e.width=256,e.height=1,!r)return new Uint8ClampedArray(1024);var n=r.createLinearGradient(0,0,256,1);for(var s in a)n.addColorStop(Number(s),a[s]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data},i.prototype._getPointTemplate=function(t,i){var a=document.createElement("canvas"),e=a.getContext("2d");if(!e)return a;var r=t,n=t;if(a.width=a.height=2*t,1===i)e.beginPath(),e.arc(r,n,t,0,2*Math.PI,!1),e.fillStyle="rgba(0,0,0,1)",e.fill();else{var s=e.createRadialGradient(r,n,t*i,r,n,t);s.addColorStop(0,"rgba(0,0,0,1)"),s.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=s,e.fillRect(0,0,2*t,2*t)}return a},i.prototype._prepareData=function(t){for(var i=[],a=t.min,e=t.max,r=t.radi,n=t.data,s=Object.keys(n),h=s.length;h--;)for(var o=s[h],d=Object.keys(n[o]),u=d.length;u--;){var l=d[u],c=n[o][l],p=r[o][l];i.push({x:Number(o),y:Number(l),value:c,radius:p})}return{min:a,max:e,data:i}},i.prototype._setStyles=function(i){this.blur=0===i.blur?0:i.blur||t.defaultBlur,i.backgroundColor&&(this.canvas.style.backgroundColor=i.backgroundColor),this.width=this.canvas.width=this.shadowCanvas.width=i.width||this.width,this.height=this.canvas.height=this.shadowCanvas.height=i.height||this.height,this.opacity=255*(i.opacity||0),this.maxOpacity=255*(i.maxOpacity||t.defaultMaxOpacity),this.minOpacity=255*(i.minOpacity||t.defaultMinOpacity),this.useGradientOpacity=!!i.useGradientOpacity},i.prototype._updateGradient=function(t){this.palette=this._getColorPalette(t)},i.prototype._drawAlpha=function(t){for(var i=this.min=t.min||0,a=this.max=t.max||100,e=t.data||[],r=e.length,n=1-this.blur;r--;){var s=e[r],h=s.x,o=s.y,d=s.radius,u=Math.min(s.value,a),l=h-d,c=o-d;if(!this.shadowCtx)return;var p=void 0;this.templates[d]?p=this.templates[d]:this.templates[d]=p=this._getPointTemplate(d,n);var m=(u-i)/(a-i);this.shadowCtx.globalAlpha=m<.01?.01:m,this.shadowCtx.drawImage(p,l,c),l<this.renderBoundaries[0]&&(this.renderBoundaries[0]=l),c<this.renderBoundaries[1]&&(this.renderBoundaries[1]=c),l+2*d>this.renderBoundaries[2]&&(this.renderBoundaries[2]=l+2*d),c+2*d>this.renderBoundaries[3]&&(this.renderBoundaries[3]=c+2*d)}},i.prototype._colorize=function(){var t=this.renderBoundaries[0],i=this.renderBoundaries[1],a=this.renderBoundaries[2]-t,e=this.renderBoundaries[3]-i,r=this.width,n=this.height;if(t<0&&(t=0),i<0&&(i=0),t+a>r&&(a=r-t),i+e>n&&(e=n-i),this.ctx&&this.shadowCtx){for(var s=this.shadowCtx.getImageData(t,i,a,e),h=3;h<s.data.length;h+=4){var o,d=s.data[h],u=4*d;if(u)o=this.opacity>0?this.opacity:d<this.maxOpacity?d<this.minOpacity?this.minOpacity:d:this.maxOpacity,s.data[h-3]=this.palette[u],s.data[h-2]=this.palette[u+1],s.data[h-1]=this.palette[u+2],s.data[h]=this.useGradientOpacity?this.palette[u+3]:o}this.ctx.putImageData(s,t,i),this.renderBoundaries=[1e3,1e3,0,0]}},i.prototype._clear=function(){this.ctx&&this.shadowCtx&&(this.ctx.clearRect(0,0,this.width,this.height),this.shadowCtx.clearRect(0,0,this.width,this.height))},i}();return function(){function i(t){this.config=t,this.renderer=new e(this.config),this.store=new a(this.config),this._init()}return i.prototype._init=function(){var i=this;this.store.coordinator.on("renderpartial",this.renderer.renderPartial,this.renderer),this.store.coordinator.on("renderall",this.renderer.renderAll,this.renderer),this.store.coordinator.on("extremachange",(function(a){i.config.onExtremaChange&&i.config.onExtremaChange({min:a.min,max:a.max,gradient:i.config.gradient||t.defaultGradient})}))},i.prototype.addData=function(t){return this.store.addData(t),this},i.prototype.setData=function(t){return this.store.setData(t),this},i.prototype.setDataMaxx=function(t){return this.store.setDataMax(t),this},i.prototype.setDataMin=function(t){return this.store.setDataMin(t),this},i.prototype.repaint=function(){return this.store.coordinator.emit("renderall",this.store._getInternalData()),this},i.prototype.getData=function(){return this.store.getData()},i.prototype.getDataURL=function(){return this.renderer.getDataURL()},i.prototype.getValueAt=function(t){return this.renderer.getValueAt(t)},i}()}();

@@ -10,4 +10,4 @@ import { AxisFields, ValueFields, DataPoint } from './interface';

interface StoreData {
max: number;
min: number;
max?: number;
min?: number;
data: DataPoint[];

@@ -14,0 +14,0 @@ }

{
"name": "heatmap-ts",
"version": "0.0.3",
"version": "0.0.4",
"description": "Forked from [pa7/heatmap.js](https://github.com/pa7/heatmap.js) for TypeScript.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# heatmap-ts
Forked from [pa7/heatmap.js](https://github.com/pa7/heatmap.js) for TypeScript.
> Tips: plugin register is not yet implemented. If you need it, please mention the problem or push your code through PR.
## Install
```bash
yarn add heatmap-ts -S
# or
npm i heatmap-ts -S
```
## Use
For more details, see [heatmap.js](https://github.com/pa7/heatmap.js).
```ts
import HeatMap from 'heatmap-ts'
const heatMap = new HeatMap({
container: document.getElementById('view'),
maxOpacity: .6,
radius: 50,
blur: 0.90,
})
heatMap.setData({
max: 100,
min: 1,
data: [
{
x: 100,
y: 100,
value: 100,
radius: 20
},
{
x: 200,
y: 250,
value: 50,
radius: 30
}
]
})
```

@@ -223,4 +223,4 @@ import { StoreConfig, StoreData } from './store'

_drawAlpha(resData: StoreData): void {
const min = this.min = resData.min
const max = this.max = resData.max
const min = this.min = resData.min || 0
const max = this.max = resData.max || 100
const data = resData.data || []

@@ -227,0 +227,0 @@

@@ -13,4 +13,4 @@ import { AxisFields, ValueFields, DataPoint } from './interface'

interface StoreData {
max: number;
min: number;
max?: number;
min?: number;
data: DataPoint[];

@@ -160,4 +160,4 @@ }

this.max = resData.max;
this.min = resData.min || 0;
this.max = resData.max || 100;

@@ -164,0 +164,0 @@ this._onExtremaChange();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc