You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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