pyramid.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { isTranspose } from '../../utils/coordinate';
  2. import { Funnel } from './funnel';
  3. /**
  4. * Adjust and return the new `points`.
  5. */
  6. function getPyramidPoints(points, nextPoints, coordinate) {
  7. const [p0, p1, p2, p3] = points;
  8. if (isTranspose(coordinate)) {
  9. const newP1 = [
  10. nextPoints ? nextPoints[0][0] : (p1[0] + p2[0]) / 2,
  11. p1[1],
  12. ];
  13. const newP2 = [
  14. nextPoints ? nextPoints[3][0] : (p1[0] + p2[0]) / 2,
  15. p2[1],
  16. ];
  17. return [p0, newP1, newP2, p3];
  18. }
  19. const newP1 = [
  20. p1[0],
  21. nextPoints ? nextPoints[0][1] : (p1[1] + p2[1]) / 2,
  22. ];
  23. const newP2 = [
  24. p2[0],
  25. nextPoints ? nextPoints[3][1] : (p1[1] + p2[1]) / 2,
  26. ];
  27. return [p0, newP1, newP2, p3];
  28. }
  29. /**
  30. * Render pyramid in different coordinate and using color channel for stroke and fill attribute.
  31. */
  32. export const Pyramid = (options) => {
  33. return Funnel(Object.assign({ adjustPoints: getPyramidPoints }, options));
  34. };
  35. Pyramid.props = {
  36. defaultMarker: 'square',
  37. };
  38. //# sourceMappingURL=pyramid.js.map