text.js 1.9 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.Text = void 0;
  15. const utils_1 = require("../../shape/utils");
  16. const selection_1 = require("../../utils/selection");
  17. const advance_1 = require("./advance");
  18. /**
  19. * todo autoRotate when in polar coordinate
  20. */
  21. const Text = (options) => {
  22. const style = __rest(options, []);
  23. return (points, value, coordinate, theme) => {
  24. const { mark, shape, defaultShape } = value;
  25. const shapeTheme = __rest((0, utils_1.getShapeTheme)(theme, mark, shape, defaultShape), []);
  26. const { color, text = '', fontSize, rotate = 0, transform = '' } = value;
  27. const textStyle = {
  28. text: String(text),
  29. stroke: color,
  30. fill: color,
  31. fontSize,
  32. };
  33. const [[x0, y0]] = points;
  34. return (0, selection_1.select)(new advance_1.Advance())
  35. .style('x', x0)
  36. .style('y', y0)
  37. .call(utils_1.applyStyle, shapeTheme)
  38. .style('transform', `${transform}rotate(${+rotate})`)
  39. .style('coordCenter', coordinate.getCenter())
  40. .call(utils_1.applyStyle, textStyle)
  41. .call(utils_1.applyStyle, style)
  42. .node();
  43. };
  44. };
  45. exports.Text = Text;
  46. exports.Text.props = {
  47. defaultMarker: 'point',
  48. defaultEnterAnimation: 'fadeIn',
  49. defaultUpdateAnimation: 'morphing',
  50. defaultExitAnimation: 'fadeOut',
  51. };
  52. //# sourceMappingURL=text.js.map