vector.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Vector = void 0;
  4. const utils_1 = require("./utils");
  5. /**
  6. * Convert value for each channel to start, end.
  7. * The angle starts from the X axis(right direction).
  8. */
  9. const Vector = () => {
  10. return (index, scale, value, coordinate) => {
  11. const { x: X, y: Y, size: S, rotate: R } = value;
  12. const [width, height] = coordinate.getSize();
  13. const P = index.map((i) => {
  14. const angle = (+R[i] / 180) * Math.PI;
  15. const s = +S[i];
  16. const a = s / width;
  17. const b = s / height;
  18. const vx = a * Math.cos(angle);
  19. const vy = -b * Math.sin(angle);
  20. return [
  21. coordinate.map([+X[i] - vx / 2, +Y[i] - vy / 2]),
  22. coordinate.map([+X[i] + vx / 2, +Y[i] + vy / 2]),
  23. ];
  24. });
  25. return [index, P];
  26. };
  27. };
  28. exports.Vector = Vector;
  29. const shapes = ['vector'];
  30. exports.Vector.props = {
  31. defaultShape: 'vector',
  32. defaultLabelShape: 'label',
  33. composite: false,
  34. channels: [
  35. ...(0, utils_1.baseGeometryChannels)({ shapes }),
  36. { name: 'x', required: true },
  37. { name: 'y', required: true },
  38. { name: 'rotate', required: true, scale: 'identity' },
  39. { name: 'size', required: true },
  40. ],
  41. preInference: [...(0, utils_1.basePreInference)()],
  42. postInference: [...(0, utils_1.basePostInference)(), ...(0, utils_1.tooltip2d)()],
  43. };
  44. //# sourceMappingURL=vector.js.map