├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── about │ │ ├── about-routing.module.ts │ │ ├── about.component.css │ │ ├── about.component.html │ │ ├── about.component.spec.ts │ │ ├── about.component.ts │ │ └── about.module.ts │ ├── app-routing.module.ts │ ├── app.component.css │ ├── app.component.html │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ └── home │ │ ├── chart.data.ts │ │ ├── home-routing.module.ts │ │ ├── home.component.css │ │ ├── home.component.html │ │ ├── home.component.ts │ │ ├── home.module.ts │ │ └── table.data.ts ├── assets │ └── .gitkeep ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 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 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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 47 | 48 | .angular -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Demo for Profiling Angular Applications 2 | 3 | This is the demo app from the video "[Profiling Angular Applications](https://www.youtube.com/watch?v=FjyX_hkscII)". 4 | 5 | ## License 6 | 7 | MIT 8 | 9 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "dashboard": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:application": { 10 | "strict": true 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/dashboard", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "assets": [ 26 | "src/favicon.ico", 27 | "src/assets" 28 | ], 29 | "styles": [ 30 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 31 | "./node_modules/hamburgers/dist/hamburgers.css", 32 | "src/styles.css" 33 | ], 34 | "scripts": [], 35 | "vendorChunk": true, 36 | "extractLicenses": false, 37 | "buildOptimizer": false, 38 | "sourceMap": true, 39 | "optimization": false, 40 | "namedChunks": true 41 | }, 42 | "configurations": { 43 | "production": { 44 | "fileReplacements": [ 45 | { 46 | "replace": "src/environments/environment.ts", 47 | "with": "src/environments/environment.prod.ts" 48 | } 49 | ], 50 | "optimization": true, 51 | "outputHashing": "all", 52 | "sourceMap": false, 53 | "namedChunks": false, 54 | "extractLicenses": true, 55 | "vendorChunk": false, 56 | "buildOptimizer": true, 57 | "budgets": [ 58 | { 59 | "type": "initial", 60 | "maximumWarning": "500kb", 61 | "maximumError": "1mb" 62 | }, 63 | { 64 | "type": "anyComponentStyle", 65 | "maximumWarning": "2kb", 66 | "maximumError": "4kb" 67 | } 68 | ] 69 | } 70 | }, 71 | "defaultConfiguration": "" 72 | }, 73 | "serve": { 74 | "builder": "@angular-devkit/build-angular:dev-server", 75 | "options": { 76 | "buildTarget": "dashboard:build" 77 | }, 78 | "configurations": { 79 | "production": { 80 | "buildTarget": "dashboard:build:production" 81 | } 82 | } 83 | }, 84 | "extract-i18n": { 85 | "builder": "@angular-devkit/build-angular:extract-i18n", 86 | "options": { 87 | "buildTarget": "dashboard:build" 88 | } 89 | }, 90 | "test": { 91 | "builder": "@angular-devkit/build-angular:karma", 92 | "options": { 93 | "main": "src/test.ts", 94 | "polyfills": "src/polyfills.ts", 95 | "tsConfig": "tsconfig.spec.json", 96 | "karmaConfig": "karma.conf.js", 97 | "assets": [ 98 | "src/favicon.ico", 99 | "src/assets" 100 | ], 101 | "styles": [ 102 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 103 | "src/styles.css" 104 | ], 105 | "scripts": [] 106 | } 107 | }, 108 | "lint": { 109 | "builder": "@angular-devkit/build-angular:tslint", 110 | "options": { 111 | "tsConfig": [ 112 | "tsconfig.app.json", 113 | "tsconfig.spec.json", 114 | "e2e/tsconfig.json" 115 | ], 116 | "exclude": [ 117 | "**/node_modules/**" 118 | ] 119 | } 120 | }, 121 | "e2e": { 122 | "builder": "@angular-devkit/build-angular:protractor", 123 | "options": { 124 | "protractorConfig": "e2e/protractor.conf.js", 125 | "devServerTarget": "dashboard:serve" 126 | }, 127 | "configurations": { 128 | "production": { 129 | "devServerTarget": "dashboard:serve:production" 130 | } 131 | } 132 | } 133 | } 134 | } 135 | }, 136 | "cli": { 137 | "analytics": "c157c09c-6887-4612-8405-c71f04cb783b" 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('dashboard app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageReporter: { 19 | dir: require('path').join(__dirname, './coverage/dashboard'), 20 | subdir: '.', 21 | reporters: [ 22 | { type: 'html' }, 23 | { type: 'text-summary' } 24 | ] 25 | }, 26 | reporters: ['progress', 'kjhtml'], 27 | port: 9876, 28 | colors: true, 29 | logLevel: config.LOG_INFO, 30 | autoWatch: true, 31 | browsers: ['Chrome'], 32 | singleRun: false, 33 | restartOnFileChange: true 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dashboard", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^17.3.12", 15 | "@angular/cdk": "^17.3.10", 16 | "@angular/common": "^17.3.12", 17 | "@angular/compiler": "^17.3.12", 18 | "@angular/core": "^17.3.12", 19 | "@angular/forms": "^17.3.12", 20 | "@angular/material": "^17.3.10", 21 | "@angular/platform-browser": "^17.3.12", 22 | "@angular/platform-browser-dynamic": "^17.3.12", 23 | "@angular/router": "^17.3.12", 24 | "@swimlane/ngx-charts": "^20.0.0", 25 | "hamburgers": "^1.1.3", 26 | "rxjs": "~6.6.0", 27 | "tslib": "^2.0.0", 28 | "zone.js": "~0.14.10" 29 | }, 30 | "devDependencies": { 31 | "@angular-devkit/build-angular": "^17.3.11", 32 | "@angular/cli": "^17.3.11", 33 | "@angular/compiler-cli": "^17.3.12", 34 | "@types/d3-scale": "^4.0.8", 35 | "@types/d3-selection": "^3.0.11", 36 | "@types/d3-shape": "^3.1.6", 37 | "@types/node": "^12.11.1", 38 | "codelyzer": "^6.0.0", 39 | "ts-node": "~8.3.0", 40 | "tslint": "~6.1.0", 41 | "typescript": "~5.4.5" 42 | } 43 | } -------------------------------------------------------------------------------- /src/app/about/about-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { AboutComponent } from './about.component'; 5 | 6 | const routes: Routes = [{ path: '', component: AboutComponent }]; 7 | 8 | @NgModule({ 9 | imports: [RouterModule.forChild(routes)], 10 | exports: [RouterModule] 11 | }) 12 | export class AboutRoutingModule { } 13 | -------------------------------------------------------------------------------- /src/app/about/about.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgechev/optimizing-apps-angular-demo/e4b0e4eba34dd585ec741cba1483c9e9f25794c6/src/app/about/about.component.css -------------------------------------------------------------------------------- /src/app/about/about.component.html: -------------------------------------------------------------------------------- 1 |

