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 | import PropTypes from 'prop-types';
|
31 | import { rgb } from 'd3-color';
|
32 | import * as d3Shape from 'd3-shape';
|
33 | import React from 'react';
|
34 |
|
35 | import { DEFAULT_OPACITY } from '../../theme';
|
36 | import { getAttributeFunctor, getAttributeValue } from '../../utils/scales-utils';
|
37 | import AbstractSeries from './abstract-series';
|
38 |
|
39 | var LineSeriesCanvas = function (_AbstractSeries) {
|
40 | _inherits(LineSeriesCanvas, _AbstractSeries);
|
41 |
|
42 | function LineSeriesCanvas() {
|
43 | _classCallCheck(this, LineSeriesCanvas);
|
44 |
|
45 | return _possibleConstructorReturn(this, (LineSeriesCanvas.__proto__ || Object.getPrototypeOf(LineSeriesCanvas)).apply(this, arguments));
|
46 | }
|
47 |
|
48 | _createClass(LineSeriesCanvas, [{
|
49 | key: 'render',
|
50 | value: function render() {
|
51 | return React.createElement('div', null);
|
52 | }
|
53 | }], [{
|
54 | key: 'renderLayer',
|
55 | value: function renderLayer(props, ctx) {
|
56 | var curve = props.curve,
|
57 | data = props.data,
|
58 | marginLeft = props.marginLeft,
|
59 | marginTop = props.marginTop,
|
60 | strokeWidth = props.strokeWidth,
|
61 | strokeDasharray = props.strokeDasharray;
|
62 |
|
63 | if (!data || data.length === 0) {
|
64 | return;
|
65 | }
|
66 |
|
67 | var x = getAttributeFunctor(props, 'x');
|
68 | var y = getAttributeFunctor(props, 'y');
|
69 | var stroke = getAttributeValue(props, 'stroke') || getAttributeValue(props, 'color');
|
70 | var strokeColor = rgb(stroke);
|
71 | var newOpacity = getAttributeValue(props, 'opacity');
|
72 | var opacity = Number.isFinite(newOpacity) ? newOpacity : DEFAULT_OPACITY;
|
73 | var line = d3Shape.line().x(function (row) {
|
74 | return x(row) + marginLeft;
|
75 | }).y(function (row) {
|
76 | return y(row) + marginTop;
|
77 | });
|
78 | if (typeof curve === 'string' && d3Shape[curve]) {
|
79 | line = line.curve(d3Shape[curve]);
|
80 | } else if (typeof curve === 'function') {
|
81 | line = line.curve(curve);
|
82 | }
|
83 |
|
84 | ctx.beginPath();
|
85 | ctx.strokeStyle = 'rgba(' + strokeColor.r + ', ' + strokeColor.g + ', ' + strokeColor.b + ', ' + opacity + ')';
|
86 | ctx.lineWidth = strokeWidth;
|
87 |
|
88 | if (strokeDasharray) {
|
89 | ctx.setLineDash(strokeDasharray);
|
90 | }
|
91 |
|
92 | line.context(ctx)(data);
|
93 | ctx.stroke();
|
94 | ctx.closePath();
|
95 |
|
96 | ctx.lineWidth = 1;
|
97 | ctx.setLineDash([]);
|
98 | }
|
99 | }, {
|
100 | key: 'requiresSVG',
|
101 | get: function get() {
|
102 | return false;
|
103 | }
|
104 | }, {
|
105 | key: 'isCanvas',
|
106 | get: function get() {
|
107 | return true;
|
108 | }
|
109 | }]);
|
110 |
|
111 | return LineSeriesCanvas;
|
112 | }(AbstractSeries);
|
113 |
|
114 | LineSeriesCanvas.displayName = 'LineSeriesCanvas';
|
115 | LineSeriesCanvas.defaultProps = _extends({}, AbstractSeries.defaultProps, {
|
116 | strokeWidth: 2
|
117 | });
|
118 |
|
119 | LineSeriesCanvas.propTypes = _extends({}, AbstractSeries.propTypes, {
|
120 | strokeWidth: PropTypes.number
|
121 | });
|
122 |
|
123 | export default LineSeriesCanvas; |
\ | No newline at end of file |