diffY.js 1.5 KB

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