import * as React from "react"; import { strokeDashTypes } from "@fishbot/chart-core"; import { LineSeries } from "./LineSeries"; import { StraightLine } from "./StraightLine"; import { SVGComponent } from "./SVGComponent"; export interface RSISeriesProps { readonly className?: string; readonly yAccessor: (data: any) => any; readonly strokeStyle?: { line: string; top: string; middle: string; bottom: string; outsideThreshold: string; insideThreshold: string; }; readonly strokeDasharray?: { line: strokeDashTypes; top: strokeDashTypes; middle: strokeDashTypes; bottom: strokeDashTypes; }; readonly strokeWidth?: { outsideThreshold: number; insideThreshold: number; top: number; middle: number; bottom: number; }; readonly overSold?: number; readonly middle?: number; readonly overBought?: number; } /** * The Relative Strength Index (RSI) is a momentum oscillator that measures the speed and change of price movements. */ export class RSISeries extends React.Component { public static defaultProps = { className: "react-financial-charts-rsi-series", strokeStyle: { line: "#000000", top: "#B8C2CC", middle: "#8795A1", bottom: "#B8C2CC", outsideThreshold: "#b300b3", insideThreshold: "#ffccff", }, strokeDasharray: { line: "Solid" as strokeDashTypes, top: "ShortDash" as strokeDashTypes, middle: "ShortDash" as strokeDashTypes, bottom: "ShortDash" as strokeDashTypes, }, strokeWidth: { outsideThreshold: 1, insideThreshold: 1, top: 1, middle: 1, bottom: 1, }, overSold: 70, middle: 50, overBought: 30, }; private clipPathId1 = `rsi-clip-${String(Math.round(Math.random() * 10000 * 10000))}`; private clipPathId2 = `rsi-clip-${String(Math.round(Math.random() * 10000 * 10000))}`; public render() { const { className, strokeStyle = RSISeries.defaultProps.strokeStyle, strokeDasharray = RSISeries.defaultProps.strokeDasharray, strokeWidth = RSISeries.defaultProps.strokeWidth, } = this.props; const { yAccessor } = this.props; const { overSold, middle, overBought } = this.props; return ( {this.renderClip} ); } private readonly renderClip = (moreProps: any) => { const { chartConfig } = moreProps; const { overSold, overBought } = this.props; const { yScale, width, height } = chartConfig; return ( ); }; private readonly mainClip = (ctx: CanvasRenderingContext2D, moreProps: any) => { const { chartConfig } = moreProps; const { overSold, overBought } = this.props; const { yScale, width, height } = chartConfig; ctx.beginPath(); ctx.rect(0, 0, width, yScale(overSold)); ctx.rect(0, yScale(overBought), width, height - yScale(overBought)); ctx.clip(); }; private readonly topAndBottomClip = (ctx: CanvasRenderingContext2D, moreProps: any) => { const { chartConfig } = moreProps; const { overSold, overBought } = this.props; const { yScale, width } = chartConfig; ctx.beginPath(); ctx.rect(0, yScale(overSold), width, yScale(overBought) - yScale(overSold)); ctx.clip(); }; }