image.js 1.1 KB

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