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