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 Animation from '../../animation';
|
34 | import { ANIMATED_SERIES_PROPS } from '../../utils/series-utils';
|
35 |
|
36 | import AbstractSeries from './abstract-series';
|
37 |
|
38 | var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--polygon';
|
39 | var DEFAULT_COLOR = '#12939A';
|
40 |
|
41 | var generatePath = function generatePath(data, xFunctor, yFunctor) {
|
42 | return data.reduce(function (res, row, i) {
|
43 | return res + ' ' + (i ? 'L' : 'M') + xFunctor(row) + ' ' + yFunctor(row);
|
44 | }, '') + ' Z';
|
45 | };
|
46 |
|
47 | var PolygonSeries = function (_AbstractSeries) {
|
48 | _inherits(PolygonSeries, _AbstractSeries);
|
49 |
|
50 | function PolygonSeries() {
|
51 | _classCallCheck(this, PolygonSeries);
|
52 |
|
53 | return _possibleConstructorReturn(this, (PolygonSeries.__proto__ || Object.getPrototypeOf(PolygonSeries)).apply(this, arguments));
|
54 | }
|
55 |
|
56 | _createClass(PolygonSeries, [{
|
57 | key: 'render',
|
58 | value: function render() {
|
59 | var _this2 = this;
|
60 |
|
61 | var _props = this.props,
|
62 | animation = _props.animation,
|
63 | color = _props.color,
|
64 | className = _props.className,
|
65 | data = _props.data,
|
66 | marginLeft = _props.marginLeft,
|
67 | marginTop = _props.marginTop,
|
68 | style = _props.style;
|
69 |
|
70 |
|
71 | if (!data) {
|
72 | return null;
|
73 | }
|
74 |
|
75 | if (animation) {
|
76 | return React.createElement(
|
77 | Animation,
|
78 | _extends({}, this.props, { animatedProps: ANIMATED_SERIES_PROPS }),
|
79 | React.createElement(PolygonSeries, _extends({}, this.props, { animation: null }))
|
80 | );
|
81 | }
|
82 | var xFunctor = this._getAttributeFunctor('x');
|
83 | var yFunctor = this._getAttributeFunctor('y');
|
84 |
|
85 | return React.createElement('path', {
|
86 | className: predefinedClassName + ' ' + className,
|
87 | onMouseOver: function onMouseOver(e) {
|
88 | return _this2._seriesMouseOverHandler(data, e);
|
89 | },
|
90 | onMouseOut: function onMouseOut(e) {
|
91 | return _this2._seriesMouseOutHandler(data, e);
|
92 | },
|
93 | onClick: this._seriesClickHandler,
|
94 | onContextMenu: this._seriesRightClickHandler,
|
95 | fill: color || DEFAULT_COLOR,
|
96 | style: style,
|
97 | d: generatePath(data, xFunctor, yFunctor),
|
98 | transform: 'translate(' + marginLeft + ',' + marginTop + ')'
|
99 | });
|
100 | }
|
101 | }], [{
|
102 | key: 'propTypes',
|
103 | get: function get() {
|
104 | return _extends({}, AbstractSeries.propTypes);
|
105 | }
|
106 | }]);
|
107 |
|
108 | return PolygonSeries;
|
109 | }(AbstractSeries);
|
110 |
|
111 | PolygonSeries.displayName = 'PolygonSeries';
|
112 |
|
113 | export default PolygonSeries; |
\ | No newline at end of file |