This commit is contained in:
2026-07-12 00:53:38 +08:00
parent d254377951
commit 25ae6f610c
14 changed files with 1208 additions and 835 deletions
+15 -27
View File
@@ -79,7 +79,7 @@
const x = center - barWidth * 1.05 + seriesIndex * barWidth * 2.1;
const y = margin.top + chartHeight - barHeight;
return `
<rect class="chart-click" data-project="${project.id}" x="${x}" y="${y}" width="${barWidth}" height="${barHeight}" rx="5" fill="${item.color}" opacity="0.92"></rect>
<rect class="chart-click" data-project="${project.id}" data-project-unit-id="${escapeHtmlAttr(project.unitId || "")}" x="${x}" y="${y}" width="${barWidth}" height="${barHeight}" rx="5" fill="${item.color}" opacity="0.92"></rect>
<text class="bar-label" x="${x + barWidth / 2}" y="${Math.max(y - 7, 14)}" text-anchor="middle">${Math.round(value)}</text>
`;
}).join("");
@@ -88,9 +88,9 @@
const statusText = project.created ? "已上线" : "未上线";
return `
${rects}
<circle class="chart-click" data-project="${project.id}" cx="${center - 18}" cy="${statusY}" r="5" fill="${statusColor}"></circle>
<text class="axis-label chart-click" data-project="${project.id}" x="${center - 8}" y="${statusY + 4}" text-anchor="start">${statusText}</text>
<text class="axis-label chart-click" data-project="${project.id}" x="${center}" y="${height - 24}" transform="rotate(-30 ${center} ${height - 24})" text-anchor="end">${shortName}</text>
<circle class="chart-click" data-project="${project.id}" data-project-unit-id="${escapeHtmlAttr(project.unitId || "")}" cx="${center - 18}" cy="${statusY}" r="5" fill="${statusColor}"></circle>
<text class="axis-label chart-click" data-project="${project.id}" data-project-unit-id="${escapeHtmlAttr(project.unitId || "")}" x="${center - 8}" y="${statusY + 4}" text-anchor="start">${statusText}</text>
<text class="axis-label chart-click" data-project="${project.id}" data-project-unit-id="${escapeHtmlAttr(project.unitId || "")}" x="${center}" y="${height - 24}" transform="rotate(-30 ${center} ${height - 24})" text-anchor="end">${shortName}</text>
`;
}).join("");
@@ -103,33 +103,21 @@
`;
}
/**
* 集团趋势加权平均。
* 按企业项目数加权汇总各企业七日趋势,避免项目少的企业对集团曲线影响过大。
*/
function averageTrend(list, key) {
const active = list.filter((enterprise) => enterprise.stats[state.dimension].projectCount > 0);
return Array.from({ length: 7 }, (_, index) => {
if (!active.length) return 0;
const weighted = active.reduce((sum, enterprise) => {
const projects = enterprise.stats[state.dimension].projectCount;
return sum + enterprise.trend[key][index] * projects;
}, 0);
const total = active.reduce((sum, enterprise) => sum + enterprise.stats[state.dimension].projectCount, 0);
return weighted / total;
});
}
/**
* 集团三率趋势图。
* 先把企业趋势压成集团趋势,再复用通用折线图渲染方法。
*/
function renderGroupTrendChart(list) {
return renderTrendChart({
online: averageTrend(list, "online"),
usage: averageTrend(list, "usage"),
accuracy: averageTrend(list, "accuracy")
}, 1840, 112);
const trendCurve = projectMasterDataState.trendCurve;
if (trendCurve && Array.isArray(trendCurve.Date) && trendCurve.Date.length) {
return renderTrendChart({
date: trendCurve.Date,
online: trendCurve.OnlineRate || [],
usage: trendCurve.UsageRate || [],
accuracy: trendCurve.AccuracyRate || []
}, 1840, 112);
}
return '<div class="empty-state compact-empty">暂无趋势数据</div>';
}
/**
@@ -140,7 +128,7 @@
const margin = { top: 14, right: 28, bottom: 28, left: 46 };
const chartWidth = width - margin.left - margin.right;
const chartHeight = height - margin.top - margin.bottom;
const dates = ["04-21", "04-22", "04-23", "04-24", "04-25", "04-26", "04-27"];
const dates = data.date || ["06-26", "06-27", "06-28", "06-29", "06-30", "07-01", "07-02"];
const series = [
{ key: "online", label: "上线", color: COLORS.online },
{ key: "usage", label: "使用", color: COLORS.usage },