feat: 优化泡泡玛特的图表

This commit is contained in:
R524809
2026-09-10 17:44:09 +08:00
parent a6387f8220
commit 417116b928
14 changed files with 327 additions and 299 deletions
+18 -8
View File
@@ -5,7 +5,7 @@ import {
/**
* 泡泡玛特主要 IP 收入占比(2026H1)
* 饼图(非环图),图例放在右侧:每项上行 IP 名、下行小字显示收入和占比。
* 扇区外直接标注 IP 名 + 数值(两行)。源:ppmt.xlsx「IP收入和占比」2026H1 列,
* 扇区外直接标注 IP 名 + 数值/占比(两行),IP 名与扇区同色。源:ppmt.xlsx「IP收入和占比」2026H1 列,
* HACIPUPU、BUNNY、PUCKY 等该期无数据的 IP 不列入。
* 占比为衍生指标:各 IP 收入 ÷ 全部列入 IP 收入合计(源表占比列未填)。
*
@@ -29,18 +29,28 @@ const COLORS = [
];
export function ppmtIpShareChart(rows, { width, height }) {
const data = rows.map((row, i) => ({
name: row.ip,
value: row.revenue,
itemStyle: { color: COLORS[i % COLORS.length] },
}));
const data = rows.map((row, i) => {
const color = COLORS[i % COLORS.length];
return {
name: row.ip,
value: row.revenue,
itemStyle: { color },
// 逐扇区覆盖标签 rich:IP 名与所在区块同色,其余样式沿用系列级配置
label: {
rich: {
name: { fontFamily: FONT, fontSize: 12, fontWeight: 600, color, lineHeight: 16 },
value: { fontFamily: FONT, fontSize: 11, color: PALETTE.grey, lineHeight: 15 },
},
},
};
});
const total = data.reduce((s, d) => s + d.value, 0);
const byName = Object.fromEntries(data.map((d) => [d.name, d]));
// 把「饼图 + 两侧外标签」当成一个整体,与图例并成一组居中摆放:
// 图例紧跟在右侧标签外缘之后,不会被推到画布边缘留下大片空白
const LEGEND_WIDTH = 152; // 最宽一行「17.7 亿元 · 10.3%」约 120px + 色块
const LEGEND_GAP = 24; // 右侧标签外缘 → 图例
const LEGEND_GAP = 56; // 右侧标签外缘 → 图例;最长数值行会侵入该间隙,实测 24px 太挤
// 左右标签占位不对称:左侧文字向左延伸(text-anchor: end)要占满,
// 右侧只需容下引导线 + 首行文字起段,留太多会在图例前空出一大块
const LABEL_LEFT = 135;
@@ -105,7 +115,7 @@ export function ppmtIpShareChart(rows, { width, height }) {
data,
label: {
show: true,
formatter: (p) => `{name|${p.name}}\n{value|${p.value.toFixed(1)} 亿元}`,
formatter: (p) => `{name|${p.name}}\n{value|${p.value.toFixed(1)} 亿元 / ${p.percent.toFixed(1)}%}`,
rich: {
name: { fontFamily: FONT, fontSize: 12, color: PALETTE.ink, fontWeight: 600, lineHeight: 16 },
value: { fontFamily: FONT, fontSize: 11, color: PALETTE.grey, lineHeight: 15 },