81 lines
3.2 KiB
JavaScript
81 lines
3.2 KiB
JavaScript
import { col } from '../csv.js';
|
||
import {
|
||
CHANNEL_COLORS, PALETTE, FONT, axisCommon, standalonePeriodAxis, titleStyle, standardLegend,
|
||
financialViewLabel, barSeries, stackedSharePoint, fanTinyLabelOffsets, footnote, watermarks, LAYOUT,
|
||
} from '../theme.js';
|
||
|
||
const CHANNELS = [
|
||
{ key: 'retail', name: '零售店', color: CHANNEL_COLORS.retail, labelColor: '#fff' },
|
||
{ key: 'online', name: '线上渠道', color: CHANNEL_COLORS.online, labelColor: '#fff' },
|
||
{ key: 'robot_store', name: '机器人商店', color: CHANNEL_COLORS.robotStore, labelColor: '#fff' },
|
||
{ key: 'wholesale', name: '批发及其他', color: CHANNEL_COLORS.wholesale, labelColor: PALETTE.ink },
|
||
];
|
||
|
||
/** 泡泡玛特全渠道收入占比:全部地区合并,每根柱按当期总收入归一化为 100%。 */
|
||
export function channelShareChart(rows, { width, height, view = 'all' }) {
|
||
const periods = col(rows, 'period');
|
||
const barWidth = view === 'all' ? 48 : 80;
|
||
// 绘图区像素高:画布高 − grid top 145 − grid bottom 100;轴固定 0–100%
|
||
const pxPerUnit = (height - LAYOUT.gridTop - 100) / 100;
|
||
const seriesKeys = CHANNELS.map((item) => item.key);
|
||
const rowOffsets = fanTinyLabelOffsets(rows, seriesKeys, pxPerUnit);
|
||
|
||
return {
|
||
backgroundColor: '#fff',
|
||
title: {
|
||
...titleStyle,
|
||
text: `泡泡玛特渠道收入占比(${financialViewLabel(view)})`,
|
||
subtext: '全部地区合并;归一化堆叠:每根柱为当期总收入的 100%',
|
||
},
|
||
legend: standardLegend(CHANNELS.map((item) => item.name)),
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
axisPointer: { type: 'shadow' },
|
||
textStyle: { fontFamily: FONT },
|
||
formatter: (params) => {
|
||
const row = rows[periods.indexOf(params[0].axisValue)];
|
||
return `<b>${params[0].axisValue}</b> 总收入 ${row.total_revenue.toFixed(2)} 亿元<br/>${params
|
||
.filter((item) => item.value !== null)
|
||
.slice()
|
||
.reverse()
|
||
.map((item) => `${item.marker}${item.seriesName}: ${item.value.toFixed(1)}%`)
|
||
.join('<br/>')}`;
|
||
},
|
||
},
|
||
grid: { left: 78, right: 42, top: LAYOUT.gridTop, bottom: 100 },
|
||
xAxis: { ...standalonePeriodAxis, data: periods },
|
||
yAxis: {
|
||
...axisCommon,
|
||
type: 'value',
|
||
min: 0,
|
||
max: 100,
|
||
interval: 20,
|
||
axisLabel: { ...axisCommon.axisLabel, formatter: '{value}%' },
|
||
},
|
||
series: CHANNELS.map((item, ci) => barSeries({
|
||
name: item.name,
|
||
data: rows.map((row, ri) => stackedSharePoint(row[item.key], {
|
||
pxPerUnit,
|
||
labelColor: item.labelColor,
|
||
dy: rowOffsets[ri][ci] ?? 0,
|
||
})),
|
||
color: item.color,
|
||
barWidth,
|
||
stack: 'channel-share',
|
||
label: {
|
||
show: true,
|
||
position: 'inside',
|
||
fontSize: 11,
|
||
fontFamily: FONT,
|
||
fontWeight: 500,
|
||
formatter: (point) => `${point.value.toFixed(1)}%`,
|
||
},
|
||
emphasis: { focus: 'series' },
|
||
})),
|
||
graphic: [
|
||
...watermarks(width, height),
|
||
footnote('数据来源:泡泡玛特分地区渠道收入披露(中国含港澳台);H2为单半年(全年−H1)\n线上渠道含抽盒机、天猫、抖音、自研APP及官网等 | @Joey知行记'),
|
||
],
|
||
};
|
||
}
|