table-overview.component.ts 3.51 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
2
import {StateService} from '../state.service';
3
4
5
6
7
8
9
10

@Component({
  selector: 'app-table-overview',
  templateUrl: './table-overview.component.html',
  styleUrls: ['./table-overview.component.css']
})
export class TableOverviewComponent implements OnInit {
  public subplots;
11
  public averages;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
12
  constructor(private state: StateService) { }
13
14

  ngOnInit(): void {
15
    this.state.onNewTable.subscribe(() => this.createHistograms());
16
    // this.state.onNewTableInfo.subscribe(() => this.createPrototypes());
17
18
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
19
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
48
  createPrototypes(): void {
    this.averages = this.state.tableInfo.prototypes.map(prototype => {
      return {
        data: [
          {
            x: [...Array(prototype.average.length).keys()],
            y: prototype.average,
            type: 'line',
          },
          {
            x: [...Array(prototype.average.length).keys()],
            y: prototype.max,
            type: 'scatter',
            fill: null,
            mode: 'lines',
            line: {
              color: 'rgb(55, 128, 191)',
              width: 3
            }
          },
          {
            x: [...Array(prototype.average.length).keys()],
            y: prototype.min,
            type: 'scatter',
            fill: 'tonexty',
            mode: 'lines',
            line: {
              color: 'rgb(55, 128, 191)',
              width: 3
            }
49
          }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
        ],
        layout: {
          showlegend: false,
          hovermode: 'closest',
          autosize: true,
          margin: {
            l: 10,
            r: 10,
            t: 10,
            b: 10,
            pad: 4
          },
          xaxis: {
            showticklabels: false
          },
          yaxis: {
            showticklabels: false
          },
          height: 100,
          width: screen.width * 0.1,
70
        }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
71
72
      };
    });
73
74
  }

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
75
  async createHistograms() {
76
    console.log('creating table histograms');
77
    this.subplots = [];
78
    this.averages = [];
79
    const tables = this.state.table;
80
81
82
    console.log('start of table histograms');
    tables.forEach((table, index) => {
      console.log(index);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
      this.subplots.push(
        {
          data: [{
            x: Object.keys(table),
            y: Object.values(table).map((values: number[]) => values.length), // / (this.service.rawValues.length - this.service.windowSize)),
            type: 'bar',
            opacity: 0.5,
            marker: {
              color: Object.keys(table).map((key) => {
                return this.getColor(Number(key) / Number(Object.keys(table)[Object.keys(table).length - 1]));
              })
            }
          }],
          layout: {
            hovermode: 'closest',
            autosize: true,
            margin: {
              l: 10,
              r: 10,
              t: 10,
              b: 10,
              pad: 4
            },
            xaxis: {
              showticklabels: false
            },
            yaxis: {
              showticklabels: false
            },
            height: 100,
            width: screen.width * 0.1,
          }
115
        }
116
117
      );
    });
118
    console.log('tables histogram created');
119
  }
120

Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
121
122
123
124
  // async setQuery(data) {
  //   this.state.queryWindow = await this.state.getQueryWindow(data[0].y);
  //   await this.state.update();
  // }
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
125
126

  public get tables() {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
127
    return this.state.table;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
128
129
130
  }

  public get visible() {
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
131
    return !this.state.querySelectionMode;
Kruyff,D.L.W. (Dylan)'s avatar
Kruyff,D.L.W. (Dylan) committed
132
  }
133
134
135
136
137

  getColor(value) {
    const hue=((1-value)*120).toString(10);
    return ["hsl(",hue,",100%,50%)"].join("");
  }
138
}