个股中心、涨停分析接口对接

This commit is contained in:
renzhijun
2026-01-31 16:59:33 +08:00
parent 44d8ecf318
commit 1c13386dfc
3 changed files with 459 additions and 611 deletions

View File

@@ -35,6 +35,15 @@ export default {
colorList: {
type: Array,
default: () => ['#60A5FA', '#FEC200', '#EF4444'] // 外圈、中间、中心
},
// 新增:字号配置,让组件更灵活
fontSizeConfig: {
type: Object,
default: () => ({
minSize: 12, // 最小字号
maxSize: 40, // 最大字号
scaleFactor: 0.1 // 缩放因子,越大字号差异越明显
})
}
},
data() {
@@ -113,6 +122,11 @@ export default {
// 按权重排序(权重越大,文字越大)
const sortedWords = [...this.wordData].sort((a, b) => b.value - a.value);
// 计算value的最大值和最小值用于归一化
const values = sortedWords.map(item => item.value);
this.valueMax = Math.max(...values);
this.valueMin = Math.min(...values);
// 逐个绘制文字
sortedWords.forEach((word, index) => {
this.placeWord(word, index);
@@ -124,24 +138,22 @@ export default {
const ctx = this.ctx;
// 优化1提高最大尝试次数从50→150让更多文字能找到位置
const maxAttempts = 150;
const baseFontSize = 12; // 基础字体大小
const { minSize, maxSize, scaleFactor } = this.fontSizeConfig;
// 分段计算分母适配不同value区间
const value = word.value;
const baseDenominator = 1000; // 基础分母
const interval = 500; // 区间步长
const step = 500; // 分母每次增加的步长
// ===== 核心优化:重新设计字号计算逻辑 =====
// 1. 归一化value0-1区间
let normalizedValue = 1;
if (this.valueMax !== this.valueMin) {
normalizedValue = (word.value - this.valueMin) / (this.valueMax - this.valueMin);
}
// 计算当前value所属区间动态确定分母
const intervalNum = Math.floor(value / interval);
let denominator = baseDenominator + (intervalNum * step);
// 兜底避免分母过小比如value为0时
denominator = Math.max(denominator, baseDenominator);
// 根据分段分母计算字体大小,限制最大值
const maxFontSize = 28; // 优化2适当减小最大字体从32→28节省空间
const fontSize = Math.min(baseFontSize + (value / denominator) * 16, maxFontSize);
// 2. 计算字号:基于归一化值,确保最小到最大的平滑过渡
// 公式:最小字号 + (最大字号 - 最小字号) * 归一化值 * 缩放因子
const fontSize = Math.min(
minSize + (maxSize - minSize) * normalizedValue * scaleFactor,
maxSize
);
// ==========================================
// 旋转角度:-60° 到 60°
const rotateAngle = (Math.random() - 0.5) * 120 * Math.PI / 180;
@@ -150,7 +162,7 @@ export default {
ctx.font = `${fontSize}px sans-serif`;
// 获取文字宽度和高度(用于碰撞检测)
const textWidth = ctx.measureText(word.name).width;
const textWidth = ctx.measureText(word.text || word.name).width; // 兼容text/name字段
// 优化3更精准的文字高度估算从1.2→1.05),减少无效空间
const textHeight = fontSize * 1.05;
@@ -193,7 +205,7 @@ export default {
ctx.fillStyle = color;
// 无重叠,绘制文字
this.drawTextAtPosition(word.name, x, y, rotateAngle, fontSize);
this.drawTextAtPosition(word.text || word.name, x, y, rotateAngle, fontSize);
// 记录已放置的文字信息(用于后续碰撞检测)
this.placedWords.push({
@@ -238,9 +250,9 @@ export default {
// 四个顶点坐标(相对于中心)
const points = [
{ x: -halfW, y: -halfH },
{ x: halfW, y: -halfH },
{ x: -halfW, y: halfH },
{ x: halfW, y: halfH },
{ x: -halfW, y: halfH }
{ x: halfW, y: -halfH }
];
// 旋转并平移到实际位置