heatmap.component.ts 2.11 KB
Newer Older
Laura Morel's avatar
Laura Morel committed
1
2
3
4
5
6
import { Component, OnInit, Input, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { NgxSpinnerService } from 'ngx-spinner';
import { CookieService } from "ngx-cookie-service";

import { DataService } from '../../data.service';
Laura Morel's avatar
Laura Morel committed
7
import { HeatmapInfoService } from '../../heatmap-info.service';
Laura Morel's avatar
Laura Morel committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { LegendComponent} from './legend/legend.component';
import { CanvasComponent } from './canvas/canvas.component';

@Component({
  selector: 'app-heatmap',
  templateUrl: './heatmap.component.html',
  styleUrls: ['./heatmap.component.css']
})
export class HeatmapComponent implements OnInit {

  @ViewChild(CanvasComponent) canvas: CanvasComponent;

  public formdata: Object;

  public src: string = "no_heatmap";
  public img: HTMLImageElement;
  public imgLoading: boolean = false;

  constructor(private dataService: DataService,
Laura Morel's avatar
Laura Morel committed
27
              private heatmapInfoService: HeatmapInfoService,
Laura Morel's avatar
Laura Morel committed
28
29
              private sanitizer: DomSanitizer,
              private spinner: NgxSpinnerService,
Laura Morel's avatar
Laura Morel committed
30
31
              private cookieService: CookieService,
            ) { }
Laura Morel's avatar
Laura Morel committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

  ngOnInit(): void {
    this.spinner.show();
    this.dataService.submittedData.subscribe(data => {
      this.formdata = data;
      this.setImg();
    });
  }

  setImg(): void{
    this.imgLoading = true;
    this.dataService.filter_highlight(this.formdata).subscribe(img => {
      this.imgFromBlob(img);
    }, error => {
      this.imgLoading = false;
Laura Morel's avatar
Laura Morel committed
47
      this.heatmapInfoService.img_loaded(false);
Laura Morel's avatar
Laura Morel committed
48
49
50
51
52
53
54
      console.log(error);
    });
  }


  setSrc(src: string): void{
    this.src = src;
Laura Morel's avatar
Laura Morel committed
55
56
57
    //let img = new Image();
    //img.src = this.src;
    //this.img = img;
Laura Morel's avatar
Laura Morel committed
58
59
60
61
62
63
64
  }

  imgFromBlob(img: Blob) {
    console.log("Getting URL from Blob");
    let reader = new FileReader();
    reader.addEventListener("load", () => {
      this.setSrc(reader.result as string);
Laura Morel's avatar
Laura Morel committed
65
      this.canvas.setImg(this.src);
Laura Morel's avatar
Laura Morel committed
66
      this.imgLoading = false;
Laura Morel's avatar
Laura Morel committed
67
      this.heatmapInfoService.img_loaded(true);
Laura Morel's avatar
Laura Morel committed
68
69
70
71
72
73
74
75
76
77
      console.log("Heatmap src changed to: ", this.src);
    }, false);

    if (img) {
      reader.readAsDataURL(img);
    }
  }


}