Project

General

Profile

1
import {
2
  ChartHelper, FilterType,
3
  Indicator, IndicatorFilterUtils,
4
  IndicatorPath, IndicatorPathType, IndicatorType,
5
  SourceType,
6
  Stakeholder,
7
  SubCategory,
8
  Topic, Visibility
9
} from "../openaireLibrary/monitor/entities/stakeholder";
10
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
11
import {Option} from "../openaireLibrary/dashboard/sharedComponents/input/input.component";
12
import {Session} from "../openaireLibrary/login/utils/helper.class";
13

    
14
export class StakeholderUtils {
15
  statuses: Option[] = [
16
    {value: 'PUBLIC', label: 'Public'},
17
    {value: 'RESTRICTED', label: 'Restricted'},
18
    {value: 'PRIVATE', label: 'Private'}
19
  ];
20
  
21
  types: Option[] = [
22
    {value: 'funder', label: 'Funder'},
23
    {value: 'ri', label: 'Reasearch Initiative'},
24
    {value: 'project', label: 'Project'},
25
    {value: 'organization', label: 'Organization'}
26
  ];
27
  getTypesByUserRoles(user, id:string = null):Option[]{
28
    let types = [];
29
    for(let type of this.types){
30
      if(Session.isCurator(type.value, user)|| Session.isPortalAdministrator(user)|| (id && Session.isManager(type.value, id, user))){
31
        types.push(type);
32
      }
33
    }
34
    return types;
35
  }
36
  visibility: Option[] = [
37
    {icon: 'world', value: "PUBLIC", label: 'Public'},
38
    {icon: 'lock', value: "RESTRICTED", label: 'Restricted'},
39
    {icon: 'users', value: "PRIVATE", label: 'Private'},
40
  ];
41

    
42
  isActive: Option[] = [
43
    {icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
44
    {icon: 'brightness_1', value: false, label: 'Inactive'},
45
  ];
46

    
47
  visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
48
    ["PUBLIC", 'earth'],
49
    ["PRIVATE", 'lock'],
50
    ["RESTRICTED", 'group']
51
  ]);
52

    
53
  isActiveIcon: string = 'brightness_1';
54

    
55
  public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[]): Stakeholder {
56
    funder.topics = defaultTopics;
57
    for (let topic of funder.topics) {
58
      // console.log('id:' + topic._id);
59
      topic.defaultId = topic._id;
60
      topic._id = null;
61
      // console.log('defaultId:' + topic.defaultId);
62
      for (let category of topic.categories) {
63
        category.defaultId = category._id;
64
        category._id = null;
65
        let subTokeep: SubCategory[] = [];
66
        for (let subCategory of category.subCategories) {
67
          subCategory.defaultId = subCategory._id;
68
          subCategory._id = null;
69
          if (!subCategory.recommendedFor || subCategory.recommendedFor.length == 0 || subCategory.recommendedFor.indexOf(funder.index_id) != -1) {
70
            subTokeep.push(subCategory);
71
          }
72
          for (let section of subCategory.charts) {
73
            let chartsTokeep: Indicator[] = [];
74
            section.defaultId = section._id;
75
            section.stakeholderAlias = funder.alias;
76
            section._id = null;
77
            for (let indicator of section.indicators) {
78
              indicator.defaultId = indicator._id;
79
              indicator._id = null;
80
              if (!indicator.recommendedFor || indicator.recommendedFor.length == 0 || indicator.recommendedFor.indexOf(funder.index_id) != -1) {
81
                chartsTokeep.push(indicator);
82
              }
83
              for (let indicatorPath of indicator.indicatorPaths) {
84
                if (indicatorPath.parameters) {
85
                  Object.keys(indicatorPath.parameters).forEach(key => {
86
                    //TODO check before delete
87
                    /*if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
88
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
89
                    } else if (indicatorPath.parameters[key].indexOf("_funder_id_") != -1) {
90
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_id_", funder.index_id);
91
                    } else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
92
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
93
                    }*/
94
                    if (key == "index_name") {
95
                      indicatorPath.parameters[key] = funder.index_name;
96
                    } else if (key == "index_id" ) {
97
                      indicatorPath.parameters[key] = funder.index_id;
98
                    }  else if (key == "index_shortName" ) {
99
                      indicatorPath.parameters[key] =  funder.index_shortName.toLowerCase();
100
                    }
101
                  });
102
                }
103
              }
104
            }
105
            section.indicators = chartsTokeep;
106
          }
107
          for (let section of subCategory.numbers) {
108
            section.defaultId = section._id;
109
            section.stakeholderAlias = funder.alias;
110
            section._id = null;
111
            for(let indicator of section.indicators) {
112
              indicator.defaultId = indicator._id;
113
              indicator._id = null;
114
              for (let indicatorPath of indicator.indicatorPaths) {
115
               /* indicatorPath.url = indicatorPath.url.replace("index_id", encodeURIComponent(funder.index_id));
116
                indicatorPath.url = indicatorPath.url.replace("index_name",  encodeURIComponent(funder.index_name));
117
                indicatorPath.url = indicatorPath.url.replace("index_shortName", encodeURIComponent(funder.index_shortName));*/
118
                // if(indicatorPath.parameters) {
119
                //   indicatorPath.parameters.forEach((value: string, key: string) => {
120
                //     if (value.indexOf("_funder_name_")!=-1) {
121
                //       indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
122
                //     }else if (value.indexOf("_fsn_")!=-1) {
123
                //       indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
124
                //     }
125
                //   });
126
                // }
127
              }
128
            }
129
          }
130

    
131
        }
132
        category.subCategories = subTokeep;
133
      }
134
    }
135
    console.log (funder)
136
    return funder;
137
  }
