Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

167 строки
7.0 KiB

  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  6. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7. // Copyright (c) 2016 - 2017 Uber Technologies, Inc.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. import React, { PureComponent } from 'react';
  27. import PropTypes from 'prop-types';
  28. import { getAttributeScale } from '../utils/scales-utils';
  29. import Animation, { AnimationPropType } from '../animation';
  30. import { getTicksTotalFromSize, getTickValues, DIRECTION } from '../utils/axis-utils';
  31. var VERTICAL = DIRECTION.VERTICAL,
  32. HORIZONTAL = DIRECTION.HORIZONTAL;
  33. var propTypes = {
  34. direction: PropTypes.oneOf([VERTICAL, HORIZONTAL]),
  35. attr: PropTypes.string.isRequired,
  36. width: PropTypes.number,
  37. height: PropTypes.number,
  38. top: PropTypes.number,
  39. left: PropTypes.number,
  40. style: PropTypes.object,
  41. tickValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
  42. tickTotal: PropTypes.number,
  43. animation: AnimationPropType,
  44. // generally supplied by xyplot
  45. marginTop: PropTypes.number,
  46. marginBottom: PropTypes.number,
  47. marginLeft: PropTypes.number,
  48. marginRight: PropTypes.number,
  49. innerWidth: PropTypes.number,
  50. innerHeight: PropTypes.number
  51. };
  52. var defaultProps = {
  53. direction: VERTICAL
  54. };
  55. var animatedProps = ['xRange', 'yRange', 'xDomain', 'yDomain', 'width', 'height', 'marginLeft', 'marginTop', 'marginRight', 'marginBottom', 'tickTotal'];
  56. var GridLines = function (_PureComponent) {
  57. _inherits(GridLines, _PureComponent);
  58. function GridLines() {
  59. _classCallCheck(this, GridLines);
  60. return _possibleConstructorReturn(this, (GridLines.__proto__ || Object.getPrototypeOf(GridLines)).apply(this, arguments));
  61. }
  62. _createClass(GridLines, [{
  63. key: '_getDefaultProps',
  64. value: function _getDefaultProps() {
  65. var _props = this.props,
  66. innerWidth = _props.innerWidth,
  67. innerHeight = _props.innerHeight,
  68. marginTop = _props.marginTop,
  69. marginLeft = _props.marginLeft,
  70. direction = _props.direction;
  71. return {
  72. left: marginLeft,
  73. top: marginTop,
  74. width: innerWidth,
  75. height: innerHeight,
  76. tickTotal: getTicksTotalFromSize(direction === VERTICAL ? innerWidth : innerHeight)
  77. };
  78. }
  79. }, {
  80. key: 'render',
  81. value: function render() {
  82. var _props2 = this.props,
  83. animation = _props2.animation,
  84. className = _props2.className;
  85. if (animation) {
  86. return React.createElement(
  87. Animation,
  88. _extends({}, this.props, { animatedProps: animatedProps }),
  89. React.createElement(GridLines, _extends({}, this.props, { animation: null }))
  90. );
  91. }
  92. var props = _extends({}, this._getDefaultProps(), this.props);
  93. var attr = props.attr,
  94. direction = props.direction,
  95. width = props.width,
  96. height = props.height,
  97. style = props.style,
  98. tickTotal = props.tickTotal,
  99. tickValues = props.tickValues,
  100. top = props.top,
  101. left = props.left;
  102. var isVertical = direction === VERTICAL;
  103. var tickXAttr = isVertical ? 'y' : 'x';
  104. var tickYAttr = isVertical ? 'x' : 'y';
  105. var length = isVertical ? height : width;
  106. var scale = getAttributeScale(props, attr);
  107. var values = getTickValues(scale, tickTotal, tickValues);
  108. return React.createElement(
  109. 'g',
  110. {
  111. transform: 'translate(' + left + ',' + top + ')',
  112. className: 'rv-xy-plot__grid-lines ' + className
  113. },
  114. values.map(function (v, i) {
  115. var _pathProps;
  116. var pos = scale(v);
  117. var pathProps = (_pathProps = {}, _defineProperty(_pathProps, tickYAttr + '1', pos), _defineProperty(_pathProps, tickYAttr + '2', pos), _defineProperty(_pathProps, tickXAttr + '1', 0), _defineProperty(_pathProps, tickXAttr + '2', length), _pathProps);
  118. return React.createElement('line', _extends({}, pathProps, {
  119. key: i,
  120. className: 'rv-xy-plot__grid-lines__line',
  121. style: style
  122. }));
  123. })
  124. );
  125. }
  126. }]);
  127. return GridLines;
  128. }(PureComponent);
  129. GridLines.displayName = 'GridLines';
  130. GridLines.defaultProps = defaultProps;
  131. GridLines.propTypes = propTypes;
  132. GridLines.requiresSVG = true;
  133. export default GridLines;