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/sharedComponents/input/input.component";
12
import {Session} from "../openaireLibrary/login/utils/helper.class";
13
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
14

    
15
export class StakeholderUtils {
16
  statuses: Option[] = [
17
    {value: 'PUBLIC', label: 'Public'},
18
    {value: 'RESTRICTED', label: 'Restricted'},
19
    {value: 'PRIVATE', label: 'Private'}
20
  ];
21
  
22
  types: Option[] = [
23
    {value: 'funder', label: 'Funder'},
24
    {value: 'ri', label: 'Reasearch Initiative'},
25
    {value: 'project', label: 'Project'},
26
    {value: 'organization', label: 'Organization'}
27
  ];
28
  
29
  visibility: Option[] = [
30
    {icon: 'world', value: "PUBLIC", label: 'Public'},
31
    {icon: 'lock', value: "RESTRICTED", label: 'Restricted'},
32
    {icon: 'users', value: "PRIVATE", label: 'Private'},
33
  ];
34
  
35

    
36
  visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
37
    ["PUBLIC", 'earth'],
38
    ["PRIVATE", 'lock'],
39
    ["RESTRICTED", 'group']
40
  ]);
41
  
42
  getTypesByUserRoles(user, id:string = null):Option[]{
43
    let types = [];
44
    for(let type of this.types){
45
      if(Session.isCurator(type.value, user)|| Session.isPortalAdministrator(user)|| (id && Session.isManager(type.value, id, user))){
46
        types.push(type);
47
      }
48
    }
49
    return types;
50
  }
51
  
52
  public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[]): Stakeholder {
53
    funder.topics = HelperFunctions.copy(defaultTopics);
54
    for (let topic of funder.topics) {
55
      // console.log('id:' + topic._id);
56
      topic.defaultId = topic._id;
57
      topic._id = null;
58
      // console.log('defaultId:' + topic.defaultId);
59
      for (let category of topic.categories) {
60
        category.defaultId = category._id;
61
        category._id = null;
62
        let subTokeep: SubCategory[] = [];
63
        for (let subCategory of category.subCategories) {
64
          subCategory.defaultId = subCategory._id;
65
          subCategory._id = null;
66
          subTokeep.push(subCategory);
67
          for (let section of subCategory.charts) {
68
            let chartsTokeep: Indicator[] = [];
69
            section.defaultId = section._id;
70
            section.stakeholderAlias = funder.alias;
71
            section._id = null;
72
            for (let indicator of section.indicators) {
73
              indicator.defaultId = indicator._id;
74
              indicator._id = null;
75
              chartsTokeep.push(indicator);
76
              for (let indicatorPath of indicator.indicatorPaths) {
77
                if (indicatorPath.parameters) {
78
                  Object.keys(indicatorPath.parameters).forEach(key => {
79
                    //TODO check before delete
80
                    /*if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
81
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
82
                    } else if (indicatorPath.parameters[key].indexOf("_funder_id_") != -1) {
83
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_id_", funder.index_id);
84
                    } else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
85
                      indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
86
                    }*/
87
                    if (key == "index_name") {
88
                      indicatorPath.parameters[key] = funder.index_name;
89
                    } else if (key == "index_id" ) {
90
                      indicatorPath.parameters[key] = funder.index_id;
91
                    }  else if (key == "index_shortName" ) {
92
                      indicatorPath.parameters[key] =  funder.index_shortName.toLowerCase();
93
                    }
94
                  });
95
                }
96
              }
97
            }
98
            section.indicators = chartsTokeep;
99
          }
100
          for (let section of subCategory.numbers) {
101
            section.defaultId = section._id;
102
            section.stakeholderAlias = funder.alias;
103
            section._id = null;
104
            for(let indicator of section.indicators) {
105
              indicator.defaultId = indicator._id;
106
              indicator._id = null;
107
              for (let indicatorPath of indicator.indicatorPaths) {
108
               /* indicatorPath.url = indicatorPath.url.replace("index_id", encodeURIComponent(funder.index_id));
109
                indicatorPath.url = indicatorPath.url.replace("index_name",  encodeURIComponent(funder.index_name));
110
                indicatorPath.url = indicatorPath.url.replace("index_shortName", encodeURIComponent(funder.index_shortName));*/
111
                // if(indicatorPath.parameters) {
112
                //   indicatorPath.parameters.forEach((value: string, key: string) => {
113
                //     if (value.indexOf("_funder_name_")!=-1) {
114
                //       indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
115
                //     }else if (value.indexOf("_fsn_")!=-1) {
116
                //       indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
117
                //     }
118
                //   });
119
                // }
120
              }
121
            }
122
          }
123

    
124
        }
125
        category.subCategories = subTokeep;
126
      }
127
    }
128
    //console.log (funder);
129
    return funder;
130
  }
