ct-react-stockcharts
Version:
Highly customizable stock charts with ReactJS and d3
175 lines (151 loc) • 6.54 kB
JavaScript
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
import React, { Component } from "react";
import PropTypes from "prop-types";
import { drawOnCanvas as _drawOnCanvas, renderSVG as _renderSVG } from "./EdgeCoordinateV3";
import GenericChartComponent from "../GenericChartComponent";
import { getAxisCanvas } from "../GenericComponent";
import { functor, strokeDashTypes } from "../utils";
var PriceCoordinate = function (_Component) {
_inherits(PriceCoordinate, _Component);
function PriceCoordinate(props) {
_classCallCheck(this, PriceCoordinate);
var _this = _possibleConstructorReturn(this, (PriceCoordinate.__proto__ || Object.getPrototypeOf(PriceCoordinate)).call(this, props));
_this.renderSVG = _this.renderSVG.bind(_this);
_this.drawOnCanvas = _this.drawOnCanvas.bind(_this);
return _this;
}
_createClass(PriceCoordinate, [{
key: "drawOnCanvas",
value: function drawOnCanvas(ctx, moreProps) {
var props = helper(this.props, moreProps);
_drawOnCanvas(ctx, props);
}
}, {
key: "renderSVG",
value: function renderSVG(moreProps) {
var props = helper(this.props, moreProps);
return _renderSVG(props);
}
}, {
key: "render",
value: function render() {
return React.createElement(GenericChartComponent, {
clip: false,
svgDraw: this.renderSVG,
canvasDraw: this.drawOnCanvas,
canvasToDraw: getAxisCanvas,
drawOn: ["pan"]
});
}
}]);
return PriceCoordinate;
}(Component);
PriceCoordinate.propTypes = {
displayFormat: PropTypes.func.isRequired,
yAxisPad: PropTypes.number,
rectWidth: PropTypes.number,
rectHeight: PropTypes.number,
orient: PropTypes.oneOf(["bottom", "top", "left", "right"]),
at: PropTypes.oneOf(["bottom", "top", "left", "right"]),
price: PropTypes.number,
dx: PropTypes.number,
arrowWidth: PropTypes.number,
opacity: PropTypes.number,
lineOpacity: PropTypes.number,
lineStroke: PropTypes.string,
fontFamily: PropTypes.string,
fontSize: PropTypes.number,
fill: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
strokeDasharray: PropTypes.oneOf(strokeDashTypes),
stroke: PropTypes.string,
strokeOpacity: PropTypes.number,
strokeWidth: PropTypes.number,
textFill: PropTypes.oneOfType([PropTypes.string, PropTypes.func])
};
PriceCoordinate.defaultProps = {
yAxisPad: 0,
rectWidth: 50,
rectHeight: 20,
orient: "left",
at: "left",
price: 0,
dx: 0,
arrowWidth: 0,
fill: "#BAB8b8",
opacity: 1,
lineOpacity: 0.2,
lineStroke: "#000000",
fontFamily: "Helvetica Neue, Helvetica, Arial, sans-serif",
fontSize: 13,
textFill: "#FFFFFF",
strokeOpacity: 1,
strokeWidth: 1,
strokeDasharray: "Solid"
};
function helper(props, moreProps) {
var width = moreProps.width;
var yScale = moreProps.chartConfig.yScale;
var _yScale$domain = yScale.domain(),
_yScale$domain2 = _slicedToArray(_yScale$domain, 2),
lowerYValue = _yScale$domain2[0],
upperYValue = _yScale$domain2[1];
var price = props.price,
stroke = props.stroke,
strokeDasharray = props.strokeDasharray,
strokeOpacity = props.strokeOpacity,
strokeWidth = props.strokeWidth;
var orient = props.orient,
at = props.at,
rectWidth = props.rectWidth,
rectHeight = props.rectHeight,
displayFormat = props.displayFormat,
dx = props.dx;
var fill = props.fill,
opacity = props.opacity,
fontFamily = props.fontFamily,
fontSize = props.fontSize,
textFill = props.textFill,
arrowWidth = props.arrowWidth,
lineOpacity = props.lineOpacity,
lineStroke = props.lineStroke;
var x1 = 0,
x2 = width;
var edgeAt = at === "right" ? width : 0;
var type = "horizontal";
var y = yScale(price);
var show = price <= upperYValue && price >= lowerYValue;
var coordinate = displayFormat(yScale.invert(y));
var hideLine = false;
var coordinateProps = {
coordinate: coordinate,
show: show,
type: type,
orient: orient,
edgeAt: edgeAt,
hideLine: hideLine,
lineOpacity: lineOpacity,
lineStroke: lineStroke,
lineStrokeDasharray: strokeDasharray,
stroke: stroke,
strokeOpacity: strokeOpacity,
strokeWidth: strokeWidth,
fill: functor(fill)(price),
textFill: functor(textFill)(price),
opacity: opacity, fontFamily: fontFamily, fontSize: fontSize,
rectWidth: rectWidth,
rectHeight: rectHeight,
arrowWidth: arrowWidth,
dx: dx,
x1: x1,
x2: x2,
y1: y,
y2: y
};
return coordinateProps;
}
export default PriceCoordinate;
//# sourceMappingURL=PriceCoordinate.js.map