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, NgZone, Input, ViewChild, ElementRef, OnDestroy, } from '@angular/core';
\r
18 import * as am4core from "@amcharts/amcharts4/core";
\r
19 import * as am4charts from "@amcharts/amcharts4/charts";
\r
20 import { StatsService } from '../stats.service';
\r
21 import { Router } from '@angular/router';
\r
22 import { Subscription } from 'rxjs';
\r
24 //am4core.useTheme(frozen);
\r
25 //am4core.useTheme(am4themes_animated);
\r
28 selector: 'app-pie-chart',
\r
29 templateUrl: './pie-chart.component.pug',
\r
30 styleUrls: ['./pie-chart.component.scss']
\r
32 export class PieChartComponent implements OnInit, OnDestroy {
\r
34 private toDestroy: Array<Subscription> = [];
\r
36 @ViewChild('pieChartDiv') PieChartDiv: ElementRef;
\r
37 @ViewChild('legendDiv') legendDiv: ElementRef;
\r
38 @Input() height: string;
\r
40 protected stats: StatsService;
\r
41 public chart: am4charts.PieChart;
\r
42 private chartData: Array<Object>;
\r
43 public loadingIndicator;
\r
45 constructor(private statsService: StatsService, private route: Router) {
\r
46 this.stats = statsService;
\r
53 this.toDestroy.push(this.stats.onDefaultDataCallStarted().subscribe(res => {
\r
54 this.showLoadingIndicator();
\r
57 this.toDestroy.push(this.stats.onTDExecutionChangeStarted().subscribe(res => {
\r
58 this.showLoadingIndicator();
\r
61 this.toDestroy.push(this.stats.onDefaultDataCallFinished().subscribe(res => {
\r
62 this.setChartData();
\r
65 this.toDestroy.push(this.stats.onTDExecutionChangeFinished().subscribe(res => {
\r
70 // //Resize if screen size changes.
\r
71 // this.stats.checkWindow().subscribe(res=>{
\r
72 // this.renderChart();
\r
78 this.toDestroy.forEach(e => e.unsubscribe());
\r
79 this.chart.dispose();
\r
82 showLoadingIndicator() {
\r
84 if(!this.loadingIndicator){
\r
85 this.loadingIndicator = this.chart.tooltipContainer.createChild(am4core.Container);
\r
86 this.loadingIndicator.background.fill = am4core.color("#fff");
\r
87 this.loadingIndicator.background.fillOpacity = 0.8;
\r
88 this.loadingIndicator.width = am4core.percent(100);
\r
89 this.loadingIndicator.height = am4core.percent(100);
\r
91 let indicatorLabel = this.loadingIndicator.createChild(am4core.Label);
\r
92 indicatorLabel.text = "Loading..";
\r
93 indicatorLabel.align = "center";
\r
94 indicatorLabel.valign = "middle";
\r
95 indicatorLabel.fontSize = 18;
\r
96 indicatorLabel.fontWeight= "bold";
\r
97 indicatorLabel.dy = 50;
\r
99 let loadingImage = this.loadingIndicator.createChild(am4core.Image);
\r
100 //loadingImage.href = "https://img.devrant.com/devrant/rant/r_647810_4FeCH.gif";
\r
101 loadingImage.href = "/assets/images/equalizer.gif";
\r
102 //loadingImage.dataSource = "/loading-pies.svg"
\r
103 loadingImage.align = "center";
\r
104 loadingImage.valign = "middle";
\r
105 loadingImage.horizontalCenter = "middle";
\r
106 loadingImage.verticalCenter = "middle";
\r
107 loadingImage.scale = 3.0;
\r
109 this.loadingIndicator.show();
\r
115 hideLoadingIndicator() {
\r
116 this.loadingIndicator.hide();
\r
120 this.chartData = this.stats.getData("TD_Results") as Array<Object>;
\r
121 if (this.chartData.length == 0) {
\r
122 this.chart.data = [{
\r
127 this.chart.series.values[0].tooltipText = "No Executions Found"
\r
129 this.chart.data = this.chartData;
\r
130 //OnClick open page for that result.
\r
131 this.chart.series.values[0].slices.template.events.on("doublehit", (clickedSlice) => {
\r
132 this.route.navigate(['/test-executions', { filter: clickedSlice.target.dataItem.dataContext['Name'].toString().toLowerCase() }]);
\r
135 this.hideLoadingIndicator();
\r
141 this.chart = am4core.create(this.PieChartDiv.nativeElement, am4charts.PieChart);
\r
142 let series = this.chart.series.push(new am4charts.PieSeries());
\r
143 this.chart.scale = 1;
\r
144 this.chart.align = "center";
\r
145 this.showLoadingIndicator();
\r
147 // this.chart.legend = new am4charts.Legend();
\r
148 // this.chart.legend.position = "right";
\r
149 // this.chart.legend.scale = .7;
\r
150 // this.chart.legend.markers.template.width = 10;
\r
151 // this.chart.legend.markers.template.height = 10;
\r
153 //chart.preloader.disabled = false;
\r
154 //chart.hiddenState.properties.opacity = 0; // this creates initial fade-in
\r
156 // var legendContainer = am4core.create(this.legendDiv.nativeElement, am4core.Container);
\r
157 // legendContainer.width = am4core.percent(100);
\r
158 // legendContainer.height = am4core.percent(100);
\r
159 // this.chart.legend.parent = legendContainer;
\r
160 series.dataFields.value = "Count";
\r
161 series.dataFields.category = "Name";
\r
162 series.slices.template.strokeWidth = 1;
\r
163 series.slices.template.strokeOpacity = 1;
\r
164 series.slices.template.propertyFields.fill = "color"
\r
167 // This creates initial animation
\r
168 series.hiddenState.properties.opacity = 1;
\r
169 series.hiddenState.properties.endAngle = -90;
\r
170 series.hiddenState.properties.startAngle = -90;
\r
171 series.ticks.template.disabled = false;
\r
172 series.labels.template.disabled = false;
\r
173 series.titleElement.textContent = 'Total Test Results'
\r
175 //responsive pie chart. if size of chart is less than 450 pixels remove legend.
\r
176 this.chart.responsive.enabled = true;
\r