|
| 1 | +import { Component, ViewChild } from "@angular/core"; |
| 2 | +import { IgxColumnComponent } from "igniteui-angular"; |
| 3 | +import { IgxLegendComponent } from "igniteui-angular-charts/ES5/igx-legend-component"; |
| 4 | +import { data } from "../../grid-crm/grid-crm/data"; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + selector: "grid-master-detail", |
| 8 | + styleUrls: ["./grid-master-detail.component.scss"], |
| 9 | + templateUrl: "grid-master-detail.component.html" |
| 10 | +}) |
| 11 | + |
| 12 | +export class GridMasterDetailSampleComponent { |
| 13 | + @ViewChild("legend", { static: true }) |
| 14 | + public legend: IgxLegendComponent; |
| 15 | + |
| 16 | + public data = []; |
| 17 | + public include = ["date", "estimated", "actual"]; |
| 18 | + constructor() { |
| 19 | + this.data = data; |
| 20 | + } |
| 21 | + |
| 22 | + public formatPieLabel = (args) => { |
| 23 | + return args.item.Value + " " + args.item.Label; |
| 24 | + } |
| 25 | + |
| 26 | + public formatDateLabel(item: any): string { |
| 27 | + return item.date.toLocaleDateString(undefined, {month: "short"}); |
| 28 | + } |
| 29 | + |
| 30 | + public formatValue(val: any): string { |
| 31 | + return val.toLocaleString("en-us", { maximumFractionDigits: 2 }); |
| 32 | + } |
| 33 | + public getPieData(dataItem) { |
| 34 | + return [ |
| 35 | + { Label: "Won", Value: dataItem.deals_won}, |
| 36 | + { Label: "Lost", Value: dataItem.deals_lost}, |
| 37 | + { Label: "Pending", Value: dataItem.deals_pending}]; |
| 38 | + } |
| 39 | + |
| 40 | + public getChartData(dataItem) { |
| 41 | + const year: number = new Date().getFullYear(); |
| 42 | + const sales: any[] = []; |
| 43 | + for (let i = 0; i < 12; i++) { |
| 44 | + const value = this.getRandomNumber(2000, 10000); |
| 45 | + sales.push({ |
| 46 | + estimated: value + this.getRandomNumber(-2000 , 1000), |
| 47 | + actual: value, date: new Date(year, i, 1) }); |
| 48 | + } |
| 49 | + dataItem.chartData = sales; |
| 50 | + return dataItem.chartData; |
| 51 | + } |
| 52 | + |
| 53 | + public gridData(dataItem) { |
| 54 | + const detailsData = []; |
| 55 | + let won = dataItem.deals_won; |
| 56 | + let lost = dataItem.deals_lost; |
| 57 | + let pending = dataItem.deals_pending; |
| 58 | + for (let j = 0; j < 3; j++) { |
| 59 | + detailsData.push({ |
| 60 | + Q: "Q" + (j + 1), |
| 61 | + Won: this.getRandomNumber(0, won), |
| 62 | + Lost: this.getRandomNumber(0, lost), |
| 63 | + Pending: this.getRandomNumber(0, pending) |
| 64 | + }); |
| 65 | + won -= detailsData[j].Won; |
| 66 | + lost -= detailsData[j].Lost; |
| 67 | + pending -= detailsData[j].Pending; |
| 68 | + } |
| 69 | + detailsData.push({ |
| 70 | + Q: "Q4", |
| 71 | + Won: won, |
| 72 | + Lost: lost, |
| 73 | + Pending: pending |
| 74 | + }); |
| 75 | + dataItem.gridData = detailsData; |
| 76 | + return dataItem.gridData; |
| 77 | + } |
| 78 | + |
| 79 | + public columnInit(event: IgxColumnComponent) { |
| 80 | + if (event.field === "Q") { |
| 81 | + event.width = "50px"; |
| 82 | + event.header = " "; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public getRandomNumber(min: number, max: number): number { |
| 87 | + return Math.round(min + Math.random() * (max - min)); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments