feat: 构建泡泡玛特相关图表

This commit is contained in:
Joey
2026-08-23 21:23:41 +08:00
commit 3ae396776d
31 changed files with 3454 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
import { col } from '../csv.js';
import {
PALETTE, FONT, axisCommon, categoryAxis, titleStyle, legendStyle,
lineSeries, footnote, watermarks, LAYOUT,
} from '../theme.js';
/**
* 图 2:四条率线拆解
* 毛利率在上方独立成带,三条费用/净利率在下方交织 —— 标签交替上下放,避免叠字
*/
export function marginChart(rows, { width, height }) {
const periods = col(rows, 'period');
const pct = (p) => `${p.value}%`;
// 交替上下:偶数点在上,奇数点在下。原图就是这么处理密集标签的
const alternate = (base) => (p) => (p.dataIndex % 2 === 0 ? base : base);
return {
backgroundColor: '#fff',
title: { ...titleStyle, text: '利润率与费用率拆解(半年与年度)' },
legend: {
...legendStyle,
top: LAYOUT.legendTop,
data: ['毛利率', '销售费用率', '管理费用率', '非国际归母净利率'].map(name => ({
name,
icon: 'emptyCircle', // 全部折线图
})),
},
grid: { left: 72, right: 48, top: LAYOUT.gridTop, bottom: 62 },
tooltip: {
trigger: 'axis',
valueFormatter: (v) => `${v}%`,
textStyle: { fontFamily: FONT },
},
xAxis: { ...categoryAxis, data: periods },
yAxis: {
...axisCommon,
type: 'value',
name: '比率(%',
nameLocation: 'middle',
nameGap: 46,
nameTextStyle: { color: PALETTE.grey, fontSize: 13, fontFamily: FONT },
min: 0,
max: 80,
interval: 25,
axisLabel: { ...axisCommon.axisLabel, formatter: '{value}%' },
},
series: [
lineSeries({
name: '毛利率',
data: col(rows, 'gross_margin'),
color: PALETTE.green,
labelPosition: 'top',
formatter: pct,
}),
lineSeries({
name: '销售费用率',
data: col(rows, 'sales_expense_rate'),
color: PALETTE.orange,
labelPosition: 'top',
formatter: pct,
}),
lineSeries({
name: '管理费用率',
data: col(rows, 'admin_expense_rate'),
color: PALETTE.purple,
labelPosition: 'bottom',
formatter: pct,
}),
lineSeries({
name: '非国际归母净利率',
data: col(rows, 'non_gaap_net_margin'),
color: PALETTE.coral,
labelPosition: 'top',
formatter: pct,
}),
],
graphic: [
...watermarks(width, height),
footnote('示例数据 | @思考的Joey'),
],
};
}