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.
 
 
 
 

102 lines
4.6 KiB

  1. 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; }; }();
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. // Copyright (c) 2018 Uber Technologies, Inc.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. import React from 'react';
  25. import PropTypes from 'prop-types';
  26. var ChartLabel = function (_React$PureComponent) {
  27. _inherits(ChartLabel, _React$PureComponent);
  28. function ChartLabel() {
  29. _classCallCheck(this, ChartLabel);
  30. return _possibleConstructorReturn(this, (ChartLabel.__proto__ || Object.getPrototypeOf(ChartLabel)).apply(this, arguments));
  31. }
  32. _createClass(ChartLabel, [{
  33. key: 'render',
  34. value: function render() {
  35. var _props = this.props,
  36. innerHeight = _props.innerHeight,
  37. innerWidth = _props.innerWidth,
  38. marginBottom = _props.marginBottom,
  39. marginLeft = _props.marginLeft,
  40. marginRight = _props.marginRight,
  41. marginTop = _props.marginTop,
  42. className = _props.className,
  43. includeMargin = _props.includeMargin,
  44. style = _props.style,
  45. text = _props.text,
  46. xPercent = _props.xPercent,
  47. yPercent = _props.yPercent;
  48. var width = innerWidth + (includeMargin ? marginLeft + marginRight : 0);
  49. var height = innerHeight + (includeMargin ? marginTop + marginBottom : 0);
  50. var xPos = width * xPercent + (includeMargin ? 0 : marginLeft);
  51. var yPos = height * yPercent + (includeMargin ? marginLeft : 0);
  52. return React.createElement(
  53. 'g',
  54. {
  55. transform: 'translate(' + xPos + ', ' + yPos + ')',
  56. className: 'rv-xy-plot__axis__title ' + className },
  57. React.createElement(
  58. 'text',
  59. style,
  60. text
  61. )
  62. );
  63. }
  64. }], [{
  65. key: 'requiresSVG',
  66. get: function get() {
  67. return true;
  68. }
  69. }]);
  70. return ChartLabel;
  71. }(React.PureComponent);
  72. ChartLabel.displayName = 'ChartLabel';
  73. ChartLabel.propTypes = {
  74. className: PropTypes.string,
  75. includeMargin: PropTypes.bool,
  76. style: PropTypes.object,
  77. text: PropTypes.string.isRequired,
  78. xPercent: PropTypes.number.isRequired,
  79. yPercent: PropTypes.number.isRequired
  80. };
  81. ChartLabel.defaultProps = {
  82. className: '',
  83. includeMargin: true,
  84. text: '',
  85. xPercent: 0,
  86. yPercent: 0,
  87. style: {}
  88. };
  89. export default ChartLabel;