parallel.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* eslint-disable @typescript-eslint/no-unused-vars */
  2. import { Linear, Point } from '@antv/scale';
  3. /**
  4. * Apples parallel coordinate transform.
  5. * @param params [x0, x1, y0, y1]
  6. * @param x x of the the bounding box of coordinate
  7. * @param y y of the the bounding box of coordinate
  8. * @param width width of the the bounding box of coordinate
  9. * @param height height of the the bounding box of coordinate
  10. * @returns transformer
  11. */
  12. export var parallel = function (params, x, y, width, height) {
  13. var _a = params, x0 = _a[0], x1 = _a[1], y0 = _a[2], y1 = _a[3];
  14. var sy = new Linear({
  15. range: [y0, y1],
  16. });
  17. return {
  18. transform: function (vector) {
  19. var v = [];
  20. var len = vector.length;
  21. var sx = new Point({
  22. domain: new Array(len).fill(0).map(function (_, i) { return i; }),
  23. range: [x0, x1],
  24. });
  25. for (var i = 0; i < len; i++) {
  26. var e = vector[i];
  27. var x_1 = sx.map(i);
  28. var y_1 = sy.map(e);
  29. v.push(x_1, y_1);
  30. }
  31. return v;
  32. },
  33. untransform: function (vector) {
  34. var v = [];
  35. for (var i = 0; i < vector.length; i += 2) {
  36. var y_2 = vector[i + 1];
  37. v.push(sy.invert(y_2));
  38. }
  39. return v;
  40. },
  41. };
  42. };
  43. //# sourceMappingURL=parallel.js.map