WIP: 修复部分问题,优化自建台站页面切换图表效率

This commit is contained in:
Xu Zhimeng 2024-08-01 17:29:22 +08:00
parent 70f49fe8b2
commit 91b1fd3b81
7 changed files with 223 additions and 118 deletions

View File

@ -26,8 +26,8 @@ export default {
}, },
autoresize: { autoresize: {
type: Boolean, type: Boolean,
default: false default: false,
} },
}, },
data() { data() {
return {} return {}
@ -72,6 +72,14 @@ export default {
getZRender() { getZRender() {
return this._chart.getZr() return this._chart.getZr()
}, },
setOption(option, opts) {
this._chart && this._chart.setOption(option, opts)
},
getOption() {
return this._chart&& this._chart.getOption()
}
}, },
watch: { watch: {
option: { option: {

View File

@ -29,9 +29,21 @@ const addSampleData = sampleData => {
const updateSampleData = ({ inputFileName, key, data }) => { const updateSampleData = ({ inputFileName, key, data }) => {
const find = sampleList.find(item => item.inputFileName == inputFileName) const find = sampleList.find(item => item.inputFileName == inputFileName)
if (find) { if (find) {
if (key.includes('.')) {
const keys = key.split('.')
const target = keys.reduce((acc, k, index) => {
if (index == keys.length - 1) {
return acc
}
return acc[k]
}, find.data)
target[keys[keys.length - 1]] = data
} else {
find.data[key] = data find.data[key] = data
} }
} }
}
/** /**
* 移除谱数据 * 移除谱数据

View File

@ -48,8 +48,6 @@
ref="betaChartRef" ref="betaChartRef"
:betaEnergyData="betaEnergyData" :betaEnergyData="betaEnergyData"
:gammaEnergyData="gammaEnergyData" :gammaEnergyData="gammaEnergyData"
:histogramDataList="histogramDataList"
:boundary="boundaryList"
:isLoading.sync="isLoading" :isLoading.sync="isLoading"
@boundaryChange="handleBoundaryChange" @boundaryChange="handleBoundaryChange"
@open-modal="handleOpenModal" @open-modal="handleOpenModal"
@ -158,13 +156,11 @@ export default {
isLoading: false, isLoading: false,
spectrumData: {}, // Detailed Infomation spectrumData: {}, // Detailed Infomation
spectraType: 'sample', spectraType: 'sample',
histogramDataList: [],
gammaEnergyData: [], gammaEnergyData: [],
betaEnergyData: [], betaEnergyData: [],
ROILists: [], ROILists: [],
ROIAnalyzeLists: [], ROIAnalyzeLists: [],
roiParamList: cloneDeep(InitialRoiParamList), roiParamList: cloneDeep(InitialRoiParamList),
boundaryList: [],
sampleDetail: {}, sampleDetail: {},
resultDisplay: [], resultDisplay: [],
timerStamp: Date.now(), timerStamp: Date.now(),
@ -191,8 +187,6 @@ export default {
} }
this.ROIAnalyzeLists = [] this.ROIAnalyzeLists = []
} }
await this.$nextTick()
this.$refs.betaChartRef.handleUnzoom()
}, },
immediate: true, immediate: true,
deep: true, deep: true,
@ -209,6 +203,10 @@ export default {
}, },
methods: { methods: {
async getAnalyzeCurrentSpectrum() { async getAnalyzeCurrentSpectrum() {
if (this.isLoading) {
return
}
try { try {
const { inputFileName, detFileName } = this.sample const { inputFileName, detFileName } = this.sample
const userId = store.getters.userInfo.id const userId = store.getters.userInfo.id
@ -397,12 +395,12 @@ export default {
this.ROILists = [ROIOneList, ROITwoList, ROIThreeList, ROIFourList] this.ROILists = [ROIOneList, ROITwoList, ROIThreeList, ROIFourList]
this.boundaryList = [ this.$refs.betaChartRef.setBoundaryList([
[ROIOneStart, ROIOneStop], [ROIOneStart, ROIOneStop],
[ROITwoStart, ROITwoStop], [ROITwoStart, ROITwoStop],
[ROIThreeStart, ROIThreeStop], [ROIThreeStart, ROIThreeStop],
[ROIFourStart, ROIFourStop], [ROIFourStart, ROIFourStop],
] ])
} else { } else {
this.isLoading = false this.isLoading = false
this.$message.error(message) this.$message.error(message)
@ -470,7 +468,6 @@ export default {
} }
if (val == 'detBg') this.currSpectrum = 'Det' if (val == 'detBg') this.currSpectrum = 'Det'
this.roiParamList = cloneDeep(InitialRoiParamList) this.roiParamList = cloneDeep(InitialRoiParamList)
this.boundaryList = []
this.ROILists = [] this.ROILists = []
const { const {
spectrumData, spectrumData,
@ -492,20 +489,22 @@ export default {
} = currSampleDetail } = currSampleDetail
this.spectrumData = spectrumData this.spectrumData = spectrumData
this.histogramDataList = histogramDataList
this.gammaEnergyData = gammaEnergyData
this.betaEnergyData = betaEnergyData
this.ROILists = [ROIOneList, ROITwoList, ROIThreeList, ROIFourList]
this.boundaryList = [ const boundaryList = [
[ROIOneStart, ROIOneStop], [ROIOneStart, ROIOneStop],
[ROITwoStart, ROITwoStop], [ROITwoStart, ROITwoStop],
[ROIThreeStart, ROIThreeStop], [ROIThreeStart, ROIThreeStop],
[ROIFourStart, ROIFourStop], [ROIFourStart, ROIFourStop],
] ]
this.roiParamList = cloneDeep(this.boundaryList) this.roiParamList = cloneDeep(boundaryList)
this.$nextTick(() => {
this.$refs.betaChartRef.setBoundaryList(boundaryList)
this.$refs.betaChartRef.setData(histogramDataList)
})
this.gammaEnergyData = gammaEnergyData
this.betaEnergyData = betaEnergyData
this.ROILists = [ROIOneList, ROITwoList, ROIThreeList, ROIFourList]
this.$bus.$emit('selfAnalyzeSampleTypeChange', val) this.$bus.$emit('selfAnalyzeSampleTypeChange', val)
}, },
cancelLastRequest() { cancelLastRequest() {
@ -533,7 +532,6 @@ export default {
// //
handleBoundaryChange(evt) { handleBoundaryChange(evt) {
const { index, start, end } = evt const { index, start, end } = evt
this.$set(this.boundaryList, index, [start, end])
this.$set(this.roiParamList, index, [start, end]) this.$set(this.roiParamList, index, [start, end])
}, },
@ -605,12 +603,16 @@ export default {
fileName, fileName,
}) })
if (success) { if (success) {
const { DetailedInformation } = result
this.spectrumData = DetailedInformation
// DetailedInfomation // DetailedInfomation
updateSampleData({ updateSampleData({
inputFileName: fileName, inputFileName: fileName,
key: 'DetailedInformation', key: `${this.spectraType}.spectrumData`,
data: [...result.DetailedInformation], data: DetailedInformation,
}) })
console.log('%c [ ]-617', 'font-size:13px; background:pink; color:#bf2c9f;', getSampleData(fileName))
} else { } else {
throw new Error(message) throw new Error(message)
} }

View File

@ -320,7 +320,7 @@ export default {
dbName, dbName,
sampleId, sampleId,
analyst, analyst,
status status,
}, },
cancelToken cancelToken
) )
@ -715,6 +715,16 @@ export default {
return index1 - index2 return index1 - index2
}) })
}, },
// DetailedInfomation
updateSpectraData(data) {
Object.entries(data).forEach(([k, v]) => {
if (['det', 'gas'].includes(k)) {
k = k + 'Bg'
}
this.sampleDetail[k].spectrumData = v
})
},
}, },
watch: { watch: {
sample: { sample: {

View File

@ -18,14 +18,17 @@
<div class="_2d-chart" ref="TwoChartRef"> <div class="_2d-chart" ref="TwoChartRef">
<CustomChart <CustomChart
ref="chartTwoDRef" ref="chartTwoDRef"
:option="twoDOption"
:opts="opts"
autoresize autoresize
@zr:mousedown="handleMouseDown" @zr:mousedown="handleMouseDown"
@zr:mouseup="handleMouseUp" @zr:mouseup="handleMouseUp"
@brushEnd="handleBrushEnd" @brushEnd="handleBrushEnd"
@resize="handleChartResize" @resize="handleChartResize"
/> />
<div class="bar">
<div>{{ visualMapMax }}</div>
<div class="bar-main"></div>
<div>0</div>
</div>
</div> </div>
<!-- 2D图表结束 --> <!-- 2D图表结束 -->
<!-- 图表上面的四边形 --> <!-- 图表上面的四边形 -->
@ -64,13 +67,15 @@
import CustomChart from '@/components/CustomChart/index.vue' import CustomChart from '@/components/CustomChart/index.vue'
import { getXAxisAndYAxisByPosition, rangeNumber } from '@/utils/chartHelper.js' import { getXAxisAndYAxisByPosition, rangeNumber } from '@/utils/chartHelper.js'
import SampleDataMixin from '../SampleDataMixin' import SampleDataMixin from '../SampleDataMixin'
import { cloneDeep } from 'lodash'
const buttons = ['Gamma', 'Beta'] const buttons = ['Gamma', 'Beta']
// Beta-Gamma // Beta-Gamma
const twoDOption = { const TwoDOption = {
grid: { grid: {
top: 10, top: 10,
left: 60, left: 60,
right: 70, right: 10,
bottom: 45, bottom: 45,
}, },
tooltip: { tooltip: {
@ -154,7 +159,7 @@ const twoDOption = {
}, },
series: { series: {
type: 'scatterGL', type: 'scatterGL',
symbolSize: 4, symbolSize: 2,
data: [], data: [],
itemStyle: { itemStyle: {
color: '#fff', color: '#fff',
@ -162,26 +167,6 @@ const twoDOption = {
}, },
brush: {}, brush: {},
animation: false, animation: false,
visualMap: {
type: 'continuous',
min: 0,
max: 0,
itemWidth: 12,
itemHeight: 0,
dimension: 2,
seriesIndex: 0,
zlevel: 0,
orient: 'vertical',
right: 0,
bottom: 20,
textStyle: {
color: '#8EC0C8',
},
calculable: true,
inRange: {
color: ['#ffffff', '#ff0000'],
},
},
} }
const ColorList = [ const ColorList = [
@ -203,6 +188,17 @@ const ColorList = [
}, },
] ]
const ChartAxis = {
xAxis: {
min: 0,
max: 512,
},
yAxis: {
min: 0,
max: 4096,
},
}
export default { export default {
mixins: [SampleDataMixin], mixins: [SampleDataMixin],
components: { components: {
@ -212,10 +208,6 @@ export default {
isLoading: { isLoading: {
type: Boolean, type: Boolean,
}, },
histogramDataList: {
type: Array,
default: () => [],
},
gammaEnergyData: { gammaEnergyData: {
type: Array, type: Array,
default: () => [], default: () => [],
@ -224,99 +216,138 @@ export default {
type: Array, type: Array,
default: () => [], default: () => [],
}, },
boundary: {
type: Array,
default: () => [],
},
},
watch: {
// 2D
histogramDataList: {
handler() {
this.buildScatterList()
this.setVisialMapParams()
},
immediate: true,
},
// 2D
boundary: {
handler() {
this.$nextTick(() => {
this.reDrawRect()
})
},
// immediate: true,
},
}, },
data() { data() {
this.buttons = buttons this.buttons = buttons
return { return {
twoDOption,
showROI: true, showROI: true,
myChart: null, myChart: null,
startChannel: null, startChannel: null,
endChannel: null, endChannel: null,
opts: {
notMerge: false,
},
boundaryList: [], // boundaryList: [], //
boundaryContainerPosition: {}, boundaryContainerPosition: {},
isLog: true, // log isLog: true, // log
currBoundaryItem: null, // currBoundaryItem: null, //
visualMapMax: 0,
chartAxis: cloneDeep(ChartAxis),
boundary: [],
} }
}, },
created() { created() {
this.scatterList = []
this.boundary = []
this.$bus.$on('roiLimitItemChange', this.handleLimitItemChange) this.$bus.$on('roiLimitItemChange', this.handleLimitItemChange)
}, },
beforeDestroy() { beforeDestroy() {
this.$bus.$off('roiLimitItemChange', this.handleLimitItemChange) this.$bus.$off('roiLimitItemChange', this.handleLimitItemChange)
}, },
mounted() { mounted() {
this.opts.notMerge = true this.setOption(cloneDeep(TwoDOption))
this.$nextTick(() => {
this.opts.notMerge = false
this.twoDOption.brush = { toolbox: [] }
this.setVisualMapHeight()
})
}, },
methods: { methods: {
setData(histogramDataList) {
this.histogramDataList = histogramDataList
this.setVisialMapParams()
this.buildScatterList()
this.initChart()
},
setBoundaryList(boundary) {
this.boundary = boundary
},
setOption(option, opts) {
this.$refs.chartTwoDRef.setOption(option, opts)
},
initChart() {
this.chartAxis = cloneDeep(ChartAxis)
this.setOption({
...this.chartAxis,
series: {
data: this.scatterList,
},
})
this.reDrawRect()
},
// scatter // scatter
buildScatterList() { buildScatterList() {
this.$bus.$emit('roiLimitItemUnzoom')
console.time('buildScatterList')
this.scatterList = this.histogramDataList
.filter(({ c }) => c)
.map(({ b, g, c }) => this.buildScatterItem(b, g, c))
console.timeEnd('buildScatterList')
},
rangeScatter() {
console.time('rangeScatter')
const { const {
xAxis: { min: minX, max: maxX }, xAxis: { min: minX, max: maxX },
yAxis: { min: minY, max: maxY }, yAxis: { min: minY, max: maxY },
} = this.twoDOption } = this.chartAxis
// this.setOption({
this.twoDOption.series.symbolSize = 2 xAxis: {
this.twoDOption.series.data = this.histogramDataList min: minX,
.filter(({ b, g, c }) => c && b >= minX && b <= maxX && g >= minY && g <= maxY) max: maxX,
.map(({ b, g, c }) => this.buildScatterItem(b, g, c)) },
yAxis: {
min: minY,
max: maxY,
},
series: {
data: this.scatterList.filter(({ value: [b, g] }) => b >= minX && b <= maxX && g >= minY && g <= maxY),
},
})
console.timeEnd('rangeScatter')
}, },
// scatter // scatter
buildScatterItem(xAxis, yAxis, count) { buildScatterItem(xAxis, yAxis, count) {
const { r, g, b } = this.interpolateColor(1 - count / this.visualMapMax)
return { return {
value: [xAxis, yAxis, count], value: [xAxis, yAxis],
itemStyle: {
color: `rgb(${r}, ${g}, ${b})`,
},
} }
}, },
setVisialMapParams() { setVisialMapParams() {
const counts = this.histogramDataList.filter(({ c }) => c).map(({ c }) => c) const counts = this.histogramDataList.filter(({ c }) => c).map(({ c }) => c)
if (counts.length) { if (counts.length) {
this.twoDOption.visualMap.max = counts.sort((a, b) => b - a)[0] this.visualMapMax = counts.sort((a, b) => b - a)[0]
} else { } else {
this.twoDOption.visualMap.max = 0 this.visualMapMax = 0
} }
}, },
//
interpolateColor(percentage) {
const color1 = { r: 255, g: 0, b: 0 },
color2 = { r: 255, g: 255, b: 255 }
const r = color1.r + (color2.r - color1.r) * percentage
const g = color1.g + (color2.g - color1.g) * percentage
const b = color1.b + (color2.b - color1.b) * percentage
return { r, g, b }
},
// //
reDrawRect() { reDrawRect() {
const chart = this.$refs.chartTwoDRef.getChartInstance() const chart = this.$refs.chartTwoDRef.getChartInstance()
// //
const { min: xMin, max: xMax } = this.twoDOption.xAxis const { min: xMin, max: xMax } = this.chartAxis.xAxis
const { min: yMin, max: yMax } = this.twoDOption.yAxis const { min: yMin, max: yMax } = this.chartAxis.yAxis
const [containerLeft, containerTop] = chart.convertToPixel({ seriesIndex: 0 }, [xMin, yMax]) // const [containerLeft, containerTop] = chart.convertToPixel({ seriesIndex: 0 }, [xMin, yMax]) //
const [containerRight, containerBottom] = chart.convertToPixel({ seriesIndex: 0 }, [xMax, yMin]) // const [containerRight, containerBottom] = chart.convertToPixel({ seriesIndex: 0 }, [xMax, yMin]) //
this.boundaryContainerPosition = { this.boundaryContainerPosition = {
@ -349,14 +380,8 @@ export default {
} }
}, },
setVisualMapHeight() {
const chartContainerRef = this.$refs.chartContainerRef
this.twoDOption.visualMap.itemHeight = chartContainerRef.offsetHeight - 40
},
handleChartResize() { handleChartResize() {
this.reDrawRect() this.reDrawRect()
this.setVisualMapHeight()
}, },
// gammabeta // gammabeta
@ -365,11 +390,8 @@ export default {
}, },
// unzoom // unzoom
handleUnzoom() { handleUnzoom() {
this.twoDOption.xAxis.min = 0 this.chartAxis = cloneDeep(ChartAxis)
this.twoDOption.xAxis.max = 512 this.rangeScatter()
this.twoDOption.yAxis.min = 0
this.twoDOption.yAxis.max = 4096
this.buildScatterList()
this.$nextTick(() => { this.$nextTick(() => {
this.reDrawRect() this.reDrawRect()
@ -380,10 +402,16 @@ export default {
// //
handleLimitItemChange(x1, x2) { handleLimitItemChange(x1, x2) {
this.twoDOption.yAxis.min = x1 this.chartAxis.yAxis = {
this.twoDOption.yAxis.max = x2 min: x1,
max: x2,
}
this.buildScatterList() this.setOption({
yAxis: { min: x1, max: x2 },
})
this.rangeScatter()
this.$nextTick(() => { this.$nextTick(() => {
this.reDrawRect() this.reDrawRect()
@ -436,17 +464,28 @@ export default {
const rangeNumberFuncX = rangeNumber(0, 512) const rangeNumberFuncX = rangeNumber(0, 512)
const rangeNumberFuncY = rangeNumber(0, 4096) const rangeNumberFuncY = rangeNumber(0, 4096)
this.twoDOption.xAxis.min = rangeNumberFuncX(x1) const xAxisMin = rangeNumberFuncX(x1),
this.twoDOption.xAxis.max = rangeNumberFuncX(x2) xAxisMax = rangeNumberFuncX(x2),
this.twoDOption.yAxis.min = rangeNumberFuncY(y1) yAxisMin = rangeNumberFuncY(y1),
this.twoDOption.yAxis.max = rangeNumberFuncY(y2) yAxisMax = rangeNumberFuncY(y2)
this.buildScatterList() this.chartAxis = {
xAxis: {
min: xAxisMin,
max: xAxisMax,
},
yAxis: {
min: yAxisMin,
max: yAxisMax,
},
}
this.rangeScatter()
// this.emitRangeChange([x1, x2, y1, y2]) // this.emitRangeChange([x1, x2, y1, y2])
this.$nextTick(() => { this.$nextTick(() => {
this.reDrawRect() this.reDrawRect()
}) })
this.$bus.$emit('roiLimitItemChange', this.twoDOption.yAxis.min, this.twoDOption.yAxis.max) this.$bus.$emit('SelfStationBetaSpectrumChange', this.chartAxis.yAxis.min, this.chartAxis.yAxis.max)
} }
this.clearBrush(chart) this.clearBrush(chart)
@ -579,7 +618,25 @@ export default {
display: flex; display: flex;
.custom-chart { .custom-chart {
width: 100%; width: calc(100% - 45px);
}
.bar {
width: 30px;
margin-left: 10px;
color: #ade6ee;
padding-top: 5px;
padding-bottom: 20px;
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
&-main {
width: 14px;
flex: 1;
background: linear-gradient(to bottom, #ff0000 0, #fff 100%);
}
} }
} }
} }

View File

@ -177,6 +177,7 @@ export default {
this.$bus.$on('changeROILimitsYAxisType', this.changeYAxisType) this.$bus.$on('changeROILimitsYAxisType', this.changeYAxisType)
this.$bus.$on('roiLimitItemUnzoom', this.handleUnZoom) this.$bus.$on('roiLimitItemUnzoom', this.handleUnZoom)
this.$bus.$on('roiLimitItemChange', this.handleLimitItemChange) this.$bus.$on('roiLimitItemChange', this.handleLimitItemChange)
this.$bus.$on('SelfStationBetaSpectrumChange', this.handleLimitItemChange)
}, },
mounted() { mounted() {
this.option.brush = { toolbox: [] } this.option.brush = { toolbox: [] }
@ -185,6 +186,7 @@ export default {
this.$bus.$off('changeROILimitsYAxisType', this.changeYAxisType) this.$bus.$off('changeROILimitsYAxisType', this.changeYAxisType)
this.$bus.$off('roiLimitItemUnzoom', this.handleUnZoom) this.$bus.$off('roiLimitItemUnzoom', this.handleUnZoom)
this.$bus.$off('roiLimitItemChange', this.handleLimitItemChange) this.$bus.$off('roiLimitItemChange', this.handleLimitItemChange)
this.$bus.$off('SelfStationBetaSpectrumChange', this.handleLimitItemChange)
}, },
methods: { methods: {
handleTooltipFormat(params) { handleTooltipFormat(params) {

View File

@ -946,6 +946,8 @@ export default {
console.error(error) console.error(error)
} }
}, },
// beta-gammaDB
handleSaveResultsToDB_Cuurrent() { handleSaveResultsToDB_Cuurrent() {
// xeflag params_toDB // xeflag params_toDB
if (this.params_toDB.savedAnalysisResult) { if (this.params_toDB.savedAnalysisResult) {
@ -972,6 +974,18 @@ export default {
this.$message.success('Save Successfully!') this.$message.success('Save Successfully!')
this.isSaving = false this.isSaving = false
this.sampleInfo = res.result.sample this.sampleInfo = res.result.sample
this.$refs.betaGammaAnalysisRef.updateSpectraData(res.result)
Object.entries(res.result).forEach(([k, v]) => {
if (['det', 'gas'].includes(k)) {
k = k + 'Bg'
}
updateSampleData({
inputFileName: this.sampleData.inputFileName,
key: `${k}.spectrumData`,
data: v,
})
})
} else { } else {
this.isSaving = false this.isSaving = false
this.$message.warning(`${res.message}`) this.$message.warning(`${res.message}`)