138

    
139
  aliasValidator(elements: any[]): ValidatorFn {
140
    return (control: AbstractControl): { [key: string]: string } | null => {
141
      if (control.value && elements.find(element =>
142
        element.alias === control.value
143
      )) {
144
        return {'error': 'Alias already in use'};
145
      }
146
      return null;
147
    }
148
  }
149
  
150
  generateAlias(name: string): string {
151
    let alias = name.toLowerCase();
152
    while (alias.includes('/') || alias.includes(' ')) {
153
      alias = alias.replace(' / ', '-');
154
      alias = alias.replace('/', '-');
155
      alias = alias.replace(' ', '-');
156
    }
157
    return alias;
158
  }
159
}
160

    
161
export class IndicatorUtils {
162

    
163
  allChartTypes: Option[] = [
164
    {value: 'pie', label: 'Pie'},
165
    {value: 'table', label: 'Table'},
166
    {value: 'line', label: 'Line'},
167
    {value: 'column', label: 'Column'},
168
    {value: 'bar', label: 'Bar'},
169
    {value: 'other', label: 'Other'}
170
  ];
171
  basicChartTypes:IndicatorPathType[] =["pie", "line", "column", "bar"];
172
  defaultChartType:IndicatorPathType = "other";
173
  indicatorSizes: Option[] = [
174
    {value: 'small', label: 'Small'},
175
    {value: 'medium', label: 'Medium'},
176
    {value: 'large', label: 'Large'}
177
  ];
178

    
179
  sourceTypes: Option[]  = [
180
    {value: 'search', label: 'Search'},
181
    {value: 'statistics', label: 'Statistics'},
182
    {value: 'metrics', label: 'Metrics'},
183
    {value: 'stats-tool', label: 'Statistics tool'}
184
  ];
185
  
186
  isPublic: Option[] = [
187
    {icon: 'public', value: true, label: 'Public'},
188
    {icon: 'lock', value: false, label: 'Private'},
189
  ];
190

    
191
  isActive: Option[] = [
192
    {icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
193
    {icon: 'brightness_1', value: false, label: 'Inactive'},
194
  ];
195

    
196
  chartTypesIcons: Map<string, string> = new Map([
197
    ['pie', 'pie_chart'],
198
    ['table', 'table_chart'],
199
    ['line', 'show_chart'],
200
    ['column', 'bar_chart'],
201
    ['bar', 'notes'],
202
    ['other', 'perm_media']
203
  ]);
204
  getChartTypes(initialType){
205
    let types: Option[]= [];
206
    if(this.basicChartTypes.indexOf(initialType) != -1){
207
      (this.allChartTypes).forEach(option => {
208
        if(this.basicChartTypes.indexOf(option.value)!=-1){
209
          types.push(option);
210
        }
211
      });
212
      return types;
213
    }else if(initialType == "table") {
214
      (this.allChartTypes).forEach(option => {
215
        if (initialType == option.value) {
216
          types.push(option);
217
        }
218
      });
219
      return types;
220
    }else {
221
      return this.allChartTypes;
222
    }
223
  }
224
  isPublicIcon: Map<boolean, string> = new Map([
225
    [true, 'public'],
226
    [false, 'lock']
227
  ]);
228

    
229
  isActiveIcon: string = 'brightness_1';
230

    
231
  ignoredParameters = ['index_name','index_id','index_shortName'];
232

    
233
  parametersValidators: Map<string, any> = new Map<string, any>([
234
    ['start_year', [Validators.required, Validators.pattern('^\\d+$')]],
235
    ['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
236
  ]);
237

    
238
  public getFullUrl(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
239
    let replacedUrl =indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
240
    if (indicatorPath.parameters) {
241
      Object.keys(indicatorPath.parameters).forEach(key => {
242
        let replacedValue = indicatorPath.parameters[key];
243
        if (startYear && key == "start_year" && indicatorPath.filters["start_year"]) {
244
          replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
245
        }
246
        if (endYear && key == "end_year" && indicatorPath.filters["end_year"]) {
247
          replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
248
        }
249
        if (key == "index_id") {
250
          replacedValue = stakeholder.index_id;
251
        }
252
        if (key == "index_name") {
253
          replacedValue = stakeholder.index_name;
254
        }
255
        if (key == "index_shortName") {
256
          replacedValue = stakeholder.index_shortName.toLowerCase();
257
        }
258

    
259
        replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
260
      });
261
    }
262
    if (indicatorPath.chartObject) {
263
      if (fundingL0 && indicatorPath.filters["fundingL0"]) {
264
        let newJsonObject = JSON.parse(replacedUrl);
265
        for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
266
          if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
267
            queries["query"]["filters"] = [];
268
          }
269
          //TODO check how it works if the query already has a filter
270
          queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["fundingL0"].replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix, fundingL0)));
271
        }
272
        replacedUrl = JSON.stringify(newJsonObject);
273
      }
