image.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.Image = void 0;
  15. const g_1 = require("@antv/g");
  16. const utils_1 = require("../utils");
  17. const selection_1 = require("../../utils/selection");
  18. const utils_2 = require("../../mark/utils");
  19. const Image = (options) => {
  20. const style = __rest(options, []);
  21. return (points, value, coordinate, theme) => {
  22. const { mark, shape, defaultShape } = value;
  23. const _a = (0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), { defaultColor } = _a, shapeTheme = __rest(_a, ["defaultColor"]);
  24. const { color = defaultColor, src = '', size = 32, transform = '' } = value;
  25. let { width = size, height = size } = style;
  26. const [[x0, y0]] = points;
  27. // Support percentage width, height.
  28. const [w, h] = coordinate.getSize();
  29. width = typeof width === 'string' ? (0, utils_2.p)(width) * w : width;
  30. height = typeof height === 'string' ? (0, utils_2.p)(height) * h : height;
  31. const x = x0 - Number(width) / 2;
  32. const y = y0 - Number(height) / 2;
  33. return (0, selection_1.select)(new g_1.Image())
  34. .call(utils_1.applyStyle, shapeTheme)
  35. .style('x', x)
  36. .style('y', y)
  37. .style('img', src)
  38. .style('stroke', color)
  39. .style('transform', transform)
  40. .call(utils_1.applyStyle, style)
  41. .style('width', width)
  42. .style('height', height)
  43. .node();
  44. };
  45. };
  46. exports.Image = Image;
  47. exports.Image.props = {
  48. defaultEnterAnimation: 'fadeIn',
  49. defaultUpdateAnimation: 'morphing',
  50. defaultExitAnimation: 'fadeOut',
  51. };
  52. //# sourceMappingURL=image.js.map