File tree Expand file tree Collapse file tree 4 files changed +14
-6
lines changed Expand file tree Collapse file tree 4 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 1
1
< d-calendar-graph > </ d-calendar-graph >
2
- < d-calendar-graph [dateRange] ="['2019-06-01', '2020-11-01'] " text ="DevUI is excellent "> </ d-calendar-graph >
2
+ < d-calendar-graph text ="❤DevUI "> </ d-calendar-graph >
3
+ < d-calendar-graph text ="DevUI is excellent "> </ d-calendar-graph >
3
4
< router-outlet > </ router-outlet >
Original file line number Diff line number Diff line change @@ -23,9 +23,16 @@ export class CalendarGraphComponent implements OnInit {
23
23
24
24
ngOnInit ( ) {
25
25
const now = moment ( ) . format ( DEFAULT_DATE_FORMAT ) ;
26
- const lastYear = moment ( ) . subtract ( 1 , "years" ) . format ( DEFAULT_DATE_FORMAT ) ;
26
+ // 开始日期默认为最近一年
27
+ let startDate = moment ( ) . subtract ( 1 , 'years' ) . format ( DEFAULT_DATE_FORMAT ) ;
28
+
29
+ if ( this . text ) {
30
+ const symbolArray = textToSymbolArray ( this . text ) ;
31
+ // 根据文本动态计算开始日期
32
+ startDate = moment ( ) . subtract ( symbolArray . length , 'weeks' ) . format ( DEFAULT_DATE_FORMAT ) ;
33
+ }
27
34
28
- let dateRange = [ lastYear , now ] ;
35
+ let dateRange = [ startDate , now ] ;
29
36
if ( this . dateRange ) {
30
37
dateRange = getCompleteDateRange ( this . dateRange ) ;
31
38
}
Original file line number Diff line number Diff line change @@ -113,5 +113,5 @@ export const SYMBOL_MAP = {
113
113
'8' : LETTER_8 ,
114
114
'9' : LETTER_9 ,
115
115
' ' : EMPTY_WEEK ,
116
- '❤️ ' : IMG_LOVE ,
116
+ '2764 ' : IMG_LOVE , // '❤️'.charCodeAt(0).toString(16) = 2764 使用Unicode编码代替具体的符号
117
117
} ;
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export function transpose(A) {
40
40
let result = [ ] , rowItem = [ ] ;
41
41
const rows = A . length ;
42
42
const cols = A [ 0 ] . length ;
43
- for ( let i = 0 ; i < cols ; i ++ ) {
43
+ for ( let i = 0 ; i < cols ; i ++ ) {
44
44
rowItem = [ ] ;
45
45
for ( let j = 0 ; j < rows ; j ++ ) {
46
46
rowItem . push ( A [ j ] [ i ] ) ;
@@ -53,7 +53,7 @@ export function transpose(A) {
53
53
// 文字转字母数组
54
54
export function textToSymbolArray ( text ) {
55
55
return text . split ( '' ) . join ( ' ' ) . split ( '' )
56
- . map ( char => SYMBOL_MAP [ char ] )
56
+ . map ( char => SYMBOL_MAP [ char ] || SYMBOL_MAP [ char . charCodeAt ( 0 ) . toString ( 16 ) ] )
57
57
. reduce ( ( a , b ) => a . concat ( b ) , [ ] ) ;
58
58
}
59
59
You can’t perform that action at this time.
0 commit comments