maybeTitle.js 1.4 KB

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