UNPKG

6.8 kBJavaScriptView Raw
1var _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
3var _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
5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7function _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
9function _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// Copyright (c) 2016 - 2017 Uber Technologies, Inc.
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the "Software"), to deal
15// in the Software without restriction, including without limitation the rights
16// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17// copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in
21// all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29// THE SOFTWARE.
30
31import React from 'react';
32
33import PropTypes from 'prop-types';
34
35import Animation from '../../animation';
36import { ANIMATED_SERIES_PROPS } from '../../utils/series-utils';
37import { warning } from '../../utils/react-utils';
38import { DEFAULT_SIZE, DEFAULT_OPACITY } from '../../theme';
39
40import AbstractSeries from './abstract-series';
41
42var predefinedClassName = 'rv-xy-plot__series rv-xy-plot__series--mark';
43var DEFAULT_STROKE_WIDTH = 1;
44
45var 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
151MarkSeries.displayName = 'MarkSeries';
152MarkSeries.propTypes = _extends({}, AbstractSeries.propTypes, {
153 getNull: PropTypes.func,
154 strokeWidth: PropTypes.number
155});
156MarkSeries.defaultProps = {
157 getNull: function getNull() {
158 return true;
159 }
160};
161
162export default MarkSeries;
\No newline at end of file