Skip to content

Commit 0681bcd

Browse files
author
Ihor Khomiak
committed
implement parsing data functionality for pie chart
1 parent 828fdc3 commit 0681bcd

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

app/components/chart/chart.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
selectionMode="DataPoint"
2323
expandRadius="0.4"
2424
outerRadiusFactor="0.7"
25-
[items]="costService.costs"
25+
[items]="pieItems"
2626
valueProperty="quantity"
27-
legendLabel="changesMonth"></PieSeries>
27+
legendLabel="type"></PieSeries>
2828
<RadLegendView tkPieLegend
2929
position="Right"
3030
title="Tasks"

app/components/chart/chart.component.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CostService } from '../../services/cost.service';
1313
export class ChartComponent {
1414
private barButtons: Array<SegmentedBarItem> = [];
1515
private barButtonsSelectedIndex = 0;
16+
private pieItems: ObservableArray<any> = new ObservableArray();
1617

1718
constructor(private costService: CostService){
1819
this.initSegmentedBar();
@@ -30,9 +31,23 @@ export class ChartComponent {
3031
this.barButtonsSelectedIndex = 0;
3132
}
3233

34+
private parseCostsForPie() {
35+
let costTypes = {};
36+
this.costService.costs.forEach(cost => {
37+
if(costTypes[cost.type] == undefined) {
38+
costTypes[cost.type] = 0;
39+
}
40+
costTypes[cost.type] += cost.quantity;
41+
});
42+
this.pieItems = new ObservableArray(this.objectToArray(costTypes));
43+
}
44+
3345
private onSelectedIndexChange(args) {
3446
let segmetedBar = <SegmentedBar>args.object;
3547
this.barButtonsSelectedIndex = segmetedBar.selectedIndex;
48+
if(segmetedBar.selectedIndex === 1) {
49+
this.parseCostsForPie();
50+
}
3651
}
3752

3853
private pullToRefresh(pullToRefreshArgs: any) {
@@ -41,4 +56,16 @@ export class ChartComponent {
4156
pullRefresh.refreshing = false;
4257
});
4358
}
59+
60+
private objectToArray(object: any): Array<any> {
61+
let arr: any = [];
62+
for (const key in object) {
63+
let element = {
64+
type: key,
65+
quantity: object[key]
66+
};
67+
arr.push(element);
68+
}
69+
return arr;
70+
}
4471
}

app/components/cost/costs.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class CostsComponent implements OnInit {
2323
@Input() set dateRange(value: any) {
2424
this._dateRange = value;
2525
if(value['startDate']) {
26-
console.log(JSON.stringify(value));
2726
this.filterData(value);
2827
}
2928
}

app/components/list/list.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class ListComponent {
3636
private getDateValue(item) {
3737
let currentDate: Date = new Date(Date.now());
3838
let itemDate: Date = new Date(item.changesDate);
39-
if(currentDate.toDateString() === itemDate.toDateString()) {
40-
return ("0" + itemDate.getHours()).slice(-2) + ":" + ("0" + itemDate.getMinutes()).slice(-2);
41-
}
39+
// if(currentDate.toDateString() === itemDate.toDateString()) {
40+
// return ("0" + itemDate.getHours()).slice(-2) + ":" + ("0" + itemDate.getMinutes()).slice(-2);
41+
// }
4242
return Utils.dateToYMD(itemDate);
4343
}
4444
}

0 commit comments

Comments
 (0)