1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Select = void 0;
|
4 | const d3_array_1 = require("d3-array");
|
5 | const helper_1 = require("./utils/helper");
|
6 | const order_1 = require("./utils/order");
|
7 | function first(I, V) {
|
8 | return [I[0]];
|
9 | }
|
10 | function last(I, V) {
|
11 | const i = I.length - 1;
|
12 | return [I[i]];
|
13 | }
|
14 | function max(I, V) {
|
15 | const i = (0, d3_array_1.maxIndex)(I, (i) => V[i]);
|
16 | return [I[i]];
|
17 | }
|
18 | function min(I, V) {
|
19 | const i = (0, d3_array_1.minIndex)(I, (i) => V[i]);
|
20 | return [I[i]];
|
21 | }
|
22 | function 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 |
|
30 |
|
31 |
|
32 |
|
33 | const 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 | };
|
43 | exports.Select = Select;
|
44 | exports.Select.props = {};
|
45 |
|
\ | No newline at end of file |