maybeTooltip.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { deepMix } from '@antv/util';
  2. import { isUnset } from '../utils/helper';
  3. /**
  4. * Infer tooltip channel from specified channel.
  5. */
  6. export const MaybeTooltip = (options) => {
  7. const { channel } = options;
  8. return (I, mark) => {
  9. const { encode, tooltip } = mark;
  10. if (isUnset(tooltip))
  11. return [I, mark];
  12. const { items = [] } = tooltip;
  13. if (!items || items.length > 0)
  14. return [I, mark];
  15. const channels = Array.isArray(channel) ? channel : [channel];
  16. const newItems = channels.flatMap((channel) => Object.keys(encode)
  17. .filter((key) => key.startsWith(channel))
  18. .map((key) => {
  19. const { field, value, inferred = false, aggregate } = encode[key];
  20. if (inferred)
  21. return null;
  22. // Do not show inferred column.
  23. if (aggregate && value)
  24. return { channel: key };
  25. if (field)
  26. return { field };
  27. if (value)
  28. return { channel: key };
  29. return null;
  30. })
  31. .filter((d) => d !== null));
  32. return [I, deepMix({}, mark, { tooltip: { items: newItems } })];
  33. };
  34. };
  35. MaybeTooltip.props = {};
  36. //# sourceMappingURL=maybeTooltip.js.map