diff --git a/src/api/uni-halo.ts b/src/api/uni-halo.ts index f250042..a53b0b6 100644 --- a/src/api/uni-halo.ts +++ b/src/api/uni-halo.ts @@ -470,7 +470,8 @@ export function getCommentWidgetCaptcha() { export interface IDataStatistics { tags: { name: string, count: number }[] categories: { name: string, total: number }[] - articles: { date: string, count: number }[] + /** 发布趋势:articleTotal=当日文章数,momentTotal=当日瞬间数,total=二者之和 */ + articles: { date: string, articleTotal: number, momentTotal: number, name: string, total: number }[] comments: { username: string, count: number }[] top10Articles: { name: string, views: number }[] [key: string]: unknown diff --git a/src/components/uh-heatmap/uh-heatmap.vue b/src/components/uh-heatmap/uh-heatmap.vue index 8f92c54..500b7a0 100644 --- a/src/components/uh-heatmap/uh-heatmap.vue +++ b/src/components/uh-heatmap/uh-heatmap.vue @@ -21,7 +21,8 @@ const weeks = ['一', '二', '三', '四', '五', '六', '日'] const currentYear = ref(new Date().getFullYear()) const currentMonth = ref(new Date().getMonth() + 1) -const intensityColors = ['#ebedf0', '#dbeafe', '#93c5fd', '#3b82f6', '#1e40af'] +/** 颜色分级(主题色系黄绿渐变,由浅到深) */ +const intensityColors = ['#ebedf0', '#f4fad8', '#e9f79f', '#d7ee52', '#b9e424'] const yearOptions = computed(() => { const years = new Set() @@ -58,9 +59,16 @@ const daysInYear = computed(() => { : 366 }) +/** 单元格:日粒度,isEmpty=前置空位(非本年日期) */ +interface IHeatmapCell { + date: string + count: number + isEmpty: boolean +} + /** 单元格列表:前置空位 + 全年每日 */ -const displayCells = computed(() => { - const cells: { date: string, count: number, isEmpty: boolean }[] = [] +const displayCells = computed(() => { + const cells: IHeatmapCell[] = [] for (let i = 0; i < firstDayOffset.value; i++) { cells.push({ date: '', count: 0, isEmpty: true }) } @@ -71,6 +79,31 @@ const displayCells = computed(() => { return cells }) +/** 按周分组为列(每列 7 天,周一~周日;跨年补足空位),列不换行,横向滚动 */ +const weekColumns = computed(() => { + const cells = displayCells.value + const columns: IHeatmapCell[][] = [] + for (let i = 0; i < cells.length; i += 7) { + columns.push(cells.slice(i, i + 7)) + } + return columns +}) + +/** 每列顶部月份标签:取该列第一个非空日期所属月份,与上一列同月则空占位(保证列高一致) */ +const columnMonths = computed(() => { + let lastMonth = -1 + return weekColumns.value.map((column) => { + const firstReal = column.find(cell => !cell.isEmpty) + if (!firstReal) + return '' + const month = dayjs(firstReal.date).month() + if (month === lastMonth) + return '' + lastMonth = month + return `${month + 1}月` + }) +}) + /** 颜色分级 */ function getDayColor(day: { count: number, isEmpty: boolean }): string { if (day.isEmpty) @@ -98,15 +131,6 @@ const totalCount = computed(() => props.chartData.reduce((sum, item) => sum + it /** 本年总数 */ const currentYearCount = computed(() => Object.values(yearDataMap.value).reduce((sum, n) => sum + n, 0)) -/** 月份标签(按 5 周跨度取整月位置,简化:每两月一个标签) */ -const monthLabels = computed(() => { - const labels: { index: number, name: string }[] = [] - for (let m = 0; m < 12; m++) { - labels.push({ index: m * 5, name: `${m + 1}月` }) - } - return labels -}) - function changeYear(value: number) { currentYear.value = value } @@ -132,27 +156,27 @@ function changeYear(value: number) { - - + + + + {{ week }} - - - - {{ month.name }} + + + + + + + {{ columnMonths[ci] }} + + + - - - - + @@ -181,8 +205,8 @@ function changeYear(value: number) { background-color: #f5f5f5; &.active { - color: #fff; - background-color: #03a9f4; + color: #303133; + background-color: #b9e424; } } } diff --git a/src/pages-blog/about/about.vue b/src/pages-blog/about/about.vue index a55cb58..4c28153 100644 --- a/src/pages-blog/about/about.vue +++ b/src/pages-blog/about/about.vue @@ -83,7 +83,7 @@ :style="{ backgroundColor: `${link.tileColor}1A` }"> {{ link.tileLetter }} - + {{ link.title }} {{ link.value }} diff --git a/src/pages-blog/data-visual/data-visual.vue b/src/pages-blog/data-visual/data-visual.vue index 8c3124d..bc0d564 100644 --- a/src/pages-blog/data-visual/data-visual.vue +++ b/src/pages-blog/data-visual/data-visual.vue @@ -41,13 +41,20 @@ }) /* ---------------- 图表配置 ---------------- */ - const chartColors = ['#3B82F6', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#14B8A6', '#F97316', '#ea7ccc', '#0EA5E9'] + /** 主题色(与 style/index.scss 的 --wot-color-theme 保持一致) */ + const themeColor = '#b9e424' + /** 图表系列色板:以主题色为基调配色,黄→绿→青相邻色系,避免杂乱 */ + const chartColors = [themeColor, '#8bc34a', '#4caf50', '#26a69a', '#ffd54f', '#d4e157', '#66bb6a', '#9ccc65', '#00bcd4', '#ffb300'] /** 标签统计(环形图) */ const tagChart = ref({ isExpand: true, type: 'ring', data: { series: [{ data: [] as { name : string, value : number }[] }] }, + /** 环形图中间标题(默认会被 uCharts 填充"收益率",需显式覆盖) */ + title: { name: '', fontSize: 13, color: '#909399' }, + /** 环形图中间数值 */ + subtitle: { name: '', fontSize: 24, color: themeColor }, }) /** 分类统计(柱状图) */ @@ -79,8 +86,11 @@ }) /* ---------------- 数据处理 ---------------- */ + /** 环形图最大展示标签数(标签过多时扇区过密,占比难读) */ + const TAG_CHART_TOP_N = 8 + function handleTagChart() { - const data = [...statistics.value.tags].sort((a, b) => b.count - a.count) + const data = [...statistics.value.tags].sort((a, b) => b.count - a.count).slice(0, TAG_CHART_TOP_N) tagChart.value.data = { series: [ { @@ -88,6 +98,10 @@ }, ], } + // 中间文案:文章总数(articles 按日 articleTotal 求和,避免多标签文章重复计数) + const total = statistics.value.articles.reduce((sum, item) => sum + item.articleTotal, 0) + tagChart.value.title = { name: '文章总数', fontSize: 13, color: '#909399' } + tagChart.value.subtitle = { name: `${total} 篇`, fontSize: 24, color: themeColor } } function handleCategoriesChart() { @@ -101,7 +115,7 @@ function handleTrendArticlesChart() { trandArticleChart.value.data = statistics.value.articles.map(item => ({ date: item.date, - count: item.count, + count: item.articleTotal, })) } @@ -202,7 +216,7 @@ + :opts="{ color: chartColors, padding: [5, 5, 5, 5], dataLabel: false, legend: { show: false }, title: tagChart.title, subtitle: tagChart.subtitle, extra: { ring: { ringWidth: 36, offsetAngle: -90, border: true, borderWidth: 1, borderColor: '#FFFFFF' } } }" /> @@ -220,7 +234,7 @@ + :opts="{ color: chartColors, padding: [20, 15, 10, 15], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 6 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" /> @@ -255,7 +269,7 @@ + :opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" /> @@ -273,7 +287,7 @@ + :opts="{ color: chartColors, padding: [20, 15, 10, 10], legend: { show: false }, xAxis: { disableGrid: true, fontSize: 10, itemCount: 5 }, yAxis: { gridType: 'dash', dashLength: 4 }, extra: { column: { type: 'group', width: 22, linearType: 'custom', seriesGap: 5, barBorderCircle: true, customColor: [themeColor] } } }" />