about works!

2 | -------------------------------------------------------------------------------- /src/app/about/about.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AboutComponent } from './about.component'; 4 | 5 | describe('AboutComponent', () => { 6 | let component: AboutComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ AboutComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AboutComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/about/about.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-about', 5 | templateUrl: './about.component.html', 6 | styleUrls: ['./about.component.css'] 7 | }) 8 | export class AboutComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/about/about.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { AboutRoutingModule } from './about-routing.module'; 5 | import { AboutComponent } from './about.component'; 6 | 7 | 8 | @NgModule({ 9 | declarations: [AboutComponent], 10 | imports: [ 11 | CommonModule, 12 | AboutRoutingModule 13 | ] 14 | }) 15 | export class AboutModule { } 16 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { 6 | path: '', 7 | pathMatch: 'full', 8 | redirectTo: 'home' 9 | }, 10 | { 11 | path: 'home', 12 | loadChildren: () => import('./home/home.module').then((m) => m.HomeModule), 13 | }, 14 | { 15 | path: 'about', 16 | loadChildren: () => 17 | import('./about/about.module').then((m) => m.AboutModule), 18 | }, 19 | ]; 20 | 21 | @NgModule({ 22 | imports: [RouterModule.forRoot(routes)], 23 | exports: [RouterModule], 24 | }) 25 | export class AppRoutingModule {} 26 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | height: 100%; 3 | } 4 | 5 | mat-icon { 6 | margin-left: 10px; 7 | margin-right: 8px; 8 | } 9 | 10 | .container { 11 | width: 100%; 12 | height: calc(100% - 64px); 13 | } 14 | 15 | mat-drawer-content { 16 | padding: 12px; 17 | display: flex; 18 | flex-direction: column; 19 | align-items: flex-start; 20 | } 21 | 22 | 23 | .hamburger { 24 | outline: none; 25 | } 26 | 27 | .hamburger-inner, .hamburger-inner::before, .hamburger-inner::after, 28 | .hamburger.is-active .hamburger-inner, .hamburger.is-active .hamburger-inner::before, .hamburger.is-active .hamburger-inner::after { 29 | background-color: white; 30 | } 31 | 32 | .hamburger-box { 33 | height: 18px; 34 | } 35 | 36 | nav { 37 | padding: 20px; 38 | } 39 | 40 | nav a { 41 | display: block; 42 | font-size: 1.2em; 43 | padding: 10px; 44 | } 45 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | analytics 14 | Dashboard 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'dashboard'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('dashboard'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('dashboard app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, signal } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = signal('Dashboard'); 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 7 | 8 | import { MatToolbarModule } from '@angular/material/toolbar'; 9 | import { MatIconModule } from '@angular/material/icon'; 10 | import { MatSidenavModule } from '@angular/material/sidenav'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent 15 | ], 16 | imports: [ 17 | BrowserModule, 18 | AppRoutingModule, 19 | BrowserAnimationsModule, 20 | MatToolbarModule, 21 | MatIconModule, 22 | MatSidenavModule 23 | ], 24 | providers: [], 25 | bootstrap: [AppComponent] 26 | }) 27 | export class AppModule { } 28 | -------------------------------------------------------------------------------- /src/app/home/chart.data.ts: -------------------------------------------------------------------------------- 1 | export const single = [ 2 | { 3 | name: 'Germany', 4 | value: 8940000, 5 | }, 6 | { 7 | name: 'USA', 8 | value: 5000000, 9 | }, 10 | { 11 | name: 'France', 12 | value: 7200000, 13 | }, 14 | { 15 | name: 'UK', 16 | value: 5200000, 17 | }, 18 | { 19 | name: 'Italy', 20 | value: 7700000, 21 | }, 22 | { 23 | name: 'Spain', 24 | value: 4300000, 25 | }, 26 | ]; 27 | 28 | export const multi = [ 29 | { 30 | name: 'Germany', 31 | series: [ 32 | { 33 | name: '1990', 34 | value: 62000000, 35 | }, 36 | { 37 | name: '2010', 38 | value: 73000000, 39 | }, 40 | { 41 | name: '2011', 42 | value: 89400000, 43 | }, 44 | ], 45 | }, 46 | 47 | { 48 | name: 'USA', 49 | series: [ 50 | { 51 | name: '1990', 52 | value: 250000000, 53 | }, 54 | { 55 | name: '2010', 56 | value: 309000000, 57 | }, 58 | { 59 | name: '2011', 60 | value: 311000000, 61 | }, 62 | ], 63 | }, 64 | 65 | { 66 | name: 'France', 67 | series: [ 68 | { 69 | name: '1990', 70 | value: 58000000, 71 | }, 72 | { 73 | name: '2010', 74 | value: 50000020, 75 | }, 76 | { 77 | name: '2011', 78 | value: 58000000, 79 | }, 80 | ], 81 | }, 82 | { 83 | name: 'UK', 84 | series: [ 85 | { 86 | name: '1990', 87 | value: 57000000, 88 | }, 89 | { 90 | name: '2010', 91 | value: 62000000, 92 | }, 93 | ], 94 | }, 95 | ]; 96 | 97 | export const barSingle = [ 98 | { 99 | name: 'Germany', 100 | value: 8940000, 101 | }, 102 | { 103 | name: 'USA', 104 | value: 5000000, 105 | }, 106 | { 107 | name: 'France', 108 | value: 7200000, 109 | }, 110 | ]; 111 | 112 | export const barMulti = [ 113 | { 114 | name: 'Germany', 115 | series: [ 116 | { 117 | name: '2010', 118 | value: 7300000, 119 | }, 120 | { 121 | name: '2011', 122 | value: 8940000, 123 | }, 124 | ], 125 | }, 126 | 127 | { 128 | name: 'USA', 129 | series: [ 130 | { 131 | name: '2010', 132 | value: 7870000, 133 | }, 134 | { 135 | name: '2011', 136 | value: 8270000, 137 | }, 138 | ], 139 | }, 140 | 141 | { 142 | name: 'France', 143 | series: [ 144 | { 145 | name: '2010', 146 | value: 5000002, 147 | }, 148 | { 149 | name: '2011', 150 | value: 5800000, 151 | }, 152 | ], 153 | }, 154 | ]; 155 | -------------------------------------------------------------------------------- /src/app/home/home-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { HomeComponent } from './home.component'; 5 | 6 | const routes: Routes = [{ path: '', component: HomeComponent }]; 7 | 8 | @NgModule({ 9 | imports: [RouterModule.forChild(routes)], 10 | exports: [RouterModule] 11 | }) 12 | export class HomeRoutingModule { } 13 | -------------------------------------------------------------------------------- /src/app/home/home.component.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: grid; 3 | grid-template-columns: 1fr 1fr 1fr; 4 | grid-template-rows: auto auto auto auto; 5 | gap: 1em 1em; 6 | grid-template-areas: 7 | "line-chart line-chart line-chart" 8 | "gauge bar-chart aggregate" 9 | "data-table data-table data-table" 10 | "popular-links popular-links popular-links"; 11 | } 12 | 13 | .line-chart { 14 | grid-area: line-chart; 15 | } 16 | 17 | .data-table { 18 | grid-area: data-table; 19 | } 20 | 21 | .gauge { 22 | grid-area: gauge; 23 | } 24 | 25 | .bar-chart { 26 | grid-area: bar-chart; 27 | } 28 | 29 | .aggregate { 30 | grid-area: aggregate; 31 | border: 1px solid #ccc; 32 | } 33 | 34 | .popular-links { 35 | grid-area: popular-links; 36 | } 37 | 38 | /* For presentation only, no need to copy the code below */ 39 | /* :host > * { 40 | border: 1px solid red; 41 | position: relative; 42 | } 43 | 44 | :host > *:after { 45 | content: attr(class); 46 | position: absolute; 47 | top: 0; 48 | left: 0; 49 | } */ 50 | 51 | .table, 52 | table { 53 | width: 100%; 54 | } 55 | -------------------------------------------------------------------------------- /src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 | 13 | 14 |
15 | 16 |
17 | 18 | 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 |
No. {{element.position}} Name {{element.name}} Weight {{element.weight}} Symbol {{element.symbol}}
48 |
49 | 50 |
51 | 58 | 59 |
60 |
61 | 72 | 73 |
74 |
75 |

Total score

76 | {{ aggregate }} 77 |
78 | 79 | 80 | 85 | 86 | 87 | 92 | 93 | 94 | 99 | -------------------------------------------------------------------------------- /src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | import { single, multi, barSingle, barMulti } from './chart.data'; 4 | import { ELEMENT_DATA } from './table.data'; 5 | 6 | @Component({ 7 | selector: 'app-home', 8 | templateUrl: './home.component.html', 9 | styleUrls: ['./home.component.css'], 10 | }) 11 | export class HomeComponent { 12 | displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; 13 | dataSource = ELEMENT_DATA; 14 | 15 | // Gauge 16 | single: any[] = []; 17 | gaugeView: [number, number] = [500, 400]; 18 | gaugeLegend = true; 19 | legendPosition = 'below'; 20 | 21 | gaugeColorScheme = { 22 | domain: ['#5AA454', '#E44D25', '#CFC0BB', '#7aa3e5', '#a8385d', '#aae3f5'], 23 | }; 24 | 25 | constructor() { 26 | Object.assign(this, { single, multi }); 27 | Object.assign(this, { barSingle, barMulti }); 28 | } 29 | 30 | onActivate(data: any): void { 31 | console.log('Activate', JSON.parse(JSON.stringify(data))); 32 | } 33 | 34 | onDeactivate(data: any): void { 35 | console.log('Deactivate', JSON.parse(JSON.stringify(data))); 36 | } 37 | 38 | // Line chart 39 | multi: any[] = []; 40 | lineChartView: [number, number] = [1400, 300]; 41 | 42 | // options 43 | lineChartLegend: boolean = true; 44 | showLabels: boolean = true; 45 | animations: boolean = true; 46 | xAxis: boolean = true; 47 | yAxis: boolean = true; 48 | showYAxisLabel: boolean = true; 49 | showXAxisLabel: boolean = true; 50 | xAxisLabel: string = 'Year'; 51 | yAxisLabel: string = 'Population'; 52 | timeline: boolean = true; 53 | 54 | lineChartColorScheme = { 55 | domain: ['#5AA454', '#E44D25', '#CFC0BB', '#7aa3e5', '#a8385d', '#aae3f5'], 56 | }; 57 | 58 | // Bar chart 59 | barSingle: any[] = []; 60 | barMulti: any[] = []; 61 | 62 | barView: [number, number] = [700, 400]; 63 | 64 | // options 65 | barShowXAxis = true; 66 | barShowYAxis = true; 67 | barGradient = false; 68 | barShowLegend = true; 69 | barShowXAxisLabel = true; 70 | barXAxisLabel = 'Country'; 71 | barShowYAxisLabel = true; 72 | barYAxisLabel = 'Population'; 73 | 74 | barColorScheme = { 75 | domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA'], 76 | }; 77 | 78 | get aggregate(): number { 79 | let total = 0; 80 | for (let i = 0; i < 15000; i++) { 81 | for (const el of ELEMENT_DATA) { 82 | total += Math.log(el.weight ** 2); 83 | } 84 | } 85 | return total; 86 | } 87 | 88 | get popularLinks(): { text: string, href: string }[] { 89 | return ELEMENT_DATA.sort((a, b) => { 90 | return a.weight - b.weight; 91 | }).map((data) => ({ 92 | href: `https://example.com/${data.name}`, 93 | text: data.name, 94 | })); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { MatTableModule } from '@angular/material/table'; 4 | 5 | import { HomeRoutingModule } from './home-routing.module'; 6 | import { HomeComponent } from './home.component'; 7 | import { NgxChartsModule } from '@swimlane/ngx-charts'; 8 | import { FormsModule } from '@angular/forms'; 9 | 10 | 11 | @NgModule({ 12 | declarations: [HomeComponent], 13 | imports: [ 14 | CommonModule, 15 | HomeRoutingModule, 16 | MatTableModule, 17 | NgxChartsModule, 18 | FormsModule 19 | ] 20 | }) 21 | export class HomeModule { } 22 | -------------------------------------------------------------------------------- /src/app/home/table.data.ts: -------------------------------------------------------------------------------- 1 | export interface PeriodicElement { 2 | name: string; 3 | position: number; 4 | weight: number; 5 | symbol: string; 6 | } 7 | 8 | export const ELEMENT_DATA: PeriodicElement[] = [ 9 | {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, 10 | {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, 11 | {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, 12 | {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, 13 | {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, 14 | {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, 15 | {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, 16 | {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, 17 | {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, 18 | {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, 19 | {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, 20 | {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, 21 | {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, 22 | {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, 23 | {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, 24 | {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, 25 | {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, 26 | {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, 27 | {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, 28 | {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, 29 | {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, 30 | {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, 31 | {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, 32 | {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, 33 | {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, 34 | {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, 35 | {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, 36 | {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, 37 | {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, 38 | {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, 39 | {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, 40 | {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, 41 | {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, 42 | {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, 43 | {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, 44 | {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, 45 | {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, 46 | {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, 47 | {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, 48 | {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, 49 | {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, 50 | {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, 51 | {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, 52 | {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, 53 | {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'}, 54 | {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'}, 55 | {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}, 56 | {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'}, 57 | {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, 58 | {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, 59 | ]; 60 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgechev/optimizing-apps-angular-demo/e4b0e4eba34dd585ec741cba1483c9e9f25794c6/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mgechev/optimizing-apps-angular-demo/e4b0e4eba34dd585ec741cba1483c9e9f25794c6/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dashboard 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | // First, initialize the Angular testing environment. 11 | getTestBed().initTestEnvironment( 12 | BrowserDynamicTestingModule, 13 | platformBrowserDynamicTesting() 14 | ); 15 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "ES2022", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ], 23 | "useDefineForClassFields": false 24 | }, 25 | "angularCompilerOptions": { 26 | "strictInjectionParameters": true, 27 | "strictInputAccessModifiers": true, 28 | "strictTemplates": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "align": { 8 | "options": [ 9 | "parameters", 10 | "statements" 11 | ] 12 | }, 13 | "array-type": false, 14 | "arrow-return-shorthand": true, 15 | "curly": true, 16 | "deprecation": { 17 | "severity": "warning" 18 | }, 19 | "eofline": true, 20 | "import-blacklist": [ 21 | true, 22 | "rxjs/Rx" 23 | ], 24 | "import-spacing": true, 25 | "indent": { 26 | "options": [ 27 | "spaces" 28 | ] 29 | }, 30 | "max-classes-per-file": false, 31 | "max-line-length": [ 32 | true, 33 | 140 34 | ], 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-console": [ 47 | true, 48 | "debug", 49 | "info", 50 | "time", 51 | "timeEnd", 52 | "trace" 53 | ], 54 | "no-empty": false, 55 | "no-inferrable-types": [ 56 | true, 57 | "ignore-params" 58 | ], 59 | "no-non-null-assertion": true, 60 | "no-redundant-jsdoc": true, 61 | "no-switch-case-fall-through": true, 62 | "no-var-requires": false, 63 | "object-literal-key-quotes": [ 64 | true, 65 | "as-needed" 66 | ], 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "semicolon": { 72 | "options": [ 73 | "always" 74 | ] 75 | }, 76 | "space-before-function-paren": { 77 | "options": { 78 | "anonymous": "never", 79 | "asyncArrow": "always", 80 | "constructor": "never", 81 | "method": "never", 82 | "named": "never" 83 | } 84 | }, 85 | "typedef": [ 86 | true, 87 | "call-signature" 88 | ], 89 | "typedef-whitespace": { 90 | "options": [ 91 | { 92 | "call-signature": "nospace", 93 | "index-signature": "nospace", 94 | "parameter": "nospace", 95 | "property-declaration": "nospace", 96 | "variable-declaration": "nospace" 97 | }, 98 | { 99 | "call-signature": "onespace", 100 | "index-signature": "onespace", 101 | "parameter": "onespace", 102 | "property-declaration": "onespace", 103 | "variable-declaration": "onespace" 104 | } 105 | ] 106 | }, 107 | "variable-name": { 108 | "options": [ 109 | "ban-keywords", 110 | "check-format", 111 | "allow-pascal-case" 112 | ] 113 | }, 114 | "whitespace": { 115 | "options": [ 116 | "check-branch", 117 | "check-decl", 118 | "check-operator", 119 | "check-separator", 120 | "check-type", 121 | "check-typecast" 122 | ] 123 | }, 124 | "component-class-suffix": true, 125 | "contextual-lifecycle": true, 126 | "directive-class-suffix": true, 127 | "no-conflicting-lifecycle": true, 128 | "no-host-metadata-property": true, 129 | "no-input-rename": true, 130 | "no-inputs-metadata-property": true, 131 | "no-output-native": true, 132 | "no-output-on-prefix": true, 133 | "no-output-rename": true, 134 | "no-outputs-metadata-property": true, 135 | "template-banana-in-box": true, 136 | "template-no-negated-async": true, 137 | "use-lifecycle-interface": true, 138 | "use-pipe-transform-interface": true, 139 | "directive-selector": [ 140 | true, 141 | "attribute", 142 | "app", 143 | "camelCase" 144 | ], 145 | "component-selector": [ 146 | true, 147 | "element", 148 | "app", 149 | "kebab-case" 150 | ] 151 | } 152 | } 153 | --------------------------------------------------------------------------------