fix: 修复Beta 2D图表右侧色盘选择颜色逻辑不正确问题

This commit is contained in:
Xu Zhimeng 2023-10-18 16:15:17 +08:00
parent 7bc449d0ce
commit edf91d5e74
2 changed files with 57 additions and 56 deletions

View File

@ -24,8 +24,8 @@
@brushEnd="handleBrushEnd" @brushEnd="handleBrushEnd"
/> />
<div class="bar"> <div class="bar">
<color-palette v-model="currCount" :maxValue="4" /> <color-palette v-model="currCount" />
<div>{{ currCount + 1 }}</div> <div>{{ currCount }}</div>
<div class="bar-main"></div> <div class="bar-main"></div>
<div>0</div> <div>0</div>
</div> </div>
@ -322,8 +322,7 @@ export default {
return { return {
active: 0, active: 0,
maxCount: 15, // count currCount: 50,
currCount: 15,
twoDOption, twoDOption,
threeDSurfaceOption, threeDSurfaceOption,
@ -359,7 +358,7 @@ export default {
this.emitRangeChange([0, 256, 0, 256]) this.emitRangeChange([0, 256, 0, 256])
this.reDrawRect() this.reDrawRect()
this.rangeScatter() this.buildScatterList()
}, },
// ROI // ROI
@ -439,26 +438,33 @@ export default {
this.reDrawRect() this.reDrawRect()
this.rangeScatter() this.buildScatterList()
} }
this.clearBrush(chart) this.clearBrush(chart)
}, },
/** // scatter
* 因scatterGL 不受axis中max和min的控制手动处理溢出部分 buildScatterList() {
*/
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.twoDOption
const data = this.histogramDataList this.twoDOption.series.data = this.histogramDataDList
.filter(({ b, g, c }) => c && b >= minX && b <= maxX && g >= minY && g <= maxY) .filter(({ b, g, c }) => c && b >= minX && b <= maxX && g >= minY && g <= maxY)
.map(({ b, g, c }) => [b, g, c]) .map(({ b, g, c }) => this.buildScatterItem(b, g, c))
},
this.twoDOption.series.data = data // scatter
buildScatterItem(xAxis, yAxis, count) {
const { r, g, b } = this.interpolateColor(1 - (count / this.currCount))
return {
value: [xAxis, yAxis],
itemStyle: {
color: `rgb(${r}, ${g}, ${b})`
}
}
}, },
// //
@ -482,7 +488,7 @@ export default {
} }
this.reDrawRect() this.reDrawRect()
this.rangeScatter() this.buildScatterList()
}, },
// //
@ -713,7 +719,10 @@ export default {
}, },
// //
interpolateColor(color1, color2, percentage) { 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 r = color1.r + (color2.r - color1.r) * percentage
const g = color1.g + (color2.g - color1.g) * percentage const g = color1.g + (color2.g - color1.g) * percentage
const b = color1.b + (color2.b - color1.b) * percentage const b = color1.b + (color2.b - color1.b) * percentage
@ -723,10 +732,9 @@ export default {
watch: { watch: {
// 2D // 2D
histogramDataList: { histogramDataList: {
handler(newVal) { handler() {
this.active = 0 this.active = 0
this.twoDOption.series.data = newVal.filter(item => item.c).map(item => [item.b, item.g, item.c]) // 2D Scatter this.buildScatterList()
this.rangeScatter()
}, },
immediate: true immediate: true
}, },
@ -759,18 +767,8 @@ export default {
}, },
currCount: { currCount: {
handler(val) { handler() {
if (val <= this.maxCount) { this.buildScatterList()
const { r, g, b } = this.interpolateColor(
{ r: 255, g: 0, b: 0 },
{ r: 255, g: 255, b: 255 },
val / this.maxCount
)
this.twoDOption.series.itemStyle.color = `rgb(${r}, ${g}, ${b})`
} else {
this.twoDOption.series.itemStyle.color = '#fff'
}
}, },
immediate: true immediate: true
} }

View File

@ -23,16 +23,19 @@
</template> </template>
<script> <script>
const startRange = [0, 36], // 1
endRange = [324, 360], // 50
angleRange = [startRange]
for (let i = 0; i <= 47; i++) {
angleRange.push([36 + i * 6, 36 + (i + 1) * 6])
}
angleRange.push(endRange)
export default { export default {
props: { props: {
value: { value: {
type: Number, type: Number,
default: 1 default: 1
}, },
maxValue: {
type: Number,
default: 0
},
circleWidth: { circleWidth: {
type: Number, type: Number,
default: 26 default: 26
@ -48,7 +51,8 @@ export default {
x: 0, x: 0,
y: 0 y: 0
}, },
isMouseDown: false isMouseDown: false,
angleRange
} }
}, },
methods: { methods: {
@ -79,16 +83,23 @@ export default {
}, },
setPositionByMouseEvent(offsetX, offsetY) { setPositionByMouseEvent(offsetX, offsetY) {
const { degree, radian } = this.getDegree([offsetX, offsetY]) const { angle } = this.getDegree([offsetX, offsetY])
for (let index = 0; index < this.range; index++) { for (let i = 0; i < this.angleRange.length; i++) {
if (degree >= this.perDegree * index && degree < this.perDegree * (index + 1)) { const [start, end] = this.angleRange[i]
this.$emit('input', index) if (angle >= start && angle <= end) {
const center = (start + end) / 2
const radian = (center * Math.PI) / 180
this.setDotPosition(radian)
this.$emit('input', i + 1)
break break
} }
} }
this.setDotPosition(radian)
}, },
/**
* 设置圆点位置
* @param {*} radian
*/
setDotPosition(radian) { setDotPosition(radian) {
const circleRadius = this.circleWidth / 2 // const circleRadius = this.circleWidth / 2 //
const dotRadius = circleRadius - this.dotWidth // const dotRadius = circleRadius - this.dotWidth //
@ -102,6 +113,7 @@ export default {
/** /**
* 根据圆心和某个点计算从圆心到该点的角度 * 根据圆心和某个点计算从圆心到该点的角度
* @returns { { radian: number; angle: number; } } radian: 弧度 angle: 角度
*/ */
getDegree(point) { getDegree(point) {
// x y // x y
@ -112,13 +124,13 @@ export default {
const deltaY = pointY - circleRadius const deltaY = pointY - circleRadius
// 使 // 使
const radian = Math.atan2(deltaX, deltaY) const radian = Math.atan2(deltaX, deltaY)
let degree = radian * (180 / Math.PI) let angle = radian * (180 / Math.PI)
if (degree < 0) { if (angle < 0) {
degree = 360 + degree angle = 360 + angle
} }
return { return {
radian, radian,
degree angle
} }
} }
}, },
@ -126,22 +138,13 @@ export default {
watch: { watch: {
value: { value: {
handler(newVal) { handler(newVal) {
const degree = newVal * this.perDegree const [start, end] = this.angleRange[newVal - 1]
const radian = (degree * Math.PI) / 180 // const center = (start + end) / 2
const radian = (center * Math.PI) / 180 //
this.setDotPosition(radian) this.setDotPosition(radian)
}, },
immediate: true immediate: true
} }
},
computed: {
range() {
return this.maxValue > 50 ? this.maxValue : 50
},
perDegree() {
return 360 / this.range
}
} }
} }
</script> </script>