131
  
132
  aliasValidatorString(elements: string[]): ValidatorFn {
133
    return (control: AbstractControl): { [key: string]: string } | null => {
134
      if (control.value && elements.find(element =>
135
        element === control.value
136
      )) {
137
        return {'error': 'Alias already in use'};
138
      }
139
      return null;
140
    }
141
  }
142

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

    
165
export class IndicatorUtils {
166

    
167
  allChartTypes: Option[] = [
168
    {value: 'pie', label: 'Pie'},
169
    {value: 'table', label: 'Table'},
170
    {value: 'line', label: 'Line'},
171
    {value: 'column', label: 'Column'},
172
    {value: 'bar', label: 'Bar'},
173
    {value: 'other', label: 'Other'}
174
  ];
175
  basicChartTypes:IndicatorPathType[] =["pie", "line", "column", "bar"];
176
  defaultChartType:IndicatorPathType = "other";
177
  indicatorSizes: Option[] = [
178
    {value: 'small', label: 'Small(Enabled only for large screens)'},
179
    {value: 'medium', label: 'Medium'},
180
    {value: 'large', label: 'Large'}
181
  ];
182

    
183
  allSourceTypes: Option[]  = [
184
    {value: 'search', label: 'Search'},
185
    {value: 'statistics', label: 'Statistics'},
186
    {value: 'metrics', label: 'Metrics'},
187
    {value: 'stats-tool', label: 'Statistics tool'}
188
  ];
189
  sourceTypes: Option[]  = [
190
    {value: 'stats-tool', label: 'Statistics tool'}
191
  ];
192
  isPublic: Option[] = [
193
    {icon: 'public', value: true, label: 'Public'},
194
    {icon: 'lock', value: false, label: 'Private'},
195
  ];
196

    
197
  isActive: Option[] = [
198
    {icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
199
    {icon: 'brightness_1', value: false, label: 'Inactive'},
200
  ];
201

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

    
235
  isActiveIcon: string = 'brightness_1';
236

    
237
  ignoredParameters = ['index_name','index_id','index_shortName'];
238

    
239
  parametersValidators: Map<string, any> = new Map<string, any>([
240
    ['start_year', [Validators.required, Validators.pattern('^\\d+$')]],
241
    ['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
242
  ]);
243

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

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

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

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

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

    
371
    //For numbers
372
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
373
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
374
    }
375
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) != -1) {
376
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
377
    }
378
    if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
379
      replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
380
    }
381

    
382
    return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
383

    
384
  }
385
  private  addFilter(replacedUrl, filterType:FilterType, filterValue){
386
    let newJsonObject = JSON.parse(replacedUrl);
387
    let filterApplied:boolean = false;
388
    let queryIndex = 0;
389
    for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
390

    
391
      if(queries["query"]["name"] && !queries["query"]["select"]){
392

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

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

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

    
585
          if (chart["library"] && (chart["library"] == "HighCharts" || chart["library"] == "eCharts" || chart["library"] == "HighMaps" )) {
586
            indicatorPath.type = this.extractType(chart, indicatorPath);
587
          } else {
588
            indicatorPath.type = this.defaultChartType;
589
          }
590

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

    
685
  private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
686
    if(stakeholder.type != "ri"){
687
      return;
688
    }
689
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
690
      if (!query["query"]["filters"]) {
691
        return;
692
      }
693
      for (let filter of query["query"]["filters"]) {
694
        if (filter["groupFilters"][0]["field"].indexOf(".context.name") != -1) {
695
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
696
          indicatorPath.parameters["index_name"] = stakeholder.index_name;
697
        }else  if (filter["groupFilters"][0]["field"].indexOf(".context.id") != -1) {
698
          filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
699
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
700
        }
701
      }
702
    }
703
  }
704

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

    
744
  private extractEndYear(obj, indicatorPath: IndicatorPath) {
745
    let end_year;
746
    for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
747
      if (!query["query"]["filters"]) {
748
        return;
749
      }
750
      for (let filter of query["query"]["filters"]) {
751
        for (let gfilter of filter["groupFilters"]) {
752
          if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) {
753
            end_year = gfilter["values"][0];
754
            gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix;
755
            indicatorPath.parameters["end_year"] = end_year;
756
          }
757
        }
758
      }
759
    }
760
  }
761

    
762
  private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
763
    let name = "";
