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

View File

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