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 model refactor rebase, PR #231
Browse files Browse the repository at this point in the history
  • Loading branch information
fungjj92 committed Sep 1, 2017
1 parent 1ec8198 commit ba250d6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 24 deletions.
8 changes: 7 additions & 1 deletion src/app/charts/chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ <h2 class="chart-label">
(thresholdParamSelected)="onThresholdSelected($event)">
</ccl-threshold-parameters>
</div>
<!-- TODO: ADD basetemp-->
<div *ngIf="isBasetempIndicator(chart.indicator.name)" class="chart-options">
<ccl-basetemp-parameters
[indicator]="chart.indicator"
[extraParams]="extraParams"
(basetempParamSelected)="onThresholdSelected($event)">
</ccl-basetemp-parameters>
</div>
<div class="chart-body">
<sk-wave [isRunning]="!chartData || ! chartData.length"></sk-wave>
<div class="chart-graphic" *ngIf="chartData && chartData.length">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<span class="optional-parameters-label">Show {{indicator.label | lowercase}} with base temperature</span>
<div class="chart-options-group">
<input type="number"
formControlName="basetempCtl">
step="1"
formControlName="basetempCtl">
</div>
<select class="form-control chart-options-group" formControlName="bastempUnitCtl">
<select class="form-control chart-options-group" formControlName="basetempUnitCtl">
<option *ngFor="let unit of basetempUnits"
[value]="unit.key">{{unit.label}}
</option>
Expand Down
21 changes: 13 additions & 8 deletions src/app/charts/extra-params-components/basetemp.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 { BasetempIndicatorQueryParams } from '../../models/basetemp-indicator-query-params.model';

import * as _ from 'lodash';

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

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

basetempForm: FormGroup;

// default form values
private defaultBasetemp = 50;
private defaultBasetempUnit = 'F';

@Output() basetempParamSelected = new EventEmitter<any>();
public basetempUnits: any[] = [
{'key': 'K', 'label': 'Kelvin'},
{'key': 'F', 'label': 'Farenheit'},
{'key': 'C', 'label': 'Centigrade'}
];

constructor(private formBuilder: FormBuilder) {}

Expand All @@ -36,10 +42,10 @@ export class BasetempComponent 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.basetempParamSelected.emit({data: {
this.basetempParamSelected.emit({
'basetemp': this.basetempForm.controls.basetempCtl.value,
'basetemp_units': this.basetempForm.controls.basetempUnitCtl.value
}});
});
}

createForm() {
Expand All @@ -49,11 +55,10 @@ export class BasetempComponent implements AfterViewInit, OnInit {
});

this.basetempForm.valueChanges.debounceTime(700).subscribe(form => {
this.basetempParamSelected.emit({data: {
'event': event,
this.basetempParamSelected.emit({
'basetemp': form.basetempCtl,
'basetemp_units': form.basetempUnitCtl
}});
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ const basetempIndicatorNames = [
const extraParamsIndicatorNames = thresholdIndicatorNames;

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

export function isThresholdIndicator(indicatorName: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/app/charts/line-graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class LineGraphComponent implements OnChanges, AfterContentInit {

/* Will setup the chart basics */
private setup(): void {
this.margin = { top: 10, right: 40, bottom: 30, left: 50 };
this.margin = { top: 10, right: 50, bottom: 30, left: 60 };
this.width = $('.chart').width() - this.margin.left - this.margin.right;
this.height = $('.line-graph').height() - this.margin.top - this.margin.bottom;
this.xScale = D3.scaleTime().range([0, this.width]);
Expand Down
2 changes: 1 addition & 1 deletion src/app/login/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '../lab';

import { ThresholdComponent,
BasetempComponent } from '../charts/extra-params-components/threshold.component';
BasetempComponent } from '../charts/extra-params-components';

import { NavbarComponent } from '../navbar/navbar.component';
import { DashboardComponent } from '../dashboard/dashboard.component';
Expand Down
10 changes: 5 additions & 5 deletions src/app/services/indicator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Indicator } from '../models/indicator.model';
import { IndicatorRequestOpts } from '../models/indicator-request-opts.model';
import { ThresholdIndicatorQueryParams } from '../models/threshold-indicator-query-params.model';
import { BasetempIndicatorQueryParams } from '../models/basetemp-indicator-query-params.model';
import { IndicatorQueryParams } from '../models/indicator-query-params.model';\
import { IndicatorQueryParams } from '../models/indicator-query-params.model';

import { ApiHttp } from '../auth/api-http.service';
import { apiHost } from '../constants';
Expand Down Expand Up @@ -46,13 +46,13 @@ export class IndicatorService {

// append extra parameters, if needed
if (isBasetempIndicator(options.indicator.name)) {
const basetempOpts: BasetempIndicatorQueryOpts = <BasetempIndicatorQueryOpts> options;
const basetempOpts = options.params as BasetempIndicatorQueryParams;
// abort request if chart is in flux (these parameters are required)
if (!basetempOpts.params.basetemp) {
if (!basetempOpts.basetemp) {
return Observable.of({url: ''});
}
searchParams.append('basetemp', basetempOpts.params.basetemp.toString());
searchParams.append('basetemp_units', basetempOpts.params.basetemp_units);
searchParams.append('basetemp', basetempOpts.basetemp.toString());
searchParams.append('basetemp_units', basetempOpts.basetemp_units);
}

if (options.params.years) {
Expand Down

0 comments on commit ba250d6

Please sign in to comment.