Skip to content

Commit

Permalink
docs: 补充API文档
Browse files Browse the repository at this point in the history
  • Loading branch information
kagol committed Nov 3, 2020
1 parent 4434fd6 commit 917f238
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 2 deletions.
122 changes: 122 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,132 @@

生成自定义的Github提交图。

## 快速开始

``` html
<d-calendar-graph text="❤ DevUI"></d-calendar-graph>
```

## 支持的字母和符号

A-Za-z0-9❤️

## API

### dateRange

自定义日期区间

``` javascript
const dateRange = ['2020-06-01', '2020-11-03'];
```

### text

自定义显示文本

``` javascript
const text = '❤ DevUI';
const text = 'DevUI is excellent';
const text = 'Today is 20201103';
```

### contributions

1. 更灵活的配置

``` javascript
const contributionsRow = [
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 ],
[ 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1 ],
[ 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 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// g
[ 0, 1, 1, 1, 0, 0, 1 ],
[ 1, 0, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 0, 1, 0, 1 ],
[ 1, 1, 1, 1, 1, 1, 0 ],

[ 0, 0, 0, 0, 0, 0, 0 ],

// o
[ 0, 0, 1, 1, 1, 0, 0 ],
[ 0, 1, 0, 0, 0, 1, 0 ],
[ 0, 1, 0, 0, 0, 1, 0 ],
[ 0, 0, 1, 1, 1, 0, 0 ],

[ 0, 0, 0, 0, 0, 0, 0 ],

// l
[ 1, 1, 1, 1, 1, 1, 0 ],

])
```

3. 也可以使用定义好的字符变量

``` javascript
const contributions = transpose([].concat(
LETTER_I, EMPTY_WEEK, EMPTY_WEEK,
LETTER_a, EMPTY_WEEK, LETTER_m, EMPTY_WEEK, EMPTY_WEEK,
LETTER_K, EMPTY_WEEK, LETTER_a, EMPTY_WEEK, LETTER_g, EMPTY_WEEK, LETTER_o, EMPTY_WEEK, LETTER_l
));
```

## 栗子🌰

❤️ DevUI
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<d-calendar-graph></d-calendar-graph>
<d-calendar-graph text="❤DevUI"></d-calendar-graph>
<d-calendar-graph [dateRange]="['2020-06-01', '2020-11-03']"></d-calendar-graph>
<d-calendar-graph text="❤ DevUI"></d-calendar-graph>
<d-calendar-graph text="DevUI is excellent"></d-calendar-graph>
<d-calendar-graph text="Today is 20201103"></d-calendar-graph>
<d-calendar-graph [contributions]="contributions"></d-calendar-graph>
<d-calendar-graph [contributions]="contributionsRow"></d-calendar-graph>
<d-calendar-graph [contributions]="contributionsColumn"></d-calendar-graph>
<router-outlet></router-outlet>
84 changes: 83 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
import { Component } from '@angular/core';
import { transpose } from './calendar-graph/calendar.util';
import { EMPTY_WEEK, LETTER_a, LETTER_g, LETTER_I, LETTER_K, LETTER_l, LETTER_m, LETTER_o } from './shared/symbol-array';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'calendar-graph';
contributions = transpose([].concat(
LETTER_I, EMPTY_WEEK, EMPTY_WEEK,
LETTER_a, EMPTY_WEEK, LETTER_m, EMPTY_WEEK, EMPTY_WEEK,
LETTER_K, EMPTY_WEEK, LETTER_a, EMPTY_WEEK, LETTER_g, EMPTY_WEEK, LETTER_o, EMPTY_WEEK, LETTER_l
));

contributionsRow = [
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 ],
[ 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1 ],
[ 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1 ],
[ 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1 ],
[ 1, 0, 0, 0, 0, 0, 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