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

Commit

Permalink
Merge pull request #17 from azavea/feature/GraphControls
Browse files Browse the repository at this point in the history
Feature/graph controls
  • Loading branch information
fungjj92 authored Aug 31, 2016
2 parents b74c795 + 2a70e93 commit 316aa6a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

# Node
npm-debug.log
node_modules/
node_modules/

coverage/
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
"@angular/platform-server": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"angular2-moment": "1.0.0-beta.1",
"angular2-ui-switch": "^1.1.0",
"bootstrap": "^3.3.6",
"core-js": "^2.4.0",
"d3": "^4.1.1",
"d3-tip": "^0.6.7",
"es6-shim": "^0.35.0",
"jquery": "2.2.2",
"lodash": "^4.8.2",
"ng2-bootstrap": "^1.0.24",
"rxjs": "5.0.0-beta.6",
"zone.js": "~0.6.12"
},
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HttpModule } from '@angular/http';

// 3rd party modules
import { Ng2AutoCompleteModule } from './auto-complete/ng2AutoComplete.module';
import { UiSwitchModule } from 'angular2-ui-switch';

// Platform and Environment providers/directives/pipes
import { PLATFORM_PROVIDERS } from '../platform/browser';
Expand All @@ -30,7 +31,8 @@ import { IndicatorsService } from './services/indicators.service';
FormsModule,
HttpModule,
routing,
Ng2AutoCompleteModule
Ng2AutoCompleteModule,
UiSwitchModule
],
providers: [
appRoutingProviders,
Expand Down
48 changes: 40 additions & 8 deletions src/app/charts/chart.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
<div class="chart-heading">
<h2 class="chart-label">
<h2 class="chart-label">
{{indicator}}
</h2>
<div class="chart-actions">
<button class="button button-link" data-toggle="tooltip" data-placement="bottom" data-delay="300" title="" data-original-title="Export"><i class="icon icon-export"></i></button>
<button class="button button-link" data-toggle="tooltip" data-placement="bottom" data-delay="300" title="" data-original-title="Options"><i class="icon icon-cog"></i></button>
</div>
</h2>
<div class="chart-actions">
<button class="button button-link" data-toggle="tooltip" data-placement="bottom" data-delay="300" title="" data-original-title="Export"><i class="icon icon-export"></i></button>
<button class="button button-link" data-toggle="tooltip" data-placement="bottom" data-delay="300" title="" data-original-title="Options"><i class="icon icon-cog"></i></button>
</div>
</div>
<div class="chart-body">
<line-graph [data]="chartData" [indicator]="indicator" [trendline]="trendline"></line-graph>
<button (click)="toggleTrendline()">Trendline</button>
<line-graph
[data]="chartData"
[indicator]="indicator"
[trendline]="trendline"
[min]="min"
[max]="max"
[minVal]="minVal"
[maxVal]="maxVal">
</line-graph>
</div>
<div class="chart-controls">
<div class="controls-header">
<h5 class="controls-label">Options</h5>
<div class="options-icon" (click)="isCollapsed = !isCollapsed">
<i class="icon-minus" *ngIf="!isCollapsed"></i>
<i class="icon-plus" *ngIf="isCollapsed"></i>
</div>

</div>
<div class="controls-body" [collapse]="isCollapsed">
<ui-switch (change)="toggleTrendline()" size="small"></ui-switch>Show Trendline
<ui-switch (change)="toggleMin()" size="small"></ui-switch>Show Min
<input
type="number"
step="any"
placeholder="0"
[(ngModel)]="minVal">
<ui-switch (change)="toggleMax()" size="small"></ui-switch>Show Max
<input
type="number"
step="any"
placeholder="0"
[(ngModel)]="maxVal">
</div>
</div>
26 changes: 23 additions & 3 deletions src/app/charts/chart.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { CollapseDirective } from 'ng2-bootstrap/ng2-bootstrap';

import { LineGraphComponent } from './line-graph.component';

Expand All @@ -8,18 +9,37 @@ import { LineGraphComponent } from './line-graph.component';
*/
@Component({
selector: 'chart',
directives: [LineGraphComponent],
directives: [LineGraphComponent, CollapseDirective],
inputs: ['indicator', 'chartData'],
templateUrl: './chart.component.html'
})

export class ChartComponent {
private trendline: Boolean;
private isCollapsed: boolean;
private trendline: boolean;
private min: boolean;
private max: boolean;
private minVal: number;
private maxVal: number;

toggleTrendline() {
this.trendline = !this.trendline;
}

toggleMin() {
this.min = !this.min;
}

toggleMax() {
this.max = !this.max;
}

constructor() {
this.trendline = false;
this.isCollapsed = false;
this.min = false;
this.max = false;
this.minVal = 0;
this.maxVal = 0;
}
}

8 changes: 7 additions & 1 deletion src/app/charts/line-graph.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import * as $ from 'jquery';
selector: 'line-graph',
encapsulation: ViewEncapsulation.None,
template: `<ng-content></ng-content>`,
inputs: [ 'data', 'indicator', 'trendline' ]
inputs: [ 'data', 'indicator', 'trendline', 'min', 'max', 'minVal', 'maxVal' ]
})
export class LineGraphComponent {
public data: ChartData[];
public extractedData: Array<DataPoint>;
public indicator: String;
public trendline: Boolean;
public min: Boolean;
public max: Boolean;
public minVal: number;
public maxVal: number;

private host; // D3 object referebcing host dom object
private svg; // SVG in which we will print our chart
Expand Down Expand Up @@ -53,6 +57,8 @@ export class LineGraphComponent {
this.drawYAxis();
this.populate();
this.drawTrendLine();
// Temporarily here to show chart control statuses
console.log("Min: " + this.min, this.minVal + "; Max: " + this.max, this.maxVal);
}

private filterData(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/lab/lab.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
display-property-name="name"
path-to-data="features"
[value-changed]="onCitySelected()"
min-chars="2" />selected: {{model4 | json}}
min-chars="2" />
</div>
<div class="dropdown">
<button class="button dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Expand Down
21 changes: 20 additions & 1 deletion src/assets/sass/components/_chart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,24 @@ chart {
stroke-width: 1px;
opacity: .7;
}
}

.chart-controls {
color: black;

.controls-header {
.controls-label {
display: inline-block;
}

.options-icon {
display: inline-block;
}
}

.controls-body {
input {
width: 50px;
}
}
}
}
1 change: 0 additions & 1 deletion src/vendor.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'rxjs/add/operator/mergeMap';

// 3rd Party Libraries
import 'jquery';
import 'bootstrap';
import 'lodash';
import 'd3';
import 'd3-tip';

0 comments on commit 316aa6a

Please sign in to comment.