range.js 1.5 KB

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