trail.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 { path as d3path } from 'd3-path';
  13. import { Path } from '@antv/g';
  14. import { select } from '../../utils/selection';
  15. import { applyStyle, getShapeTheme } from '../utils';
  16. import { angle, sub, add } from '../../utils/vector';
  17. import { Curve } from './curve';
  18. /**
  19. *
  20. * x9-x0---------x1-x2
  21. * / |r1 |r2 \
  22. *x8---p0---------p1---x3
  23. * \ r4| | r3 /
  24. * x7-x6--------x5-x4
  25. */
  26. function stroke(path, p0, p1, s0, s1) {
  27. const v = sub(p1, p0);
  28. const a = angle(v);
  29. const a1 = a + Math.PI / 2;
  30. const r1 = [(s0 / 2) * Math.cos(a1), (s0 / 2) * Math.sin(a1)];
  31. const r2 = [(s1 / 2) * Math.cos(a1), (s1 / 2) * Math.sin(a1)];
  32. const r3 = [(s1 / 2) * Math.cos(a), (s1 / 2) * Math.sin(a)];
  33. const r4 = [(s0 / 2) * Math.cos(a), (s0 / 2) * Math.sin(a)];
  34. const x0 = add(p0, r1);
  35. const x1 = add(p1, r2);
  36. const x2 = add(x1, r3);
  37. const x3 = add(p1, r3);
  38. const x4 = sub(x3, r2);
  39. const x5 = sub(p1, r2);
  40. const x6 = sub(p0, r1);
  41. const x7 = sub(x6, r4);
  42. const x8 = sub(p0, r4);
  43. const x9 = sub(x0, r4);
  44. path.moveTo(...x0);
  45. path.lineTo(...x1);
  46. path.arcTo(...x2, ...x3, s1 / 2);
  47. path.arcTo(...x4, ...x5, s1 / 2);
  48. path.lineTo(...x6);
  49. path.arcTo(...x7, ...x8, s0 / 2);
  50. path.arcTo(...x9, ...x0, s0 / 2);
  51. path.closePath();
  52. }
  53. export const Trail = (options) => {
  54. return (P, value, coordinate, theme) => {
  55. const { mark, shape, defaultShape, seriesSize, color } = value;
  56. const _a = getShapeTheme(theme, mark, shape, defaultShape), { defaultColor } = _a, defaults = __rest(_a, ["defaultColor"]);
  57. const path = d3path();
  58. for (let i = 0; i < P.length - 1; i++) {
  59. const p0 = P[i];
  60. const p1 = P[i + 1];
  61. const s0 = seriesSize[i];
  62. const s1 = seriesSize[i + 1];
  63. stroke(path, p0, p1, s0, s1);
  64. }
  65. return select(new Path({}))
  66. .call(applyStyle, defaults)
  67. .style('fill', color || defaultColor)
  68. .style('d', path.toString())
  69. .call(applyStyle, options)
  70. .node();
  71. };
  72. };
  73. Trail.props = Object.assign(Object.assign({}, Curve.props), { defaultMarker: 'line' });
  74. //# sourceMappingURL=trail.js.map