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

Commit

Permalink
Rebase ontop basetemp params and factor out constants
Browse files Browse the repository at this point in the history
  • Loading branch information
fungjj92 committed Sep 1, 2017
1 parent 37f96d9 commit 0b9192f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/app/charts/chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 class="chart-label">
<ccl-basetemp-parameters
[indicator]="chart.indicator"
[extraParams]="extraParams"
(basetempParamSelected)="onThresholdSelected($event)">
(basetempParamSelected)="onExtraParamsSelected($event)">
</ccl-basetemp-parameters>
</div>
<div *ngIf="isPercentileIndicator(chart.indicator.name)" class="chart-options">
Expand Down
2 changes: 1 addition & 1 deletion src/app/charts/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DataExportService } from '../services/data-export.service';
import { ImageExportService } from '../services/image-export.service';

import { isBasetempIndicator,
isPercentileIndicator
isPercentileIndicator,
isThresholdIndicator } from '../charts/extra-params-components/extra-params.constants';

import * as _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
formControlName="basetempCtl">
</div>
<select class="form-control chart-options-group" formControlName="basetempUnitCtl">
<option *ngFor="let unit of basetempUnits"
<option *ngFor="let unit of temperatureUnits"
[value]="unit.key">{{unit.label}}
</option>
</select>
</div>
</form>
</div>
</div>
8 changes: 2 additions & 6 deletions src/app/charts/extra-params-components/basetemp.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';

import { Indicator } from '../../models/indicator.model';
import { BasetempIndicatorQueryParams } from '../../models/basetemp-indicator-query-params.model';
import { TemperatureUnits } from './extra-params.constants';

import * as _ from 'lodash';

Expand All @@ -25,12 +26,7 @@ export class BasetempComponent implements AfterViewInit, OnInit {
// default form values
private defaultBasetemp = 50;
private defaultBasetempUnit = 'F';

public basetempUnits: any[] = [
{'key': 'K', 'label': 'Kelvin'},
{'key': 'F', 'label': 'Farenheit'},
{'key': 'C', 'label': 'Centigrade'}
];
private temperatureUnits = TemperatureUnits;

constructor(private formBuilder: FormBuilder) {}

Expand Down
14 changes: 13 additions & 1 deletion src/app/charts/extra-params-components/extra-params.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ const percentileIndicatorNames = [

const extraParamsIndicatorNames = [].concat(thresholdIndicatorNames, percentileIndicatorNames);

export const TemperatureUnits: any[] = [
{'key': 'K', 'label': 'Kelvin'},
{'key': 'F', 'label': 'Farenheit'},
{'key': 'C', 'label': 'Centigrade'}
];

export const PrecipitationUnits: any[] = [
{'key': 'mm', 'label': 'millimeters'},
{'key': 'in', 'label': 'inches'},
{'key': 'kg/m^2', 'label': 'kg/m^2'}
];

export function isBasetempIndicator(indicatorName: string): boolean {
return basetempIndicatorNames.indexOf(indicatorName) !== -1;
}
Expand All @@ -33,4 +45,4 @@ export function hasExtraParams(indicatorName: string): boolean {

export function isPercentileIndicator(indicatorName: string): boolean {
return percentileIndicatorNames.indexOf(indicatorName) !== -1;
}
}
24 changes: 8 additions & 16 deletions src/app/charts/extra-params-components/threshold.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';

import { Indicator } from '../../models/indicator.model';
import { ThresholdIndicatorQueryParams } from '../../models/threshold-indicator-query-params.model';
import { PrecipitationUnits,
TemperatureUnits } from './extra-params.constants';

import * as _ from 'lodash';

Expand All @@ -22,24 +24,15 @@ export class ThresholdComponent implements AfterViewInit, OnInit {

thresholdForm: FormGroup;

private thresholdTemperatureUnits: any[] = [
{'key': 'K', 'label': 'Kelvin'},
{'key': 'F', 'label': 'Farenheit'},
{'key': 'C', 'label': 'Centigrade'}
];

private thresholdComparators: any[] = [
private thresholdComparators: any[] = [
{'key': 'gte', 'label': 'greater than or equal to'},
{'key': 'lte', 'label': 'less than or equal to'},
{'key': 'gt', 'label': 'greater than'},
{'key': 'lt', 'label': 'less than'}
];

private thresholdPrecipitationUnits: any[] = [
{'key': 'mm', 'label': 'millimeters'},
{'key': 'in', 'label': 'inches'},
{'key': 'kg/m^2', 'label': 'kg/m^2'}
];
private temperatureUnits = TemperatureUnits;
private precipitationUnits = PrecipitationUnits;

// default form values
private defaultThreshold = 50;
Expand All @@ -49,8 +42,7 @@ export class ThresholdComponent implements AfterViewInit, OnInit {
private defaultComparator = 'lte';

@Input() comparators: any[] = this.thresholdComparators;

@Input() thresholdUnits: any[] = this.thresholdTemperatureUnits;
@Input() thresholdUnits: any[] = this.temperatureUnits;

constructor(private formBuilder: FormBuilder) {}

Expand Down Expand Up @@ -90,10 +82,10 @@ export class ThresholdComponent implements AfterViewInit, OnInit {
// Set component to precip or temperature
if (this.indicator.variables.includes('pr')) {
this.defaultUnit = this.defaultPrecipitationUnit;
this.thresholdUnits = this.thresholdPrecipitationUnits;
this.thresholdUnits = this.precipitationUnits;
} else {
this.defaultUnit = this.defaultTemperatureUnit;
this.thresholdUnits = this.thresholdTemperatureUnits;
this.thresholdUnits = this.temperatureUnits;
}
}
}
3 changes: 0 additions & 3 deletions src/app/services/indicator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { BasetempIndicatorQueryParams } from '../models/basetemp-indicator-query
import { PercentileIndicatorQueryParams } from '../models/percentile-indicator-query-params.model';
import { IndicatorQueryParams } from '../models/indicator-query-params.model';

import { ApiHttp } from '../auth/api-http.service';
import { apiHost } from '../constants';

import { isBasetempIndicator,
isPercentileIndicator,
isThresholdIndicator } from '../charts/extra-params-components/extra-params.constants';
Expand Down

0 comments on commit 0b9192f

Please sign in to comment.