Standardize financial chart colors and improve label placement
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
import { col } from '../csv.js';
|
||||
import {
|
||||
PALETTE, FONT, axisCommon, periodAxis, titleStyle, legendStyle,
|
||||
PALETTE, FINANCIAL_COLORS, FONT, axisCommon, periodAxis, titleStyle, legendStyle,
|
||||
lineSeries, footnote, watermarks, LAYOUT,
|
||||
} from '../theme.js';
|
||||
|
||||
/** 泡泡玛特营运资本效率:存货、应收、应付与现金转换周期。 */
|
||||
export function workingCapitalDaysChart(rows, { width, height }) {
|
||||
const series = [
|
||||
{ key: 'inventory_days', name: '存货周转天数', color: PALETTE.orange, width: 2.4 },
|
||||
{ key: 'receivable_days', name: '应收周转天数', color: PALETTE.blue, width: 2.2 },
|
||||
{ key: 'payable_days', name: '应付周转天数', color: PALETTE.purple, width: 2.2 },
|
||||
{ key: 'cash_conversion_cycle', name: '现金转换周期', color: PALETTE.red, width: 3.2 },
|
||||
];
|
||||
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: {
|
||||
@@ -20,7 +38,7 @@ export function workingCapitalDaysChart(rows, { width, height }) {
|
||||
text: '泡泡玛特营运资本效率',
|
||||
subtext: '现金转换周期 = 存货周转天数 + 应收周转天数 − 应付周转天数',
|
||||
},
|
||||
legend: { ...legendStyle, top: LAYOUT.legendTop, data: series.map((item) => item.name) },
|
||||
legend: { ...legendStyle, top: LAYOUT.legendTop, data: SERIES.map((item) => item.name) },
|
||||
grid: { left: 78, right: 42, top: LAYOUT.gridTop, bottom: 90 },
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
@@ -37,17 +55,25 @@ export function workingCapitalDaysChart(rows, { width, height }) {
|
||||
nameTextStyle: { color: PALETTE.grey, fontSize: 13, fontFamily: FONT },
|
||||
min: 0,
|
||||
},
|
||||
series: series.map((item) => ({
|
||||
series: SERIES.map((item) => ({
|
||||
...lineSeries({
|
||||
name: item.name,
|
||||
data: col(rows, item.key),
|
||||
data: labeledData(rows, item.key),
|
||||
color: item.color,
|
||||
formatter: (p) => p.value.toFixed(0),
|
||||
width: item.width,
|
||||
}),
|
||||
label: item.key === 'cash_conversion_cycle'
|
||||
? { show: true, color: item.color, fontFamily: FONT, fontSize: 11, formatter: (p) => `${p.value.toFixed(0)}天` }
|
||||
: { show: false },
|
||||
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: [
|
||||
|
||||
Reference in New Issue
Block a user