Skip to content

Commit fb5b804

Browse files
first commit
0 parents  commit fb5b804

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+15963
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
14+
[*.md]
15+
max_line_length = off
16+
trim_trailing_whitespace = false

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
# Only exists if Bazel was run
8+
/bazel-out
9+
10+
# dependencies
11+
/node_modules
12+
13+
# profiling files
14+
chrome-profiler-events*.json
15+
speed-measure-plugin*.json
16+
17+
# IDEs and editors
18+
/.idea
19+
.project
20+
.classpath
21+
.c9/
22+
*.launch
23+
.settings/
24+
*.sublime-workspace
25+
26+
# IDE - VSCode
27+
.vscode/*
28+
!.vscode/settings.json
29+
!.vscode/tasks.json
30+
!.vscode/launch.json
31+
!.vscode/extensions.json
32+
.history/*
33+
34+
# misc
35+
/.sass-cache
36+
/connect.lock
37+
/coverage
38+
/libpeerconnection.log
39+
npm-debug.log
40+
yarn-error.log
41+
testem.log
42+
/typings
43+
44+
# System Files
45+
.DS_Store
46+
Thumbs.db

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Duc Trung Mai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Angular D3 Word Cloud
2+
D3 Cloud component for Angular built upon d3-cloud
3+
4+
<img src="./demo.png">
5+
6+
# Installation
7+
```
8+
npm install --save angular-d3-cloud
9+
```
10+
# Usage
11+
First import the package to your app module
12+
```ts
13+
// app.module.ts
14+
import { AngularD3CloudModule } from 'angular-d3-cloud'
15+
@NgModule({
16+
imports: [
17+
AngularD3CloudModule
18+
],
19+
...
20+
})
21+
```
22+
Now the component is ready to use.
23+
24+
```html
25+
<!-- app.component.html -->
26+
<angular-d3-cloud
27+
[data]="data"
28+
[width]="700"
29+
[height]="600"
30+
[padding]="5"
31+
font="serif"
32+
[rotate]="0"
33+
[autoFill]="true"
34+
(wordClick)="onWorkClick($event)"
35+
></angular-d3-cloud>
36+
```
37+
```ts
38+
// app.component.ts
39+
export class AppComponent {
40+
data = [
41+
"Hello", "world", "normally", "you", "want", "more", "words",
42+
"than", "this"].map(function (d) {
43+
return { text: d, value: 10 + Math.random() * 90};
44+
})
45+
}
46+
```
47+
# Props
48+
| Name | Description | Type | Required | Default |
49+
|----------------|------------------------------------------------------------------------------------------------------------|-----------------------------------------------|----------|---------------------|
50+
| data | The input data for rendering | Array<{ text: string, value: number }> || |
51+
| width | Width of component (px) | number | | 700 |
52+
| height | Height of component (px) | number | | 600 |
53+
| fontSizeMapper | Map each element of data to font size (px) | Function: (word: string, idx: number): number | | word => word.value; |
54+
| rotate | Map each element of data to font rotation degree. Or simply provide a number for global rotation. (degree) | Function \| number | | 0 |
55+
| padding | Map each element of data to font padding. Or simply provide a number for global padding. (px) | Function \| number | | 5 |
56+
| font | The font of text shown | Function \| string | | serif |
57+
| autoFill | Whether texts should be fill with random color or not | boolean | | false |
58+
59+
# Events
60+
| Name | Description | Payload |
61+
|---------------|----------------------------------------------------------|-----------------------------------|
62+
| wordClick | Event triggered when click event triggered on a word | { event: MouseEvent, word: Word } |
63+
| wordMouseOver | Event triggered when mouseover event triggered on a word | { event: MouseEvent, word: Word } |
64+
| wordMouseOut | Event triggered when mouseout event triggered on a word | { event: MouseEvent, word: Word } |
65+
66+
> The `Word` interface imported from `d3-cloud`
67+
# Example
68+
Run the following commands to start sample project:
69+
```
70+
ng build angular-d3-cloud --watch
71+
npm start # in a separate terminal
72+
```
73+
# Thanks
74+
This project is built with the idea of [React D3 Cloud](https://github.com/Yoctol/react-d3-cloud)

angular.json

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"angular-d3-cloud": {
7+
"projectType": "library",
8+
"root": "projects/angular-d3-cloud",
9+
"sourceRoot": "projects/angular-d3-cloud/src",
10+
"prefix": "lib",
11+
"architect": {
12+
"build": {
13+
"builder": "@angular-devkit/build-angular:ng-packagr",
14+
"options": {
15+
"tsConfig": "projects/angular-d3-cloud/tsconfig.lib.json",
16+
"project": "projects/angular-d3-cloud/ng-package.json"
17+
},
18+
"configurations": {
19+
"production": {
20+
"tsConfig": "projects/angular-d3-cloud/tsconfig.lib.prod.json"
21+
}
22+
}
23+
},
24+
"test": {
25+
"builder": "@angular-devkit/build-angular:karma",
26+
"options": {
27+
"main": "projects/angular-d3-cloud/src/test.ts",
28+
"tsConfig": "projects/angular-d3-cloud/tsconfig.spec.json",
29+
"karmaConfig": "projects/angular-d3-cloud/karma.conf.js"
30+
}
31+
},
32+
"lint": {
33+
"builder": "@angular-devkit/build-angular:tslint",
34+
"options": {
35+
"tsConfig": [
36+
"projects/angular-d3-cloud/tsconfig.lib.json",
37+
"projects/angular-d3-cloud/tsconfig.spec.json"
38+
],
39+
"exclude": [
40+
"**/node_modules/**"
41+
]
42+
}
43+
}
44+
}
45+
},
46+
"example": {
47+
"projectType": "application",
48+
"schematics": {},
49+
"root": "projects/example",
50+
"sourceRoot": "projects/example/src",
51+
"prefix": "app",
52+
"architect": {
53+
"build": {
54+
"builder": "@angular-devkit/build-angular:browser",
55+
"options": {
56+
"outputPath": "dist/example",
57+
"index": "projects/example/src/index.html",
58+
"main": "projects/example/src/main.ts",
59+
"polyfills": "projects/example/src/polyfills.ts",
60+
"tsConfig": "projects/example/tsconfig.app.json",
61+
"aot": true,
62+
"assets": [
63+
"projects/example/src/favicon.ico",
64+
"projects/example/src/assets"
65+
],
66+
"styles": [
67+
"projects/example/src/styles.css"
68+
],
69+
"scripts": []
70+
},
71+
"configurations": {
72+
"production": {
73+
"fileReplacements": [
74+
{
75+
"replace": "projects/example/src/environments/environment.ts",
76+
"with": "projects/example/src/environments/environment.prod.ts"
77+
}
78+
],
79+
"optimization": true,
80+
"outputHashing": "all",
81+
"sourceMap": false,
82+
"namedChunks": false,
83+
"extractLicenses": true,
84+
"vendorChunk": false,
85+
"buildOptimizer": true,
86+
"budgets": [
87+
{
88+
"type": "initial",
89+
"maximumWarning": "2mb",
90+
"maximumError": "5mb"
91+
},
92+
{
93+
"type": "anyComponentStyle",
94+
"maximumWarning": "6kb",
95+
"maximumError": "10kb"
96+
}
97+
]
98+
}
99+
}
100+
},
101+
"serve": {
102+
"builder": "@angular-devkit/build-angular:dev-server",
103+
"options": {
104+
"browserTarget": "example:build"
105+
},
106+
"configurations": {
107+
"production": {
108+
"browserTarget": "example:build:production"
109+
}
110+
}
111+
},
112+
"extract-i18n": {
113+
"builder": "@angular-devkit/build-angular:extract-i18n",
114+
"options": {
115+
"browserTarget": "example:build"
116+
}
117+
},
118+
"test": {
119+
"builder": "@angular-devkit/build-angular:karma",
120+
"options": {
121+
"main": "projects/example/src/test.ts",
122+
"polyfills": "projects/example/src/polyfills.ts",
123+
"tsConfig": "projects/example/tsconfig.spec.json",
124+
"karmaConfig": "projects/example/karma.conf.js",
125+
"assets": [
126+
"projects/example/src/favicon.ico",
127+
"projects/example/src/assets"
128+
],
129+
"styles": [
130+
"projects/example/src/styles.css"
131+
],
132+
"scripts": []
133+
}
134+
},
135+
"lint": {
136+
"builder": "@angular-devkit/build-angular:tslint",
137+
"options": {
138+
"tsConfig": [
139+
"projects/example/tsconfig.app.json",
140+
"projects/example/tsconfig.spec.json",
141+
"projects/example/e2e/tsconfig.json"
142+
],
143+
"exclude": [
144+
"**/node_modules/**"
145+
]
146+
}
147+
},
148+
"e2e": {
149+
"builder": "@angular-devkit/build-angular:protractor",
150+
"options": {
151+
"protractorConfig": "projects/example/e2e/protractor.conf.js",
152+
"devServerTarget": "example:serve"
153+
},
154+
"configurations": {
155+
"production": {
156+
"devServerTarget": "example:serve:production"
157+
}
158+
}
159+
}
160+
}
161+
}
162+
},
163+
"defaultProject": "angular-d3-cloud"
164+
}

demo.png

607 KB
Loading

0 commit comments

Comments
 (0)