polygon.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Polygon = void 0;
  4. const utils_1 = require("./utils");
  5. /**
  6. * Convert value for each channel to polygon shapes.
  7. */
  8. const Polygon = () => {
  9. return (index, scale, value, coordinate) => {
  10. const Xn = Object.entries(value)
  11. .filter(([key]) => key.startsWith('x'))
  12. .map(([, value]) => value);
  13. const Yn = Object.entries(value)
  14. .filter(([key]) => key.startsWith('y'))
  15. .map(([, value]) => value);
  16. const P = index.map((i) => {
  17. const Pn = [];
  18. for (let j = 0; j < Xn.length; j++) {
  19. const x = Xn[j][i];
  20. if (x === undefined)
  21. break;
  22. const y = Yn[j][i];
  23. Pn.push(coordinate.map([+x, +y]));
  24. }
  25. return Pn;
  26. });
  27. return [index, P];
  28. };
  29. };
  30. exports.Polygon = Polygon;
  31. const shapes = ['polygon', 'ribbon'];
  32. exports.Polygon.props = {
  33. defaultShape: 'polygon',
  34. defaultLabelShape: 'label',
  35. composite: false,
  36. channels: [
  37. ...(0, utils_1.baseGeometryChannels)({ shapes }),
  38. { name: 'x', required: true },
  39. { name: 'y', required: true },
  40. ],
  41. preInference: [...(0, utils_1.basePreInference)()],
  42. postInference: [...(0, utils_1.basePostInference)(), ...(0, utils_1.tooltip2d)()],
  43. };
  44. //# sourceMappingURL=polygon.js.map