274
      if (startYear && indicatorPath.filters["start_year"]) {
275
        let newJsonObject = JSON.parse(replacedUrl);
276

    
277
        for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
278
          if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
279
            queries["query"]["filters"] = [];
280
          }
281
          //TODO check how it works if the query already has a filter
282
          queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["start_year"].replace(ChartHelper.prefix + "start_year" + ChartHelper.suffix, startYear)));
283
        }
284
        replacedUrl = JSON.stringify(newJsonObject);
285
      }
286
      if (endYear && indicatorPath.filters["end_year"]) {
287
        let newJsonObject = JSON.parse(replacedUrl);
288
        for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
289
          if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
290
            queries["query"]["filters"] = [];
291
          }
292
          //TODO check how it works if the query already has a filter
293
          queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["end_year"].replace(ChartHelper.prefix + "end_year" + ChartHelper.suffix, endYear)));
294
        }
295
        replacedUrl = JSON.stringify(newJsonObject);
296
      }
297

    
298
    }
299
    //For numbers
300
    if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){
301
      indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
302
    }
303
    if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){
304
      indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
305
    }
306
    if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){
307
      indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
308
    }
309
    return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
310
  }
311
  public getFullUrlWithFilters(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded:boolean=false): string {
312
    indicatorPath.filtersApplied = 0;
313
    let replacedUrl = indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
314
    if (indicatorPath.parameters) {
315
      Object.keys(indicatorPath.parameters).forEach(key => {
316
        let replacedValue = indicatorPath.parameters[key];
317
        if (startYear && key == "start_year") {
318
          replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
319
        }
320
        if (endYear && key == "end_year") {
321
          replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
322
        }
323
        if (key == "index_id") {
324
          replacedValue = stakeholder.index_id;
325
        }
326
        if (key == "index_name") {
327
          replacedValue = stakeholder.index_name;
328
        }
329
        if (key == "index_shortName") {
330
          replacedValue = stakeholder.index_shortName.toLowerCase();
331
        }
332

    
333
        replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
334
      });
335
    }
336
    if (fundingL0) {
337
      if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
338
        let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
339
        replacedUrl = filterResults.url;
340
        indicatorPath.filtersApplied += filterResults.filtersApplied;
341
      }
342
    }
