added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / components / stats / horiz-bar-chart / horiz-bar-chart.component.ts
diff --git a/otf-frontend/client/src/app/layout/components/stats/horiz-bar-chart/horiz-bar-chart.component.ts b/otf-frontend/client/src/app/layout/components/stats/horiz-bar-chart/horiz-bar-chart.component.ts
new file mode 100644 (file)
index 0000000..af6175e
--- /dev/null
@@ -0,0 +1,175 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, OnInit, NgZone, Input, ViewChild, ElementRef, OnDestroy, } from '@angular/core';\r
+import * as am4core from "@amcharts/amcharts4/core";\r
+import * as am4charts from "@amcharts/amcharts4/charts";\r
+import { StatsService } from '../stats.service'\r
+\r
+// am4core.useTheme(am4themes_animated);\r
+\r
+@Component({\r
+  selector: 'app-horiz-bar-chart',\r
+  templateUrl: './horiz-bar-chart.component.pug',\r
+  styleUrls: ['./horiz-bar-chart.component.scss']\r
+})\r
+export class HorizBarChartComponent implements OnInit, OnDestroy {\r
+\r
+  @ViewChild('horizBarChartDiv') HorizBarChartDiv: ElementRef;\r
+  @Input() height: string;\r
+\r
+  public chart: am4charts.XYChart;\r
+  public testInstanceData;\r
+  public loadingIndicator;\r
+  protected stats: StatsService;\r
+\r
+  constructor(private statsService: StatsService) {\r
+    this.stats = statsService;\r
+  }\r
+\r
+\r
+  ngOnInit() {\r
+    this.renderChart();\r
+\r
+    this.stats.onDefaultDataCallStarted().subscribe(res => {\r
+      this.showLoadingIndicator();\r
+    })\r
+\r
+    this.stats.onTIExecutionChangeStarted().subscribe(res => {\r
+      this.showLoadingIndicator();\r
+    })\r
+\r
+    this.stats.onDefaultDataCallFinished().subscribe(res => {\r
+      this.setChartData();\r
+    })\r
+\r
+    this.stats.onTIExecutionChangeFinished().subscribe(res => {\r
+      this.setChartData()\r
+    })\r
+\r
+  }\r
+\r
+  ngOnDestroy() {\r
+    this.chart.dispose();\r
+  }\r
+\r
+  showLoadingIndicator() {\r
+    if(!this.loadingIndicator){\r
+      this.loadingIndicator = this.chart.tooltipContainer.createChild(am4core.Container);\r
+      this.loadingIndicator.background.fill = am4core.color("#fff");\r
+      this.loadingIndicator.background.fillOpacity = 0.8;\r
+      this.loadingIndicator.width = am4core.percent(100);\r
+      this.loadingIndicator.height = am4core.percent(100);\r
+\r
+      let indicatorLabel = this.loadingIndicator.createChild(am4core.Label);\r
+      indicatorLabel.text = "Loading..";\r
+      indicatorLabel.align = "center";\r
+      indicatorLabel.valign = "middle";\r
+      indicatorLabel.fontSize = 18;\r
+      indicatorLabel.fontWeight= "bold";\r
+      indicatorLabel.dy = 50;\r
+\r
+      let loadingImage = this.loadingIndicator.createChild(am4core.Image);\r
+      //loadingImage.href = "https://img.devrant.com/devrant/rant/r_647810_4FeCH.gif";\r
+      loadingImage.href = "/assets/images/equalizer.gif";\r
+      //loadingImage.dataSource = "/loading-pies.svg"\r
+      loadingImage.align = "center";\r
+      loadingImage.valign = "middle";\r
+      loadingImage.horizontalCenter = "middle";\r
+      loadingImage.verticalCenter = "middle";\r
+      loadingImage.scale = 3.0;\r
+    }else{\r
+      this.loadingIndicator.show();\r
+    }\r
+\r
+  }\r
+\r
+  hideLoadingIndicator() {\r
+    this.loadingIndicator.hide();\r
+  }\r
+\r
+  setChartData() {\r
+    this.testInstanceData = this.stats.getData('testInstances');\r
+    this.chart.data = this.testInstanceData;\r
+\r
+    // Displays the average time for each bar. \r
+    // If there is no time recorded for the Test Instance, display No Time Recorded.\r
+    let series = this.chart.series.values[0] as am4charts.ColumnSeries;\r
+    \r
+    \r
+    series.columns.template.adapter.add("tooltipText", (text, target) => {\r
+      if (target.dataItem) {\r
+        if (this.chart.data[target.dataItem.index].Average > 0) {\r
+          return this.chart.data[target.dataItem.index].Count.toString() + " Executions \n Avg Time: " + this.chart.data[target.dataItem.index].Average.toFixed(2).toString() + " seconds";\r
+        } else\r
+          return this.chart.data[target.dataItem.index].Count.toString() + " Executions \n No Time Recorded";\r
+      }\r
+    });\r
+    series.columns.template.adapter.add("fill", (fill, target) => this.chart.colors.getIndex(target.dataItem.index));\r
+    // console.log(this.chart.yAxes);\r
+    this.chart.yAxes.values[0].zoomToIndexes(0, 6, false, true);\r
+    this.hideLoadingIndicator();\r
+    \r
+  }\r
+\r
+  renderChart() {\r
+    this.chart = am4core.create(this.HorizBarChartDiv.nativeElement, am4charts.XYChart);\r
+    this.chart.cursor = new am4charts.XYCursor();\r
+    this.showLoadingIndicator();\r
+\r
+    this.chart.responsive.enabled = true;\r
+\r
+    // Create axes\r
+    var categoryAxis = this.chart.yAxes.push(new am4charts.CategoryAxis());\r
+    categoryAxis.dataFields.category = "Name";\r
+    categoryAxis.numberFormatter.numberFormat = "#";\r
+    categoryAxis.renderer.inversed = true;\r
+    categoryAxis.renderer.minGridDistance = 5;\r
+    categoryAxis.title.text = "Test Instances";\r
+    categoryAxis.title.fontSize = "10px";\r
+\r
+    var valueAxis = this.chart.xAxes.push(new am4charts.ValueAxis());\r
+    valueAxis.renderer.minWidth = 10;\r
+\r
+    // Create series\r
+    var series = this.chart.series.push(new am4charts.ColumnSeries());\r
+    series.dataFields.valueX = "Count";\r
+    series.dataFields.categoryY = "Name";\r
+    series.columns.template.tooltipText = " ";\r
+\r
+    let label = categoryAxis.renderer.labels.template;\r
+    label.truncate = true;\r
+    label.maxWidth = 130;\r
+    label.fontSize = 13;\r
+\r
+    //Scrollbar on the right. \r
+    let scrollBarY = new am4charts.XYChartScrollbar();\r
+    scrollBarY.series.push(series);\r
+    this.chart.scrollbarY = scrollBarY;\r
+    this.chart.scrollbarY.contentHeight = 100;\r
+    this.chart.scrollbarY.minWidth = 20;\r
+    this.chart.scrollbarY.thumb.minWidth = 20;\r
+\r
+    //set initial Scrollbar Zoom to the Top 6 Instances. \r
+  //   this.chart.events.on("ready", () => {\r
+  //     console.log("here")\r
+  //     categoryAxis.zoomToIndexes(0, 6, false, true);\r
+  //   });\r
+   }\r
+\r
+}\r
+\r
+\r