3 lines
80 KiB
JavaScript
3 lines
80 KiB
JavaScript
|
define("echarts/chart/scatter",["require","./base","../util/shape/Symbol","../component/axis","../component/grid","../component/dataZoom","../component/dataRange","../config","zrender/tool/util","zrender/tool/color","../chart"],function(t){function e(t,e,s,o,n){i.call(this,t,e,s,o,n),this.refresh(o)}var i=t("./base"),s=t("../util/shape/Symbol");t("../component/axis"),t("../component/grid"),t("../component/dataZoom"),t("../component/dataRange");var o=t("../config");o.scatter={zlevel:0,z:2,clickable:!0,legendHoverLink:!0,xAxisIndex:0,yAxisIndex:0,symbolSize:4,large:!1,largeThreshold:2e3,itemStyle:{normal:{label:{show:!1}},emphasis:{label:{show:!1}}}};var n=t("zrender/tool/util"),a=t("zrender/tool/color");return e.prototype={type:o.CHART_TYPE_SCATTER,_buildShape:function(){var t=this.series;this._sIndex2ColorMap={},this._symbol=this.option.symbolList,this._sIndex2ShapeMap={},this.selectedMap={},this.xMarkMap={};for(var e,i,s,n,r=this.component.legend,h=[],l=0,d=t.length;d>l;l++)if(e=t[l],i=e.name,e.type===o.CHART_TYPE_SCATTER){if(t[l]=this.reformOption(t[l]),this.legendHoverLink=t[l].legendHoverLink||this.legendHoverLink,this._sIndex2ShapeMap[l]=this.query(e,"symbol")||this._symbol[l%this._symbol.length],r){if(this.selectedMap[i]=r.isSelected(i),this._sIndex2ColorMap[l]=a.alpha(r.getColor(i),.5),s=r.getItemShape(i)){var n=this._sIndex2ShapeMap[l];s.style.brushType=n.match("empty")?"stroke":"both",n=n.replace("empty","").toLowerCase(),n.match("rectangle")&&(s.style.x+=Math.round((s.style.width-s.style.height)/2),s.style.width=s.style.height),n.match("star")&&(s.style.n=n.replace("star","")-0||5,n="star"),n.match("image")&&(s.style.image=n.replace(new RegExp("^image:\\/\\/"),""),s.style.x+=Math.round((s.style.width-s.style.height)/2),s.style.width=s.style.height,n="image"),s.style.iconType=n,r.setItemShape(i,s)}}else this.selectedMap[i]=!0,this._sIndex2ColorMap[l]=a.alpha(this.zr.getColor(l),.5);this.selectedMap[i]&&h.push(l)}this._buildSeries(h),this.addShapeList()},_buildSeries:function(t){if(0!==t.length){for(var e,i,s,o,n,a,r,h,l=this.series,d={},c=0,p=t.length;p>c;c++)if(e=t[c],i=l[e],0!==i.data.length){n=this.component.xAxis.getAxis(i.xAxisIndex||0),a=this.component.yAxis.getAxis(i.yAxisIndex||0),d[e]=[];for(var u=0,g=i.data.length;g>u;u++)s=i.data[u],o=this.getDataFromOption(s,"-"),"-"===o||o.length<2||(r=n.getCoord(o[0]),h=a.getCoord(o[1]),d[e].push([r,h,u,s.name||""]));this.xMarkMap[e]=this._markMap(n,a,i.data,d[e]),this.buildMark(e)}this._buildPointList(d)}},_markMap:function(t,e,i,s){for(var o,n={min0:Number.POSITIVE_INFINITY,max0:Number.NEGATIVE_INFINITY,sum0:0,counter0:0,average0:0,min1:Number.POSITIVE_INFINITY,max1:Number.NEGATIVE_INFINITY,sum1:0,counter1:0,average1:0},a=0,r=s.length;r>a;a++)o=i[s[a][2]].value||i[s[a][2]],n.min0>o[0]&&(n.min0=o[0],n.minY0=s[a][1],n.minX0=s[a][0]),n.max0<o[0]&&(n.max0=o[0],n.maxY0=s[a][1],n.maxX0=s[a][0]),n.sum0+=o[0],n.counter0++,n.min1>o[1]&&(n.min1=o[1],n.minY1=s[a][1],n.minX1=s[a][0]),n.max1<o[1]&&(n.max1=o[1],n.maxY1=s[a][1],n.maxX1=s[a][0]),n.sum1+=o[1],n.counter1++;var h=this.component.grid.getX(),l=this.component.grid.getXend(),d=this.component.grid.getY(),c=this.component.grid.getYend();n.average0=n.sum0/n.counter0;var p=t.getCoord(n.average0);n.averageLine0=[[p,c],[p,d]],n.minLine0=[[n.minX0,c],[n.minX0,d]],n.maxLine0=[[n.maxX0,c],[n.maxX0,d]],n.average1=n.sum1/n.counter1;var u=e.getCoord(n.average1);return n.averageLine1=[[h,u],[l,u]],n.minLine1=[[h,n.minY1],[l,n.minY1]],n.maxLine1=[[h,n.maxY1],[l,n.maxY1]],n},_buildPointList:function(t){var e,i,s,o,n=this.series;for(var a in t)if(e=n[a],i=t[a],e.large&&e.data.length>e.largeThreshold)this.shapeList.push(this._getLargeSymbol(i,this.getItemStyleColor(this.query(e,"itemStyle.normal.color"),a,-1)||this._sIndex2ColorMap[a]));else for(var r=0,h=i.length;h>r;r++)s=i[r],o=this._getSymbol(a,s[2],s[3],s[0],s[1]),o&&this.shapeList.push(o)},_getSymbol:function(t,e,i,s,o){var n,a=this.series,r=a[t],h=r.data[e],l=this.component.dataRange;if(l){if(n=isNaN(h[2])?this._sIndex2ColorMap[t]:l.getColor(h[2]),!n)return null}else n=this._sI
|
||
|
i.call(this,t,e,s,o,n);var r=this;r._ondrift=function(t,e){return r.__ondrift(this,t,e)},r._ondragend=function(){return r.__ondragend()},r._dataRangeSelected=function(t){return r.__dataRangeSelected(t)},r._dispatchHoverLink=function(t){return r.__dispatchHoverLink(t)},r._onhoverlink=function(t){return r.__onhoverlink(t)},this._selectedMap={},this._range={},this.refresh(o),e.bind(a.EVENT.HOVER,this._onhoverlink)}var i=t("./base"),s=t("zrender/shape/Text"),o=t("zrender/shape/Rectangle"),n=t("../util/shape/HandlePolygon"),a=t("../config");a.dataRange={zlevel:0,z:4,show:!0,orient:"vertical",x:"left",y:"bottom",backgroundColor:"rgba(0,0,0,0)",borderColor:"#ccc",borderWidth:0,padding:1,itemGap:15,itemWidth:25,itemHeight:25,precision:0,splitNumber:5,calculable:!1,selectedMode:!0,hoverLink:!0,realtime:!0,color:["#006edd","#e0ffff"],textStyle:{fontSize:18,color:"#333"}};var r=t("zrender/tool/util"),h=t("zrender/tool/event"),l=t("zrender/tool/area"),d=t("zrender/tool/color");return e.prototype={type:a.COMPONENT_TYPE_DATARANGE,_textGap:10,_buildShape:function(){if(this._itemGroupLocation=this._getItemGroupLocation(),this._buildBackground(),this.dataRangeOption.splitNumber<=0||this.dataRangeOption.calculable?this._buildGradient():this._buildItem(),this.dataRangeOption.show)for(var t=0,e=this.shapeList.length;e>t;t++)this.zr.addShape(this.shapeList[t]);this._syncShapeFromRange()},_buildItem:function(){var t,e,i,n,a=this._valueTextList,r=a.length,h=this.getFont(this.dataRangeOption.textStyle),d=this._itemGroupLocation.x,c=this._itemGroupLocation.y,p=this.dataRangeOption.itemWidth,u=this.dataRangeOption.itemHeight,g=this.dataRangeOption.itemGap,f=l.getTextHeight("国",h);"vertical"==this.dataRangeOption.orient&&"right"==this.dataRangeOption.x&&(d=this._itemGroupLocation.x+this._itemGroupLocation.width-p);var m=!0;this.dataRangeOption.text&&(m=!1,this.dataRangeOption.text[0]&&(i=this._getTextShape(d,c,this.dataRangeOption.text[0]),"horizontal"==this.dataRangeOption.orient?d+=l.getTextWidth(this.dataRangeOption.text[0],h)+this._textGap:(c+=f+this._textGap,i.style.y+=f/2+this._textGap,i.style.textBaseline="bottom"),this.shapeList.push(new s(i))));for(var y=0;r>y;y++)t=a[y],n=this.getColorByIndex(y),e=this._getItemShape(d,c,p,u,this._selectedMap[y]?n:"#ccc"),e._idx=y,e.onmousemove=this._dispatchHoverLink,this.dataRangeOption.selectedMode&&(e.clickable=!0,e.onclick=this._dataRangeSelected),this.shapeList.push(new o(e)),m&&(i={zlevel:this.getZlevelBase(),z:this.getZBase(),style:{x:d+p+5,y:c,color:this._selectedMap[y]?this.dataRangeOption.textStyle.color:"#ccc",text:a[y],textFont:h,textBaseline:"top"},highlightStyle:{brushType:"fill"}},"vertical"==this.dataRangeOption.orient&&"right"==this.dataRangeOption.x&&(i.style.x-=p+10,i.style.textAlign="right"),i._idx=y,i.onmousemove=this._dispatchHoverLink,this.dataRangeOption.selectedMode&&(i.clickable=!0,i.onclick=this._dataRangeSelected),this.shapeList.push(new s(i))),"horizontal"==this.dataRangeOption.orient?d+=p+(m?5:0)+(m?l.getTextWidth(t,h):0)+g:c+=u+g;!m&&this.dataRangeOption.text[1]&&("horizontal"==this.dataRangeOption.orient?d=d-g+this._textGap:c=c-g+this._textGap,i=this._getTextShape(d,c,this.dataRangeOption.text[1]),"horizontal"!=this.dataRangeOption.orient&&(i.style.y-=5,i.style.textBaseline="top"),this.shapeList.push(new s(i)))},_buildGradient:function(){var e,i,n=this.getFont(this.dataRangeOption.textStyle),a=this._itemGroupLocation.x,r=this._itemGroupLocation.y,h=this.dataRangeOption.itemWidth,d=this.dataRangeOption.itemHeight,c=l.getTextHeight("国",n),p=6,u=!0;this.dataRangeOption.text&&(u=!1,this.dataRangeOption.text[0]&&(i=this._getTextShape(a,r,this.dataRangeOption.text[0]),"horizontal"==this.dataRangeOption.orient?a+=l.getTextWidth(this.dataRangeOption.text[0],n)+this._textGap:(r+=c+this._textGap,i.style.y+=c/2+this._textGap,i.style.textBaseline="bottom"),this.shapeList.push(new s(i))));for(var g=t("zrender/tool/color"),f=1/(this.dataRangeOption.color.length-1),m=[],y=0,_=this.dataRangeOption.color.length;_>y;y++)m.push([y*f,this.dataRangeOption.color[y]]);"horizontal"==this.dat
|
||
|
for(var h in a)this[h]=a[h];this.refresh(o,r)}var i=t("./base"),s=t("zrender/shape/Text"),o=t("zrender/shape/Line"),n=t("zrender/shape/Rectangle"),a=t("../config");a.valueAxis={zlevel:0,z:0,show:!0,position:"left",name:"",nameLocation:"end",nameTextStyle:{},boundaryGap:[0,0],axisLine:{show:!1,onZero:!0,lineStyle:{color:"#48b",width:2,type:"solid"}},axisTick:{show:!1,inside:!1,length:5,lineStyle:{color:"#333",width:1}},axisLabel:{show:!0,rotate:0,margin:-1,textStyle:{align:"left",baseline:"bottom",color:"#333"}},splitLine:{show:!0,lineStyle:{color:["#ccc"],width:1,type:"solid"}},splitArea:{show:!1,areaStyle:{color:["rgba(250,250,250,0.3)","rgba(200,200,200,0.3)"]}}};var r=t("../util/date"),h=t("zrender/tool/util");return e.prototype={type:a.COMPONENT_TYPE_AXIS_VALUE,_buildShape:function(){if(this._hasData=!1,this._calculateValue(),this._hasData&&this.option.show){this.option.splitArea.show&&this._buildSplitArea(),this.option.splitLine.show&&this._buildSplitLine(),this.option.axisLine.show&&this._buildAxisLine(),this.option.axisTick.show&&this._buildAxisTick(),this.option.axisLabel.show&&this._buildAxisLabel();for(var t=0,e=this.shapeList.length;e>t;t++)this.zr.addShape(this.shapeList[t])}},_buildAxisTick:function(){var t,e=this._valueList,i=this._valueList.length,s=this.option.axisTick,n=s.length,a=s.lineStyle.color,r=s.lineStyle.width;if(this.isHorizontal())for(var h,l="bottom"===this.option.position?s.inside?this.grid.getYend()-n-1:this.grid.getYend()+1:s.inside?this.grid.getY()+1:this.grid.getY()-n-1,d=0;i>d;d++)h=this.subPixelOptimize(this.getCoord(e[d]),r),t={_axisShape:"axisTick",zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:!1,style:{xStart:h,yStart:l,xEnd:h,yEnd:l+n,strokeColor:a,lineWidth:r}},this.shapeList.push(new o(t));else for(var c,p="left"===this.option.position?s.inside?this.grid.getX()+1:this.grid.getX()-n-1:s.inside?this.grid.getXend()-n-1:this.grid.getXend()+1,d=0;i>d;d++)c=this.subPixelOptimize(this.getCoord(e[d]),r),t={_axisShape:"axisTick",zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:!1,style:{xStart:p,yStart:c,xEnd:p+n,yEnd:c,strokeColor:a,lineWidth:r}},this.shapeList.push(new o(t))},_buildAxisLabel:function(){var t,e=this._valueList,i=this._valueList.length,o=this.option.axisLabel.rotate,n=this.option.axisLabel.margin,a=this.option.axisLabel.clickable,r=this.option.axisLabel.textStyle;if(this.isHorizontal()){var h,l;"bottom"===this.option.position?(h=this.grid.getYend()+n,l="top"):(h=this.grid.getY()-n,l="bottom");for(var d=0;i>d;d++)t={zlevel:this.getZlevelBase(),z:this.getZBase()+3,hoverable:!1,style:{x:this.getCoord(e[d]),y:h,color:"function"==typeof r.color?r.color(e[d]):r.color,text:this._valueLabel[d],textFont:this.getFont(r),textAlign:r.align||"center",textBaseline:r.baseline||l}},o&&(t.style.textAlign=o>0?"bottom"===this.option.position?"right":"left":"bottom"===this.option.position?"left":"right",t.rotation=[o*Math.PI/180,t.style.x,t.style.y]),this.shapeList.push(new s(this._axisLabelClickable(a,t)))}else{var c,p;"left"===this.option.position?(c=this.grid.getX()-n,p="right"):(c=this.grid.getXend()+n,p="left");for(var d=0;i>d;d++)t={zlevel:this.getZlevelBase(),z:this.getZBase()+3,hoverable:!1,style:{x:c,y:this.getCoord(e[d]),color:"function"==typeof r.color?r.color(e[d]):r.color,text:this._valueLabel[d],textFont:this.getFont(r),textAlign:r.align||p,textBaseline:r.baseline||(0===d&&""!==this.option.name?"bottom":d===i-1&&""!==this.option.name?"top":"middle")}},o&&(t.rotation=[o*Math.PI/180,t.style.x,t.style.y]),this.shapeList.push(new s(this._axisLabelClickable(a,t)))}},_buildSplitLine:function(){var t,e=this._valueList,i=this._valueList.length,s=this.option.splitLine,n=s.lineStyle.type,a=s.lineStyle.width,r=s.lineStyle.color;r=r instanceof Array?r:[r];var h=r.length;if(this.isHorizontal())for(var l,d=this.grid.getY(),c=this.grid.getYend(),p=0;i>p;p++)l=this.subPixelOptimize(this.getCoord(e[p]),a),t={zlevel:this.getZlevelBase(),z:this.getZBase(),hoverable:!1,style:{xStart:l,yStart:d,xEnd:l,yEnd:c,strokeColor:r[p%h],lineType:n,lineWidth:a}},this.shapeList.push(new o(t));
|