343
    if (startYear) {
344
      if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
345
        let filterResults =  this.addFilter(replacedUrl, 'start_year', startYear);
346
        replacedUrl = filterResults.url;
347
        indicatorPath.filtersApplied += filterResults.filtersApplied;
348
      }
349
    }
350
    if (endYear ) {
351
      if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
352
        let filterResults = this.addFilter(replacedUrl, 'end_year', endYear);
353
        replacedUrl = filterResults.url;
354
        indicatorPath.filtersApplied += filterResults.filtersApplied;
355
      }
356
    }
357
    if (coFunded ) {
358
      if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
359
        let filterResults = this.addFilter(replacedUrl, 'co-funded', endYear);
360
        replacedUrl = filterResults.url;
361
        indicatorPath.filtersApplied += filterResults.filtersApplied;
362
      }
363
    }
364

    
365
    //For numbers
366
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
367
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
368
    }
369
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) != -1) {
370
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
371
    }
372
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
373
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
374
    }
375

    
376
    return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
377

    
378
  }
379
  private  addFilter(replacedUrl, filterType:FilterType, filterValue){
380
    let newJsonObject = JSON.parse(replacedUrl);
381
    let filterApplied:boolean = false;
382
    let queryIndex = 0;
383
    for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
384

    
385
      if(queries["query"]["name"] && !queries["query"]["select"]){
386

    
387
        if(queries["query"]["name"].indexOf("monitor.")==-1 || !queries["query"]["parameters"]){
388
          continue;
389
        }
390
        if(filterType == 'fundingL0') {
391
          let paramFields = queries["query"]["name"].split(".").slice(3);
392
          let filterPosition = queries["query"]["name"].split(".").indexOf(filterType == "fundingL0" ? 'fl0' : filterType) ;
393
          if (filterPosition != -1) {
394
            //already filtered
395
            //TODO double check if we need to override if the fl0 is already filtered
396
            filterPosition -=3;
397
           /* //update the value
398
           if(paramFields.length == queries["query"]["parameters"].length ){
399
              //ok
400
              queries["query"]["parameters"][filterPosition] = filterValue;
401
            }else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
402
              queries["query"]["parameters"][filterPosition + 2]=filterValue;
403
              filterApplied = true;
404
            }
405
            if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
406
                 queries["query"]["parameters"][(2* filterPosition) + 5]=filterValue;
407
            }*/
408
           //if applied with the same value mark as filtered
409
            if(paramFields.length == queries["query"]["parameters"].length &&  queries["query"]["parameters"][filterPosition] == filterValue){
410
              filterApplied = true;
411
            }else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition + 2]==filterValue){
412
              filterApplied = true;
413
            }
414
          } else {
415
            // if((paramFields.length*2) == queries["query"]["parameters"].length){
416
            //   queries["query"]["parameters"].splice(paramFields.length, 0, filterValue);
417
            // }
418
            if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
419
              queries["query"]["parameters"].splice(paramFields.length + 1, 0, filterValue);
420
            }
421
            queries["query"]["name"] = queries["query"]["name"] + ".fl0";
422
            queries["query"]["parameters"].push(filterValue);
423
            filterApplied = true;
424
          }
425
        }else{
426
          let paramFields = queries["query"]["name"].split(".").slice(3);
427
          // console.debug("Field Params length:" + paramFields.length)
428
          // console.debug(paramFields)
429
          // console.debug("Parameters length:" + queries["query"]["parameters"].length)
430
          console.debug("Parameters length:" + queries["query"]["parameters"].length)
431

    
432
          if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
433
            filterApplied = true;
434
           if(filterType == "start_year"){
435
             queries["query"]["parameters"][0] = parseInt(filterValue);
436
           }else if(filterType == "end_year"){
437
             queries["query"]["parameters"][1] = parseInt(filterValue);
438
           }
439
          }
440
          if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
441
            filterApplied = true;
442
            if(filterType == "start_year"){
443
              queries["query"]["parameters"][paramFields.length + 2] = parseInt(filterValue);
444
            }else if(filterType == "end_year"){
445
              queries["query"]["parameters"][paramFields.length + 3] = parseInt(filterValue);
446
            }
