UNPKG

react-financial-charts

Version:
55 lines 2.82 kB
import * as React from "react"; import { OverlayBarSeries } from "./OverlayBarSeries"; import { StraightLine } from "./StraightLine"; export class ElderRaySeries extends React.Component { constructor() { super(...arguments); this.yAccessorBullTop = (d) => { const { yAccessor } = this.props; return yAccessor(d) && (yAccessor(d).bullPower > 0 ? yAccessor(d).bullPower : undefined); }; this.yAccessorBearTop = (d) => { const { yAccessor } = this.props; return yAccessor(d) && (yAccessor(d).bearPower > 0 ? yAccessor(d).bearPower : undefined); }; this.yAccessorBullBottom = (d) => { const { yAccessor } = this.props; return yAccessor(d) && (yAccessor(d).bullPower < 0 ? 0 : undefined); }; this.yAccessorBearBottom = (d) => { const { yAccessor } = this.props; return yAccessor(d) && (yAccessor(d).bullPower < 0 || yAccessor(d).bullPower * yAccessor(d).bearPower < 0 // bullPower is +ve and bearPower is -ve ? Math.min(0, yAccessor(d).bullPower) : undefined); }; this.yAccessorForBarBase = (xScale, yScale, d) => { const { yAccessor } = this.props; const y = yAccessor(d) && Math.min(yAccessor(d).bearPower, 0); return yScale(y); }; this.fillForEachBar = (d, yAccessorNumber) => { const { bullPowerFill, bearPowerFill } = this.props; return yAccessorNumber % 2 === 0 ? bullPowerFill : bearPowerFill; }; } render() { const { className, clip, stroke, strokeOpacity, straightLineStroke, straightLineStrokeDasharray, straightLineOpacity, widthRatio, } = this.props; return (React.createElement("g", { className: className }, React.createElement(OverlayBarSeries, { baseAt: this.yAccessorForBarBase, className: "react-financial-charts-elderray-bar", stroke: stroke, fill: this.fillForEachBar, opacity: strokeOpacity, widthRatio: widthRatio, clip: clip, yAccessor: [this.yAccessorBullTop, this.yAccessorBearTop, this.yAccessorBullBottom, this.yAccessorBearBottom] }), React.createElement(StraightLine, { className: "react-financial-charts-elderray-straight-line", yValue: 0, stroke: straightLineStroke, strokeDasharray: straightLineStrokeDasharray, opacity: straightLineOpacity }))); } } ElderRaySeries.defaultProps = { bearPowerFill: "#ef5350", bullPowerFill: "#26a69a", className: "react-financial-charts-elderray-series", clip: true, opacity: 0.7, stroke: true, strokeOpacity: 0.7, straightLineStroke: "#000000", straightLineStrokeDasharray: "Dash", straightLineOpacity: 0.7, widthRatio: 0.8, }; //# sourceMappingURL=ElderRaySeries.js.map