WIP: 修改Interactive Tools 弹窗数据的获取方式,底下的表格最后一项改为溢出隐藏,操作markLine时如不可见,则自动居中

This commit is contained in:
Xu Zhimeng 2023-10-30 19:56:56 +08:00
parent 1a849ec336
commit a7b18c57c7
2 changed files with 182 additions and 163 deletions

20
src/utils/sampleHelper.js Normal file
View File

@ -0,0 +1,20 @@
/**
* 在返回的allData中查找指定的数据
* @param {Array} allData
* @param {*} name
* @param {*} group
*/
export const getLineData = (allData, name, group, isList = false) => {
const arrFunc = isList ? Array.prototype.filter : Array.prototype.find
return arrFunc.call(allData, item => item.name == name && item.group == group) || {}
}
/**
* 转换pointlist类型数据到series的data可用的数据
*/
export const transformPointListData = pointlist => {
if (!pointlist) {
return []
}
return pointlist.map(({ x, y }) => [x, y])
}

View File

@ -36,6 +36,7 @@
<span @click="handleChangeMarkLine('next')">&gt;</span>
</p>
<custom-table
size="small"
:class="list.length ? 'has-data' : ''"
:list="list"
:columns="columns"
@ -215,6 +216,7 @@ import Response from './Response.json'
import { updateBaseLine } from '@/utils/WasmHelper'
import RectList from './components/RectList.vue'
import { isNullOrUndefined } from '@/utils/util'
import { getLineData, transformPointListData } from '@/utils/sampleHelper'
//
const initialOption = {
@ -223,7 +225,7 @@ const initialOption = {
left: 40,
right: 30,
bottom: 30,
containLabel: true
containLabel: true,
},
title: {
text: '',
@ -234,39 +236,39 @@ const initialOption = {
rich: {
a: {
padding: [0, 20, 0, 0],
fontSize: 16
}
}
}
fontSize: 16,
},
},
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
color: '#3CAEBB',
width: 1
}
width: 1,
},
},
formatter: undefined,
className: 'figure-chart-option-tooltip'
className: 'figure-chart-option-tooltip',
},
xAxis: {
axisLine: {
lineStyle: {
color: '#ade6ee'
}
color: '#ade6ee',
},
},
splitLine: {
show: false
show: false,
},
axisLabel: {
textStyle: {
color: '#ade6ee'
}
color: '#ade6ee',
},
},
min: 1,
max: 'dataMax',
animation: false
animation: false,
},
yAxis: {
type: 'log',
@ -275,31 +277,31 @@ const initialOption = {
nameGap: 40,
nameTextStyle: {
color: '#8FD4F8',
fontSize: 16
fontSize: 16,
},
axisLine: {
show: true,
lineStyle: {
color: '#ade6ee'
}
color: '#ade6ee',
},
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(173, 230, 238, .2)'
}
color: 'rgba(173, 230, 238, .2)',
},
},
axisLabel: {
textStyle: {
color: '#ade6ee'
}
color: '#ade6ee',
},
},
min: 0.1,
max: 'dataMax',
animation: false
animation: false,
},
series: [],
brush: {}
brush: {},
}
const columns = [
@ -308,61 +310,62 @@ const columns = [
customRender: (_, __, index) => {
return index + 1
},
width: 60
width: 60,
},
{
title: 'Energy (keV)',
dataIndex: 'energy',
width: 120,
customRender: text => {
customRender: (text) => {
return text.toFixed(3)
}
},
},
{
title: 'Centroid (C)',
dataIndex: 'peakCentroid',
width: 120,
customRender: text => {
customRender: (text) => {
return text.toFixed(3)
}
},
},
{
title: 'FWHM (keV)',
dataIndex: 'fwhm',
width: 120,
customRender: text => {
customRender: (text) => {
return text.toFixed(3)
}
},
},
{
title: 'Area',
dataIndex: 'area',
width: 120,
customRender: text => {
customRender: (text) => {
return text.toFixed(3)
}
},
},
{
title: 'Detectability',
dataIndex: 'significance',
width: 120,
customRender: text => {
customRender: (text) => {
return text.toFixed(3)
}
},
},
{
title: '#Cmnt',
dataIndex: 'comments',
width: 120
width: 120,
},
{
title: 'Nuclides',
dataIndex: 'nuclides',
width: 120,
customRender: text => {
ellipsis: true,
customRender: (text) => {
return text && text.join(';')
}
}
},
},
]
//
@ -371,43 +374,43 @@ const thumbnailOption = {
top: 0,
left: 5,
right: 5,
bottom: 0
bottom: 0,
},
xAxis: {
type: 'category',
axisLine: {
show: false
show: false,
},
splitLine: {
show: false
show: false,
},
axisLabel: {
show: false
show: false,
},
min: 1,
max: 'dataMax'
max: 'dataMax',
},
yAxis: {
type: 'value',
axisLine: {
show: false
show: false,
},
splitLine: {
show: false
show: false,
},
axisLabel: {
show: false
show: false,
},
min: 0.1,
max: 'dataMax'
max: 'dataMax',
},
series: null
series: null,
}
const nuclideIdentifyModal = {
possibleNuclide: '',
tolerance: 0.5,
identifiedNuclide: ''
identifiedNuclide: '',
}
//
@ -415,7 +418,7 @@ const Operators = {
ADD: 1, //
REMOVE: 2, //
MODIFY: 3, //
SLOPE_CHANGE: 4 // slope
SLOPE_CHANGE: 4, // slope
}
export default {
@ -428,7 +431,7 @@ export default {
NuclideReviewModal,
GeneralCommentModal,
EditSlopeModal,
RectList
RectList,
},
data() {
this.columns = columns
@ -477,66 +480,47 @@ export default {
isReploting: false,
operationStack: [], //
replotNeeded: false
replotNeeded: false,
}
},
created() {
this.option.tooltip.formatter = params => {
this.option.tooltip.formatter = (params) => {
const channel = parseInt(params[0].value[0])
const energy = this.energy[channel - 1]
const energy = this.energy.pointlist ? this.energy.pointlist[channel - 1].x : 0
return `<div class="channel">Channel: ${channel}</div>
<div class="energy">${isNullOrUndefined(energy) ? '' : `Energy: ${energy.toFixed(2)}`}</div>`
}
},
methods: {
async getInfo() {
try {
this.isLoading = true
this.option.series = []
this.thumbnailOption.series = []
this.list = []
this.model = cloneDeep(nuclideIdentifyModal)
const { success, result, message } = await getAction('/gamma/InteractiveTool', {
sampleId: this.sampleId,
fileName: this.fileName
})
const { inputFileName } = this.sampleData
// const { success, result, message } = cloneDeep(Response)
if (success) {
this.isLoading = false
const currSampleDetailInfo = await this.$store.dispatch('GET_SAMPLE_DATA', inputFileName)
const {
barChart,
channelBaseCPChart,
channelBaseLineChart,
channelCountChart,
channelPeakChart,
energy,
table,
BaseCtrls,
FitBaseLine
} = result
data: { allData, shadowChannelChart, shapeChannelData, peak },
} = currSampleDetailInfo
console.log('%c [ ]-374', 'font-size:13px; background:pink; color:#bf2c9f;', result)
const channelBaseLine = getLineData(allData, 'BaseLine', 'channel')
const channelPeakGroup = getLineData(allData, 'Peak', 'channel', true)
this.channelBaseCPChart = channelBaseCPChart
this.channelBaseLineChart = channelBaseLineChart
this.channelCountChart = channelCountChart
this.channelPeakChart = channelPeakChart
this.energy = energy
this.BaseCtrls = BaseCtrls
this.FitBaseLine = FitBaseLine
this.barChart = barChart
const allEnergy = getLineData(allData, 'Energy', 'energy')
this.setChartOption(channelBaseLineChart, channelCountChart, channelPeakChart, channelBaseCPChart, barChart)
this.list = table
} else {
this.$message.error(message)
}
} catch (error) {
console.error(error)
}
this.channelBaseCPChart = shapeChannelData
this.channelBaseLineChart = channelBaseLine
this.channelCountChart = shadowChannelChart
this.channelPeakChart = channelPeakGroup
this.energy = allEnergy
// this.BaseCtrls = BaseCtrls
// this.FitBaseLine = FitBaseLine
this.barChart = shadowChannelChart
this.setChartOption(channelBaseLine, shadowChannelChart, channelPeakGroup, shapeChannelData, shadowChannelChart)
this.list = peak
},
setChartOption(baseLine, count, peaks, baseCP, bar) {
@ -554,7 +538,7 @@ export default {
// 线
series.push(this.buildCtrlPoint(baseCP))
this.thumbnailOption.series = this.buildBarChart(bar)
// this.thumbnailOption.series = this.buildBarChart(bar)
this.option.series = series
},
@ -573,10 +557,6 @@ export default {
},
beforeModalOpen() {
const { sampleId, inputFileName } = this.sampleData
this.sampleId = sampleId
this.fileName = inputFileName
this.getInfo()
this.reset()
},
@ -640,7 +620,7 @@ export default {
left = channel
}
const peaksBetweenChannel = this.list.filter(peak => {
const peaksBetweenChannel = this.list.filter((peak) => {
const centroidId = peak.peakCentroid
return centroidId >= left && centroidId <= right
})
@ -672,7 +652,7 @@ export default {
const maxXAxises = this.getPeakMaxValues()
if (direction == 'next') {
// prevAxisxAxis
const find = maxXAxises.find(xAxis => xAxis > prevAxis)
const find = maxXAxises.find((xAxis) => xAxis > prevAxis)
if (find) {
markLineOption.xAxis = find
}
@ -680,7 +660,7 @@ export default {
// prevAxisxAxis
const find = cloneDeep(maxXAxises)
.reverse()
.find(xAxis => xAxis < prevAxis)
.find((xAxis) => xAxis < prevAxis)
if (find) {
markLineOption.xAxis = find
}
@ -688,11 +668,24 @@ export default {
const xAxis = markLineOption.xAxis
if (xAxis >= 0) {
const index = maxXAxises.findIndex(item => item == xAxis)
const index = maxXAxises.findIndex((item) => item == xAxis)
if (index !== -1) {
this.selectedKeys = [this.list[index].index]
}
}
const { xAxis: chartXAxisOption } = this.option
const { max, min } = chartXAxisOption
//
if (xAxis >= max || xAxis <= min) {
const halfDiff = (max - min) / 2
const lastChannel = this.channelCountChart.pointlist[this.channelCountChart.pointlist.length - 1].x
let nextMax = xAxis + halfDiff
let nextMin = xAxis - halfDiff
chartXAxisOption.max = nextMax > lastChannel ? lastChannel : nextMax
chartXAxisOption.min = nextMin < 1 ? 1 : nextMin
}
},
// possible nuclide identified nuclide
@ -703,10 +696,11 @@ export default {
if (!row._possible) {
this.$set(row, '_loading', true)
try {
const { sampleId, inputFileName: fileName } = this.sampleData
const { success, result, message } = await getAction('/gamma/getSelPosNuclide', {
sampleId: this.sampleId,
sampleId,
channel: parseInt(row.peakCentroid),
fileName: this.fileName
fileName,
})
if (success) {
const { possible } = result
@ -724,9 +718,9 @@ export default {
// Channel
getPeakMaxValues() {
const maxXAxises = this.channelPeakChart.map(item => {
const allY = item.pointlist.map(point => point.y)
const max = item.pointlist.find(point => point.y == Math.max(...allY))
const maxXAxises = this.channelPeakChart.map((item) => {
const allY = item.pointlist.map((point) => point.y)
const max = item.pointlist.find((point) => point.y == Math.max(...allY))
return max.x
})
return maxXAxises
@ -772,7 +766,7 @@ export default {
shadowEnergyChart,
shapeChannelData,
shapeEnergyData,
table
table,
} = result
this.$bus.$emit('gammaRefresh', {
@ -781,7 +775,7 @@ export default {
shadowChannelChart,
shadowEnergyChart,
shapeChannelData,
shapeEnergyData
shapeEnergyData,
})
this.channelPeakChart = channelPeakChart
@ -828,8 +822,8 @@ export default {
content: 'Are you sure to delete this peak?',
cancelButtonProps: {
props: {
type: 'warn'
}
type: 'warn',
},
},
onOk: async () => {
// this.list.splice(findIndex, 1)
@ -850,7 +844,7 @@ export default {
const { inputFileName: fileName } = this.sampleData
const { success, result, message } = await getAction('/gamma/deletePeak', {
fileName,
curRow: this.curRow
curRow: this.curRow,
})
if (success) {
const {
@ -860,7 +854,7 @@ export default {
shadowEnergyChart,
shapeChannelData,
shapeEnergyData,
table
table,
} = result
this.$bus.$emit('gammaRefresh', {
@ -869,7 +863,7 @@ export default {
shadowChannelChart,
shadowEnergyChart,
shapeChannelData,
shapeEnergyData
shapeEnergyData,
})
this.channelPeakChart = channelPeakChart
@ -896,7 +890,7 @@ export default {
} catch (error) {
console.error(error)
}
}
},
})
},
@ -928,6 +922,19 @@ export default {
this.option.series[0].markLine.data[0].xAxis = channel
const { xAxis: chartXAxisOption } = this.option
const { max, min } = chartXAxisOption
//
if (channel >= max || channel <= min) {
const halfDiff = (max - min) / 2
const lastChannel = this.channelCountChart.pointlist[this.channelCountChart.pointlist.length - 1].x
let nextMax = channel + halfDiff
let nextMin = channel - halfDiff
chartXAxisOption.max = nextMax > lastChannel ? lastChannel : nextMax
chartXAxisOption.min = nextMin < 1 ? 1 : nextMin
}
this.getSelPosNuclide(row)
this.selectedTableItem = row
@ -946,8 +953,8 @@ export default {
key: 'brush',
brushOption: {
// brush brushType false
brushType: 'rect'
}
brushType: 'rect',
},
})
},
@ -962,12 +969,12 @@ export default {
//
chart.dispatchAction({
type: 'brush',
areas: []
areas: [],
})
//
chart.dispatchAction({
type: 'takeGlobalCursor'
type: 'takeGlobalCursor',
})
},
@ -978,8 +985,8 @@ export default {
if (areas) {
const range = areas.range
const [[minX, maxX], [minY, maxY]] = range
const point1 = chart.convertFromPixel({ seriesIndex: 0 }, [minX, minY]).map(num => parseInt(num.toFixed()))
const point2 = chart.convertFromPixel({ seriesIndex: 0 }, [maxX, maxY]).map(num => parseInt(num.toFixed()))
const point1 = chart.convertFromPixel({ seriesIndex: 0 }, [minX, minY]).map((num) => parseInt(num.toFixed()))
const point2 = chart.convertFromPixel({ seriesIndex: 0 }, [maxX, maxY]).map((num) => parseInt(num.toFixed()))
const xAxisMax = chart.getModel().getComponent('xAxis').axis.scale._extent[1]
const yAxisMax = this.option.yAxis.max
let [x1, y2, x2, y1] = [...point1, ...point2] //
@ -1036,7 +1043,7 @@ export default {
this.baseCtrls_Copy.baseline.map((val, index) => [index + 1, val]),
this.FitBaseLine,
{
zlevel: 21
zlevel: 21,
}
)
this.option.series.push(baseLineEditSeries)
@ -1050,13 +1057,13 @@ export default {
this.btnGroupType = 1
this.opts.notMerge = true
const baseLineEditSeries = findSeriesByName(this.option.series, 'BaseLine_Edit')
const index = this.option.series.findIndex(item => item == baseLineEditSeries)
const index = this.option.series.findIndex((item) => item == baseLineEditSeries)
this.option.series.splice(index, 1)
this.clearRect()
const baseLineSeries = findSeriesByName(this.option.series, 'BaseLine')
baseLineSeries.data = this.channelBaseLineChart.pointlist.map(({ x, y }) => [x, y]) // 线
baseLineSeries.data = transformPointListData(this.channelBaseLineChart.pointlist) // 线
const baseLineCP = findSeriesByName(this.option.series, 'BaseLine_Ctrl_Point')
baseLineCP.data = this.buildCPPointData(this.channelBaseCPChart)
@ -1096,7 +1103,7 @@ export default {
this.isModifying = false
this.pushOperationStack(Operators.MODIFY, {
index,
prevYAxis
prevYAxis,
})
},
@ -1120,7 +1127,7 @@ export default {
// Peaks
redrawPeaks(peakList) {
this.option.series = this.option.series.filter(item => {
this.option.series = this.option.series.filter((item) => {
return !item.name.includes('Peak_')
})
this.option.series.push(...this.buildPeaks(peakList))
@ -1196,7 +1203,7 @@ export default {
index: i,
removeXAxis,
removeYAxis,
removeYSlope
removeYSlope,
})
},
@ -1232,7 +1239,7 @@ export default {
this.$refs.editSlopeModal.open({
index: i,
value: yslope[i],
allowNaN: !(i == 0 || i == n - 1)
allowNaN: !(i == 0 || i == n - 1),
})
},
@ -1246,7 +1253,7 @@ export default {
yslope[index] = slope
this.pushOperationStack(Operators.SLOPE_CHANGE, {
index,
slope: prevSlope
slope: prevSlope,
})
this.redrawBaseLine()
this.buildRect()
@ -1269,7 +1276,7 @@ export default {
const { success, result, message } = await postAction('/gamma/replotBaseLine', {
...this.baseCtrls_Copy,
fileName,
replotNeeded: this.replotNeeded
replotNeeded: this.replotNeeded,
})
if (success) {
const { chartData, peakSet, shapeData } = result
@ -1288,8 +1295,8 @@ export default {
color,
point: {
x: xAxis,
y: yctrl[index]
}
y: yctrl[index],
},
}
})
baseLineCP.data = this.buildCPPointData(baseCPPoints)
@ -1323,8 +1330,8 @@ export default {
itemStyle: {
color: 'transparent',
borderColor: color,
borderWidth: size / 2
}
borderWidth: size / 2,
},
}
})
},
@ -1358,7 +1365,7 @@ export default {
this.isAccepting = true
const { success, result, message } = await postAction('/gamma/acceptBaseLine', {
...this.baseCtrls_Copy,
fileName
fileName,
})
if (success) {
this.BaseCtrls = cloneDeep(this.baseCtrls_Copy)
@ -1372,7 +1379,7 @@ export default {
shadowEnergyChart,
shapeChannelData,
shapeData,
shapeEnergyData
shapeEnergyData,
} = result
this.channelBaseLineChart = channelBaseLineChart
@ -1416,7 +1423,7 @@ export default {
curRow: this.curRow,
nuclideName: possibleNuclide,
fileName,
list_identify: nuclides
list_identify: nuclides,
})
if (success) {
nuclides.push(possibleNuclide)
@ -1439,7 +1446,7 @@ export default {
if (this.selectedTableItem._deleting) {
return
}
const findIndex = nuclides.findIndex(nuclide => nuclide == this.model.identifiedNuclide)
const findIndex = nuclides.findIndex((nuclide) => nuclide == this.model.identifiedNuclide)
if (-1 !== findIndex) {
try {
this.$set(this.selectedTableItem, '_deleting', true)
@ -1448,7 +1455,7 @@ export default {
curRow: this.curRow,
nuclideName: this.model.identifiedNuclide,
fileName,
list_identify: nuclides
list_identify: nuclides,
})
if (success) {
nuclides.splice(findIndex, 1)
@ -1467,43 +1474,35 @@ export default {
buildBaseLine(channelBaseLineChart) {
return buildLineSeries(
'BaseLine',
channelBaseLineChart.pointlist.map(({ x, y }) => [x, y]),
transformPointListData(channelBaseLineChart.pointlist),
channelBaseLineChart.color,
{
markLine: {
silent: true,
symbol: 'none',
label: {
show: false
show: false,
},
lineStyle: {
color: 'red',
width: 1
width: 1,
},
data: [{ xAxis: -1 }]
data: [{ xAxis: -1 }],
},
zlevel: 10
zlevel: 10,
}
)
},
// count
buildCountLine(channelCountChart) {
return buildLineSeries(
'CountChart',
channelCountChart.pointlist.map(({ x, y }) => [x, y]),
channelCountChart.color
)
return buildLineSeries('CountChart', transformPointListData(channelCountChart.pointlist), channelCountChart.color)
},
// Peaks
buildPeaks(channelPeakChart) {
return channelPeakChart.map((item, index) => {
return buildLineSeries(
'Peak_' + (index + 1),
item.pointlist.map(({ x, y }) => [x, y]),
item.color
)
return buildLineSeries('Peak_' + (index + 1), transformPointListData(item.pointlist), item.color)
})
},
@ -1515,7 +1514,7 @@ export default {
data: this.buildCPPointData(channelBaseCPChart),
silent: true,
animation: false,
zlevel: 20
zlevel: 20,
}
},
@ -1526,7 +1525,7 @@ export default {
barChart.map(({ x, y }) => [x, y]),
'#fff',
{
silent: true
silent: true,
}
)
},
@ -1539,7 +1538,7 @@ export default {
pushOperationStack(operator, operand) {
this.operationStack.push({
operator,
operand
operand,
})
},
@ -1584,19 +1583,19 @@ export default {
*/
clearOperationStack() {
this.operationStack = []
}
},
},
computed: {
curRow() {
const [selectedKey] = this.selectedKeys
const findIndex = this.list.findIndex(item => item.index == selectedKey)
const findIndex = this.list.findIndex((item) => item.index == selectedKey)
return findIndex
},
isOperationStackEmpty() {
return this.operationStack.length == 0
}
}
},
},
}
</script>