UNPKG

1.58 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.MaybeTitle = void 0;
4const util_1 = require("@antv/util");
5const helper_1 = require("../utils/helper");
6const dateFormat_1 = require("../utils/dateFormat");
7const helper_2 = require("./utils/helper");
8/**
9 * Infer title channel from x-position channel.
10 */
11const MaybeTitle = (options = {}) => {
12 const { channel = 'x' } = options;
13 return (I, mark) => {
14 const { encode } = mark;
15 const { tooltip } = mark;
16 if ((0, helper_1.isUnset)(tooltip))
17 return [I, mark];
18 const { title } = tooltip;
19 if (title !== undefined)
20 return [I, mark];
21 const titles = Object.keys(encode)
22 .filter((key) => key.startsWith(channel))
23 .filter((key) => !encode[key].inferred)
24 .map((key) => (0, helper_2.columnOf)(encode, key))
25 .filter(([T]) => T)
26 .map((d) => d[0]);
27 if (titles.length === 0)
28 return [I, mark];
29 const T = [];
30 for (const i of I) {
31 T[i] = {
32 value: titles
33 .map((t) => t[i] instanceof Date ? (0, dateFormat_1.dynamicFormatDateTime)(t[i]) : t[i])
34 .join(', '),
35 };
36 }
37 return [
38 I,
39 (0, util_1.deepMix)({}, mark, {
40 tooltip: {
41 title: T,
42 },
43 }),
44 ];
45 };
46};
47exports.MaybeTitle = MaybeTitle;
48exports.MaybeTitle.props = {};
49//# sourceMappingURL=maybeTitle.js.map
\No newline at end of file