|
@@ -0,0 +1,366 @@
|
|
|
|
+import * as echarts from 'echarts'
|
|
|
|
+import * as zrender from 'zrender'
|
|
|
|
+import drawUtils from './drawUtils'
|
|
|
|
+import utils from './utils'
|
|
|
|
+
|
|
|
|
+function LiquidCurve(containerId,refCtxMenu){
|
|
|
|
+ this.containerId=containerId
|
|
|
|
+ this.refCtxMenu=refCtxMenu
|
|
|
|
+ this.zr=null
|
|
|
|
+ this.container=null
|
|
|
|
+ this.mask=null
|
|
|
|
+ this.tipEl=null //提示文本显示对象
|
|
|
|
+ this.origin=null
|
|
|
|
+ this.origin2=null
|
|
|
|
+ this.axisEnd=null
|
|
|
|
+ this.xAxisGap=30 //中间轴与下部顶边间隙
|
|
|
|
+ this.xRatio=null
|
|
|
|
+ this.yRatio=null
|
|
|
|
+
|
|
|
|
+ this.wellHeadPos=1
|
|
|
|
+ this.hoopSerial={}
|
|
|
|
+ this.liquidSerial={}
|
|
|
|
+
|
|
|
|
+ this.indicateLine=null
|
|
|
|
+ this.wellHeadMark=null //井口标记线
|
|
|
|
+ this.liquidMark=null //液面标记线
|
|
|
|
+ this.soundMark=null //音标标记线
|
|
|
|
+ this.hoopStartMark=null //起始接箍标记线
|
|
|
|
+ this.hoopEndMark=null //截止接箍标记线
|
|
|
|
+ this.ruleGroup=null //标尺容器
|
|
|
|
+ this.init(containerId)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+LiquidCurve.prototype={
|
|
|
|
+ init(containerId){
|
|
|
|
+ this.zr = zrender.init(document.getElementById(containerId))
|
|
|
|
+ this.container = new zrender.Group()
|
|
|
|
+ this.zr.add(this.container)
|
|
|
|
+ this.zr.on('contextmenu',(event)=>{
|
|
|
|
+ //console.log(event.event)
|
|
|
|
+ event.event.preventDefault()
|
|
|
|
+ this.refCtxMenu.value={x:event.offsetX,y:event.offsetY,show:true}
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ this.zr.on('click',(event)=>{
|
|
|
|
+ event.event.preventDefault()
|
|
|
|
+ this.refCtxMenu.value={show:false}
|
|
|
|
+ //console.log(this.wellHeadMark)
|
|
|
|
+ //this.wellHeadMark.setPosition([event.event.offsetX,0])
|
|
|
|
+ //this.wellHeadMark.dirty()
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ addChild(displayObj){
|
|
|
|
+ this.container.add(displayObj)
|
|
|
|
+ },
|
|
|
|
+ build(){
|
|
|
|
+
|
|
|
|
+ let glbH=this.zr.getHeight(),glbW=this.zr.getWidth(),midH=(glbH-this.xAxisGap)/2
|
|
|
|
+
|
|
|
|
+ this.origin={
|
|
|
|
+ x:0,
|
|
|
|
+ y:midH
|
|
|
|
+ }
|
|
|
|
+ this.axisEnd={
|
|
|
|
+ x:glbW,
|
|
|
|
+ y:midH
|
|
|
|
+ }
|
|
|
|
+ this.origin2={
|
|
|
|
+ x:0,
|
|
|
|
+ y:glbH
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //标尺容器
|
|
|
|
+ this.ruleGroup=new zrender.Group()
|
|
|
|
+ this.container.add(this.ruleGroup)
|
|
|
|
+
|
|
|
|
+ //指示线
|
|
|
|
+ this.indicateLine=drawUtils.drawLine(10,0,10,glbH,{stroke:'#ff0000'})
|
|
|
|
+ this.container.add(this.indicateLine)
|
|
|
|
+ this.indicateLine.attr({
|
|
|
|
+ zlevel:8,
|
|
|
|
+ style:{
|
|
|
|
+ lineDash:[5,3]
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ //标记线
|
|
|
|
+ this.wellHeadMark=this.drawMarkLine(glbH,'井口','#ff0000')
|
|
|
|
+ this.liquidMark=this.drawMarkLine(glbH,'液面','#00a800')
|
|
|
|
+ this.soundMark=this.drawMarkLine(glbH,'音标','#00aaff')
|
|
|
|
+ this.hoopStartMark=this.drawMarkLine(glbH,'起始接箍','#c6c600')
|
|
|
|
+ this.hoopEndMark=this.drawMarkLine(glbH,'截止接箍','#b99f1e')
|
|
|
|
+
|
|
|
|
+ //提示文本
|
|
|
|
+ this.tipEl=drawUtils.drawText('',glbW/2,glbH/2,'center|middle')
|
|
|
|
+ this.tipEl.attr({zlevel:101,style:{fill:'#436cff'}})
|
|
|
|
+ this.tipEl.hide()
|
|
|
|
+ this.container.add(this.tipEl)
|
|
|
|
+
|
|
|
|
+ //遮罩层
|
|
|
|
+ this.mask=new zrender.Rect({
|
|
|
|
+ cursor:'default',
|
|
|
|
+ zlevel:100,
|
|
|
|
+ shape:{
|
|
|
|
+ x:0,
|
|
|
|
+ y:0,
|
|
|
|
+ width:glbW,
|
|
|
|
+ height:glbH
|
|
|
|
+ },
|
|
|
|
+ style: {
|
|
|
|
+ fill: 'rgb(0,0,0,.2)', // 填充颜色,默认#000
|
|
|
|
+ lineWidth: 0 // 线宽, 默认1
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ this.mask.hide()
|
|
|
|
+ this.container.add(this.mask)
|
|
|
|
+
|
|
|
|
+ //图形区(主要为了能响应鼠标移动事件)
|
|
|
|
+ let plot = new zrender.Rect({
|
|
|
|
+ cursor:'default',
|
|
|
|
+ zlevel:10,
|
|
|
|
+ shape:{
|
|
|
|
+ x:0,
|
|
|
|
+ y:0,
|
|
|
|
+ width:glbW,
|
|
|
|
+ height:glbH
|
|
|
|
+ },
|
|
|
|
+ style: {
|
|
|
|
+ fill: 'transparent', // 填充颜色,默认#000
|
|
|
|
+ stroke: '#999', // 描边颜色,默认null
|
|
|
|
+ lineWidth: 1 // 线宽, 默认1
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ this.container.add(plot)
|
|
|
|
+
|
|
|
|
+ plot.on('mousemove',(event)=>{
|
|
|
|
+ this.indicateHandle({x:event.offsetX,y:event.offsetX})
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ plot.on("mouseout",(event)=>{
|
|
|
|
+ //this.parent.sendNotice({show:false})
|
|
|
|
+ })*/
|
|
|
|
+
|
|
|
|
+ this.drawCoordinate()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ drawCoordinate(){
|
|
|
|
+ this.addChild(drawUtils.drawLine(this.origin.x,this.origin.y,this.axisEnd.x,this.axisEnd.y,{stroke:'#0070a8'}))
|
|
|
|
+ this.addChild(drawUtils.drawLine(this.origin.x,this.origin.y+this.xAxisGap,this.axisEnd.x,this.axisEnd.y+this.xAxisGap,{stroke:'#999'}))
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ setData({hoopDatas,liquidDatas,initData}){
|
|
|
|
+
|
|
|
|
+ //将数据的index作为x值,目前单个曲线有5000点,画布width太小会导致数据点堆积
|
|
|
|
+ let xRange=Math.max(hoopDatas.length,liquidDatas.length)
|
|
|
|
+ let xAxisLen=this.axisEnd.x-this.origin.x
|
|
|
|
+ this.xRatio=xAxisLen/xRange
|
|
|
|
+
|
|
|
|
+ let yRange=300 //指定值
|
|
|
|
+ this.yRatio=this.origin.y/yRange
|
|
|
|
+
|
|
|
|
+ this.hoopSerial.datas=hoopDatas
|
|
|
|
+ this.liquidSerial.datas=liquidDatas
|
|
|
|
+ if(!this.hoopSerial.curve){
|
|
|
|
+ this.hoopSerial.curve=this.drawCurve(hoopDatas,"#009900",this.origin)
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ this.refreshCurve(this.hoopSerial.curve,hoopDatas,this.origin)
|
|
|
|
+ }
|
|
|
|
+ if(!this.liquidSerial.curve){
|
|
|
|
+ this.liquidSerial.curve=this.drawCurve(liquidDatas,"#009900",this.origin2)
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ this.refreshCurve(this.liquidSerial.curve,liquidDatas,this.origin2)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.setInitData(initData)
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //初始化标线位置
|
|
|
|
+ setInitData(initData){
|
|
|
|
+ if(!initData || !initData.computeMode){
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if(initData.computeMode=='hoop'){
|
|
|
|
+ this.setMarkLinePos('hoopStart',initData.hoopStartPos||2)
|
|
|
|
+ this.setMarkLinePos('hoopEnd',initData.hoopEndPos||2)
|
|
|
|
+ }
|
|
|
|
+ else if(initData.computeMode=='sound_mark'){
|
|
|
|
+ this.setMarkLinePos('sound',initData.soundMarkPos||2)
|
|
|
|
+ }
|
|
|
|
+ this.setMarkLinePos('wellHead',initData.wellHeadPos||1)
|
|
|
|
+ this.setMarkLinePos('liquid',initData.liquidSufacePos||2)
|
|
|
|
+
|
|
|
|
+ if(initData.liquidDepth){
|
|
|
|
+ this.drawDepthRule(initData.liquidDepth)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ drawCurve(datas,color,origin){ //datas=[[x,y],...[xn,yn]] 动液面数据只有y,x可以自生成
|
|
|
|
+ let pts=[],pt=null
|
|
|
|
+ for(let i=0,len=datas.length;i<len;i++){
|
|
|
|
+ pt=this.getDrawPoint([i,datas[i]],origin)
|
|
|
|
+ pts.push([pt.x,pt.y])
|
|
|
|
+ }
|
|
|
|
+ let curve=drawUtils.drawPolyline(pts,{stroke:color,lineWidth:1})
|
|
|
|
+ this.addChild(curve)
|
|
|
|
+ return curve
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //刷新曲线-更新曲线对象的数据
|
|
|
|
+ refreshCurve(curve,datas,origin){
|
|
|
|
+ let pts=[],pt=null
|
|
|
|
+ for(let i=0,len=datas.length;i<len;i++){
|
|
|
|
+ pt=this.getDrawPoint([i,datas[i]],origin)
|
|
|
|
+ pts.push([pt.x,pt.y])
|
|
|
|
+ }
|
|
|
|
+ curve.attr({
|
|
|
|
+ shape:{
|
|
|
|
+ points:pts
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ curve.show()
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //绘制深度标尺
|
|
|
|
+ drawDepthRule(liquidDepth){
|
|
|
|
+ this.ruleGroup.removeAll()
|
|
|
|
+ let whidx=this.wellHeadMark.crtIdx,liqidx=this.liquidMark.crtIdx
|
|
|
|
+ let points=this.hoopSerial.curve.shape.points
|
|
|
|
+ let depthpx=points[liqidx][0]-points[whidx][0] //液面深度对应的像素长
|
|
|
|
+ let xRatio=liquidDepth/depthpx
|
|
|
|
+
|
|
|
|
+ let rulepx=points[points.length-1][0]-points[whidx][0] //要绘制标尺像素长(基于井口位置)
|
|
|
|
+ let maxDepth=rulepx*xRatio
|
|
|
|
+ let {pieceProj,pieceCount}=utils.calcAxis(maxDepth,rulepx) //utils.calcAxis返回的piecePx 是修正过的,不符合xRatio,要另算
|
|
|
|
+ let piecePx=pieceProj/xRatio
|
|
|
|
+ let xpos=points[whidx][0],lab=0
|
|
|
|
+ for(let i=0;i<=pieceCount;i++){
|
|
|
|
+
|
|
|
|
+ this.ruleGroup.add(drawUtils.drawLineSimple(xpos,this.origin.y,xpos,this.origin.y+5))
|
|
|
|
+ this.ruleGroup.add(drawUtils.drawText(lab+'',xpos,this.origin.y+6,'center'))
|
|
|
|
+ lab+=pieceProj
|
|
|
|
+ xpos+=piecePx
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //绘制标记线:井口、液面、起始接箍、截止接箍、音标
|
|
|
|
+ drawMarkLine(lineH,name,color){
|
|
|
|
+ let mark=new zrender.Group()
|
|
|
|
+ this.container.add(mark)
|
|
|
|
+ let line=drawUtils.drawLine(0,0,0,lineH,{stroke:color})
|
|
|
|
+
|
|
|
|
+ mark.add(line)
|
|
|
|
+ let mkname=drawUtils.drawText(name,0,1,'center')
|
|
|
|
+ mkname.attr({
|
|
|
|
+ style:{
|
|
|
|
+ fill:'#fff',
|
|
|
|
+ x:mkname.style.x-4.5,
|
|
|
|
+ padding:[4,4,2,4],
|
|
|
|
+ backgroundColor:color
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ mark.add(mkname)
|
|
|
|
+ mark.hide()
|
|
|
|
+ return mark
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ moveMarkLine(markKey){
|
|
|
|
+
|
|
|
|
+ this.setMarkLinePos(markKey,this.indicateLine.crtIdx)
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ setMarkLinePos(markKey,idx){
|
|
|
|
+ let markline=this[markKey+'Mark']
|
|
|
|
+ let pos=this.hoopSerial.curve.shape.points[idx]
|
|
|
|
+ markline.setPosition([pos[0],0])
|
|
|
|
+ markline.dirty()
|
|
|
|
+ markline.show()
|
|
|
|
+ markline.crtIdx=idx
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ indicateHandle({x,y}){
|
|
|
|
+ if(!this.hoopSerial.curve){
|
|
|
|
+ console.log('there is no curve exists')
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let idx=utils.getNearestPtIdxByX(this.hoopSerial.curve.shape.points,x)
|
|
|
|
+ let pos=this.hoopSerial.curve.shape.points[idx]
|
|
|
|
+ this.indicateLine.attr({
|
|
|
|
+ shape:{
|
|
|
|
+ x1:pos[0],
|
|
|
|
+ x2:pos[0]
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ this.indicateLine.crtIdx=idx
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ reset(){
|
|
|
|
+ //清除标量线
|
|
|
|
+ ['hoopStart','hoopEnd','sound','wellHead','liquid'].forEach(key=>{
|
|
|
|
+ this[key+'Mark'].hide()
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if(this.hoopSerial.curve){
|
|
|
|
+ this.hoopSerial.curve.hide()
|
|
|
|
+ }
|
|
|
|
+ if(this.liquidSerial.curve){
|
|
|
|
+ this.liquidSerial.curve.hide()
|
|
|
|
+ }
|
|
|
|
+ //清除标尺
|
|
|
|
+ this.ruleGroup.removeAll()
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getMarkPos(){
|
|
|
|
+ return {
|
|
|
|
+ wellHeadPos:this.wellHeadMark.crtIdx,
|
|
|
|
+ liquidSufacePos:this.liquidMark.crtIdx,
|
|
|
|
+ soundMarkPos:this.soundMark.crtIdx,
|
|
|
|
+ hoopStartPos:this.hoopStartMark.crtIdx,
|
|
|
|
+ hoopEndPos:this.hoopEndMark.crtIdx,
|
|
|
|
+ datalen:this.hoopSerial.datas.length
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ getDrawPoint(projary,origin){
|
|
|
|
+ let xmin=0,ymin=0
|
|
|
|
+ return {x:origin.x+(projary[0]-xmin)*this.xRatio,y:origin.y-(projary[1]-ymin)*this.yRatio}
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ dispose(){
|
|
|
|
+ if(this.zr){
|
|
|
|
+ this.zr.dispose()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ resize(){
|
|
|
|
+ this.zr.resize({
|
|
|
|
+ width:'auto',
|
|
|
|
+ height:'auto'
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ showTip(msg,showMask){
|
|
|
|
+ this.tipEl.attr({style:{text:msg}})
|
|
|
|
+ this.tipEl.show()
|
|
|
|
+ if(showMask){
|
|
|
|
+ this.mask.show()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ hideTip(){
|
|
|
|
+ this.tipEl.hide()
|
|
|
|
+ this.mask.hide()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export {LiquidCurve}
|