dodgeX.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var __rest = (this && this.__rest) || function (s, e) {
  2. var t = {};
  3. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  4. t[p] = s[p];
  5. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  6. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  7. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  8. t[p[i]] = s[p[i]];
  9. }
  10. return t;
  11. };
  12. import { deepMix } from '@antv/util';
  13. import { column, columnOf, maybeColumnOf } from './utils/helper';
  14. import { createGroups, normalizeComparator, applyOrder, domainOf, } from './utils/order';
  15. /**
  16. * The dodge group marks into series by color or series channel,
  17. * and then produce new series channel for each series by specified order,
  18. * say to form horizontal "columns" by specified channels.
  19. */
  20. export const DodgeX = (options = {}) => {
  21. const { groupBy = 'x', reverse = false, orderBy, padding } = options, rest = __rest(options, ["groupBy", "reverse", "orderBy", "padding"]);
  22. return (I, mark) => {
  23. const { data, encode, scale } = mark;
  24. const { series: scaleSeries } = scale;
  25. const [Y] = columnOf(encode, 'y');
  26. const [S] = maybeColumnOf(encode, 'series', 'color');
  27. const domainSeries = domainOf(S, scaleSeries);
  28. // Create groups and apply specified order for each group.
  29. const groups = createGroups(groupBy, I, mark);
  30. const createComparator = normalizeComparator(orderBy);
  31. const comparator = createComparator(data, Y, S);
  32. if (comparator)
  33. applyOrder(groups, comparator);
  34. // Update series for each mark related to series domain.
  35. const newS = new Array(I.length);
  36. for (const G of groups) {
  37. if (reverse)
  38. G.reverse();
  39. for (let i = 0; i < G.length; i++) {
  40. newS[G[i]] = domainSeries[i];
  41. }
  42. }
  43. return [
  44. I,
  45. deepMix({}, mark, {
  46. scale: {
  47. series: {
  48. domain: domainSeries,
  49. paddingInner: padding,
  50. },
  51. },
  52. encode: {
  53. series: column(newS),
  54. },
  55. }),
  56. ];
  57. };
  58. };
  59. DodgeX.props = {};
  60. //# sourceMappingURL=dodgeX.js.map