crossfilter: fixed definition and test

This commit is contained in:
Igor Oleinikov
2013-12-19 14:39:30 +04:00
parent d6768e5ca8
commit 750401e208
2 changed files with 10 additions and 8 deletions
+8 -6
View File
@@ -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<number>((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)
+2 -2
View File
@@ -102,8 +102,8 @@ declare module CrossFilter {
top(k: number): T[];
bottom(k: number): T[];
dispose(): void;
group(): Group<T, TDimension, number>;
group<TGroup>(groupValue: (data: T) => TGroup): Group<T, TDimension, TGroup>;
group(): Group<T, TDimension, TDimension>;
group<TGroup>(groupValue: (data: TDimension) => TGroup): Group<T, TDimension, TGroup>;
groupAll(): GroupAll<T>;
}
}