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

Feature/fix lab #121

Merged
merged 2 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/charts/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class ChartComponent implements OnChanges {
indicator: this.chart.indicator,
scenario: this.scenario,
city: this.city,
climateModels: this.models
climateModels: this.models,
// As a temporary solution, the time agg defaults to the 1st valid option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a github issue to add selecting non-yearly granularities? That'd be pretty handy to have

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it has be discussed, but now that we do time aggs that seems like a necessary feature to lab.

// Really, this should a user selectable option
time_aggregation: this.chart.indicator.valid_aggregations[0]
}).subscribe(data => this.chartData = this.chartService.convertChartData([data]));
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/charts/line-graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class LineGraphComponent implements OnInit, OnDestroy {
ngOnInit(): void {
// Set up global chart mouseover communication chain if set to multi-chart scrubber
// ** CURRENTLY ONLY FOR YEARLY INDICATORS**
if (this.multiChartScrubber && this.indicator.time_aggregation === 'yearly') {
if (this.multiChartScrubber && this.data[0].time_aggregation === 'yearly') {
this.multiChartScrubberHoverSubscription = this.chartService.multiChartScrubberHoverObservable.subscribe(data => {
this.hover = data;
this.hover ? $('.' + this.id).toggleClass('hidden', false) : $('.' + this.id).toggleClass('hidden', true);
Expand All @@ -116,7 +116,7 @@ export class LineGraphComponent implements OnInit, OnDestroy {
}

ngOnDestroy(): void {
if (this.multiChartScrubber && this.indicator.time_aggregation === 'yearly') {
if (this.multiChartScrubber && this.data[0].time_aggregation === 'yearly') {
this.multiChartScrubberInfoSubscription.unsubscribe();
this.multiChartScrubberHoverSubscription.unsubscribe();
}
Expand Down
14 changes: 11 additions & 3 deletions src/app/models/chart-data.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { MultiDataPoint } from './multi-data-point.model';
import { Indicator } from './indicator.model';
import { City } from './city.model';
import { ClimateModel } from './climate-model.model';
import { Scenario } from './scenario.model';

export class ChartData {
indicator: string;
indicator: Indicator;
data: MultiDataPoint[];
time_agg: string[];
time_aggregation: string;
time_format: string;
}
city?: City;
climate_models?: ClimateModel[];
scenario?: Scenario;
units?: string
}
3 changes: 2 additions & 1 deletion src/app/models/indicator-query-opts.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface IndicatorQueryOpts {
scenario: Scenario;
climateModels?: ClimateModel[];
years?: string[];
}
time_aggregation?: string;
}
5 changes: 4 additions & 1 deletion src/app/models/indicator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export class Indicator {
description: string;
time_aggregation: string;
variables: string[];
available_units?: string[];
default_units?: string;
parameters?: any[];
valid_aggregations?: string[];
}

4 changes: 2 additions & 2 deletions src/app/services/chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ChartService {
_.each(data, obj => {
let indicatorData: MultiDataPoint[] = [];
let indicator = obj.indicator;
let timeFormat = this.timeOptions[indicator.time_aggregation];
let timeFormat = this.timeOptions[obj.time_aggregation];
let parseTime = D3.timeParse(timeFormat);

_.each(obj.data, (values, key) => {
Expand All @@ -75,7 +75,7 @@ export class ChartService {
chartData.push({
'indicator': indicator,
'data': indicatorData,
'time_agg': indicator.time_aggregation,
'time_aggregation': obj.time_aggregation,
'time_format': timeFormat
} as ChartData);
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/services/indicator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class IndicatorService {
if (options.climateModels) {
searchParams.append('models', options.climateModels.map(m => m.name).join(','));
}
if (options.time_aggregation) {
searchParams.append('time_aggregation', options.time_aggregation);
}

let requestOptions = new RequestOptions({search: searchParams});
return this.apiHttp.get(url, requestOptions).map(resp => resp.json());
Expand Down
9 changes: 2 additions & 7 deletions src/app/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ export class SidebarComponent implements OnInit {

private groupIndicators(indicators: Indicator[]) {
this.tempIndicators = indicators.filter(i => {
return this.isValidIndicator(i) &&
(i.variables.indexOf('tasmax') !== -1 || i.variables.indexOf('tasmin') !== -1);
return (i.variables.indexOf('tasmax') !== -1 || i.variables.indexOf('tasmin') !== -1);
});
this.precipIndicators = indicators.filter(i => {
return this.isValidIndicator(i) && i.variables.indexOf('pr') !== -1;
return i.variables.indexOf('pr') !== -1;
});
}

private isValidIndicator(indicator: Indicator): boolean {
return indicator.time_aggregation !== 'daily';
}
}