maybeStackY.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import { StackY } from './stackY';
  2. // Avoid duplicate stackY.
  3. // In most of case only one of stackY and dodgeX is needed.
  4. // So pass statistic with stackY and dodgeX.
  5. function exclude(transform) {
  6. const { type } = transform;
  7. const excludes = ['stackY', 'dodgeX', 'groupX'];
  8. return typeof type === 'string' && excludes.includes(type);
  9. }
  10. /**
  11. * Add zero constant encode for x channel.
  12. * This is useful for interval geometry.
  13. */
  14. export const MaybeStackY = (options) => {
  15. return (I, mark, context) => {
  16. // Skip some transform.
  17. const { encode, transform = [] } = mark;
  18. if (transform.some(exclude))
  19. return [I, mark];
  20. // StackY need both x and y channel values.
  21. const { x, y } = encode;
  22. if (x === undefined || y === undefined)
  23. return [I, mark];
  24. const { series } = options;
  25. const groupBy = series ? ['x', 'series'] : 'x';
  26. return StackY({ groupBy })(I, mark, context);
  27. };
  28. };
  29. MaybeStackY.props = {};
  30. //# sourceMappingURL=maybeStackY.js.map