Skip to content

Commit c80fafa

Browse files
committed
Update data.ts
1 parent 042c72e commit c80fafa

File tree

1 file changed

+150
-9
lines changed
  • demos/gantt/many-tasks/src/app

1 file changed

+150
-9
lines changed

demos/gantt/many-tasks/src/app/data.ts

Lines changed: 150 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ interface IRowGenerateOrdersData {
2828

2929
interface ITaskGenerateData {
3030
id: number | string;
31-
status: string;
32-
text: string;
31+
status?: string;
32+
text?: string;
3333
tags?: string;
3434
priority?: string;
3535
progress?: number;
@@ -839,7 +839,7 @@ export function GetEmployees() {
839839
"Anne has a BA degree in English from St. Lawrence College. She is fluent in French and German."];
840840
var k = 0;
841841
for (var i = 0; i < firstNames.length; i++) {
842-
var row = {};
842+
var row: any = {};
843843
row["firstName"] = firstNames[k];
844844
row["lastName"] = lastNames[k];
845845
row["title"] = titles[k];
@@ -1020,7 +1020,7 @@ export function GetOrdersData(rowscount?: number): IRowGenerateOrdersData[] {
10201020
}
10211021

10221022
export function GetKanbanData(locale = 'en') {
1023-
const text = {
1023+
const text: any = {
10241024
en: [
10251025
'Research', 'Displaying data from data source', 'Showing cover and title', 'Property validation',
10261026
'formatFunction and formatSettings', 'Expand/collapse arrow', 'Virtual scrolling', 'Deferred scrolling',
@@ -1036,7 +1036,7 @@ export function GetKanbanData(locale = 'en') {
10361036
'שימוש חוזר באלמנטים HTML קיימים', 'וירטואליזציה של כרטיסים שהתמוטטו'
10371037
]
10381038
},
1039-
tags = {
1039+
tags: any = {
10401040
en: ['initial', 'data', 'visual', 'property', 'scrolling', 'method'],
10411041
he: ['התחלתי', 'נתונים', 'חזותי', 'תכונה', 'גלילה', 'שיטה']
10421042
},
@@ -1297,7 +1297,7 @@ export function GetKanbanHierarchicalData() {
12971297

12981298
export function GeneratePivotData(numberOfRecords: number, numberOfYears: number = 4): any {
12991299
const continents: string[] = ['Africa', 'Asia', 'Australia', 'Europe', 'North America', 'South America'],
1300-
cities = {
1300+
cities: any = {
13011301
Africa: ['Cairo', 'Lagos', 'Kinshasa', 'Luanda', 'Khartoum'],
13021302
Asia: ['Tokyo', 'Delhi', 'Shanghai', 'Mumbai', 'Beijing'],
13031303
Australia: ['Sydney', 'Melbourne', 'Brisbane', 'Perth', 'Adelaide'],
@@ -1306,7 +1306,7 @@ export function GeneratePivotData(numberOfRecords: number, numberOfYears: number
13061306
'South America': ['São Paulo', 'Buenos Aires', 'Rio de Janeiro', 'Bogotá', 'Lima']
13071307
},
13081308
allMonths: string[] = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
1309-
months = {
1309+
months: any = {
13101310
Q1: ['January', 'February', 'March'],
13111311
Q2: ['April', 'May', 'June'],
13121312
Q3: ['July', 'August', 'September'],
@@ -1317,13 +1317,15 @@ export function GeneratePivotData(numberOfRecords: number, numberOfYears: number
13171317
let result: any = [];
13181318

13191319
for (let i = 0; i < numberOfRecords; i++) {
1320-
const dataPoint = {} as IPivotRowGenerateData;
1320+
const dataPoint: any = {} as IPivotRowGenerateData;
13211321

13221322
dataPoint.continent = continents[Math.floor(Math.random() * continents.length)];
13231323
dataPoint.city = cities[dataPoint.continent][Math.floor(Math.random() * cities[dataPoint.continent].length)];
13241324
dataPoint.year = Math.floor(Math.random() * (maxYear - minYear + 1)) + minYear;
13251325
dataPoint.quarter = ['Q1', 'Q2', 'Q3', 'Q4'][Math.floor(Math.random() * 4)];
1326-
dataPoint.month = months[dataPoint.quarter][[Math.floor(Math.random() * 3)]];
1326+
1327+
const randomQuarter: number = Math.floor(Math.random() * 3);
1328+
dataPoint.month = months[dataPoint.quarter][randomQuarter];
13271329
dataPoint.revenue = Math.floor(Math.random() * (10000 - 1001)) + 1000;
13281330
dataPoint.expense = -1 * Math.floor(Math.random() * (10000 - 1001)) + 1000;
13291331

@@ -1368,6 +1370,8 @@ export function GeneratePivotData(numberOfRecords: number, numberOfYears: number
13681370

13691371
return result * (directions[i] === 'asc' ? 1 : -1);
13701372
}
1373+
1374+
return 0;
13711375
});
13721376

13731377
for (let i = 0; i < dataSource.length; i++) {
@@ -1377,4 +1381,141 @@ export function GeneratePivotData(numberOfRecords: number, numberOfYears: number
13771381
}
13781382

13791383
return result;
1384+
}
1385+
1386+
1387+
export function GetGanttChartTreeData(count: number = 50, minDate?: Date, maxDate?: Date) {
1388+
const data = [];
1389+
1390+
if (!minDate || isNaN(new Date(minDate).getTime())) {
1391+
minDate = new Date();
1392+
}
1393+
1394+
if (!maxDate || isNaN(new Date(maxDate).getTime())) {
1395+
maxDate = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate() + 1);
1396+
}
1397+
1398+
const dateMin = new Date(minDate),
1399+
dateMax = new Date(maxDate);
1400+
let [taskCounter, projectCounter] = [0, 0];
1401+
1402+
function getTasks(n: number = 1, includeSubProjects?: boolean): any[] {
1403+
let tasks = [];
1404+
1405+
for (let i = 0; i < n; i += 1) {
1406+
const rand = getRandom();
1407+
let task;
1408+
1409+
if (includeSubProjects && rand % 5 === 0) {
1410+
task = getProject(rand);
1411+
}
1412+
else {
1413+
task = {
1414+
label: 'Task ' + taskCounter,
1415+
dateStart: `${dateMin.getFullYear()}-${dateMin.getMonth()}-${dateMin.getDate()}`,
1416+
dateEnd: `${dateMax.getFullYear()}-${dateMax.getMonth()}-${dateMax.getDate()}`,
1417+
type: 'task'
1418+
};
1419+
}
1420+
1421+
// if (i % 5 === 0) {
1422+
// task.connections = [{
1423+
// target: rand % count,
1424+
// type: rand % 3
1425+
// }];
1426+
// }
1427+
1428+
tasks.push(task);
1429+
1430+
dateMin.setDate(dateMin.getDate() + rand);
1431+
dateMax.setDate(dateMax.getDate() + rand + getRandom());
1432+
taskCounter++;
1433+
}
1434+
1435+
return tasks
1436+
}
1437+
1438+
function getProject(rand: number): any {
1439+
const isEven = rand % 2 === 0,
1440+
projObj = {
1441+
label: 'Project ' + projectCounter,
1442+
dateStart: `${dateMin.getFullYear()}-${dateMin.getMonth()}-${dateMin.getDate()}`,
1443+
dateEnd: `${dateMax.getFullYear()}-${dateMax.getMonth()}-${dateMax.getDate()}`,
1444+
type: 'project',
1445+
expanded: isEven,
1446+
tasks: getTasks(rand, isEven)
1447+
}
1448+
1449+
projectCounter++;
1450+
dateMin.setDate(dateMin.getDate() + rand);
1451+
dateMax.setDate(dateMax.getDate() + rand + getRandom());
1452+
1453+
return projObj
1454+
}
1455+
1456+
for (let i = 0; i < count; i += 1) {
1457+
const rand = getRandom();
1458+
1459+
if (rand % 5 === 0) {
1460+
data.push(getProject(rand));
1461+
}
1462+
else {
1463+
data.push(getTasks()[0]);
1464+
}
1465+
}
1466+
1467+
return data
1468+
}
1469+
1470+
function getRandom(coeff = 10) {
1471+
return Math.round(Math.random() * coeff)
1472+
}
1473+
1474+
export function GetGanttChartFlatData(count: number = 50, minDate?: Date, maxDate?: Date) {
1475+
const data = [];
1476+
1477+
if (!minDate || isNaN(new Date(minDate).getTime())) {
1478+
minDate = new Date();
1479+
}
1480+
1481+
if (!maxDate || isNaN(new Date(maxDate).getTime())) {
1482+
maxDate = new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate() + getRandom(50));
1483+
}
1484+
1485+
const dateMin = new Date(minDate),
1486+
dateMax = new Date(maxDate);
1487+
let dateMinYear = dateMin.getFullYear(),
1488+
dateMinMonth = dateMin.getMonth(),
1489+
dateMinDate = dateMin.getDate(),
1490+
dateMaxYear = dateMax.getFullYear(),
1491+
dateMaxMonth = dateMax.getMonth(),
1492+
dateMaxDate = dateMax.getDate(),
1493+
[taskCounter, projectCounter] = [0, 0];
1494+
1495+
for (let i = 0; i < count; i += 1) {
1496+
const rand = getRandom(),
1497+
task: any = {
1498+
label: 'Task ' + (taskCounter + 1),
1499+
dateStart: `${dateMinYear}-${dateMinMonth}-${dateMinDate}`,
1500+
dateEnd: `${dateMaxYear}-${dateMaxMonth}-${dateMaxDate}`,
1501+
type: 'task'
1502+
};
1503+
1504+
if (i % 4 === 0) {
1505+
task.connections = [{
1506+
target: i + rand % count,
1507+
type: rand % 3
1508+
}];
1509+
}
1510+
1511+
dateMinMonth = rand;
1512+
dateMaxMonth = rand + getRandom(20);
1513+
dateMinDate = getRandom();
1514+
dateMaxDate = getRandom(20);
1515+
taskCounter++;
1516+
1517+
data.push(task);
1518+
}
1519+
1520+
return data
13801521
}

0 commit comments

Comments
 (0)