diff --git a/src/app/data/data.service.ts b/src/app/data/data.service.ts index 88ec34a..94eff33 100644 --- a/src/app/data/data.service.ts +++ b/src/app/data/data.service.ts @@ -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': [ @@ -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' + } } }; } diff --git a/src/app/ui-toolbox/bar-chart/bar-chart.component.ts b/src/app/ui-toolbox/bar-chart/bar-chart.component.ts index 2c64bf6..b379f96 100644 --- a/src/app/ui-toolbox/bar-chart/bar-chart.component.ts +++ b/src/app/ui-toolbox/bar-chart/bar-chart.component.ts @@ -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; @@ -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[] = []; @@ -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 => { diff --git a/src/app/ui-toolbox/bar-chart/bar-chart.html b/src/app/ui-toolbox/bar-chart/bar-chart.html index 11136a7..188ab0f 100644 --- a/src/app/ui-toolbox/bar-chart/bar-chart.html +++ b/src/app/ui-toolbox/bar-chart/bar-chart.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/ui-toolbox/widget/widget.ts b/src/app/ui-toolbox/widget/widget.ts index 614af16..ab4dbc8 100644 --- a/src/app/ui-toolbox/widget/widget.ts +++ b/src/app/ui-toolbox/widget/widget.ts @@ -1,5 +1,5 @@ export interface Widget { data: any; - config: any; + options: any; setWidgetConfig(widgetConfig: any); }