From 750401e208911c1e2c203879687bf54898ee24ed Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Thu, 19 Dec 2013 14:39:30 +0400 Subject: [PATCH] crossfilter: fixed definition and test --- crossfilter/crossfilter-tests.ts | 14 ++++++++------ crossfilter/crossfilter.d.ts | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crossfilter/crossfilter-tests.ts b/crossfilter/crossfilter-tests.ts index 222096566..745ed3aa4 100644 --- a/crossfilter/crossfilter-tests.ts +++ b/crossfilter/crossfilter-tests.ts @@ -44,28 +44,30 @@ paymentsByTotal.filterFunction(d => 0 <= d && d < 10 || 20 <= d && d < 30); paymentsByTotal.filterAll(); // selects all payments var topPayments = paymentsByTotal.top(4); // the top four payments, by total -topPayments[0]; // the biggest payment +{var p: Payment = topPayments[0];} // the biggest payment topPayments[1]; // the second-biggest payment var allPayments = paymentsByTotal.top(Infinity); var bottomPayments = paymentsByTotal.bottom(4); // the bottom four payments, by total -bottomPayments[0]; // the smallest payment +{var p: Payment = bottomPayments[0];} // the smallest payment bottomPayments[1]; // the second-smallest payment var paymentGroupsByTotal = paymentsByTotal.group(total => Math.floor(total / 100)); paymentGroupsByTotal.size(); -paymentGroupsByTotal.reduce((p, v) => p + 1, (p, v) => p - 1, () => 0); +// bug of TS 0.9.5 https://typescript.codeplex.com/discussions/471751 +//paymentGroupsByTotal.reduce((p, v) => p + 1, (p, v) => p - 1, () => 0); +paymentGroupsByTotal.reduce((p, v) => p + 1, (p, v) => p - 1, () => 0); paymentGroupsByTotal.reduceCount(); var paymentsByType = payments.dimension(d => d.type), paymentVolumeByType = paymentsByType.group().reduceSum(d => d.total), topTypes = paymentVolumeByType.top(1); -topTypes[0].key; // the top payment type (e.g., "tab") -topTypes[0].value; // the payment volume for that type (e.g., 900) +{var s: string = topTypes[0].key;} // the top payment type (e.g., "tab") +{var n: number = topTypes[0].value;} // the payment volume for that type (e.g., 900) interface Group { count: number; @@ -101,7 +103,7 @@ topTotals[0].value; // reduced value for that type (e.g., {count:8, total:920}) paymentGroupsByTotal.orderNatural(); -var paymentCountByType = paymentsByType.group(); +var paymentCountByType = paymentsByType.group().reduceCount(); topTypes = paymentCountByType.top(1); topTypes[0].key; // the top payment type (e.g., "tab") topTypes[0].value; // the count of payments of that type (e.g., 8) diff --git a/crossfilter/crossfilter.d.ts b/crossfilter/crossfilter.d.ts index e01cf1fcb..c98d20867 100644 --- a/crossfilter/crossfilter.d.ts +++ b/crossfilter/crossfilter.d.ts @@ -102,8 +102,8 @@ declare module CrossFilter { top(k: number): T[]; bottom(k: number): T[]; dispose(): void; - group(): Group; - group(groupValue: (data: T) => TGroup): Group; + group(): Group; + group(groupValue: (data: TDimension) => TGroup): Group; groupAll(): GroupAll; } }