Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

180 righe
7.6 KiB

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