cell.js 1.5 KB

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