447
          }
448
        }
449
        // console.debug(queries["query"])
450
        // it is a name query
451
        continue;
452
      }
453
      if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
454
        queries["query"]["filters"] = [];
455
      }
456
      let field = queries["query"]["select"][0]["field"];
457
      let filterString =  IndicatorFilterUtils.getFilter(field&&field.length > 0? field.split(".")[0]:"",filterType);
458
      if(filterString){
459
        let filter = JSON.parse(filterString);
460
        let filterposition = IndicatorFilterUtils.filterIndexOf(filter,queries["query"]["filters"])
461
        if(filterposition){
462
          if(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] != filter['groupFilters'][0]["values"][0].replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)){
463
            //change filter value
464
            // queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filter['groupFilters'][0]["values"][0].replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue);
465
            //add user filter value
466
            // queries["query"]["filters"].push(JSON.parse(filterString.replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)));
467
            // update colors
468
            //if noit a pie, map and chart has more than one query
469
            //
470
            if(!newJsonObject.hasOwnProperty("mapDescription") && queries["type"]!="pie" && this.isComparingChart(newJsonObject, filter)) {
471
              let activeColors = ["#7CB5EC", "#434348", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"];
472
              let inActiveColors = ["#E4EFFB", "#D8D8D9", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"];
473
              if (!newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"]) {
474
                newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"] = activeColors;
475
              }
476
              newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"][queryIndex] = inActiveColors[queryIndex];
477
              filterApplied = true;
478
            }else if (filterType == "start_year" || filterType == "end_year") {
479
            //if has date filter already
480
               if(filterType == "start_year" && parseInt(filterValue) > parseInt(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0])){
481
                 queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filterValue;
482
               }else if(filterType == "end_year" && parseInt(filterValue) < parseInt(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0])) {
483
                 queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filterValue;
484
               }
485
              filterApplied = true;
486
            }
487
          }else{
488
            filterApplied = true;
489
          }
490
        }else {
491
          queries["query"]["filters"].push(JSON.parse(filterString.replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)));
492
          filterApplied = true;
493
        }
494
      }
495
      queryIndex++;
496
    }
497
    return  { "url":JSON.stringify(newJsonObject), "filtersApplied":(filterApplied)?1:0};
498
  }
499

    
500
  isComparingChart(newJsonObject, filter,){
501
    let queriesCount = this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length:newJsonObject[this.getDescriptionObjectName(newJsonObject)].length;
502
    let values = [];
503
    if(queriesCount < 2){
504
      return false;
505
    }
506
    for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
507
      let filterposition = IndicatorFilterUtils.filterIndexOf(filter, queries["query"]["filters"]);
508
      if (filterposition) {
509
        if (values.indexOf(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]) == -1) {
510
          values.push(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]);
511
        }
512
      }
513
    }
514
    console.debug(values);
515
    return values.length > 1;
516
  }
517
  generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type:IndicatorType, addParameters:boolean = true ): Indicator {
518
    let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
519
      form.width, form.visibility, indicatorPaths, form.defaultId);
520
    indicator._id = form._id;
521
    form.indicatorPaths.forEach((indicatorPath, index) => {
522
      indicator.indicatorPaths[index].type = indicatorPath.type;
523
      if(addParameters) {
524
        indicatorPath.parameters.forEach(parameter => {
525
          indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
526
          if (parameter.key === 'type') {
527
            indicator.indicatorPaths[index].type = parameter.value;
528
          }
529
        });
530
      }
531
    });
532
    return indicator;
533
  }
534
  generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder:Stakeholder, jsonPath = []): IndicatorPath {
535
    let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath);
