axisRadar.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 { angleOf } from '../utils/coordinate';
  13. import { LinearAxis } from './axis';
  14. function inferTitleTransform(orientation) {
  15. const internalOrientation = orientation % (Math.PI * 2);
  16. if (internalOrientation === Math.PI / 2) {
  17. return { titleTransform: 'translate(0, 50%)' };
  18. }
  19. if (internalOrientation > -Math.PI / 2 && internalOrientation < Math.PI / 2) {
  20. return { titleTransform: 'translate(50%, 0)' };
  21. }
  22. if (internalOrientation > Math.PI / 2 &&
  23. internalOrientation < (Math.PI * 3) / 2) {
  24. return { titleTransform: 'translate(-50%, 0)' };
  25. }
  26. return {};
  27. }
  28. function inferAxisStyle(options, theme, coordinate, value) {
  29. const { radar } = options;
  30. const { scales: [{ name }], } = value;
  31. const [startAngle, endAngle] = angleOf(coordinate);
  32. const { axisRadar: radarTheme = {} } = theme;
  33. return Object.assign(Object.assign({}, radarTheme), { grid: name === 'position', gridConnect: 'line', gridControlAngles: new Array(radar.count).fill(0).map((_, i) => {
  34. const angle = (endAngle - startAngle) / radar.count;
  35. return angle * i;
  36. }) });
  37. }
  38. export const AxisRadar = (options) => {
  39. const { important = {} } = options, restOptions = __rest(options, ["important"]);
  40. return (context) => {
  41. const { theme, coordinate, value } = context;
  42. return LinearAxis(Object.assign(Object.assign(Object.assign({}, restOptions), inferTitleTransform(options.orientation)), { important: Object.assign(Object.assign({}, inferAxisStyle(options, theme, coordinate, value)), important) }))(context);
  43. };
  44. };
  45. AxisRadar.props = Object.assign(Object.assign({}, LinearAxis.props), { defaultPosition: 'center' });
  46. //# sourceMappingURL=axisRadar.js.map