maybeStackY.js 1.2 KB

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