Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

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