image.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { Image as GImage } from '@antv/g';
  13. import { applyStyle, getShapeTheme } from '../utils';
  14. import { select } from '../../utils/selection';
  15. import { p } from '../../mark/utils';
  16. export const Image = (options) => {
  17. const style = __rest(options, []);
  18. return (points, value, coordinate, theme) => {
  19. const { mark, shape, defaultShape } = value;
  20. const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  21. const { color = defaultColor, src = '', size = 32, transform = '' } = value;
  22. let { width = size, height = size } = style;
  23. const [[x0, y0]] = points;
  24. // Support percentage width, height.
  25. const [w, h] = coordinate.getSize();
  26. width = typeof width === 'string' ? p(width) * w : width;
  27. height = typeof height === 'string' ? p(height) * h : height;
  28. const x = x0 - Number(width) / 2;
  29. const y = y0 - Number(height) / 2;
  30. return select(new GImage())
  31. .call(applyStyle, shapeTheme)
  32. .style('x', x)
  33. .style('y', y)
  34. .style('img', src)
  35. .style('stroke', color)
  36. .style('transform', transform)
  37. .call(applyStyle, style)
  38. .style('width', width)
  39. .style('height', height)
  40. .node();
  41. };
  42. };
  43. Image.props = {
  44. defaultEnterAnimation: 'fadeIn',
  45. defaultUpdateAnimation: 'morphing',
  46. defaultExitAnimation: 'fadeOut',
  47. };
  48. //# sourceMappingURL=image.js.map