536
    if (source === 'stats-tool') {
537
      indicatorPath.url = url.split("json=")[0] + "json=";
538
      indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
539
      indicatorPath.chartObject = decodeURIComponent(url.indexOf("json=")!=-1?url.split("json=")[1]:"");
540
      let chart = JSON.parse(indicatorPath.chartObject);
541
      this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
542
      this.extractStakeHolders(chart, indicatorPath, stakeholder);
543
      indicatorPath.chartObject = JSON.stringify(chart);
544
      // this.addResultFilters(chart, indicatorPath);
545
    }else {
546
      try {
547
        if (url.indexOf(encodeURIComponent(stakeholder.index_id)) !== -1) {
548
          url = url.split(encodeURIComponent(stakeholder.index_id)).join(ChartHelper.prefix + "index_id" + ChartHelper.suffix);
549
        }
550
        if (url.indexOf(encodeURIComponent(stakeholder.index_name)) !== -1) {
551
          url = url.split(encodeURIComponent(stakeholder.index_name)).join(ChartHelper.prefix + "index_name" + ChartHelper.suffix);
552
        }
553
        if (url.indexOf(encodeURIComponent(stakeholder.index_shortName)) !== -1) {
554
          url = url.split(encodeURIComponent(stakeholder.index_shortName)).join(ChartHelper.prefix + "index_shortName" + ChartHelper.suffix);
555
        }
556
        indicatorPath.url = url;
557
      } catch (e) {
558
        console.error(e);
559
      }
560
    }
561
    return indicatorPath;
562
  }
563
  generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
564
    let indicatorPath = new IndicatorPath(type, source, "", "", []);
565
    try {
566
      if (source === 'stats-tool') {
567
        indicatorPath.url = url.split("json=")[0] + "json=";
568
        indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
569
        indicatorPath.chartObject = decodeURIComponent(url.split("json=")[1]);
570
        let chart = JSON.parse(indicatorPath.chartObject);
571
        // console.debug(indicatorPath);
572
        if (indicatorPath.url == "chart?json=") {
573

    
574
          if (chart["library"] && (chart["library"] == "HighCharts" || chart["library"] == "eCharts" || chart["library"] == "HighMaps" )) {
575
            indicatorPath.type = this.extractType(chart, indicatorPath);
576
          } else {
577
            indicatorPath.type = this.defaultChartType;
578
          }
579

    
580
          this.extractTitle(chart, indicatorPath);
581
          this.extractSubTitle(chart, indicatorPath);
582
          this.extractXTitle(chart, indicatorPath);
583
          this.extractYTitle(chart, indicatorPath);
584
        }else if(indicatorPath.url == "table?json="){
585
          indicatorPath.type = "table";
586
        }
587
        if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") {
588
          // common for tables and other chart types
589
          this.extractDataTitle(chart, indicatorPath);
590
          this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
591
          this.extractStakeHolders(chart, indicatorPath, stakeholder);
592
          this.extractStartYear(chart, indicatorPath);
593
          this.extractEndYear(chart, indicatorPath);
594
          indicatorPath.chartObject = JSON.stringify(chart);
595
        }
596
      } else if (source === 'old') {
597
        indicatorPath.url = url.split("data=")[0].split("/stats/")[1] + "data=";
598
        indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1].split("&")[0]);
599
        indicatorPath.type = type;
600
        let chart = JSON.parse(indicatorPath.chartObject);
601
        this.extractOldToolTitle(chart, indicatorPath);
602
        this.extractOldToolXTitle(chart, indicatorPath);
603
        this.extractOldToolYTitle(chart, indicatorPath);
604
        indicatorPath.chartObject = JSON.stringify(chart);
605
      } else {
606
        indicatorPath.url = url;
607
        indicatorPath.type = type;
608
      }
609
    }catch(e){
610
      console.error(e);
611
      indicatorPath.url = url;
612
      indicatorPath.type = type;
613
    }
614
    // console.debug(indicatorPath.parameters);
615
    // console.debug(indicatorPath.chartObject);
616
    if(indicatorPath.type == null){
617
      indicatorPath.type = this.defaultChartType;
618
    }
619
    return indicatorPath;
620
  }
621
  private getQueryObjectName(obj){
622
    if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")){
623
        return "queriesInfo";
624
    }else if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) {
625
      return "queries";
626
    }
627
  }
628
  private getDescriptionObjectName(obj){
629
    if(obj.hasOwnProperty("mapDescription")){
630
      return "mapDescription";
631
    }else if(obj.hasOwnProperty("chartDescription")) {
632
      return "chartDescription";
633
    }else if(obj.hasOwnProperty("tableDescription") ){
634
      return "tableDescription";
635
    }else if(obj.hasOwnProperty("series") ){
636
      return "series";
637
    }
638
    }
639
  private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
640
    let type = (obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"])?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"]:"";
