UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MaybeTooltip = void 0;
4const util_1 = require("@antv/util");
5const helper_1 = require("../utils/helper");
6/**
7 * Infer tooltip channel from specified channel.
8 */
9const MaybeTooltip = (options) => {
10 const { channel } = options;
11 return (I, mark) => {
12 const { encode, tooltip } = mark;
13 if ((0, helper_1.isUnset)(tooltip))
14 return [I, mark];
15 const { items = [] } = tooltip;
16 if (!items || items.length > 0)
17 return [I, mark];
18 const channels = Array.isArray(channel) ? channel : [channel];
19 const newItems = channels.flatMap((channel) => Object.keys(encode)
20 .filter((key) => key.startsWith(channel))
21 .map((key) => {
22 const { field, value, inferred = false, aggregate } = encode[key];
23 if (inferred)
24 return null;
25 // Do not show inferred column.
26 if (aggregate && value)
27 return { channel: key };
28 if (field)
29 return { field };
30 if (value)
31 return { channel: key };
32 return null;
33 })
34 .filter((d) => d !== null));
35 return [I, (0, util_1.deepMix)({}, mark, { tooltip: { items: newItems } })];
36 };
37};
38exports.MaybeTooltip = MaybeTooltip;
39exports.MaybeTooltip.props = {};
40//# sourceMappingURL=maybeTooltip.js.map
\No newline at end of file