vector.js 1.4 KB

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