#1330 UI Circle Progress Library

This commit is contained in:
Andreas Schickinger
2021-01-19 15:26:40 +01:00
parent 9c4a6b31ed
commit 01ef455eb5
19 changed files with 304 additions and 2 deletions

View File

@@ -1576,6 +1576,46 @@
}
}
}
},
"@ui/progress": {
"projectType": "library",
"root": "apps/ui/progress",
"sourceRoot": "apps/ui/progress/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "apps/ui/progress/tsconfig.lib.json",
"project": "apps/ui/progress/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "apps/ui/progress/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "apps/ui/progress/src/test.ts",
"tsConfig": "apps/ui/progress/tsconfig.spec.json",
"karmaConfig": "apps/ui/progress/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/ui/progress/tsconfig.lib.json",
"apps/ui/progress/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "sales"

View File

@@ -5,6 +5,6 @@
<div class="text">Bons von {{ card.kpi.target }} schon geschafft</div>
</div>
<div class="chart">
<!-- TODO Add Pie Chart-->
<ui-circle-progress [progress]="card.kpi.percantage"></ui-circle-progress>
</div>
</div>

View File

@@ -9,8 +9,9 @@ import { RecommandationCardComponent } from './components/recommandation-card/re
import { SharedModule } from '../../shared/shared.module';
import { LoadingModule, IconModule } from '@libs/ui';
import { KpiCardComponent } from './components/kpi-card/kpi-card.component';
import { UiProgressModule } from 'apps/ui/progress/src/lib/ui-progress.module';
@NgModule({
imports: [CommonModule, SharedModule, LoadingModule, IconModule],
imports: [CommonModule, SharedModule, LoadingModule, IconModule, UiProgressModule],
exports: [DashboardComponent],
declarations: [
DashboardComponent,

View File

@@ -0,0 +1,25 @@
# Progress
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.1.2.
## Code scaffolding
Run `ng generate component component-name --project progress` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project progress`.
> Note: Don't forget to add `--project progress` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build progress` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build progress`, go to the dist folder `cd dist/progress` and run `npm publish`.
## Running unit tests
Run `ng test progress` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@@ -0,0 +1,32 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../../coverage/ui/progress'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};

View File

@@ -0,0 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/ui/progress",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "@ui/progress",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^10.1.2",
"@angular/core": "^10.1.2"
},
"dependencies": {
"tslib": "^2.0.0"
}
}

View File

@@ -0,0 +1,4 @@
// start:ng42.barrel
export * from './ui-circle-progress.component';
export * from './ui-progress.module';
// end:ng42.barrel

View File

@@ -0,0 +1,22 @@
<svg class="progress" [attr.height]="size" [attr.width]="size">
<circle
fill="transparent"
[attr.cx]="this.size / 2"
[attr.cy]="this.size / 2"
[attr.stroke-width]="this.strokeWidth"
[attr.r]="radius"
[attr.stroke]="background"
/>
<circle
fill="none"
stroke-linecap="round"
[attr.cx]="this.size / 2"
[attr.cy]="this.size / 2"
[attr.stroke-width]="this.strokeWidth"
[attr.stroke]="foreground"
[attr.r]="radius"
[attr.stroke-dasharray]="circumference"
[attr.stroke-dashoffset]="dashoffset"
/>
</svg>

After

Width:  |  Height:  |  Size: 566 B

View File

@@ -0,0 +1,3 @@
.progress {
transform: rotate(-90deg);
}

View File

@@ -0,0 +1,47 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
@Component({
selector: 'ui-circle-progress',
templateUrl: 'ui-circle-progress.component.html',
styleUrls: ['ui-circle-progress.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UiCircleProgressComponent implements OnChanges {
@Input()
size: number = 100;
@Input()
strokeWidth: number = 12;
@Input()
background: string = '#e6eff9';
@Input()
foreground: string = '#26830c';
@Input()
progress: number = 0;
radius: number;
circumference: number;
dashoffset: number;
constructor(private cdr: ChangeDetectorRef) {
this.calculateProgress(this.progress);
}
ngOnChanges({ progress, size, strokeWidth }: SimpleChanges): void {
if (progress || size || strokeWidth) {
this.calculateProgress(this.progress);
}
}
calculateProgress(value: number): void {
value = Math.min(Math.max(0, value), 100);
this.radius = this.size / 2 - this.strokeWidth / 2;
this.circumference = 2 * Math.PI * this.radius;
this.dashoffset = this.circumference * (1 - value / 100);
this.cdr.markForCheck();
}
}

View File

@@ -0,0 +1,9 @@
import { NgModule } from '@angular/core';
import { UiCircleProgressComponent } from './ui-circle-progress.component';
@NgModule({
declarations: [UiCircleProgressComponent],
imports: [],
exports: [UiCircleProgressComponent],
})
export class UiProgressModule {}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of progress
*/
export * from './lib';

View File

@@ -0,0 +1,24 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,25 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}

View File

@@ -0,0 +1,17 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/spec",
"types": [
"jasmine"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@@ -0,0 +1,17 @@
{
"extends": "../../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

View File

@@ -154,6 +154,9 @@
],
"@ui/radio": [
"apps/ui/radio/src/public-api.ts"
],
"@ui/progress": [
"apps/ui/progress/src/public-api.ts"
]
}
}