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 |
|
3 | 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; }; }();
|
4 |
|
5 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6 |
|
7 | 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; }
|
8 |
|
9 | 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; }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | import React from 'react';
|
32 |
|
33 | import PropTypes from 'prop-types';
|
34 |
|
35 | import Animation from '../../animation';
|
36 | import { ANIMATED_SERIES_PROPS } from '../../utils/series-utils';
|
37 | import { warning } from '../../utils/react-utils';
|
38 | import { DEFAULT_SIZE, DEFAULT_OPACITY } from '../../theme';
|
39 |
|
40 | import AbstractSeries from './abstract-series';
|
41 |
|
42 | var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--mark';
|
43 | var DEFAULT_STROKE_WIDTH = 1;
|
44 |
|
45 | var MarkSeries = function (_AbstractSeries) {
|
46 | _inherits(MarkSeries, _AbstractSeries);
|
47 |
|
48 | function MarkSeries() {
|
49 | _classCallCheck(this, MarkSeries);
|
50 |
|
51 | return _possibleConstructorReturn(this, (MarkSeries.__proto__ || Object.getPrototypeOf(MarkSeries)).apply(this, arguments));
|
52 | }
|
53 |
|
54 | _createClass(MarkSeries, [{
|
55 | key: '_renderCircle',
|
56 | value: function _renderCircle(d, i, strokeWidth, style, scalingFunctions) {
|
57 | var _this2 = this;
|
58 |
|
59 | var fill = scalingFunctions.fill,
|
60 | opacity = scalingFunctions.opacity,
|
61 | size = scalingFunctions.size,
|
62 | stroke = scalingFunctions.stroke,
|
63 | x = scalingFunctions.x,
|
64 | y = scalingFunctions.y;
|
65 |
|
66 |
|
67 | var attrs = {
|
68 | r: size ? size(d) : DEFAULT_SIZE,
|
69 | cx: x(d),
|
70 | cy: y(d),
|
71 | style: _extends({
|
72 | opacity: opacity ? opacity(d) : DEFAULT_OPACITY,
|
73 | stroke: stroke && stroke(d),
|
74 | fill: fill && fill(d),
|
75 | strokeWidth: strokeWidth || DEFAULT_STROKE_WIDTH
|
76 | }, style),
|
77 | key: i,
|
78 | onClick: function onClick(e) {
|
79 | return _this2._valueClickHandler(d, e);
|
80 | },
|
81 | onContextMenu: function onContextMenu(e) {
|
82 | return _this2._valueRightClickHandler(d, e);
|
83 | },
|
84 | onMouseOver: function onMouseOver(e) {
|
85 | return _this2._valueMouseOverHandler(d, e);
|
86 | },
|
87 | onMouseOut: function onMouseOut(e) {
|
88 | return _this2._valueMouseOutHandler(d, e);
|
89 | }
|
90 | };
|
91 | return React.createElement('circle', attrs);
|
92 | }
|
93 | }, {
|
94 | key: 'render',
|
95 | value: function render() {
|
96 | var _this3 = this;
|
97 |
|
98 | var _props = this.props,
|
99 | animation = _props.animation,
|
100 | className = _props.className,
|
101 | data = _props.data,
|
102 | marginLeft = _props.marginLeft,
|
103 | marginTop = _props.marginTop,
|
104 | strokeWidth = _props.strokeWidth,
|
105 | style = _props.style;
|
106 |
|
107 |
|
108 | if (this.props.nullAccessor) {
|
109 | warning('nullAccessor has been renamed to getNull', true);
|
110 | }
|
111 |
|
112 | var getNull = this.props.nullAccessor || this.props.getNull;
|
113 |
|
114 | if (!data) {
|
115 | return null;
|
116 | }
|
117 |
|
118 | if (animation) {
|
119 | return React.createElement(
|
120 | Animation,
|
121 | _extends({}, this.props, { animatedProps: ANIMATED_SERIES_PROPS }),
|
122 | React.createElement(MarkSeries, _extends({}, this.props, { animation: null }))
|
123 | );
|
124 | }
|
125 |
|
126 | var scalingFunctions = {
|
127 | fill: this._getAttributeFunctor('fill') || this._getAttributeFunctor('color'),
|
128 | opacity: this._getAttributeFunctor('opacity'),
|
129 | size: this._getAttributeFunctor('size'),
|
130 | stroke: this._getAttributeFunctor('stroke') || this._getAttributeFunctor('color'),
|
131 | x: this._getAttributeFunctor('x'),
|
132 | y: this._getAttributeFunctor('y')
|
133 | };
|
134 |
|
135 | return React.createElement(
|
136 | 'g',
|
137 | {
|
138 | className: predefinedClassName + ' ' + className,
|
139 | transform: 'translate(' + marginLeft + ',' + marginTop + ')'
|
140 | },
|
141 | data.map(function (d, i) {
|
142 | return getNull(d) && _this3._renderCircle(d, i, strokeWidth, style, scalingFunctions);
|
143 | })
|
144 | );
|
145 | }
|
146 | }]);
|
147 |
|
148 | return MarkSeries;
|
149 | }(AbstractSeries);
|
150 |
|
151 | MarkSeries.displayName = 'MarkSeries';
|
152 | MarkSeries.propTypes = _extends({}, AbstractSeries.propTypes, {
|
153 | getNull: PropTypes.func,
|
154 | strokeWidth: PropTypes.number
|
155 | });
|
156 | MarkSeries.defaultProps = {
|
157 | getNull: function getNull() {
|
158 | return true;
|
159 | }
|
160 | };
|
161 |
|
162 | export default MarkSeries; |
\ | No newline at end of file |