polygon.js 1.3 KB

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