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 |
|
3 | 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; };
|
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 { arc as arcBuilder } from 'd3-shape';
|
38 |
|
39 | import AbstractSeries from './abstract-series';
|
40 | import { getAttributeFunctor, getAttr0Functor, extractScalePropsFromProps, getMissingScaleProps, getScalePropTypesByAttribute } from '../../utils/scales-utils';
|
41 |
|
42 | var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--arc';
|
43 | var ATTRIBUTES = ['radius', 'angle'];
|
44 |
|
45 | var defaultProps = _extends({}, AbstractSeries.defaultProps, {
|
46 | center: { x: 0, y: 0 },
|
47 | arcClassName: '',
|
48 | className: '',
|
49 | style: {},
|
50 | padAngle: 0
|
51 | });
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | function modifyRow(row) {
|
62 | var radius = row.radius,
|
63 | angle = row.angle,
|
64 | angle0 = row.angle0;
|
65 |
|
66 | var truedAngle = -1 * angle + Math.PI / 2;
|
67 | var truedAngle0 = -1 * angle0 + Math.PI / 2;
|
68 | return _extends({}, row, {
|
69 | x: radius * Math.cos(truedAngle),
|
70 | y: radius * Math.sin(truedAngle),
|
71 | angle: truedAngle,
|
72 | angle0: truedAngle0
|
73 | });
|
74 | }
|
75 |
|
76 | var ArcSeries = function (_AbstractSeries) {
|
77 | _inherits(ArcSeries, _AbstractSeries);
|
78 |
|
79 | function ArcSeries(props) {
|
80 | _classCallCheck(this, ArcSeries);
|
81 |
|
82 | var _this = _possibleConstructorReturn(this, (ArcSeries.__proto__ || Object.getPrototypeOf(ArcSeries)).call(this, props));
|
83 |
|
84 | var scaleProps = _this._getAllScaleProps(props);
|
85 | _this.state = { scaleProps: scaleProps };
|
86 | return _this;
|
87 | }
|
88 |
|
89 | _createClass(ArcSeries, [{
|
90 | key: 'componentWillReceiveProps',
|
91 | value: function componentWillReceiveProps(nextProps) {
|
92 | this.setState({ scaleProps: this._getAllScaleProps(nextProps) });
|
93 | }
|
94 |
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | }, {
|
104 | key: '_getAllScaleProps',
|
105 | value: function _getAllScaleProps(props) {
|
106 | var defaultScaleProps = this._getDefaultScaleProps(props);
|
107 | var userScaleProps = extractScalePropsFromProps(props, ATTRIBUTES);
|
108 | var missingScaleProps = getMissingScaleProps(_extends({}, defaultScaleProps, userScaleProps), props.data, ATTRIBUTES);
|
109 |
|
110 | return _extends({}, defaultScaleProps, userScaleProps, missingScaleProps);
|
111 | }
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | }, {
|
121 | key: '_getDefaultScaleProps',
|
122 | value: function _getDefaultScaleProps(props) {
|
123 | var innerWidth = props.innerWidth,
|
124 | innerHeight = props.innerHeight;
|
125 |
|
126 | var radius = Math.min(innerWidth / 2, innerHeight / 2);
|
127 | return {
|
128 | radiusRange: [0, radius],
|
129 | _radiusValue: radius,
|
130 | angleType: 'literal'
|
131 | };
|
132 | }
|
133 | }, {
|
134 | key: 'render',
|
135 | value: function render() {
|
136 | var _this2 = this;
|
137 |
|
138 | var _props = this.props,
|
139 | arcClassName = _props.arcClassName,
|
140 | animation = _props.animation,
|
141 | className = _props.className,
|
142 | center = _props.center,
|
143 | data = _props.data,
|
144 | disableSeries = _props.disableSeries,
|
145 | hideSeries = _props.hideSeries,
|
146 | marginLeft = _props.marginLeft,
|
147 | marginTop = _props.marginTop,
|
148 | padAngle = _props.padAngle,
|
149 | style = _props.style;
|
150 |
|
151 |
|
152 | if (!data) {
|
153 | return null;
|
154 | }
|
155 |
|
156 | if (animation) {
|
157 | var cloneData = data.map(function (d) {
|
158 | return _extends({}, d);
|
159 | });
|
160 | return React.createElement(
|
161 | 'g',
|
162 | { className: 'rv-xy-plot__series--arc__animation-wrapper' },
|
163 | React.createElement(
|
164 | Animation,
|
165 | _extends({}, this.props, {
|
166 | animatedProps: ANIMATED_SERIES_PROPS,
|
167 | data: cloneData
|
168 | }),
|
169 | React.createElement(ArcSeries, _extends({}, this.props, {
|
170 | animation: null,
|
171 | disableSeries: true,
|
172 | data: cloneData
|
173 | }))
|
174 | ),
|
175 | React.createElement(ArcSeries, _extends({}, this.props, {
|
176 | animation: null,
|
177 | hideSeries: true,
|
178 | style: { stroke: 'red' }
|
179 | }))
|
180 | );
|
181 | }
|
182 |
|
183 | var scaleProps = this.state.scaleProps;
|
184 | var radiusDomain = scaleProps.radiusDomain;
|
185 |
|
186 |
|
187 | var radius = getAttributeFunctor(scaleProps, 'radius');
|
188 | var radius0 = getAttr0Functor(scaleProps, 'radius');
|
189 | var angle = getAttributeFunctor(scaleProps, 'angle');
|
190 | var angle0 = getAttr0Functor(scaleProps, 'angle');
|
191 |
|
192 | var fill = this._getAttributeFunctor('fill') || this._getAttributeFunctor('color');
|
193 | var stroke = this._getAttributeFunctor('stroke') || this._getAttributeFunctor('color');
|
194 | var opacity = this._getAttributeFunctor('opacity');
|
195 | var x = this._getAttributeFunctor('x');
|
196 | var y = this._getAttributeFunctor('y');
|
197 |
|
198 | return React.createElement(
|
199 | 'g',
|
200 | {
|
201 | className: predefinedClassName + ' ' + className,
|
202 | onMouseOver: this._seriesMouseOverHandler,
|
203 | onMouseOut: this._seriesMouseOutHandler,
|
204 | onClick: this._seriesClickHandler,
|
205 | onContextMenu: this._seriesRightClickHandler,
|
206 | opacity: hideSeries ? 0 : 1,
|
207 | pointerEvents: disableSeries ? 'none' : 'all',
|
208 | transform: 'translate(' + (marginLeft + x(center)) + ',' + (marginTop + y(center)) + ')'
|
209 | },
|
210 | data.map(function (row, i) {
|
211 | var noRadius = radiusDomain[1] === radiusDomain[0];
|
212 | var arcArg = {
|
213 | innerRadius: noRadius ? 0 : radius0(row),
|
214 | outerRadius: radius(row),
|
215 | startAngle: angle0(row) || 0,
|
216 | endAngle: angle(row)
|
217 | };
|
218 | var arcedData = arcBuilder().padAngle(padAngle);
|
219 | var rowStyle = row.style || {};
|
220 | var rowClassName = row.className || '';
|
221 | return React.createElement('path', {
|
222 | style: _extends({
|
223 | opacity: opacity && opacity(row),
|
224 | stroke: stroke && stroke(row),
|
225 | fill: fill && fill(row)
|
226 | }, style, rowStyle),
|
227 | onClick: function onClick(e) {
|
228 | return _this2._valueClickHandler(modifyRow(row), e);
|
229 | },
|
230 | onContextMenu: function onContextMenu(e) {
|
231 | return _this2._valueRightClickHandler(modifyRow(row), e);
|
232 | },
|
233 | onMouseOver: function onMouseOver(e) {
|
234 | return _this2._valueMouseOverHandler(modifyRow(row), e);
|
235 | },
|
236 | onMouseOut: function onMouseOut(e) {
|
237 | return _this2._valueMouseOutHandler(modifyRow(row), e);
|
238 | },
|
239 | key: i,
|
240 | className: predefinedClassName + '-path ' + arcClassName + ' ' + rowClassName,
|
241 | d: arcedData(arcArg)
|
242 | });
|
243 | })
|
244 | );
|
245 | }
|
246 | }]);
|
247 |
|
248 | return ArcSeries;
|
249 | }(AbstractSeries);
|
250 |
|
251 | ArcSeries.propTypes = _extends({}, AbstractSeries.propTypes, getScalePropTypesByAttribute('radius'), getScalePropTypesByAttribute('angle'), {
|
252 | center: PropTypes.shape({
|
253 | x: PropTypes.number,
|
254 | y: PropTypes.number
|
255 | }),
|
256 | arcClassName: PropTypes.string,
|
257 | padAngle: PropTypes.oneOfType([PropTypes.func, PropTypes.number])
|
258 | });
|
259 | ArcSeries.defaultProps = defaultProps;
|
260 | ArcSeries.displayName = 'ArcSeries';
|
261 |
|
262 | export default ArcSeries; |
\ | No newline at end of file |