Skip to content

Commit

Permalink
💄 fix: 优化 tooltip 为显示次数
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Feb 13, 2021
1 parent a07d5fd commit efe48ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

## 特性

- 💄 美化文章排版样式
- 💄 优化排版格式
- 🌙 深色模式
- 🔍 增强搜索框
- 🔥 活跃日历

## 更新日志

Expand Down
9 changes: 6 additions & 3 deletions src/contentScripts/activityMap/app/Heatmap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Heatmap, G2 } from '@ant-design/charts';
import type { HeatmapConfig } from '@ant-design/charts/es/heatmap/index';
import type { G2HeatmapData } from '@/utils';
import { useDarkTheme } from '@/hooks';
import { mapDataCountToLevel } from '@/utils';

const colorMap = ['#eaecef', '#9be9a8', '#40c463', '#30a14e', '#216e39'];
const colorMapDark = ['#161b22', '#003820', '#00602d', '#1d9d47', '#26d545'];
Expand Down Expand Up @@ -50,8 +51,11 @@ const DemoHeatmap: FC<HeatMapProps> = ({ data }) => {
padding: [0, 0, 0, 20],
xField: 'week',
yField: 'day',
colorField: 'level',
color: theme === 'light' ? colorMap : colorMapDark,
colorField: 'commits',
color: (commits) => {
const level = mapDataCountToLevel(Number(commits));
return theme === 'light' ? colorMap[level] : colorMapDark[level];
},
reflect: 'y',
shape: 'boundary-polygon',
meta: {
Expand All @@ -62,7 +66,6 @@ const DemoHeatmap: FC<HeatMapProps> = ({ data }) => {
week: { type: 'cat' },
commits: { sync: true, alias: '修改次数' },
date: { type: 'cat' },
level: { alias: '活跃等级' },
},
limitInPlot: true,
yAxis: { grid: null },
Expand Down
9 changes: 3 additions & 6 deletions src/utils/activityMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface ActivityDoc {

export interface G2HeatmapData {
date: string;
level: number;
commits: number;
month: number;
day: number;
Expand Down Expand Up @@ -131,13 +130,13 @@ export const getActivityData = async () => {
* 活跃等级映射
* @param count
*/
const mapDataCountToLevel = (count: number) => {
export const mapDataCountToLevel = (count: number) => {
if (count === 0) return 0;
if (count < 2) return 1;
if (count < 5) return 2;
if (count < 10) return 3;
if (count < 20) return 4;
return 5;
// if (count < 20) return 4;
return 4;
};
/**
* 计算距今天开始是第几天
Expand Down Expand Up @@ -170,7 +169,6 @@ export const lastYearData = () => {
data.push({
date,
commits: 0,
level: 0,
month: calcDateDiff(date, 'month'),
day: dayjs(date).day(),
week: calcDateDiff(date, 'week'),
Expand Down Expand Up @@ -201,7 +199,6 @@ export const mapToHeatData = (docs: ActivityDoc[]): G2HeatmapData[] => {
return {
date,
commits: item.length,
level: mapDataCountToLevel(item.length),
month: calcDateDiff(date, 'month'),
day: dayjs(date).day(),
week: calcDateDiff(date, 'week'),
Expand Down

0 comments on commit efe48ee

Please sign in to comment.