| 1 | var _excluded = ["children"];
|
|---|
| 2 | function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|---|
| 3 | function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|---|
| 4 | function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|---|
| 5 | import * as React from 'react';
|
|---|
| 6 | import { forwardRef } from 'react';
|
|---|
| 7 | import { useChartHeight, useChartWidth } from '../context/chartLayoutContext';
|
|---|
| 8 | import { useAccessibilityLayer } from '../context/accessibilityContext';
|
|---|
| 9 | import { useIsPanorama } from '../context/PanoramaContext';
|
|---|
| 10 | import { Surface } from './Surface';
|
|---|
| 11 | import { useAppSelector } from '../state/hooks';
|
|---|
| 12 | import { selectBrushDimensions } from '../state/selectors/brushSelectors';
|
|---|
| 13 | import { isPositiveNumber } from '../util/isWellBehavedNumber';
|
|---|
| 14 | import { AllZIndexPortals } from '../zIndex/ZIndexPortal';
|
|---|
| 15 | var FULL_WIDTH_AND_HEIGHT = {
|
|---|
| 16 | width: '100%',
|
|---|
| 17 | height: '100%',
|
|---|
| 18 | /*
|
|---|
| 19 | * display: block is necessary here because the default for an SVG is display: inline,
|
|---|
| 20 | * which in some browsers (Chrome) adds a little bit of extra space above and below the SVG
|
|---|
| 21 | * to make space for the descender of letters like "g" and "y". This throws off the height calculation
|
|---|
| 22 | * and causes the container to grow indefinitely on each render with responsive=true.
|
|---|
| 23 | * Display: block removes that extra space.
|
|---|
| 24 | *
|
|---|
| 25 | * Interestingly, Firefox does not have this problem, but it doesn't hurt to add the style anyway.
|
|---|
| 26 | */
|
|---|
| 27 | display: 'block'
|
|---|
| 28 | };
|
|---|
| 29 | var MainChartSurface = /*#__PURE__*/forwardRef((props, ref) => {
|
|---|
| 30 | var width = useChartWidth();
|
|---|
| 31 | var height = useChartHeight();
|
|---|
| 32 | var hasAccessibilityLayer = useAccessibilityLayer();
|
|---|
| 33 | if (!isPositiveNumber(width) || !isPositiveNumber(height)) {
|
|---|
| 34 | return null;
|
|---|
| 35 | }
|
|---|
| 36 | var {
|
|---|
| 37 | children,
|
|---|
| 38 | otherAttributes,
|
|---|
| 39 | title,
|
|---|
| 40 | desc
|
|---|
| 41 | } = props;
|
|---|
| 42 | var tabIndex, role;
|
|---|
| 43 | if (otherAttributes != null) {
|
|---|
| 44 | if (typeof otherAttributes.tabIndex === 'number') {
|
|---|
| 45 | tabIndex = otherAttributes.tabIndex;
|
|---|
| 46 | } else {
|
|---|
| 47 | tabIndex = hasAccessibilityLayer ? 0 : undefined;
|
|---|
| 48 | }
|
|---|
| 49 | if (typeof otherAttributes.role === 'string') {
|
|---|
| 50 | role = otherAttributes.role;
|
|---|
| 51 | } else {
|
|---|
| 52 | role = hasAccessibilityLayer ? 'application' : undefined;
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | return /*#__PURE__*/React.createElement(Surface, _extends({}, otherAttributes, {
|
|---|
| 56 | title: title,
|
|---|
| 57 | desc: desc,
|
|---|
| 58 | role: role,
|
|---|
| 59 | tabIndex: tabIndex,
|
|---|
| 60 | width: width,
|
|---|
| 61 | height: height,
|
|---|
| 62 | style: FULL_WIDTH_AND_HEIGHT,
|
|---|
| 63 | ref: ref
|
|---|
| 64 | }), children);
|
|---|
| 65 | });
|
|---|
| 66 | var BrushPanoramaSurface = _ref => {
|
|---|
| 67 | var {
|
|---|
| 68 | children
|
|---|
| 69 | } = _ref;
|
|---|
| 70 | var brushDimensions = useAppSelector(selectBrushDimensions);
|
|---|
| 71 | if (!brushDimensions) {
|
|---|
| 72 | return null;
|
|---|
| 73 | }
|
|---|
| 74 | var {
|
|---|
| 75 | width,
|
|---|
| 76 | height,
|
|---|
| 77 | y,
|
|---|
| 78 | x
|
|---|
| 79 | } = brushDimensions;
|
|---|
| 80 | return /*#__PURE__*/React.createElement(Surface, {
|
|---|
| 81 | width: width,
|
|---|
| 82 | height: height,
|
|---|
| 83 | x: x,
|
|---|
| 84 | y: y
|
|---|
| 85 | }, children);
|
|---|
| 86 | };
|
|---|
| 87 | export var RootSurface = /*#__PURE__*/forwardRef((_ref2, ref) => {
|
|---|
| 88 | var {
|
|---|
| 89 | children
|
|---|
| 90 | } = _ref2,
|
|---|
| 91 | rest = _objectWithoutProperties(_ref2, _excluded);
|
|---|
| 92 | var isPanorama = useIsPanorama();
|
|---|
| 93 | if (isPanorama) {
|
|---|
| 94 | return /*#__PURE__*/React.createElement(BrushPanoramaSurface, null, /*#__PURE__*/React.createElement(AllZIndexPortals, {
|
|---|
| 95 | isPanorama: true
|
|---|
| 96 | }, children));
|
|---|
| 97 | }
|
|---|
| 98 | return /*#__PURE__*/React.createElement(MainChartSurface, _extends({
|
|---|
| 99 | ref: ref
|
|---|
| 100 | }, rest), /*#__PURE__*/React.createElement(AllZIndexPortals, {
|
|---|
| 101 | isPanorama: false
|
|---|
| 102 | }, children));
|
|---|
| 103 | }); |
|---|