764
    for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
765
      //monitor.{{stakeholderType}}.{{queryname}}
766
      //parameters: stakeholderId*, type
767
      if (query["query"]["name"]) {
768
        name = query["query"]["name"];
769
        let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[];
770
        if(name.split('.')[0] == "rcd" && parameters.length > 0  && stakeholder.type=="ri") {
771
          //rcd.{{queryname}}
772
          parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
773
          indicatorPath.parameters["index_id"] = stakeholder.index_id;
774
        }else if(name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type=="funder"){
775
          // old saved queries without params
776
          //monitor.{{funder_shortName}}.{{type}}.{{queryname}}
777
          let stakeholderSN = name.split('.')[1];
778
          query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1];
779
          indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
780
        }else if(name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1]  == stakeholder.type) {
781
          // new parameterized queries
782
          //monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0]
783

    
784
          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]);
785
          for(let i of index) {
786
            if (name.split('.').length > 3 && name.split('.')[3] == "id") {
787
              parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
788
              indicatorPath.parameters["index_id"] = stakeholder.index_id;
789
            } else if (name.split('.').length > 3 && name.split('.')[3] == "shortname") {
790
              parameters[i] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
791
              indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
792
            } else if (name.split('.').length > 3 && name.split('.')[3] == "name") {
793
              parameters[i] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
794
              indicatorPath.parameters["index_name"] = stakeholder.index_name;
795
            }
796
          }
797
        }
798
      }
799
    }
800
  }
801
  private extractDataTitle(obj, indicatorPath: IndicatorPath) {
802
    let index = 0;
803
    if(!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){
804
      return;
805
    }
806
    for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
807
      if (query["name"]) {
808
        let name = query["name"];
809
        query["name"] =  ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix;
810
        indicatorPath.parameters["data_title_"+index] = name;
811
      }
812
      index++;
813
    }
814
  }
815
  private extractTitle(obj, indicatorPath: IndicatorPath) {
816
    let title = "";
817
    if (obj[this.getDescriptionObjectName(obj)]["title"]) {
818
      title = obj[this.getDescriptionObjectName(obj)]["title"]["text"];
819
      obj[this.getDescriptionObjectName(obj)]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
820
    }else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["title"]) {
821
      title = obj[this.getDescriptionObjectName(obj)]["options"]["title"];
822
      obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
823
    }
824
    indicatorPath.parameters["title"] = title ? title : "";
825
  }
826

    
827
  private extractSubTitle(obj, indicatorPath: IndicatorPath) {
828
    let subtitle = "";
829
    if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) {
830
      subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"];
831
      obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
832
      indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
833
    }else if (obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]) {
834
      subtitle = obj[this.getDescriptionObjectName(obj)]["title"]["subtext"];
835
      obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
836
      indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
837
    }
838
  }
839

    
840
  private extractXTitle(obj, indicatorPath: IndicatorPath) {
841
    let title = "";
842
    if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) {
843
      title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"];
844
      obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
845
    }else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]) {
846
      title = obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"];
847
      obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
848
    }else if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]) {
849
      title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"];
850
      obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
851
    }
852
    indicatorPath.parameters["xAxisTitle"] = title ? title : "";
853
  }
854

    
855
  private extractYTitle(obj, indicatorPath: IndicatorPath) {
856
    let title = "";
857
    if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"] ) {
858
      title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"];
859
      obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
860
    }else if (obj[this.getDescriptionObjectName(obj)]["options"]&& obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]) {
861
      title = obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"];
862
      obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
863
    }else if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]) {
864
      title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"];
865
      obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
866
    }
867
    indicatorPath.parameters["yAxisTitle"] = title ? title : "";
868
  }
869

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

    
877
    }
878
  }
879

    
880
  private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
881
    let title = "";
882
    if (obj["xaxistitle"]) {
883
      title = obj["xaxistitle"];
884
      obj["xaxistitle"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
885
      indicatorPath.parameters["xAxisTitle"] = title;
886
    }
887
  }
888

    
889
  private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
890
    let title = "";
891
    if (obj["fieldsheaders"]) {
892
      title = Array.isArray(obj["fieldsheaders"]) ? obj["fieldsheaders"][0] : obj["fieldsheaders"];
893
      if (Array.isArray(obj["fieldsheaders"])) {
894
        obj["fieldsheaders"][0] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
895
      } else {
896
        obj["fieldsheaders"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
897
      }
898
      indicatorPath.parameters["yAxisTitle"] = title;
899
    }
900
  }
901

    
902
}
(2-2/2)