85 lines
3.0 KiB
JavaScript
85 lines
3.0 KiB
JavaScript
import { col } from '../csv.js';
|
|
import {
|
|
PALETTE, FINANCIAL_COLORS, FONT, axisCommon, periodAxis, titleStyle, legendStyle,
|
|
lineSeries, footnote, watermarks, LAYOUT,
|
|
} from '../theme.js';
|
|
|
|
/** 泡泡玛特营运资本效率:存货、应收、应付与现金转换周期。 */
|
|
const SERIES = [
|
|
{ key: 'inventory_days', name: '存货周转天数', color: FINANCIAL_COLORS.financingCashFlow, width: 2.4 },
|
|
{ key: 'receivable_days', name: '应收周转天数', color: FINANCIAL_COLORS.investingCashFlow, width: 2.2 },
|
|
{ key: 'payable_days', name: '应付周转天数', color: FINANCIAL_COLORS.cashConversion, width: 2.2 },
|
|
{ key: 'cash_conversion_cycle', name: '现金转换周期', color: FINANCIAL_COLORS.netCashIncrease, width: 3.2 },
|
|
];
|
|
|
|
/**
|
|
* 同一期间的多条线将标签放到离最近相邻值更远的一侧,确保每个数值都可见。
|
|
*/
|
|
function labeledData(rows, key) {
|
|
return rows.map((row) => {
|
|
const value = row[key];
|
|
const ranked = SERIES.map((series) => row[series.key]).sort((a, b) => b - a);
|
|
const rank = ranked.indexOf(value);
|
|
const gapUp = rank > 0 ? ranked[rank - 1] - value : Infinity;
|
|
const gapDown = rank < ranked.length - 1 ? value - ranked[rank + 1] : Infinity;
|
|
|
|
return {
|
|
value,
|
|
label: { position: gapUp >= gapDown ? 'top' : 'bottom', distance: 9 },
|
|
};
|
|
});
|
|
}
|
|
|
|
export function workingCapitalDaysChart(rows, { width, height }) {
|
|
return {
|
|
backgroundColor: '#fff',
|
|
title: {
|
|
...titleStyle,
|
|
text: '泡泡玛特营运资本效率',
|
|
subtext: '现金转换周期 = 存货周转天数 + 应收周转天数 − 应付周转天数(中报按181天、年报按365天)',
|
|
},
|
|
legend: { ...legendStyle, top: LAYOUT.legendTop, data: SERIES.map((item) => item.name) },
|
|
grid: { left: 78, right: 42, top: LAYOUT.gridTop, bottom: 90 },
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
textStyle: { fontFamily: FONT },
|
|
valueFormatter: (value) => `${value.toFixed(1)} 天`,
|
|
},
|
|
xAxis: { ...periodAxis, data: col(rows, 'period') },
|
|
yAxis: {
|
|
...axisCommon,
|
|
type: 'value',
|
|
name: '天数',
|
|
nameLocation: 'middle',
|
|
nameGap: 42,
|
|
nameTextStyle: { color: PALETTE.grey, fontSize: 13, fontFamily: FONT },
|
|
min: 0,
|
|
},
|
|
series: SERIES.map((item) => ({
|
|
...lineSeries({
|
|
name: item.name,
|
|
data: labeledData(rows, item.key),
|
|
color: item.color,
|
|
formatter: (p) => p.value.toFixed(0),
|
|
width: item.width,
|
|
}),
|
|
label: {
|
|
show: true,
|
|
color: item.color,
|
|
fontFamily: FONT,
|
|
fontSize: 11,
|
|
fontWeight: 500,
|
|
formatter: (p) => `${p.value.toFixed(0)}天`,
|
|
textBorderColor: '#fff',
|
|
textBorderWidth: 3,
|
|
},
|
|
labelLayout: { hideOverlap: true },
|
|
z: item.key === 'cash_conversion_cycle' ? 10 : 1,
|
|
})),
|
|
graphic: [
|
|
...watermarks(width, height),
|
|
footnote('数据来源:泡泡玛特财务指标(合并报表);原始180/360天口径已换算为181/365天 | @思考的Joey'),
|
|
],
|
|
};
|
|
}
|