UNPKG

1.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Select = void 0;
4const d3_array_1 = require("d3-array");
5const helper_1 = require("./utils/helper");
6const order_1 = require("./utils/order");
7function first(I, V) {
8 return [I[0]];
9}
10function last(I, V) {
11 const i = I.length - 1;
12 return [I[i]];
13}
14function max(I, V) {
15 const i = (0, d3_array_1.maxIndex)(I, (i) => V[i]);
16 return [I[i]];
17}
18function min(I, V) {
19 const i = (0, d3_array_1.minIndex)(I, (i) => V[i]);
20 return [I[i]];
21}
22function normalizeSelector(selector) {
23 if (typeof selector === 'function')
24 return selector;
25 const registry = { first, last, max, min };
26 return registry[selector] || first;
27}
28/**
29 * The select transform groups marks with specified channels, and
30 * filter index by specified selector for each series, say to
31 * pull a single or multiple values out of each series.
32 */
33const Select = (options = {}) => {
34 const { groupBy = 'series', channel, selector } = options;
35 return (I, mark) => {
36 const { encode } = mark;
37 const groups = (0, order_1.createGroups)(groupBy, I, mark);
38 const [V] = (0, helper_1.columnOf)(encode, channel);
39 const selectFunction = normalizeSelector(selector);
40 return [groups.flatMap((GI) => selectFunction(GI, V)), mark];
41 };
42};
43exports.Select = Select;
44exports.Select.props = {};
45//# sourceMappingURL=select.js.map
\No newline at end of file