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 { rgb } from 'd3-color';
|
32 |
|
33 | import { DEFAULT_SIZE, DEFAULT_OPACITY } from '../../theme';
|
34 | import { getAttributeFunctor } from '../../utils/scales-utils';
|
35 |
|
36 | import AbstractSeries from './abstract-series';
|
37 |
|
38 | var MarkSeriesCanvas = function (_AbstractSeries) {
|
39 | _inherits(MarkSeriesCanvas, _AbstractSeries);
|
40 |
|
41 | function MarkSeriesCanvas() {
|
42 | _classCallCheck(this, MarkSeriesCanvas);
|
43 |
|
44 | return _possibleConstructorReturn(this, (MarkSeriesCanvas.__proto__ || Object.getPrototypeOf(MarkSeriesCanvas)).apply(this, arguments));
|
45 | }
|
46 |
|
47 | _createClass(MarkSeriesCanvas, [{
|
48 | key: 'render',
|
49 | value: function render() {
|
50 | return null;
|
51 | }
|
52 | }], [{
|
53 | key: 'renderLayer',
|
54 | value: function renderLayer(props, ctx) {
|
55 | var data = props.data,
|
56 | marginLeft = props.marginLeft,
|
57 | marginTop = props.marginTop;
|
58 |
|
59 |
|
60 | var x = getAttributeFunctor(props, 'x');
|
61 | var y = getAttributeFunctor(props, 'y');
|
62 | var size = getAttributeFunctor(props, 'size') || function (p) {
|
63 | return DEFAULT_SIZE;
|
64 | };
|
65 | var fill = getAttributeFunctor(props, 'fill') || getAttributeFunctor(props, 'color');
|
66 | var stroke = getAttributeFunctor(props, 'stroke') || getAttributeFunctor(props, 'color');
|
67 | var opacity = getAttributeFunctor(props, 'opacity');
|
68 |
|
69 | data.forEach(function (row) {
|
70 | var fillColor = rgb(fill(row));
|
71 | var strokeColor = rgb(stroke(row));
|
72 | var rowOpacity = opacity(row) || DEFAULT_OPACITY;
|
73 | ctx.beginPath();
|
74 | ctx.arc(x(row) + marginLeft, y(row) + marginTop, size(row), 0, 2 * Math.PI);
|
75 | ctx.fillStyle = 'rgba(' + fillColor.r + ', ' + fillColor.g + ', ' + fillColor.b + ', ' + rowOpacity + ')';
|
76 | ctx.fill();
|
77 | ctx.strokeStyle = 'rgba(' + strokeColor.r + ', ' + strokeColor.g + ', ' + strokeColor.b + ', ' + rowOpacity + ')';
|
78 | ctx.stroke();
|
79 | });
|
80 | }
|
81 | }, {
|
82 | key: 'requiresSVG',
|
83 | get: function get() {
|
84 | return false;
|
85 | }
|
86 | }, {
|
87 | key: 'isCanvas',
|
88 | get: function get() {
|
89 | return true;
|
90 | }
|
91 | }]);
|
92 |
|
93 | return MarkSeriesCanvas;
|
94 | }(AbstractSeries);
|
95 |
|
96 | MarkSeriesCanvas.displayName = 'MarkSeriesCanvas';
|
97 |
|
98 | MarkSeriesCanvas.propTypes = _extends({}, AbstractSeries.propTypes);
|
99 |
|
100 | export default MarkSeriesCanvas; |
\ | No newline at end of file |