shape.js 986 B

12345678910111213141516171819202122232425262728293031323334
  1. import { basePreInference, createBandOffset, visualMark } from './utils';
  2. /**
  3. * @todo Unify with text, image and point.
  4. */
  5. export const Shape = (options) => {
  6. const { cartesian } = options;
  7. if (cartesian)
  8. return visualMark;
  9. return (index, scale, value, coordinate) => {
  10. const { x: X, y: Y } = value;
  11. const offset = createBandOffset(scale, value, options);
  12. const P = Array.from(index, (i) => {
  13. const p = [+X[i], +Y[i]];
  14. return [coordinate.map(offset(p, i))];
  15. });
  16. return [index, P];
  17. };
  18. };
  19. Shape.props = {
  20. defaultShape: 'shape',
  21. defaultLabelShape: 'label',
  22. composite: false,
  23. channels: [
  24. { name: 'x', required: true },
  25. { name: 'y', required: true },
  26. ],
  27. preInference: [
  28. ...basePreInference(),
  29. { type: 'maybeTuple' },
  30. { type: 'maybeVisualPosition' },
  31. { type: 'maybeFunctionAttribute' },
  32. ],
  33. };
  34. //# sourceMappingURL=shape.js.map