range.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Range = exports.AbstractRange = void 0;
  4. const utils_1 = require("./utils");
  5. function extend(channel, extended, value, scale) {
  6. if (extended)
  7. return () => [0, 1];
  8. const { [channel]: C, [`${channel}1`]: C1 } = value;
  9. return (i) => {
  10. var _a;
  11. const offset = ((_a = scale.getBandWidth) === null || _a === void 0 ? void 0 : _a.call(scale, scale.invert(+C1[i]))) || 0;
  12. return [C[i], C1[i] + offset];
  13. };
  14. }
  15. function AbstractRange(options = {}) {
  16. const { extendX = false, extendY = false } = options;
  17. return (index, scale, value, coordinate) => {
  18. const x = extend('x', extendX, value, scale.x);
  19. const y = extend('y', extendY, value, scale.y);
  20. const P = Array.from(index, (i) => {
  21. const [x1, x2] = x(i);
  22. const [y1, y2] = y(i);
  23. const p1 = [x1, y1];
  24. const p2 = [x2, y1];
  25. const p3 = [x2, y2];
  26. const p4 = [x1, y2];
  27. return [p1, p2, p3, p4].map((d) => coordinate.map(d));
  28. });
  29. return [index, P];
  30. };
  31. }
  32. exports.AbstractRange = AbstractRange;
  33. const Range = () => {
  34. return AbstractRange();
  35. };
  36. exports.Range = Range;
  37. const shapes = ['range'];
  38. exports.Range.props = {
  39. defaultShape: 'range',
  40. defaultLabelShape: 'label',
  41. composite: false,
  42. channels: [
  43. ...(0, utils_1.baseAnnotationChannels)({ shapes }),
  44. { name: 'x', required: true },
  45. { name: 'y', required: true },
  46. ],
  47. preInference: [...(0, utils_1.basePreInference)()],
  48. postInference: [...(0, utils_1.basePostInference)()],
  49. };
  50. //# sourceMappingURL=range.js.map