UNPKG

react-stockcharts-ferdibiflator

Version:

Highly customizable stock charts with ReactJS and d3

95 lines (85 loc) 2.71 kB
"use strict"; import React from "react"; import PropTypes from "prop-types"; import { hexToRGBA, functor } from "../utils"; function Triangle(props) { var className = props.className, stroke = props.stroke, strokeWidth = props.strokeWidth, opacity = props.opacity, fill = props.fill, point = props.point, width = props.width; var w = functor(width)(point.datum); var x = point.x, y = point.y; var _getTrianglePoints = getTrianglePoints(w), innerOpposite = _getTrianglePoints.innerOpposite, innerHypotenuse = _getTrianglePoints.innerHypotenuse; var points = "\n\t\t" + x + " " + (y - innerHypotenuse) + ",\n\t\t" + (x + w / 2) + " " + (y + innerOpposite) + ",\n\t\t" + (x - w / 2) + " " + (y + innerOpposite) + "\n\t"; return React.createElement("polygon", { className: className, points: points, stroke: stroke, strokeWidth: strokeWidth, fillOpacity: opacity, fill: fill }); } Triangle.propTypes = { stroke: PropTypes.string, fill: PropTypes.string.isRequired, opacity: PropTypes.number.isRequired, point: PropTypes.shape({ x: PropTypes.number.isRequired, y: PropTypes.number.isRequired, datum: PropTypes.object.isRequired }).isRequired, className: PropTypes.string, strokeWidth: PropTypes.number, width: PropTypes.oneOfType([PropTypes.number, PropTypes.func]).isRequired }; Triangle.defaultProps = { stroke: "#4682B4", strokeWidth: 1, opacity: 0.5, fill: "#4682B4", className: "react-stockcharts-marker-triangle" }; Triangle.drawOnCanvas = function (props, point, ctx) { var stroke = props.stroke, fill = props.fill, opacity = props.opacity, strokeWidth = props.strokeWidth; ctx.strokeStyle = stroke; ctx.lineWidth = strokeWidth; if (fill !== "none") { ctx.fillStyle = hexToRGBA(fill, opacity); } Triangle.drawOnCanvasWithNoStateChange(props, point, ctx); }; Triangle.drawOnCanvasWithNoStateChange = function (props, point, ctx) { var width = props.width; var w = functor(width)(point.datum); var x = point.x, y = point.y; var _getTrianglePoints2 = getTrianglePoints(w), innerOpposite = _getTrianglePoints2.innerOpposite, innerHypotenuse = _getTrianglePoints2.innerHypotenuse; ctx.beginPath(); ctx.moveTo(x, y - innerHypotenuse); ctx.lineTo(x + w / 2, y + innerOpposite); ctx.lineTo(x - w / 2, y + innerOpposite); ctx.stroke(); ctx.fill(); }; export default Triangle; function getTrianglePoints(width) { var innerHypotenuse = width / 2 * (1 / Math.cos(30 * Math.PI / 180)); var innerOpposite = width / 2 * (1 / Math.tan(60 * Math.PI / 180)); return { innerOpposite: innerOpposite, innerHypotenuse: innerHypotenuse }; } //# sourceMappingURL=TriangleMarker.js.map