@tidyjs/tidy 2.4.4 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/groupBy.js +2 -1
- package/dist/es/groupBy.js.map +1 -1
- package/dist/es/helpers/isObject.js +7 -0
- package/dist/es/helpers/isObject.js.map +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/item/rate.js +7 -7
- package/dist/es/item/rate.js.map +1 -1
- package/dist/es/mutate.js +5 -5
- package/dist/es/mutate.js.map +1 -1
- package/dist/es/summary/deviation.js.map +1 -1
- package/dist/es/summary/first.js.map +1 -1
- package/dist/es/summary/last.js.map +1 -1
- package/dist/es/summary/max.js.map +1 -1
- package/dist/es/summary/mean.js.map +1 -1
- package/dist/es/summary/meanRate.js.map +1 -1
- package/dist/es/summary/median.js.map +1 -1
- package/dist/es/summary/min.js.map +1 -1
- package/dist/es/summary/n.js +5 -1
- package/dist/es/summary/n.js.map +1 -1
- package/dist/es/summary/nDistinct.js +2 -1
- package/dist/es/summary/nDistinct.js.map +1 -1
- package/dist/es/summary/sum.js +7 -2
- package/dist/es/summary/sum.js.map +1 -1
- package/dist/es/summary/variance.js.map +1 -1
- package/dist/es/vector/cumsum.js.map +1 -1
- package/dist/es/vector/lag.js +1 -1
- package/dist/es/vector/lag.js.map +1 -1
- package/dist/es/vector/lead.js +1 -1
- package/dist/es/vector/lead.js.map +1 -1
- package/dist/es/vector/roll.js +4 -3
- package/dist/es/vector/roll.js.map +1 -1
- package/dist/es/vector/rowNumber.js +10 -0
- package/dist/es/vector/rowNumber.js.map +1 -0
- package/dist/lib/groupBy.js +2 -1
- package/dist/lib/groupBy.js.map +1 -1
- package/dist/lib/helpers/isObject.js +11 -0
- package/dist/lib/helpers/isObject.js.map +1 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/item/rate.js +7 -7
- package/dist/lib/item/rate.js.map +1 -1
- package/dist/lib/mutate.js +5 -5
- package/dist/lib/mutate.js.map +1 -1
- package/dist/lib/summary/deviation.js.map +1 -1
- package/dist/lib/summary/first.js.map +1 -1
- package/dist/lib/summary/last.js.map +1 -1
- package/dist/lib/summary/max.js.map +1 -1
- package/dist/lib/summary/mean.js.map +1 -1
- package/dist/lib/summary/meanRate.js.map +1 -1
- package/dist/lib/summary/median.js.map +1 -1
- package/dist/lib/summary/min.js.map +1 -1
- package/dist/lib/summary/n.js +5 -1
- package/dist/lib/summary/n.js.map +1 -1
- package/dist/lib/summary/nDistinct.js +2 -1
- package/dist/lib/summary/nDistinct.js.map +1 -1
- package/dist/lib/summary/sum.js +7 -2
- package/dist/lib/summary/sum.js.map +1 -1
- package/dist/lib/summary/variance.js.map +1 -1
- package/dist/lib/vector/cumsum.js.map +1 -1
- package/dist/lib/vector/lag.js +1 -1
- package/dist/lib/vector/lag.js.map +1 -1
- package/dist/lib/vector/lead.js +1 -1
- package/dist/lib/vector/lead.js.map +1 -1
- package/dist/lib/vector/roll.js +4 -3
- package/dist/lib/vector/roll.js.map +1 -1
- package/dist/lib/vector/rowNumber.js +14 -0
- package/dist/lib/vector/rowNumber.js.map +1 -0
- package/dist/tidy.d.ts +40 -19
- package/dist/umd/tidy.js +47 -22
- package/dist/umd/tidy.js.map +1 -1
- package/dist/umd/tidy.min.js +1 -1
- package/dist/umd/tidy.min.js.map +1 -1
- package/package.json +2 -2
package/dist/tidy.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ declare function summarizeAll<T extends object, F extends SummaryKeyFn<T>>(summa
|
|
|
125
125
|
declare function summarizeIf<T extends object, F extends SummaryKeyFn<T>>(predicateFn: (vector: Vector<T>) => boolean, summaryFn: F): TidyFn<T, A.Compute<Record<keyof T, SummaryFnOutput<T, F>>>>;
|
|
126
126
|
declare function summarizeAt<T extends object, Keys extends (keyof T)[], F extends SummaryKeyFn<T, Keys[number]>>(keys: Keys, summaryFn: F): TidyFn<T, A.Compute<Record<Keys[number], SummaryFnOutput<T, F>>>>;
|
|
127
127
|
|
|
128
|
-
declare type MutateSpecValue<T, O = any> = ((item: T) => O) | NonFunctionValue;
|
|
128
|
+
declare type MutateSpecValue<T, O = any> = ((item: T, index: number, array: Iterable<T>) => O) | NonFunctionValue;
|
|
129
129
|
declare type MutateSpec<T> = Record<Key, MutateSpecValue<T>>;
|
|
130
130
|
declare type ResolvedObj<Obj extends Record<Key, MutateSpecValue<any>>> = {
|
|
131
131
|
[K in keyof Obj]: Obj[K] extends (...args: any) => any ? ReturnType<Obj[K]> extends any[] ? ReturnType<Obj[K]>[number] : ReturnType<Obj[K]> : Obj[K];
|
|
@@ -1269,19 +1269,25 @@ declare type Options = {
|
|
|
1269
1269
|
declare function debug<T extends object>(label?: string | null | undefined, options?: Options | null | undefined): TidyFn<T>;
|
|
1270
1270
|
|
|
1271
1271
|
declare type RateOptions<T> = {
|
|
1272
|
-
predicate?: (d: T) => boolean;
|
|
1272
|
+
predicate?: (d: T, index: number, array: Iterable<T>) => boolean;
|
|
1273
1273
|
allowDivideByZero?: boolean;
|
|
1274
1274
|
};
|
|
1275
1275
|
/**
|
|
1276
1276
|
* Returns a function that computes a rate (numerator / denominator), setting the value to
|
|
1277
1277
|
* 0 if denominator = 0 and numerator = 0.
|
|
1278
1278
|
*/
|
|
1279
|
-
declare function rate<T extends object>(numerator: keyof T | ((d: T) => number), denominator: keyof T | ((d: T) => number), options?: RateOptions<T>): (d: T) => number | undefined;
|
|
1279
|
+
declare function rate<T extends object>(numerator: keyof T | ((d: T, index: number, array: Iterable<T>) => number), denominator: keyof T | ((d: T, index: number, array: Iterable<T>) => number), options?: RateOptions<T>): (d: T, index: number, array: Iterable<T>) => number | undefined;
|
|
1280
1280
|
|
|
1281
|
-
declare function cumsum<T extends object>(key: keyof T | ((d: T) => number | null | undefined)): (items: T[]) => Float64Array;
|
|
1281
|
+
declare function cumsum<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number | null | undefined)): (items: T[]) => Float64Array;
|
|
1282
1282
|
|
|
1283
1283
|
declare type RollOptions = {
|
|
1284
1284
|
partial?: boolean;
|
|
1285
|
+
/** which direction the window is aligned to (default: right, looking back)
|
|
1286
|
+
* - right: current row is the last item [1,2,**3**]
|
|
1287
|
+
* - left: current row is the first item [**1**,2,3]
|
|
1288
|
+
* - center: current row is the center item [1,**2**,3]
|
|
1289
|
+
*/
|
|
1290
|
+
align?: 'left' | 'center' | 'right';
|
|
1285
1291
|
};
|
|
1286
1292
|
/**
|
|
1287
1293
|
* Returns a function that computes the a rolling value (e.g. moving average) by
|
|
@@ -1304,7 +1310,7 @@ declare type LagOptions = {
|
|
|
1304
1310
|
* @param key The key or accessor to lag
|
|
1305
1311
|
* @param options Options to configure roll. e.g. whether to run on partial windows.
|
|
1306
1312
|
*/
|
|
1307
|
-
declare function lag<T extends object>(key: keyof T | ((d: T) => any), options?: LagOptions | undefined | null): (items:
|
|
1313
|
+
declare function lag<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => any), options?: LagOptions | undefined | null): (items: T[]) => any[];
|
|
1308
1314
|
|
|
1309
1315
|
declare type LeadOptions = {
|
|
1310
1316
|
/** Number of positions to lead by (default: 1) */
|
|
@@ -1318,67 +1324,82 @@ declare type LeadOptions = {
|
|
|
1318
1324
|
* @param key The key or accessor to lead
|
|
1319
1325
|
* @param options Options to configure roll. e.g. whether to run on partial windows.
|
|
1320
1326
|
*/
|
|
1321
|
-
declare function lead<T extends object>(key: keyof T | ((d: T) => any), options?: LeadOptions | undefined | null): (items:
|
|
1327
|
+
declare function lead<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => any), options?: LeadOptions | undefined | null): (items: T[]) => any[];
|
|
1322
1328
|
|
|
1329
|
+
declare type RowNumberOptions = {
|
|
1330
|
+
/** what to start row numbers at, default is 0 */
|
|
1331
|
+
startAt?: number;
|
|
1332
|
+
};
|
|
1333
|
+
/**
|
|
1334
|
+
* Returns a vector of row numbers, starting at 0
|
|
1335
|
+
*/
|
|
1336
|
+
declare function rowNumber<T>(options?: RowNumberOptions): (items: T[]) => number[];
|
|
1337
|
+
|
|
1338
|
+
declare type SumOptions<T> = {
|
|
1339
|
+
predicate?: (d: T, index: number, array: Iterable<T>) => boolean;
|
|
1340
|
+
};
|
|
1323
1341
|
/**
|
|
1324
1342
|
* Returns a function that computes the sum over an array of items
|
|
1325
1343
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1326
1344
|
*/
|
|
1327
|
-
declare function sum<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number;
|
|
1345
|
+
declare function sum<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number), options?: SumOptions<T>): (items: T[]) => number;
|
|
1328
1346
|
|
|
1329
1347
|
/**
|
|
1330
1348
|
* Returns a function that computes the min over an array of items
|
|
1331
1349
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1332
1350
|
*/
|
|
1333
|
-
declare function min<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1351
|
+
declare function min<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1334
1352
|
|
|
1335
1353
|
/**
|
|
1336
1354
|
* Returns a function that computes the max over an array of items
|
|
1337
1355
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1338
1356
|
*/
|
|
1339
|
-
declare function max<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1357
|
+
declare function max<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1340
1358
|
|
|
1341
1359
|
/**
|
|
1342
1360
|
* Returns a function that computes the mean over an array of items
|
|
1343
1361
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1344
1362
|
*/
|
|
1345
|
-
declare function mean<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1363
|
+
declare function mean<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1346
1364
|
|
|
1347
1365
|
/**
|
|
1348
1366
|
* Returns a function that computes the mean of a rate over an array of items
|
|
1349
1367
|
* @param numerator A string key of the object or an accessor converting the object to a number
|
|
1350
1368
|
* @param denominator A string key of the object or an accessor converting the object to a number
|
|
1351
1369
|
*/
|
|
1352
|
-
declare function meanRate<T extends object>(numerator: keyof T | ((d: T) => number), denominator: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1370
|
+
declare function meanRate<T extends object>(numerator: keyof T | ((d: T, index: number, array: Iterable<T>) => number), denominator: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1353
1371
|
|
|
1354
1372
|
/**
|
|
1355
1373
|
* Returns a function that computes the median over an array of items
|
|
1356
1374
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1357
1375
|
*/
|
|
1358
|
-
declare function median<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1376
|
+
declare function median<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1359
1377
|
|
|
1360
1378
|
/**
|
|
1361
1379
|
* Returns a function that computes the deviation over an array of items
|
|
1362
1380
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1363
1381
|
*/
|
|
1364
|
-
declare function deviation<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1382
|
+
declare function deviation<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1365
1383
|
|
|
1366
1384
|
/**
|
|
1367
1385
|
* Returns a function that computes the variance over an array of items
|
|
1368
1386
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1369
1387
|
*/
|
|
1370
|
-
declare function variance<T extends object>(key: keyof T | ((d: T) => number)): (items: T[]) => number | undefined;
|
|
1388
|
+
declare function variance<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => number)): (items: T[]) => number | undefined;
|
|
1371
1389
|
|
|
1390
|
+
declare type NOptions<T> = {
|
|
1391
|
+
predicate?: (d: T, index: number, array: Iterable<T>) => boolean;
|
|
1392
|
+
};
|
|
1372
1393
|
/**
|
|
1373
1394
|
* Returns a function that computes the count over an array of items
|
|
1374
1395
|
*/
|
|
1375
|
-
declare function n(): (items:
|
|
1396
|
+
declare function n<T>(options?: NOptions<T>): (items: T[]) => number;
|
|
1376
1397
|
|
|
1377
1398
|
/**
|
|
1378
1399
|
* Returns a function that computes the distinct count for a key
|
|
1379
1400
|
* over an array of items. By default it counts nulls but not undefined
|
|
1380
1401
|
*/
|
|
1381
|
-
declare function nDistinct<T extends object>(key: keyof T | ((d: T) => any), options?: {
|
|
1402
|
+
declare function nDistinct<T extends object>(key: keyof T | ((d: T, index: number, array: Iterable<T>) => any), options?: {
|
|
1382
1403
|
includeNull?: boolean;
|
|
1383
1404
|
includeUndefined?: boolean;
|
|
1384
1405
|
}): (items: T[]) => number;
|
|
@@ -1387,13 +1408,13 @@ declare function nDistinct<T extends object>(key: keyof T | ((d: T) => any), opt
|
|
|
1387
1408
|
* Returns a function that returns the first value for the specified key
|
|
1388
1409
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1389
1410
|
*/
|
|
1390
|
-
declare function first<T extends object>(key: keyof T | ((d: T) =>
|
|
1411
|
+
declare function first<T extends object>(key: keyof T | ((d: T) => any)): (items: T[]) => any;
|
|
1391
1412
|
|
|
1392
1413
|
/**
|
|
1393
1414
|
* Returns a function that returns the last value for the specified key
|
|
1394
1415
|
* @param key A string key of the object or an accessor converting the object to a number
|
|
1395
1416
|
*/
|
|
1396
|
-
declare function last<T extends object>(key: keyof T | ((d: T) =>
|
|
1417
|
+
declare function last<T extends object>(key: keyof T | ((d: T) => any)): (items: T[]) => any;
|
|
1397
1418
|
|
|
1398
1419
|
/**
|
|
1399
1420
|
* Returns all keys
|
|
@@ -1448,4 +1469,4 @@ declare namespace math {
|
|
|
1448
1469
|
};
|
|
1449
1470
|
}
|
|
1450
1471
|
|
|
1451
|
-
export { Comparator, Datum, Granularity, GroupKey, Grouped, Key, KeyOrFn, LevelSpec, NonFunctionValue, Primitive, SummarizeOptions, SummarizeSpec, math as TMath, TidyContext, TidyFn, TidyGroupExportFn, Vector, addRows as addItems, addRows, arrange, asc, complete, contains, count, cumsum, debug, desc, deviation, distinct, endsWith, everything, expand, fill, filter, first, fixedOrder, fullJoin, fullSeq, fullSeqDate, fullSeqDateISOString, groupBy, innerJoin, lag, last, lead, leftJoin, map, matches, max, mean, meanRate, median, min, mutate, mutateWithSummary, n, nDistinct, negate, numRange, select as pick, pivotLonger, pivotWider, rate, rename, replaceNully, roll, select, slice, sliceHead, sliceMax, sliceMin, sliceSample, sliceTail, arrange as sort, startsWith, sum, summarize, summarizeAll, summarizeAt, summarizeIf, tally, tidy, total, totalAll, totalAt, totalIf, transmute, variance, vectorSeq, vectorSeqDate, when };
|
|
1472
|
+
export { Comparator, Datum, Granularity, GroupKey, Grouped, Key, KeyOrFn, LevelSpec, NonFunctionValue, Primitive, SummarizeOptions, SummarizeSpec, math as TMath, TidyContext, TidyFn, TidyGroupExportFn, Vector, addRows as addItems, addRows, arrange, asc, complete, contains, count, cumsum, debug, desc, deviation, distinct, endsWith, everything, expand, fill, filter, first, fixedOrder, fullJoin, fullSeq, fullSeqDate, fullSeqDateISOString, groupBy, innerJoin, lag, last, lead, leftJoin, map, matches, max, mean, meanRate, median, min, mutate, mutateWithSummary, n, nDistinct, negate, numRange, select as pick, pivotLonger, pivotWider, rate, rename, replaceNully, roll, rowNumber, select, slice, sliceHead, sliceMax, sliceMin, sliceSample, sliceTail, arrange as sort, startsWith, sum, summarize, summarizeAll, summarizeAt, summarizeIf, tally, tidy, total, totalAll, totalAt, totalIf, transmute, variance, vectorSeq, vectorSeqDate, when };
|
package/dist/umd/tidy.js
CHANGED
|
@@ -217,15 +217,15 @@
|
|
|
217
217
|
|
|
218
218
|
function mutate(mutateSpec) {
|
|
219
219
|
const _mutate = (items) => {
|
|
220
|
-
const mutatedItems =
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
const mutatedItems = items.map((d) => ({...d}));
|
|
221
|
+
let i = 0;
|
|
222
|
+
for (const mutatedItem of mutatedItems) {
|
|
223
223
|
for (const key in mutateSpec) {
|
|
224
224
|
const mutateSpecValue = mutateSpec[key];
|
|
225
|
-
const mutatedResult = typeof mutateSpecValue === "function" ? mutateSpecValue(mutatedItem) : mutateSpecValue;
|
|
225
|
+
const mutatedResult = typeof mutateSpecValue === "function" ? mutateSpecValue(mutatedItem, i, mutatedItems) : mutateSpecValue;
|
|
226
226
|
mutatedItem[key] = mutatedResult;
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
++i;
|
|
229
229
|
}
|
|
230
230
|
return mutatedItems;
|
|
231
231
|
};
|
|
@@ -301,6 +301,11 @@
|
|
|
301
301
|
|
|
302
302
|
const identity = (d) => d;
|
|
303
303
|
|
|
304
|
+
function isObject(obj) {
|
|
305
|
+
const type = typeof obj;
|
|
306
|
+
return obj != null && (type === "object" || type === "function");
|
|
307
|
+
}
|
|
308
|
+
|
|
304
309
|
function groupBy(groupKeys, fns, options) {
|
|
305
310
|
if (typeof fns === "function") {
|
|
306
311
|
fns = [fns];
|
|
@@ -368,7 +373,7 @@
|
|
|
368
373
|
const keyCache = new Map();
|
|
369
374
|
return (d) => {
|
|
370
375
|
const keyValue = keyFn(d);
|
|
371
|
-
const keyValueOf =
|
|
376
|
+
const keyValueOf = isObject(keyValue) ? keyValue.valueOf() : keyValue;
|
|
372
377
|
if (keyCache.has(keyValueOf)) {
|
|
373
378
|
return keyCache.get(keyValueOf);
|
|
374
379
|
}
|
|
@@ -510,12 +515,21 @@
|
|
|
510
515
|
return groupTraversal(grouped, initialOutputObject, [], addSubgroup, addLeaf);
|
|
511
516
|
}
|
|
512
517
|
|
|
513
|
-
function n() {
|
|
518
|
+
function n(options) {
|
|
519
|
+
if (options == null ? void 0 : options.predicate) {
|
|
520
|
+
const predicate = options.predicate;
|
|
521
|
+
return (items) => items.reduce((n2, d, i) => predicate(d, i, items) ? n2 + 1 : n2, 0);
|
|
522
|
+
}
|
|
514
523
|
return (items) => items.length;
|
|
515
524
|
}
|
|
516
525
|
|
|
517
|
-
function sum(key) {
|
|
518
|
-
|
|
526
|
+
function sum(key, options) {
|
|
527
|
+
let keyFn = typeof key === "function" ? key : (d) => d[key];
|
|
528
|
+
if (options == null ? void 0 : options.predicate) {
|
|
529
|
+
const originalKeyFn = keyFn;
|
|
530
|
+
const predicate = options.predicate;
|
|
531
|
+
keyFn = (d, index, array) => predicate(d, index, array) ? originalKeyFn(d, index, array) : 0;
|
|
532
|
+
}
|
|
519
533
|
return (items) => d3Array.fsum(items, keyFn);
|
|
520
534
|
}
|
|
521
535
|
|
|
@@ -1100,15 +1114,15 @@
|
|
|
1100
1114
|
const numeratorFn = typeof numerator === "function" ? numerator : (d) => d[numerator];
|
|
1101
1115
|
const denominatorFn = typeof denominator === "function" ? denominator : (d) => d[denominator];
|
|
1102
1116
|
const {predicate, allowDivideByZero} = options != null ? options : {};
|
|
1103
|
-
return predicate == null ? (d) => {
|
|
1104
|
-
const denom = denominatorFn(d);
|
|
1105
|
-
const numer = numeratorFn(d);
|
|
1117
|
+
return predicate == null ? (d, index, array) => {
|
|
1118
|
+
const denom = denominatorFn(d, index, array);
|
|
1119
|
+
const numer = numeratorFn(d, index, array);
|
|
1106
1120
|
return rate(numer, denom, allowDivideByZero);
|
|
1107
|
-
} : (d) => {
|
|
1108
|
-
if (!predicate(d))
|
|
1121
|
+
} : (d, index, array) => {
|
|
1122
|
+
if (!predicate(d, index, array))
|
|
1109
1123
|
return void 0;
|
|
1110
|
-
const denom = denominatorFn(d);
|
|
1111
|
-
const numer = numeratorFn(d);
|
|
1124
|
+
const denom = denominatorFn(d, index, array);
|
|
1125
|
+
const numer = numeratorFn(d, index, array);
|
|
1112
1126
|
return rate(numer, denom, allowDivideByZero);
|
|
1113
1127
|
};
|
|
1114
1128
|
}
|
|
@@ -1134,11 +1148,12 @@
|
|
|
1134
1148
|
}
|
|
1135
1149
|
|
|
1136
1150
|
function roll(width, rollFn, options) {
|
|
1137
|
-
const {partial = false} = options != null ? options : {};
|
|
1151
|
+
const {partial = false, align = "right"} = options != null ? options : {};
|
|
1152
|
+
const halfWidth = Math.floor(width / 2);
|
|
1138
1153
|
return (items) => {
|
|
1139
1154
|
return items.map((_, i) => {
|
|
1140
|
-
const endIndex = i;
|
|
1141
|
-
if (!partial && endIndex - width + 1 < 0) {
|
|
1155
|
+
const endIndex = align === "right" ? i : align === "center" ? i + halfWidth : i + width - 1;
|
|
1156
|
+
if (!partial && (endIndex - width + 1 < 0 || endIndex >= items.length)) {
|
|
1142
1157
|
return void 0;
|
|
1143
1158
|
}
|
|
1144
1159
|
const startIndex = Math.max(0, endIndex - width + 1);
|
|
@@ -1154,7 +1169,7 @@
|
|
|
1154
1169
|
return (items) => {
|
|
1155
1170
|
return items.map((_, i) => {
|
|
1156
1171
|
const lagItem = items[i - n];
|
|
1157
|
-
return lagItem == null ? defaultValue : keyFn(lagItem);
|
|
1172
|
+
return lagItem == null ? defaultValue : keyFn(lagItem, i, items);
|
|
1158
1173
|
});
|
|
1159
1174
|
};
|
|
1160
1175
|
}
|
|
@@ -1165,11 +1180,19 @@
|
|
|
1165
1180
|
return (items) => {
|
|
1166
1181
|
return items.map((_, i) => {
|
|
1167
1182
|
const leadItem = items[i + n];
|
|
1168
|
-
return leadItem == null ? defaultValue : keyFn(leadItem);
|
|
1183
|
+
return leadItem == null ? defaultValue : keyFn(leadItem, i, items);
|
|
1169
1184
|
});
|
|
1170
1185
|
};
|
|
1171
1186
|
}
|
|
1172
1187
|
|
|
1188
|
+
function rowNumber(options) {
|
|
1189
|
+
var _a;
|
|
1190
|
+
const startAt = (_a = options == null ? void 0 : options.startAt) != null ? _a : 0;
|
|
1191
|
+
return (items) => {
|
|
1192
|
+
return items.map((_, i) => i + startAt);
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1173
1196
|
function min(key) {
|
|
1174
1197
|
const keyFn = typeof key === "function" ? key : (d) => d[key];
|
|
1175
1198
|
return (items) => d3Array.min(items, keyFn);
|
|
@@ -1215,8 +1238,9 @@
|
|
|
1215
1238
|
return (items) => {
|
|
1216
1239
|
const uniques = new Map();
|
|
1217
1240
|
let count = 0;
|
|
1241
|
+
let i = 0;
|
|
1218
1242
|
for (const item of items) {
|
|
1219
|
-
const value = keyFn(item);
|
|
1243
|
+
const value = keyFn(item, i++, items);
|
|
1220
1244
|
if (!uniques.has(value)) {
|
|
1221
1245
|
if (!options.includeUndefined && value === void 0 || options.includeNull === false && value === null) {
|
|
1222
1246
|
continue;
|
|
@@ -1350,6 +1374,7 @@
|
|
|
1350
1374
|
exports.rename = rename;
|
|
1351
1375
|
exports.replaceNully = replaceNully;
|
|
1352
1376
|
exports.roll = roll;
|
|
1377
|
+
exports.rowNumber = rowNumber;
|
|
1353
1378
|
exports.select = select;
|
|
1354
1379
|
exports.slice = slice;
|
|
1355
1380
|
exports.sliceHead = sliceHead;
|