641
    if (this.basicChartTypes.indexOf(type) == -1) {
642
      type = this.defaultChartType;
643
    } else {
644
      obj[this.getDescriptionObjectName(obj)]["queries"][0]["type"] = ChartHelper.prefix + "type" + ChartHelper.suffix;
645
      indicatorPath.parameters['type'] = type;
646
    }
647
    return type;
648
  }
649
  private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
650
    this.extractFunder(obj, indicatorPath, stakeholder);
651
    this.extractRI(obj, indicatorPath, stakeholder);
652
    this.extractOrganization(obj, indicatorPath, stakeholder);
653
  }
654
  private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
655
    if(stakeholder.type != "funder"){
656
      return;
657
    }
658
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
659
      if (!query["query"]["filters"]) {
660
        return;
661
      }
662
      for (let filter of query["query"]["filters"]) {
663
        if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) {
664
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
665
          indicatorPath.parameters["index_name"] = stakeholder.index_name;
666
        }else  if (filter["groupFilters"][0]["field"].indexOf(".funder.id") != -1) {
667
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
668
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
669
        }
670
      }
671
    }
672
  }
673

    
674
  private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
675
    if(stakeholder.type != "ri"){
676
      return;
677
    }
678
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
679
      if (!query["query"]["filters"]) {
680
        return;
681
      }
682
      for (let filter of query["query"]["filters"]) {
683
        if (filter["groupFilters"][0]["field"].indexOf(".context.name") != -1) {
684
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
685
          indicatorPath.parameters["index_name"] = stakeholder.index_name;
686
        }else  if (filter["groupFilters"][0]["field"].indexOf(".context.id") != -1) {
687
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
688
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
689
        }
690
      }
691
    }
692
  }
693

    
694
  private extractOrganization(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
695
    // works for publication.project.organization.name
696
    // and publication.organization.name
697
    if(stakeholder.type != "organization"){
698
      return;
699
    }
700
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
701
      if (!query["query"]["filters"]) {
702
        return;
703
      }
704
      for (let filter of query["query"]["filters"]) {
705
        if (filter["groupFilters"][0]["field"].indexOf(".organization.name") != -1) {
706
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
707
          indicatorPath.parameters["index_name"] = stakeholder.index_name;
708
        }else  if (filter["groupFilters"][0]["field"].indexOf(".organization.id") != -1) {
709
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
710
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
711
        }
712
      }
713
    }
714
  }
715
  private extractStartYear(obj, indicatorPath: IndicatorPath) {
716
    let start_year;
717
    for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
718
      if (!query["query"]["filters"]) {
719
        return;
720
      }
721
      for (let filter of query["query"]["filters"]) {
722
        for (let gfilter of filter["groupFilters"]) {
723
          if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) {
724
            start_year = gfilter["values"][0];
725
            gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix;
726
            indicatorPath.parameters["start_year"] = start_year;
727
          }
728
        }
729
      }
730
    }
731
  }
732

    
733
  private extractEndYear(obj, indicatorPath: IndicatorPath) {
734
    let end_year;
735
    for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
736
      if (!query["query"]["filters"]) {
737
        return;
738
      }
739
      for (let filter of query["query"]["filters"]) {
740
        for (let gfilter of filter["groupFilters"]) {
741
          if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) {
742
            end_year = gfilter["values"][0];
743
            gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix;
744
            indicatorPath.parameters["end_year"] = end_year;
745
          }
746
        }
747
      }
748
    }
749
  }
750

    
751
  private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
752
    let name = "";
753
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
754
      //monitor.{{stakeholderType}}.{{queryname}}
755
      //parameters: stakeholderId*, type
