1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Component, OnInit, ViewChild, ElementRef, Input, Output, EventEmitter } from '@angular/core';
\r
18 import { Subscription } from 'rxjs';
\r
19 import { StatsService } from 'app/layout/components/stats/stats.service';
\r
20 import * as moment from 'moment';
\r
21 import * as am4core from "@amcharts/amcharts4/core";
\r
22 import * as am4charts from "@amcharts/amcharts4/charts";
\r
25 selector: 'app-test-head-executions-line-chart',
\r
26 templateUrl: './test-head-executions-line-chart.component.pug',
\r
27 styleUrls: ['./test-head-executions-line-chart.component.scss']
\r
29 export class TestHeadExecutionsLineChartComponent implements OnInit {
\r
31 private toDestroy: Array<Subscription> = [];
\r
33 @ViewChild('linechartdiv') LineChartDiv: ElementRef;
\r
34 @Input() height: string;
\r
35 @Input() testHeadId;
\r
36 @Output() total: EventEmitter<any> = new EventEmitter();
\r
38 //public testDefinitionName = "Hello";
\r
39 private chart: am4charts.XYChart;
\r
40 private loadingIndicator;
\r
42 constructor(private stats: StatsService) {
\r
50 this.toDestroy.push(this.stats.onTDExecutionChangeStarted().subscribe(res => {
\r
51 this.showLoadingIndicator();
\r
54 this.toDestroy.push(this.stats.onDefaultDataCallStarted().subscribe(res => {
\r
55 this.showLoadingIndicator();
\r
58 this.toDestroy.push(this.stats.onDefaultDataCallFinished().subscribe(res => {
\r
59 this.setChartData();
\r
62 this.toDestroy.push(this.stats.onTDExecutionChangeFinished().subscribe(res => {
\r
63 this.setChartData();
\r
70 this.chart.dispose();
\r
73 //Sets count to 0 for any dates that dont have data
\r
74 setupPoints(rawData) {
\r
75 let formattedData = [];
\r
76 let dayRange = moment(this.stats.filters.endDate).add(1, 'days').diff(moment(this.stats.filters.startDate), 'days');
\r
78 for(let i = 0; i < dayRange; i++){
\r
79 //find date in raw data
\r
80 let d = rawData.find(e => moment(e.date).isSame(moment(this.stats.filters.startDate).add(i, 'days'), 'day'));
\r
85 formattedData.push({
\r
86 date: moment(this.stats.filters.startDate).startOf('day').add(i, 'days').toDate(),
\r
91 return formattedData;
\r
94 showLoadingIndicator() {
\r
96 //this.height = "380px";
\r
97 if(!this.loadingIndicator){
\r
98 this.loadingIndicator = this.chart.tooltipContainer.createChild(am4core.Container);
\r
99 this.loadingIndicator.background.fill = am4core.color("#fff");
\r
100 this.loadingIndicator.background.fillOpacity = 0.8;
\r
101 this.loadingIndicator.width = am4core.percent(100);
\r
102 this.loadingIndicator.height = am4core.percent(100);
\r
104 let indicatorLabel = this.loadingIndicator.createChild(am4core.Label);
\r
105 indicatorLabel.text = "Loading..";
\r
106 indicatorLabel.align = "center";
\r
107 indicatorLabel.valign = "middle";
\r
108 indicatorLabel.fontSize = 18;
\r
109 indicatorLabel.fontWeight = "bold";
\r
110 indicatorLabel.dy = 50;
\r
112 let loadingImage = this.loadingIndicator.createChild(am4core.Image);
\r
113 //loadingImage.href = "https://img.devrant.com/devrant/rant/r_647810_4FeCH.gif";
\r
114 loadingImage.href = "/assets/images/equalizer.gif";
\r
115 //loadingImage.dataSource = "/loading-pies.svg"
\r
116 loadingImage.align = "center";
\r
117 loadingImage.valign = "middle";
\r
118 loadingImage.horizontalCenter = "middle";
\r
119 loadingImage.verticalCenter = "middle";
\r
120 loadingImage.scale = 3.0;
\r
122 this.loadingIndicator.show();
\r
126 hideLoadingIndicator() {
\r
127 this.loadingIndicator.hide();
\r
133 this.stats.executionList.forEach(e => {
\r
134 if (e.testHeadResults && e.testHeadResults.length > 0) {
\r
136 e.testHeadResults.forEach((result, index) => {
\r
138 if(result.testHeadId == this.testHeadId){
\r
140 let dataIndex = data.findIndex(d => moment(d.date).isSame(result.startTime, 'day'));
\r
142 if (dataIndex == -1) {
\r
143 data.push({ date: moment(result.startTime).toDate(), count: 1 });
\r
145 data[dataIndex].count++;
\r
154 this.chart.data = this.setupPoints(data);
\r
155 this.total.emit(total);
\r
156 this.hideLoadingIndicator();
\r
162 this.chart.dispose();
\r
164 this.chart = am4core.create(this.LineChartDiv.nativeElement, am4charts.XYChart);
\r
165 this.chart.preloader.disabled = true;
\r
166 this.showLoadingIndicator();
\r
168 let dateAxis = this.chart.xAxes.push(new am4charts.DateAxis());
\r
169 dateAxis.fontSize = "10px";
\r
171 let valueAxis = this.chart.yAxes.push(new am4charts.ValueAxis());
\r
172 valueAxis.title.text = "Executions";
\r
173 valueAxis.title.fontSize = "10px";
\r
175 let series = this.chart.series.push(new am4charts.LineSeries());
\r
176 series.dataFields.dateX = "date";
\r
177 series.dataFields.valueY = "count";
\r
178 series.strokeWidth = 3;
\r
180 series.fillOpacity = .5;
\r
181 // series.tensionX = 0.8;
\r
182 series.sequencedInterpolation = false;
\r
183 series.tooltipText = "{valueY.value}";
\r
185 this.chart.cursor = new am4charts.XYCursor();
\r
187 this.chart.responsive.enabled = true;
\r