basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 6.6 kB
JavaScript
import{aO as e,_ as t,t as a,j as i,R as r,k as n,o as s,a8 as o,C as l,m as p,c as h,aP as g,S as u}from"./index.js";import{i as d}from"./CoordinateSystem.js";var c=function(){function t(){this.blurSize=30,this.pointSize=20,this.maxOpacity=1,this.minOpacity=0,this._gradientPixels={inRange:null,outOfRange:null};var t=e.createCanvas();this.canvas=t}return t.prototype.update=function(e,t,a,i,r,n){var s=this._getBrush(),o=this._getGradient(r,"inRange"),l=this._getGradient(r,"outOfRange"),p=this.pointSize+this.blurSize,h=this.canvas,g=h.getContext("2d"),u=e.length;h.width=t,h.height=a;for(var d=0;d<u;++d){var c=e[d],m=c[0],y=c[1],v=i(c[2]);g.globalAlpha=v,g.drawImage(s,m-p,y-p)}if(!h.width||!h.height)return h;for(var f=g.getImageData(0,0,h.width,h.height),S=f.data,w=0,x=S.length,b=this.minOpacity,O=this.maxOpacity-b;w<x;){v=S[w+3]/256;var C=4*Math.floor(255*v);if(v>0){var _=n(v)?o:l;v>0&&(v=v*O+b),S[w++]=_[C],S[w++]=_[C+1],S[w++]=_[C+2],S[w++]=_[C+3]*v*256}else w+=4}return g.putImageData(f,0,0),h},t.prototype._getBrush=function(){var t=this._brushCanvas||(this._brushCanvas=e.createCanvas()),a=this.pointSize+this.blurSize,i=2*a;t.width=i,t.height=i;var r=t.getContext("2d");return r.clearRect(0,0,i,i),r.shadowOffsetX=i,r.shadowBlur=this.blurSize,r.shadowColor="#000",r.beginPath(),r.arc(-a,a,this.pointSize,0,2*Math.PI,!0),r.closePath(),r.fill(),t},t.prototype._getGradient=function(e,t){for(var a=this._gradientPixels,i=a[t]||(a[t]=new Uint8ClampedArray(1024)),r=[0,0,0,0],n=0,s=0;s<256;s++)e[t](s/255,!0,r),i[n++]=r[0],i[n++]=r[1],i[n++]=r[2],i[n++]=r[3];return i},t}();function m(e){var t=e.dimensions;return"lng"===t[0]&&"lat"===t[1]}var y=function(e){function l(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=l.type,t}return t(l,e),l.prototype.render=function(e,t,a){var i;if(t.eachComponent("visualMap",(function(t){t.eachTargetSeries((function(a){a===e&&(i=t)}))})),!i)throw new Error("Heatmap must use with visualMap");this._progressiveEls=null,this.group.removeAll();var r=e.coordinateSystem;"cartesian2d"===r.type||"calendar"===r.type?this._renderOnCartesianAndCalendar(e,a,0,e.getData().count()):m(r)&&this._renderOnGeo(r,e,i,a)},l.prototype.incrementalPrepareRender=function(e,t,a){this.group.removeAll()},l.prototype.incrementalRender=function(e,t,a,i){var r=t.coordinateSystem;r&&(m(r)?this.render(t,a,i):(this._progressiveEls=[],this._renderOnCartesianAndCalendar(t,i,e.start,e.end,!0)))},l.prototype.eachRendered=function(e){a(this._progressiveEls||this.group,e)},l.prototype._renderOnCartesianAndCalendar=function(e,t,a,o,l){var p,h,g,u,c=e.coordinateSystem,m=d(c,"cartesian2d");if(m){var y=c.getAxis("x"),v=c.getAxis("y");if("category"!==y.type||"category"!==v.type)throw new Error("Heatmap on cartesian must have two category axes");if(!y.onBand||!v.onBand)throw new Error("Heatmap on cartesian must have two axes with boundaryGap true");p=y.getBandWidth()+.5,h=v.getBandWidth()+.5,g=y.scale.getExtent(),u=v.scale.getExtent()}for(var f=this.group,S=e.getData(),w=e.getModel(["emphasis","itemStyle"]).getItemStyle(),x=e.getModel(["blur","itemStyle"]).getItemStyle(),b=e.getModel(["select","itemStyle"]).getItemStyle(),O=e.get(["itemStyle","borderRadius"]),C=i(e),_=e.getModel("emphasis"),M=_.get("focus"),R=_.get("blurScope"),I=_.get("disabled"),z=m?[S.mapDimension("x"),S.mapDimension("y"),S.mapDimension("value")]:[S.mapDimension("time"),S.mapDimension("value")],D=a;D<o;D++){var E=void 0,A=S.getItemVisual(D,"style");if(m){var P=S.get(z[0],D),N=S.get(z[1],D);if(isNaN(S.get(z[2],D))||isNaN(P)||isNaN(N)||P<g[0]||P>g[1]||N<u[0]||N>u[1])continue;var B=c.dataToPoint([P,N]);E=new r({shape:{x:B[0]-p/2,y:B[1]-h/2,width:p,height:h},style:A})}else{if(isNaN(S.get(z[1],D)))continue;E=new r({z2:1,shape:c.dataToRect([S.get(z[0],D)]).contentShape,style:A})}if(S.hasItemOption){var G=S.getItemModel(D),T=G.getModel("emphasis");w=T.getModel("itemStyle").getItemStyle(),x=G.getModel(["blur","itemStyle"]).getItemStyle(),b=G.getModel(["select","itemStyle"]).getItemStyle(),O=G.get(["itemStyle","borderRadius"]),M=T.get("focus"),R=T.get("blurScope"),I=T.get("disabled"),C=i(G)}E.shape.r=O;var V=e.getRawValue(D),H="-";V&&null!=V[2]&&(H=V[2]+""),n(E,C,{labelFetcher:e,labelDataIndex:D,defaultOpacity:A.opacity,defaultText:H}),E.ensureState("emphasis").style=w,E.ensureState("blur").style=x,E.ensureState("select").style=b,s(E,M,R,I),E.incremental=l,l&&(E.states.emphasis.hoverLayer=!0),f.add(E),S.setItemGraphicEl(D,E),this._progressiveEls&&this._progressiveEls.push(E)}},l.prototype._renderOnGeo=function(e,t,a,i){var r=a.targetVisuals.inRange,n=a.targetVisuals.outOfRange,s=t.getData(),l=this._hmLayer||this._hmLayer||new c;l.blurSize=t.get("blurSize"),l.pointSize=t.get("pointSize"),l.minOpacity=t.get("minOpacity"),l.maxOpacity=t.get("maxOpacity");var h=e.getViewRect().clone(),g=e.getRoamTransform();h.applyTransform(g);var u=Math.max(h.x,0),d=Math.max(h.y,0),m=Math.min(h.width+h.x,i.getWidth()),y=Math.min(h.height+h.y,i.getHeight()),v=m-u,f=y-d,S=[s.mapDimension("lng"),s.mapDimension("lat"),s.mapDimension("value")],w=s.mapArray(S,(function(t,a,i){var r=e.dataToPoint([t,a]);return r[0]-=u,r[1]-=d,r.push(i),r})),x=a.getExtent(),b="visualMap.continuous"===a.type?function(e,t){var a=e[1]-e[0];return t=[(t[0]-e[0])/a,(t[1]-e[0])/a],function(e){return e>=t[0]&&e<=t[1]}}(x,a.option.range):function(e,t,a){var i=e[1]-e[0],r=(t=p(t,(function(t){return{interval:[(t.interval[0]-e[0])/i,(t.interval[1]-e[0])/i]}}))).length,n=0;return function(e){var i;for(i=n;i<r;i++)if((s=t[i].interval)[0]<=e&&e<=s[1]){n=i;break}if(i===r)for(i=n-1;i>=0;i--){var s;if((s=t[i].interval)[0]<=e&&e<=s[1]){n=i;break}}return i>=0&&i<r&&a[i]}}(x,a.getPieceList(),a.option.selected);l.update(w,v,f,r.color.getNormalizer(),{inRange:r.color.getColorMapper(),outOfRange:n.color.getColorMapper()},b);var O=new o({style:{width:v,height:f,x:u,y:d,image:l.canvas},silent:!0});this.group.add(O)},l.type="heatmap",l}(l),v=function(e){function a(){var t=null!==e&&e.apply(this,arguments)||this;return t.type=a.type,t}return t(a,e),a.prototype.getInitialData=function(e,t){return h(null,this,{generateCoord:"value"})},a.prototype.preventIncremental=function(){var e=g.get(this.get("coordinateSystem"));if(e&&e.dimensions)return"lng"===e.dimensions[0]&&"lat"===e.dimensions[1]},a.type="series.heatmap",a.dependencies=["grid","geo","calendar"],a.defaultOption={coordinateSystem:"cartesian2d",z:2,geoIndex:0,blurSize:30,pointSize:20,maxOpacity:1,minOpacity:0,select:{itemStyle:{borderColor:"#212121"}}},a}(u);function f(e){e.registerChartView(y),e.registerSeriesModel(v)}export{f as install};