Skip to content
Snippets Groups Projects
app.component.ts 1.17 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Component, ViewChild, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
    import { Subscription } from 'rxjs';
    import { DeaggResponse, Deaggregation, DeaggregationGraphView } from '@nshmp/disagg-d3/src/disagg';
    import { Collection } from '@nshmp/disagg-d3/src/mvc';
    
    import { AppService } from './app.service';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss'],
    })
    export class AppComponent implements AfterViewInit, OnDestroy {
      title = 'example';
    
      @ViewChild('example')
      el: ElementRef<HTMLElement>;
    
      sub: Subscription;
    
      constructor(private service: AppService) {}
    
      ngAfterViewInit(): void {
        this.sub = this.service.callDeagg$.subscribe((usageResponse) => {
          const response = new DeaggResponse(usageResponse.response.pop());
          const deaggs = response.get<Collection<Deaggregation>>('deaggregations').data();
          const collection = new Collection(deaggs);
          collection.select(collection.data()[0]);
    
          const view = new DeaggregationGraphView({
            el: this.el.nativeElement,
            collection,
          });
        });
      }
    
      ngOnDestroy(): void {
        this.sub.unsubscribe();
      }
    }