Skip to content

Commit

Permalink
Added config passing too, works
Browse files Browse the repository at this point in the history
  • Loading branch information
thehoneymad committed Apr 8, 2017
1 parent 9e8e985 commit 4697f85
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/app/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class DataService {
type: 'bar-chart',
datamap: {
'labels': {
path: '$[*]._id.CreateDate.$date', // Can be JSONPath?
path: '$[*]._id.CreateDate[\'$date\']', // Can be JSONPath?
type: 'datestring',
},
'datasets': [
Expand All @@ -143,6 +143,16 @@ export class DataService {
path: '$[*].count'
}
]
},
config: {
title: {
display: true,
text: 'Orders from last couple of days',
fontSize: 16
},
legend: {
position: 'bottom'
}
}
};
}
Expand Down
20 changes: 15 additions & 5 deletions src/app/ui-toolbox/bar-chart/bar-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LoggerService } from '../../shared/index';
templateUrl: 'bar-chart.html'
})
export class BarChartComponent implements Widget {
config: any;
options: any;
data: any;

isDataAvailable: boolean = false;
Expand All @@ -30,6 +30,12 @@ export class BarChartComponent implements Widget {

setWidgetConfig(widgetConfig: any) {
if (widgetConfig) {
if (!this.options && widgetConfig.config) {
this.options = widgetConfig.config;
}

let datamap = widgetConfig.datamap;

this.dataService.executeAggregation(widgetConfig.connectionId, widgetConfig.collectionName, widgetConfig.query)
.subscribe(result => {
let barChartLabels: string[] = [];
Expand All @@ -38,12 +44,16 @@ export class BarChartComponent implements Widget {

if (result) {
let res: any[] = result;
jobCountArray = jsonpath.query(res, '$[*].count');
barChartLabels = jsonpath.query(res, '$[*]._id.CreateDate[\'$date\']');
barChartLabels = barChartLabels.map(x => this.dataConverterService.convert(x, 'datestring'));

// Currently we only support a single dataset
jobCountArray = jsonpath.query(res, datamap.datasets[0].path);
barChartLabels = jsonpath.query(res, datamap.labels.path);
if (datamap.labels.type) {
barChartLabels = barChartLabels.map(x => this.dataConverterService.convert(x, datamap.labels.type));
}
}

barChartData = [{ data: jobCountArray, label: 'Orders' }];
barChartData = [{ data: jobCountArray, label: datamap.datasets[0].label }];
this.data = { labels: barChartLabels, datasets: barChartData };
this.isDataAvailable = true;
}, error => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui-toolbox/bar-chart/bar-chart.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p-chart #chart *ngIf="isDataAvailable" type="bar" [data]="data"></p-chart>
<p-chart #chart *ngIf="isDataAvailable" type="bar" [data]="data" [options]="options"></p-chart>
2 changes: 1 addition & 1 deletion src/app/ui-toolbox/widget/widget.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Widget {
data: any;
config: any;
options: any;
setWidgetConfig(widgetConfig: any);
}

0 comments on commit 4697f85

Please sign in to comment.