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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6 |
|
7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8 |
|
9 | 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; }
|
10 |
|
11 | 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; }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | import React from 'react';
|
34 |
|
35 | import PropTypes from 'prop-types';
|
36 |
|
37 | import Animation from '../../animation';
|
38 | import { ANIMATED_SERIES_PROPS, getStackParams } from '../../utils/series-utils';
|
39 |
|
40 | import AbstractSeries from './abstract-series';
|
41 |
|
42 | var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--bar';
|
43 |
|
44 | var BarSeries = function (_AbstractSeries) {
|
45 | _inherits(BarSeries, _AbstractSeries);
|
46 |
|
47 | function BarSeries() {
|
48 | _classCallCheck(this, BarSeries);
|
49 |
|
50 | return _possibleConstructorReturn(this, (BarSeries.__proto__ || Object.getPrototypeOf(BarSeries)).apply(this, arguments));
|
51 | }
|
52 |
|
53 | _createClass(BarSeries, [{
|
54 | key: 'render',
|
55 | value: function render() {
|
56 | var _this2 = this;
|
57 |
|
58 | var _props = this.props,
|
59 | animation = _props.animation,
|
60 | className = _props.className,
|
61 | data = _props.data,
|
62 | linePosAttr = _props.linePosAttr,
|
63 | lineSizeAttr = _props.lineSizeAttr,
|
64 | marginLeft = _props.marginLeft,
|
65 | marginTop = _props.marginTop,
|
66 | style = _props.style,
|
67 | valuePosAttr = _props.valuePosAttr,
|
68 | valueSizeAttr = _props.valueSizeAttr,
|
69 | barWidth = _props.barWidth;
|
70 |
|
71 |
|
72 | if (!data) {
|
73 | return null;
|
74 | }
|
75 |
|
76 | if (animation) {
|
77 | return React.createElement(
|
78 | Animation,
|
79 | _extends({}, this.props, { animatedProps: ANIMATED_SERIES_PROPS }),
|
80 | React.createElement(BarSeries, _extends({}, this.props, { animation: null }))
|
81 | );
|
82 | }
|
83 |
|
84 | var _getStackParams = getStackParams(this.props),
|
85 | sameTypeTotal = _getStackParams.sameTypeTotal,
|
86 | sameTypeIndex = _getStackParams.sameTypeIndex;
|
87 |
|
88 | var distance = this._getScaleDistance(linePosAttr);
|
89 | var lineFunctor = this._getAttributeFunctor(linePosAttr);
|
90 | var valueFunctor = this._getAttributeFunctor(valuePosAttr);
|
91 | var value0Functor = this._getAttr0Functor(valuePosAttr);
|
92 | var fillFunctor = this._getAttributeFunctor('fill') || this._getAttributeFunctor('color');
|
93 | var strokeFunctor = this._getAttributeFunctor('stroke') || this._getAttributeFunctor('color');
|
94 | var opacityFunctor = this._getAttributeFunctor('opacity');
|
95 |
|
96 | var halfSpace = distance / 2 * barWidth;
|
97 |
|
98 | return React.createElement(
|
99 | 'g',
|
100 | {
|
101 | className: predefinedClassName + ' ' + className,
|
102 | transform: 'translate(' + marginLeft + ',' + marginTop + ')'
|
103 | },
|
104 | data.map(function (d, i) {
|
105 | var _attrs;
|
106 |
|
107 |
|
108 |
|
109 | var totalSpaceAvailable = halfSpace * 2;
|
110 | var totalSpaceCenter = lineFunctor(d);
|
111 |
|
112 | var totalSpaceStartingPoint = totalSpaceCenter - halfSpace;
|
113 |
|
114 | var spaceTakenByInterBarsPixels = (sameTypeTotal - 1) / sameTypeTotal;
|
115 |
|
116 | var spacePerBar = totalSpaceAvailable / sameTypeTotal - spaceTakenByInterBarsPixels;
|
117 |
|
118 | var barStartingPoint = totalSpaceStartingPoint + spacePerBar * sameTypeIndex + sameTypeIndex;
|
119 |
|
120 | var attrs = (_attrs = {
|
121 | style: _extends({
|
122 | opacity: opacityFunctor && opacityFunctor(d),
|
123 | stroke: strokeFunctor && strokeFunctor(d),
|
124 | fill: fillFunctor && fillFunctor(d)
|
125 | }, style)
|
126 | }, _defineProperty(_attrs, linePosAttr, barStartingPoint), _defineProperty(_attrs, lineSizeAttr, spacePerBar), _defineProperty(_attrs, valuePosAttr, Math.min(value0Functor(d), valueFunctor(d))), _defineProperty(_attrs, valueSizeAttr, Math.abs(-value0Functor(d) + valueFunctor(d))), _defineProperty(_attrs, 'onClick', function onClick(e) {
|
127 | return _this2._valueClickHandler(d, e);
|
128 | }), _defineProperty(_attrs, 'onContextMenu', function onContextMenu(e) {
|
129 | return _this2._valueRightClickHandler(d, e);
|
130 | }), _defineProperty(_attrs, 'onMouseOver', function onMouseOver(e) {
|
131 | return _this2._valueMouseOverHandler(d, e);
|
132 | }), _defineProperty(_attrs, 'onMouseOut', function onMouseOut(e) {
|
133 | return _this2._valueMouseOutHandler(d, e);
|
134 | }), _defineProperty(_attrs, 'key', i), _attrs);
|
135 | return React.createElement('rect', attrs);
|
136 | })
|
137 | );
|
138 | }
|
139 | }], [{
|
140 | key: 'propTypes',
|
141 | get: function get() {
|
142 | return _extends({}, AbstractSeries.propTypes, {
|
143 | linePosAttr: PropTypes.string,
|
144 | valuePosAttr: PropTypes.string,
|
145 | lineSizeAttr: PropTypes.string,
|
146 | valueSizeAttr: PropTypes.string,
|
147 | cluster: PropTypes.string,
|
148 | barWidth: PropTypes.number
|
149 | });
|
150 | }
|
151 | }, {
|
152 | key: 'defaultProps',
|
153 | get: function get() {
|
154 | return {
|
155 | barWidth: 0.85
|
156 | };
|
157 | }
|
158 | }]);
|
159 |
|
160 | return BarSeries;
|
161 | }(AbstractSeries);
|
162 |
|
163 | BarSeries.displayName = 'BarSeries';
|
164 |
|
165 | export default BarSeries; |
\ | No newline at end of file |