756
      if (query["query"]["name"]) {
757
        name = query["query"]["name"];
758
        let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[];
759
        if(name.split('.')[0] == "rcd" && parameters.length > 0  && stakeholder.type=="ri") {
760
          //rcd.{{queryname}}
761
          parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
762
          indicatorPath.parameters["index_id"] = stakeholder.index_id;
763
        }else if(name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type=="funder"){
764
          // old saved queries without params
765
          //monitor.{{funder_shortName}}.{{type}}.{{queryname}}
766
          let stakeholderSN = name.split('.')[1];
767
          query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1];
768
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
769
        }else if(name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1]  == stakeholder.type) {
770
          // new parameterized queries
771
          //monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0]
772

    
773
          let index = (name.split('.').slice(3).length +2 == parameters.length)?[2]:((name.split('.').slice(3).length * 2 + 4 == parameters.length)?[2,name.split('.').slice(3).length+4]:[0]);
774
          for(let i of index) {
775
            if (name.split('.').length > 3 && name.split('.')[3] == "id") {
776
              parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
777
              indicatorPath.parameters["index_id"] = stakeholder.index_id;
778
            } else if (name.split('.').length > 3 && name.split('.')[3] == "shortname") {
779
              parameters[i] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
780
              indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
781
            } else if (name.split('.').length > 3 && name.split('.')[3] == "name") {
782
              parameters[i] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
783
              indicatorPath.parameters["index_name"] = stakeholder.index_name;
784
            }
785
          }
786
        }
787
      }
788
    }
789
  }
790
  private extractDataTitle(obj, indicatorPath: IndicatorPath) {
791
    let index = 0;
792
    if(!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){
793
      return;
794
    }
795
    for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
796
      if (query["name"]) {
797
        let name = query["name"];
798
        query["name"] =  ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix;
799
        indicatorPath.parameters["data_title_"+index] = name;
800
      }
801
      index++;
802
    }
803
  }
804
  private extractTitle(obj, indicatorPath: IndicatorPath) {
805
    let title = "";
806
    if (obj[this.getDescriptionObjectName(obj)]["title"]) {
807
      title = obj[this.getDescriptionObjectName(obj)]["title"]["text"];
808
      obj[this.getDescriptionObjectName(obj)]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
809
    }else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["title"]) {
810
      title = obj[this.getDescriptionObjectName(obj)]["options"]["title"];
811
      obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
812
    }
813
    indicatorPath.parameters["title"] = title ? title : "";
814
  }
815

    
816
  private extractSubTitle(obj, indicatorPath: IndicatorPath) {
817
    let subtitle = "";
818
    if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) {
819
      subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"];
820
      obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
821
      indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
822
    }else if (obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]) {
823
      subtitle = obj[this.getDescriptionObjectName(obj)]["title"]["subtext"];
824
      obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
825
      indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
826
    }
827
  }
828

    
829
  private extractXTitle(obj, indicatorPath: IndicatorPath) {
830
    let title = "";
831
    if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) {
832
      title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"];
833
      obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
834
    }else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]) {
835
      title = obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"];
836
      obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
837
    }else if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]) {
838
      title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"];
839
      obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
840
    }
841
    indicatorPath.parameters["xAxisTitle"] = title ? title : "";
842
  }
843

    
844
  private extractYTitle(obj, indicatorPath: IndicatorPath) {
845
    let title = "";
846
    if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"] ) {
847
      title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"];
848
      obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
849
    }else if (obj[this.getDescriptionObjectName(obj)]["options"]&& obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]) {
850
      title = obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"];
851
      obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
852
    }else if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]) {
853
      title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"];
854
      obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
855
    }
856
    indicatorPath.parameters["yAxisTitle"] = title ? title : "";
857
  }
858

    
859
  private extractOldToolTitle(obj, indicatorPath: IndicatorPath) {
860
    let title = "";
861
    if (obj["title"]) {
862
      title = obj["title"];
863
      obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
864
      indicatorPath.parameters["title"] = title;
865

    
866
    }
867
  }
868

    
869
  private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
870
    let title = "";
871
    if (obj["xaxistitle"]) {
872
      title = obj["xaxistitle"];
873
      obj["xaxistitle"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
874
      indicatorPath.parameters["xAxisTitle"] = title;
875
    }
876
  }
877

    
878
  private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
879
    let title = "";
880
    if (obj["fieldsheaders"]) {
881
      title = Array.isArray(obj["fieldsheaders"]) ? obj["fieldsheaders"][0] : obj["fieldsheaders"];
882
      if (Array.isArray(obj["fieldsheaders"])) {
883
        obj["fieldsheaders"][0] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
884
      } else {
885
        obj["fieldsheaders"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
886
      }
887
      indicatorPath.parameters["yAxisTitle"] = title;
888
    }
889
  }
890

    
891
}
(2-2/3)