Refactor financial chart implementation
This commit is contained in:
+19
-6
@@ -14,11 +14,23 @@ const STYLE_RULES = {
|
||||
};
|
||||
|
||||
function entriesFromManifest(value) {
|
||||
const ids = new Set();
|
||||
const entries = [];
|
||||
value.companies.forEach((company) => company.tabs.forEach((tab) => (tab.charts || []).forEach((chart) => {
|
||||
if (!chart.id || ids.has(chart.id)) throw new Error(`manifest 图表 id 重复或为空:${chart.id || '(空)'}`);
|
||||
ids.add(chart.id);
|
||||
value.companies.forEach((company) => {
|
||||
if (!company.chartCatalog || !Array.isArray(company.tabs)) {
|
||||
throw new Error(`公司 ${company.id || '(空)'} 缺少 chartCatalog 或 tabs`);
|
||||
}
|
||||
const chartIds = Object.keys(company.chartCatalog);
|
||||
company.tabs.forEach((tab) => {
|
||||
if (!Array.isArray(tab.chartRefs)) throw new Error(`栏目 ${tab.id} 缺少 chartRefs`);
|
||||
const refs = new Set();
|
||||
tab.chartRefs.forEach((chartId) => {
|
||||
if (!company.chartCatalog[chartId]) throw new Error(`栏目 ${tab.id} 引用了不存在的图表:${chartId}`);
|
||||
if (refs.has(chartId)) throw new Error(`栏目 ${tab.id} 重复引用图表:${chartId}`);
|
||||
refs.add(chartId);
|
||||
});
|
||||
});
|
||||
chartIds.forEach((id) => {
|
||||
const chart = company.chartCatalog[id];
|
||||
if (!getChartBuilder(chart.key)) throw new Error(`manifest 图表 ${chart.id} 引用了未注册 key:${chart.key}`);
|
||||
if (Boolean(chart.csv) === Boolean(chart.views)) {
|
||||
throw new Error(`manifest 图表 ${chart.id} 必须声明 csv 或 views 之一`);
|
||||
@@ -32,8 +44,9 @@ function entriesFromManifest(value) {
|
||||
if (!sources.every(({ csv }) => typeof csv === 'string' && csv.length > 0)) {
|
||||
throw new Error(`manifest 图表 ${chart.id} 缺少 CSV`);
|
||||
}
|
||||
sources.forEach(({ view, csv }) => entries.push({ ...chart, company, tab, view, csv }));
|
||||
})));
|
||||
sources.forEach(({ view, csv }) => entries.push({ ...chart, id, company, view, csv }));
|
||||
});
|
||||
});
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user