cell.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Cell = void 0;
  4. const utils_1 = require("./utils");
  5. /**
  6. * Convert value for each channel to Cell shapes.
  7. * Calc the bbox of each Cell based on x, y and r.
  8. * This is for allowing their radius can be affected by coordinate(e.g. fisheye).
  9. */
  10. const Cell = () => {
  11. return (index, scale, value, coordinate) => {
  12. const { x: X, y: Y } = value;
  13. const x = scale.x;
  14. const y = scale.y;
  15. const P = Array.from(index, (i) => {
  16. const width = x.getBandWidth(x.invert(+X[i]));
  17. const height = y.getBandWidth(y.invert(+Y[i]));
  18. const x1 = +X[i];
  19. const y1 = +Y[i];
  20. const p1 = [x1, y1];
  21. const p2 = [x1 + width, y1];
  22. const p3 = [x1 + width, y1 + height];
  23. const p4 = [x1, y1 + height];
  24. return [p1, p2, p3, p4].map((d) => coordinate.map(d));
  25. });
  26. return [index, P];
  27. };
  28. };
  29. exports.Cell = Cell;
  30. const shapes = ['cell', 'hollow'];
  31. exports.Cell.props = {
  32. defaultShape: 'cell',
  33. defaultLabelShape: 'label',
  34. composite: false,
  35. channels: [
  36. ...(0, utils_1.baseGeometryChannels)({ shapes }),
  37. { name: 'x', required: true, scale: 'band' },
  38. { name: 'y', required: true, scale: 'band' },
  39. ],
  40. preInference: [
  41. ...(0, utils_1.basePreInference)(),
  42. { type: 'maybeZeroX' },
  43. { type: 'maybeZeroY' },
  44. { type: 'maybeZeroPadding' },
  45. ],
  46. postInference: [...(0, utils_1.basePostInference)(), ...(0, utils_1.tooltip2d)()],
  47. };
  48. //# sourceMappingURL=cell.js.map