diffY.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.DiffY = void 0;
  4. const util_1 = require("@antv/util");
  5. const helper_1 = require("./utils/helper");
  6. const order_1 = require("./utils/order");
  7. /**
  8. * The DiffY transform apply offset for y0 channels.
  9. * Keep y unchanged, set y1 = max(otherY), if y1 > y, remove the data.
  10. */
  11. const DiffY = (options = {}) => {
  12. const { groupBy = 'x', series = true } = options;
  13. return (I, mark) => {
  14. const { encode } = mark;
  15. const [Y] = (0, helper_1.columnOf)(encode, 'y');
  16. const [_, fy1] = (0, helper_1.columnOf)(encode, 'y1');
  17. const [S] = series
  18. ? (0, helper_1.maybeColumnOf)(encode, 'series', 'color')
  19. : (0, helper_1.columnOf)(encode, 'color');
  20. // Create groups and apply specified order for each group.
  21. const groups = (0, order_1.createGroups)(groupBy, I, mark);
  22. // Only adjust Y1 channel.
  23. const newY1 = new Array(I.length);
  24. for (const G of groups) {
  25. const YG = G.map((i) => +Y[i]);
  26. // Process each series.
  27. for (let idx = 0; idx < G.length; idx++) {
  28. const i = G[idx];
  29. // Get the max Y of current group with current Y exclude.
  30. const max = Math.max(...YG.filter((_, _i) => _i !== idx));
  31. // Diff Y value.
  32. newY1[i] = Y[i] > max ? max : Y[i];
  33. }
  34. }
  35. return [
  36. I,
  37. (0, util_1.deepMix)({}, mark, {
  38. encode: {
  39. y1: (0, helper_1.column)(newY1, fy1),
  40. },
  41. }),
  42. ];
  43. };
  44. };
  45. exports.DiffY = DiffY;
  46. exports.DiffY.props = {};
  47. //# sourceMappingURL=diffY.js.map