area.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.area = void 0;
  4. const d3_array_1 = require("d3-array");
  5. const vector_1 = require("../../../utils/vector");
  6. /**
  7. * Only for Area label.
  8. */
  9. function area(position, points, value, coordinate) {
  10. const l = points.length / 2;
  11. const Y1 = points.slice(0, l);
  12. const Y0 = points.slice(l);
  13. // Get the maximal space for label.
  14. let idx = (0, d3_array_1.maxIndex)(Y1, (p, i) => Math.abs(p[1] - Y0[i][1]));
  15. // Do not show label at first and last.
  16. idx = Math.max(Math.min(idx, l - 2), 1);
  17. const mid = (i) => [Y1[i][0], (Y1[i][1] + Y0[i][1]) / 2];
  18. const point = mid(idx);
  19. const prev = mid(idx - 1);
  20. const next = mid(idx + 1);
  21. // todo: G rotate only support deg.
  22. const rotate = ((0, vector_1.angle)((0, vector_1.sub)(next, prev)) / Math.PI) * 180;
  23. return {
  24. x: point[0],
  25. y: point[1],
  26. transform: `rotate(${rotate})`,
  27. textAlign: 'center',
  28. textBaseline: 'middle',
  29. };
  30. }
  31. exports.area = area;
  32. //# sourceMappingURL=area.js.map