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 | import PropTypes from 'prop-types';
|
33 | import * as d3Shape from 'd3-shape';
|
34 |
|
35 | import Animation from '../../animation';
|
36 | import { DEFAULT_OPACITY } from '../../theme';
|
37 | import { ANIMATED_SERIES_PROPS } from '../../utils/series-utils';
|
38 | import { warning } from '../../utils/react-utils';
|
39 |
|
40 | import AbstractSeries from './abstract-series';
|
41 |
|
42 | var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--line';
|
43 |
|
44 | var STROKE_STYLES = {
|
45 | dashed: '6, 2',
|
46 | solid: null
|
47 | };
|
48 |
|
49 | var LineSeries = function (_AbstractSeries) {
|
50 | _inherits(LineSeries, _AbstractSeries);
|
51 |
|
52 | function LineSeries() {
|
53 | _classCallCheck(this, LineSeries);
|
54 |
|
55 | return _possibleConstructorReturn(this, (LineSeries.__proto__ || Object.getPrototypeOf(LineSeries)).apply(this, arguments));
|
56 | }
|
57 |
|
58 | _createClass(LineSeries, [{
|
59 | key: '_renderLine',
|
60 | value: function _renderLine(data, x, y, curve, getNull) {
|
61 | var line = d3Shape.line();
|
62 | if (curve !== null) {
|
63 | if (typeof curve === 'string' && d3Shape[curve]) {
|
64 | line = line.curve(d3Shape[curve]);
|
65 | } else if (typeof curve === 'function') {
|
66 | line = line.curve(curve);
|
67 | }
|
68 | }
|
69 | line = line.defined(getNull);
|
70 | line = line.x(x).y(y);
|
71 | return line(data);
|
72 | }
|
73 | }, {
|
74 | key: 'render',
|
75 | value: function render() {
|
76 | var _props = this.props,
|
77 | animation = _props.animation,
|
78 | className = _props.className,
|
79 | data = _props.data;
|
80 |
|
81 |
|
82 | if (this.props.nullAccessor) {
|
83 | warning('nullAccessor has been renamed to getNull', true);
|
84 | }
|
85 |
|
86 | if (!data) {
|
87 | return null;
|
88 | }
|
89 |
|
90 | if (animation) {
|
91 | return React.createElement(
|
92 | Animation,
|
93 | _extends({}, this.props, { animatedProps: ANIMATED_SERIES_PROPS }),
|
94 | React.createElement(LineSeries, _extends({}, this.props, { animation: null }))
|
95 | );
|
96 | }
|
97 |
|
98 | var _props2 = this.props,
|
99 | curve = _props2.curve,
|
100 | marginLeft = _props2.marginLeft,
|
101 | marginTop = _props2.marginTop,
|
102 | strokeDasharray = _props2.strokeDasharray,
|
103 | strokeStyle = _props2.strokeStyle,
|
104 | strokeWidth = _props2.strokeWidth,
|
105 | style = _props2.style;
|
106 |
|
107 |
|
108 | var x = this._getAttributeFunctor('x');
|
109 | var y = this._getAttributeFunctor('y');
|
110 | var stroke = this._getAttributeValue('stroke') || this._getAttributeValue('color');
|
111 | var newOpacity = this._getAttributeValue('opacity');
|
112 | var opacity = Number.isFinite(newOpacity) ? newOpacity : DEFAULT_OPACITY;
|
113 | var getNull = this.props.nullAccessor || this.props.getNull;
|
114 | var d = this._renderLine(data, x, y, curve, getNull);
|
115 |
|
116 | return React.createElement('path', {
|
117 | d: d,
|
118 | className: predefinedClassName + ' ' + className,
|
119 | transform: 'translate(' + marginLeft + ',' + marginTop + ')',
|
120 | onMouseOver: this._seriesMouseOverHandler,
|
121 | onMouseOut: this._seriesMouseOutHandler,
|
122 | onClick: this._seriesClickHandler,
|
123 | onContextMenu: this._seriesRightClickHandler,
|
124 | style: _extends({
|
125 | opacity: opacity,
|
126 | strokeDasharray: STROKE_STYLES[strokeStyle] || strokeDasharray,
|
127 | strokeWidth: strokeWidth,
|
128 | stroke: stroke
|
129 | }, style)
|
130 | });
|
131 | }
|
132 | }]);
|
133 |
|
134 | return LineSeries;
|
135 | }(AbstractSeries);
|
136 |
|
137 | LineSeries.displayName = 'LineSeries';
|
138 | LineSeries.propTypes = _extends({}, AbstractSeries.propTypes, {
|
139 | strokeStyle: PropTypes.oneOf(Object.keys(STROKE_STYLES)),
|
140 | curve: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
141 | getNull: PropTypes.func
|
142 | });
|
143 | LineSeries.defaultProps = _extends({}, AbstractSeries.defaultProps, {
|
144 | strokeStyle: 'solid',
|
145 | style: {},
|
146 | opacity: 1,
|
147 | curve: null,
|
148 | className: '',
|
149 | getNull: function getNull() {
|
150 | return true;
|
151 | }
|
152 | });
|
153 |
|
154 | export default LineSeries; |
\ | No newline at end of file |