maybeTitle.js 1.2 KB

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