summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/chart-wizard/chart-wizard.component.ts
blob: 2d9a52c0da8a4ae8b2558c61b8c6d4d2569bfd1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import {Component, OnInit, Input} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Router} from '@angular/router';
import {ChartWizard} from './chart-wizard.service';
import {RangeAxisListModel} from './chart-wizard-model/range-axis-list-model';
import {error} from 'util';
import {forEach} from '@angular/router/src/utils/collection';
import {MatDialog, MatDialogConfig} from '@angular/material';

@Component({
    selector: 'app-chart-wizard',
    templateUrl: './chart-wizard.component.html',
    styleUrls: ['./chart-wizard.component.css']
})
export class ChartWizardComponent implements OnInit {


    @Input() reportId: string;

    chartJson: any;
    showSpinner: boolean;
    isFirstBar: boolean;
    isFirstTimeSeries: boolean;
    lineTypes = [
        {index: 0, value: 'default', title: 'Default'},
        {index: 1, value: 'dotted_lines', title: 'Dotted Lines'},
        {index: 2, value: 'dashed_lines', title: 'Dashed Lines'}
    ];
    rangeColors = [
        {index: 0, value: '#1f77b4', title: 'Dodger Blue'},
        {index: 1, value: '#ff7f0e', title: 'Vivid orange'},
        {index: 2, value: '#2ca02c', title: 'Forest Green'},
        {index: 3, value: '#8c864b', title: 'Greenish Red'},
        {index: 4, value: '#9467bd', title: 'Desaturated violet'},
        {index: 5, value: '#8c564b', title: 'Dark moderate red'},
        {index: 6, value: '#e377c2', title: 'Soft pink'},
        {index: 7, value: '#7f7f7f', title: 'Dark gray'},
        {index: 8, value: '#bcbd22', title: 'Strong yellow'},
        {index: 9, value: '#17becf', title: 'Strong cyan'},
        {index: 10, value: '#dc143c', title: 'Vivid red'},
        {index: 11, value: '#800080', title: 'Dark magenta'},
        {index: 12, value: '#0000FF', title: 'Blue'},
        {index: 13, value: '#008000', title: 'Dark lime green'},
        {index: 14, value: '#D2691E', title: 'Reddish Orange'},
        {index: 15, value: '#FF0000', title: 'Red'},
        {index: 16, value: '#000000', title: 'Black'},
        {index: 17, value: '#DB7093', title: 'Pink'},
        {index: 18, value: '#FF00FF', title: 'Pure Magenta'},
        {index: 19, value: '#7B68EE', title: 'Soft blue'},
        {index: 20, value: '#1f77b6', title: 'Strong blue'},
        {index: 21, value: '#9edae5', title: 'Very soft cyan'},
        {index: 22, value: '#393b79', title: 'Dark Blue'},
        {index: 23, value: '#5254a3', title: 'Dark moderate Blue'},
        {index: 24, value: '#6b6ecf', title: 'Slightly desaturated blue'},
        {index: 25, value: '#9c9ede', title: 'Very soft blue'},
        {index: 26, value: '#637939', title: 'Dark Green'},
        {index: 27, value: '#8ca252', title: 'Dark moderate green'},
        {index: 28, value: '#b5cf6b', title: 'Slightly desaturated green'},
        {index: 29, value: '#cedb9c', title: 'Desaturated Green'},

        /* Old Colors  */
        {index: 30, value: '#00FFFF', title: 'Aqua'},
        {index: 31, value: '#000000', title: 'Black'},
        {index: 32, value: '#0000FF', title: 'Blue'},
        {index: 33, value: '#FF00FF', title: 'Fuchsia'},
        {index: 34, value: '#808080', title: 'Gray'},
        {index: 35, value: '#008000', title: 'Green'},
        {index: 36, value: '#00FF00', title: 'Lime'},
        {index: 37, value: '#800000', title: 'Maroon'},
        {index: 38, value: '#000080', title: 'Navy'},
        {index: 39, value: '#808000', title: 'Olive'},
        {index: 40, value: '#FF9900', title: 'Orange'},
        {index: 41, value: '#800080', title: 'Purple'},
        {index: 42, value: '#FF0000', title: 'Red'},
        {index: 43, value: '#C0C0C0', title: 'Silver'},
        {index: 44, value: '#008080', title: 'Teal'},
        {index: 45, value: '#FFFFFF', title: 'White'},
        {index: 46, value: '#FFFF00', title: 'Yellow'}
    ];
    displayedColumns: string[] = ['Range Axis', 'Y Axis', 'Chart Title', 'Color', 'Line Type'];
    rangeAxisRemoveList: RangeAxisListModel[];
    hideChart = false;
    displayOptions: {}[];

