Skip to content

Commit

Permalink
Added some type definition for the WidgetConfig and made sure the bar…
Browse files Browse the repository at this point in the history
…-chart supports multiple data
  • Loading branch information
thehoneymad committed Apr 8, 2017
1 parent 4697f85 commit f62d512
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"API_BASE": "http://localhost:5000/api/",
"API_BASE": "http://datacat.nerdcats.io/api/",
"AUTH_BASE": "http://auth.nerdcats.co/",
"AUTH_ENDPOINT": "connect/token",
"CLIENT_ID": "datacat.client",
Expand Down
2 changes: 1 addition & 1 deletion src/app/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DataService {
}

// INFO: Temporary test method to test out how a widget could have behaved.
getSampleWidgetConfig(): any {
getSampleWidgetConfig(): WidgetConfig {
// INLINE query, these needs to be saved in the database of course
let aggDocument: any = {
'aggregate': [
Expand Down
11 changes: 7 additions & 4 deletions src/app/ui-toolbox/bar-chart/bar-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,23 @@ export class BarChartComponent implements Widget {
.subscribe(result => {
let barChartLabels: string[] = [];
let barChartData: any[];
let jobCountArray: any[] = [];
let barChartDataArray: any[] = [];

if (result) {
let res: any[] = result;

// 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));
}

for (let i = 0; i < datamap.datasets.length; i++) {
let jobCountArray = jsonpath.query(res, datamap.datasets[i].path);
barChartDataArray.push({ data: jobCountArray, label: datamap.datasets[i].label });
}
}

barChartData = [{ data: jobCountArray, label: datamap.datasets[0].label }];
barChartData = barChartDataArray;
this.data = { labels: barChartLabels, datasets: barChartData };
this.isDataAvailable = true;
}, error => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/ui-toolbox/widget/widget-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export interface WidgetConfig {
connectionId: string;
collectionName: string;
type: string;
datamap: { [key: string]: any };
config: any;
}

0 comments on commit f62d512

Please sign in to comment.