added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / components / stats / line-chart / line-chart.component.ts
diff --git a/otf-frontend/client/src/app/layout/components/stats/line-chart/line-chart.component.ts b/otf-frontend/client/src/app/layout/components/stats/line-chart/line-chart.component.ts
new file mode 100644 (file)
index 0000000..e7f0780
--- /dev/null
@@ -0,0 +1,172 @@
+/*  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, Input, ViewChild, ElementRef, OnDestroy } from '@angular/core';\r
+import { StatsService } from '../stats.service';\r
+import * as am4core from "@amcharts/amcharts4/core";\r
+import * as am4charts from "@amcharts/amcharts4/charts";\r
+import { _ } from 'ag-grid-community';\r
+import * as moment from 'moment';\r
+import { Subscription } from 'rxjs';\r
+\r
+// am4core.useTheme(am4themes_animated);\r
+\r
+@Component({\r
+  selector: 'app-line-chart',\r
+  templateUrl: './line-chart.component.pug',\r
+  styleUrls: ['./line-chart.component.scss']\r
+})\r
+export class LineChartComponent implements OnInit, OnDestroy {\r
+\r
+  private toDestroy: Array<Subscription> = [];\r
+\r
+  @ViewChild('linechartdiv') LineChartDiv: ElementRef;\r
+  @Input() height: string;\r
+\r
+  //public testDefinitionName = "Hello";\r
+  private chart: am4charts.XYChart;\r
+  private loadingIndicator;\r
+\r
+  constructor(private stats: StatsService) {\r
+  }\r
+\r
+  ngOnInit() {\r
+\r
+    this.renderChart();\r
+\r
+    this.toDestroy.push(this.stats.onTDExecutionChangeStarted().subscribe(res => {\r
+      this.showLoadingIndicator();\r
+    }));\r
+\r
+    this.toDestroy.push(this.stats.onDefaultDataCallStarted().subscribe(res => {\r
+      this.showLoadingIndicator();\r
+    }));\r
+\r
+    this.toDestroy.push(this.stats.onDefaultDataCallFinished().subscribe(res => {\r
+      this.setChartData();\r
+    }));\r
+\r
+    this.toDestroy.push(this.stats.onTDExecutionChangeFinished().subscribe(res => {\r
+      this.setChartData();\r
+    }));\r
+\r
+  }\r
+\r
+  ngOnDestroy(){\r
+    //destory chart\r
+    this.chart.dispose();\r
+  }\r
+\r
+  //Sets count to 0 for any dates that dont have data\r
+  setupPoints(rawData) {\r
+    \r
+    let formattedData = []; \r
+    let dayRange = moment(this.stats.filters.endDate).add(1, 'days').diff(moment(this.stats.filters.startDate), 'days');\r
+    \r
+    for(let i = 0; i < dayRange; i++){\r
+      //find date in raw data\r
+      let d = rawData.find(e => moment(e.date).isSame(moment(this.stats.filters.startDate).add(i, 'days'), 'day'));\r
+      let count = 0;\r
+      if(d){\r
+        count = d.count;\r
+      }\r
+      formattedData.push({\r
+        date: moment(this.stats.filters.startDate).startOf('day').add(i, 'days').toDate(),\r
+        count: count\r
+      })\r
+    }\r
+\r
+    return formattedData;\r
+  }\r
+\r
+  showLoadingIndicator() {\r
+\r
+    //this.height = "380px";\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
+  hideLoadingIndicator() {\r
+    this.loadingIndicator.hide();\r
+  }\r
+\r
+  setChartData() {\r
+    let executions = this.stats.getData('TD_Executions');\r
+    this.chart.data = this.setupPoints(executions);\r
+\r
+    this.hideLoadingIndicator();\r
+  }\r
+\r
+  renderChart() {\r
+\r
+    if(this.chart){\r
+      this.chart.dispose();\r
+    }\r
+    this.chart = am4core.create(this.LineChartDiv.nativeElement, am4charts.XYChart);\r
+    this.chart.preloader.disabled = true;\r
+    this.showLoadingIndicator();\r
+\r
+    let dateAxis = this.chart.xAxes.push(new am4charts.DateAxis());\r
+    dateAxis.fontSize = "10px";\r
+\r
+    let valueAxis = this.chart.yAxes.push(new am4charts.ValueAxis());\r
+    valueAxis.title.text = "Executions";\r
+    valueAxis.title.fontSize = "10px";\r
+\r
+    let series = this.chart.series.push(new am4charts.LineSeries());\r
+    series.dataFields.dateX = "date";\r
+    series.dataFields.valueY = "count";\r
+    series.strokeWidth = 3;\r
+\r
+    series.fillOpacity = .5;\r
+    // series.tensionX = 0.8;\r
+    series.sequencedInterpolation = false;\r
+    series.tooltipText = "{valueY.value}";\r
+\r
+    this.chart.cursor = new am4charts.XYCursor();\r
+\r
+    this.chart.responsive.enabled = true;\r
+  }\r
+\r
+\r
+\r
+\r
+}\r