    constructor(private _http: HttpClient, private _router: Router, private chartService: ChartWizard,  private dialog: MatDialog) {
    }

    ngOnInit() {
        this.showSpinner = true;
        this.isFirstBar = false;
        this.isFirstTimeSeries = false;
        this.chartService.getReportTypeData(this.reportId).subscribe(
            (respone) => {
                this.displayOptions = respone['displayOptions'];
                for (let dpOption = 0 ; dpOption < this.displayOptions.length ; dpOption++) {
                    if (this.displayOptions[dpOption]['name'] === 'HideChart') {
                        this.hideChart = this.displayOptions[dpOption]['selected'];
                    }
                }
            });
        if (!this.hideChart) {
            this.chartService.getChartData(this.reportId).subscribe(
                (response) => {
                    this.chartJson = response;
                    // @ts-ignore
                    this.rangeAxisRemoveList = response.rangeAxisRemoveList;
                    this.showSpinner = false;
                });
        }
    }

    saveChartData(value: String) {
        this.showSpinner = true;
        this.chartJson.chartTypeJSON = {
            index: 0,
            value: this.chartJson.chartType,
            title: ''
        };
        this.chartJson.categoryAxisJSON = this.chartJson.categoryAxisJSON || {};
        if (this.chartJson.categoryAxis) {
            this.chartJson.categoryAxisJSON = {
                index: 0,
                value: this.chartJson.categoryAxis,
                title: this.chartJson.categoryAxis
            };
        } 
		else {
            this.chartJson.categoryAxisJSON = {};
        }
        this.rangeAxisRemoveList = this.rangeAxisRemoveList || [];
        this.chartJson.rangeAxisRemoveList = this.rangeAxisRemoveList;
        for (const removeList of this.rangeAxisRemoveList) {
            this.chartJson.rangeAxisList.push(removeList);
        }

          this.chartService.saveChartData(this.chartJson, value).subscribe(
              (response) => {
                  this.ngOnInit();
              });
        this.showSpinner = false;
    }

    addRangeAxisRow() {
        this.chartJson.rangeAxisList = this.chartJson.rangeAxisList || {};
        this.chartJson.rangeAxisList.push(new RangeAxisListModel());
    }

    removeRangeAxisRow(d: any) {
        this.chartJson.rangeAxisList = this.chartJson.rangeAxisList.filter(item => item !== d);
        this.rangeAxisRemoveList = this.rangeAxisRemoveList || [];
        this.rangeAxisRemoveList.push(d);
        this.chartJson.rangeAxisRemoveList = this.rangeAxisRemoveList;
    }

    setBarChartOptions() {
        this.chartJson.barChartOptions = this.chartJson.barChartOptions || {
            verticalOrientation: null,
            stackedChart: null,
            displayBarControls: null,
            xAxisDateType: null,
            minimizeXAxisTickers: null,
            timeAxis: null,
            yAxisLogScale: null
        };
    }

    setTimeSeriesChartOptions() {
          this.chartJson.timeSeriesChartOptions = this.chartJson.timeSeriesChartOptions || {
              lineChartRenderer: null,
              showXAxisLabel: null,
              addXAxisTicker: null,
              nonTimeAxis: null,
              multiSeries: null
          };
    }

}