-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathcell-calendar-horizontal.ts
More file actions
82 lines (73 loc) · 2 KB
/
Copy pathcell-calendar-horizontal.ts
File metadata and controls
82 lines (73 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { Chart } from '@antv/g2';
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/github-commit.json')
.then((res) => res.json())
.then((data) => {
const chart = new Chart({
container: 'container',
autoFit: true,
height: 500,
paddingTop: 150,
paddingRight: 30,
paddingBottom: 150,
paddingLeft: 70,
});
chart
.scale('x', { type: 'band' })
.scale('y', { type: 'band' })
.scale('color', {
domain: [0, 10, 20],
range: ['#BAE7FF', '#1890FF', '#0050B3'],
});
chart.axis('x', {
title: false,
tick: false,
line: false,
label: true,
labelFontSize: 12,
labelFill: '#666',
labelFormatter: (val: string) => {
if (val === '2') return 'MAY';
if (val === '6') return 'JUN';
if (val === '10') return 'JUL';
if (val === '15') return 'AUG';
if (val === '19') return 'SEP';
if (val === '24') return 'OCT';
return '';
},
});
chart.axis('y', {
title: false,
label: true,
tick: false,
grid: false,
labelFormatter: (val: string) => {
const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
return days[parseInt(val)];
},
});
chart.legend(false);
chart.interaction('tooltip', {
title: 'date',
showMarkers: false,
});
chart
.cell()
.data(data)
.encode('x', 'week')
.encode('y', 'day')
.encode('color', 'commits')
.style('inset', 0.5)
.style('stroke', (d: any) => {
if (d.lastWeek && d.lastDay) return '#404040';
if (d.lastWeek) return '#404040';
return '#fff';
})
.style('lineWidth', (d: any) => {
if (d.lastWeek || d.lastDay) return 2;
return 1;
})
.state('active', { stroke: '#000', lineWidth: 2 })
.state('inactive', { opacity: 0.6 });
chart.interaction('elementHighlight', true);
chart.render();
});