Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Clean up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
fungjj92 committed Sep 1, 2017
1 parent b8d1e37 commit 5906d6d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
21 changes: 3 additions & 18 deletions src/app/charts/extra-params-components/extra-params.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,13 @@ const percentileIndicatorNames = [
const extraParamsIndicatorNames = [].concat(thresholdIndicatorNames, percentileIndicatorNames);

export function isThresholdIndicator(indicatorName: string): boolean {
for (const thresholdName of thresholdIndicatorNames) {
if (indicatorName === thresholdName) {
return true;
}
}
return false;
return thresholdIndicatorNames.indexOf(indicatorName) !== -1;
}

export function hasExtraParams(indicatorName: string): boolean {
for (const extraParamName of extraParamsIndicatorNames) {
if (indicatorName === extraParamName) {
return true;
}
}
return false;
return extraParamsIndicatorNames.indexOf(indicatorName) !== -1;
}

export function isPercentileIndicator(indicatorName: string): boolean {
for (const percentileName of percentileIndicatorNames) {
if (indicatorName === percentileName) {
return true;
}
}
return false;
return percentileIndicatorNames.indexOf(indicatorName) !== -1;
}
22 changes: 11 additions & 11 deletions src/app/charts/extra-params-components/percentile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AfterViewInit, Component, EventEmitter, Input, Output, OnInit } from '@
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

import { Indicator } from '../../models/indicator.model';
import { PercentileIndicatorQueryParams } from '../../models/percentile-indicator-query-params.model';

import * as _ from 'lodash';

Expand All @@ -16,15 +17,14 @@ import * as _ from 'lodash';
export class PercentileComponent implements AfterViewInit, OnInit {

@Input() indicator: Indicator;
@Input() extraParams: any;
@Input() extraParams: PercentileIndicatorQueryParams;
@Output() percentileParamSelected = new EventEmitter<PercentileIndicatorQueryParams>();

percentileForm: FormGroup;

// default form values
private defaultPercentile = 50;

@Output() percentileParamSelected = new EventEmitter<any>();

constructor(private formBuilder: FormBuilder) {}

ngOnInit() {
Expand All @@ -35,9 +35,9 @@ export class PercentileComponent implements AfterViewInit, OnInit {
ngAfterViewInit() {
// Since valueChanges triggers initially before parent is ready, wait until
// parent is ready here and trigger it to draw chart with extra parameters.
this.percentileParamSelected.emit({data: {
this.percentileParamSelected.emit({
'percentile': this.percentileForm.controls.percentileCtl.value
}});
});
}

createForm() {
Expand All @@ -46,12 +46,12 @@ export class PercentileComponent implements AfterViewInit, OnInit {
});

this.percentileForm.valueChanges.debounceTime(700).subscribe(form => {
// only accept percentiles [1, 100]
if (form.percentileCtl > 100 || form.percentileCtl < 1) { return; }
this.percentileParamSelected.emit({data: {
'event': event,
'percentile': form.percentileCtl
}});
// only accept percentiles [1, 100] as integers
const pctl = form.percentileCtl;
if (pctl > 100 || pctl < 1) { return; }
this.percentileParamSelected.emit({
'percentile': parseInt(pctl)
});
});
}
}
6 changes: 2 additions & 4 deletions src/app/models/percentile-indicator-query-params.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { IndicatorQueryParams } from './indicator-query-paramas.model';
import { IndicatorQueryParams } from './indicator-query-params.model';

export interface PercentileIndicatorQueryParams extends IndicatorQueryParams {
params: {
percentile: Number;
}
percentile: Number;
}
6 changes: 3 additions & 3 deletions src/app/services/indicator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export class IndicatorService {
}

if (isPercentileIndicator(options.indicator.name)) {
const percentileOpts: PercentileIndicatorQueryParams = <PercentileIndicatorQueryParams> options;
const percentileOpts = options.params as PercentileIndicatorQueryParams;
// abort request if chart is in flux (these parameters are required)
if (!percentileOpts.params.percentile) {
if (!percentileOpts.percentile) {
return Observable.of({url: ''});
}
searchParams.append('percentile', percentileOpts.params.percentile.toString());
searchParams.append('percentile', percentileOpts.percentile.toString());
}

if (options.params.years) {
Expand Down

0 comments on commit 5906d6d

Please sign in to comment.