From 5856ae01893f2c796e64f22e6cff03dc46656f7a Mon Sep 17 00:00:00 2001
From: Brandon Clayton <bclayton@usgs.gov>
Date: Tue, 30 Aug 2022 08:28:10 -0600
Subject: [PATCH] add bounds

---
 example/src/app/app.component.ts | 36 +++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/example/src/app/app.component.ts b/example/src/app/app.component.ts
index 99bbfd8..5531090 100644
--- a/example/src/app/app.component.ts
+++ b/example/src/app/app.component.ts
@@ -1,9 +1,9 @@
-import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
-import { nshmpHaz } from '@ghsc/nshmp-web-utils';
+import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
+import { nshmpHaz} from '@ghsc/nshmp-web-utils';
 import { DisaggGraphView, Disaggregation, DisaggResponse } from '@nshmp/disagg-d3/src/disagg';
 import { Collection } from '@nshmp/disagg-d3/src/mvc';
 
-import deagg from '../assets/deagg.json';
+import disagg from '../assets/disagg-response.json';
 
 @Component({
   selector: 'app-root',
@@ -12,8 +12,9 @@ import deagg from '../assets/deagg.json';
 })
 export class AppComponent implements AfterViewInit {
   title = 'Disaggregation';
-
-  data = deagg.response as nshmpHaz.disaggService.DisaggResponseData;
+  disaggCollection = new Collection<Disaggregation>([]);
+  data = disagg.response as nshmpHaz.disaggService.DisaggResponseData;
+  view: DisaggGraphView;
 
   @ViewChild('example')
   el: ElementRef<HTMLElement>;
@@ -22,13 +23,28 @@ export class AppComponent implements AfterViewInit {
 
   ngAfterViewInit(): void {
     const response = new DisaggResponse(this.data);
-    const deaggs = response.get<Collection<Disaggregation>>('disaggregations').data();
-    const collection = new Collection(deaggs);
-    collection.select(collection.data()[0]);
+    const disaggs = response.get<Collection<Disaggregation>>('disaggregations').data();
+    this.disaggCollection.addAll(disaggs);
+    this.disaggCollection.select(this.disaggCollection.data()[0]);
 
-    const view = new DisaggGraphView({
+    this.view = new DisaggGraphView({
       el: this.el.nativeElement,
-      collection,
+      collection: this.disaggCollection,
+      bounds: this.bounds(this.data),
     });
   }
+
+  bounds(data: nshmpHaz.disaggService.DisaggResponseData): number[][]{
+    const totalComponent = data.disaggs[0].data.find(d => d.component === 'Total');
+    return DisaggGraphView.calculateBounds(totalComponent.data);
+  }
+
+  onComponentChange(component: string): void {
+    const componentData = this.disaggCollection
+      .data()
+      .find(d => d.get('component') === component);
+
+   this.disaggCollection.select(componentData);
+  }
+
 }
-- 
GitLab