UNPKG

react-financial-charts

Version:
47 lines 2.7 kB
import { format } from "d3-format"; import * as React from "react"; import GenericChartComponent from "../GenericChartComponent"; import { default as defaultDisplayValuesFor } from "./displayValuesFor"; import { functor } from "../utils"; import { ToolTipText } from "./ToolTipText"; import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel"; export class StochasticTooltip extends React.Component { constructor() { super(...arguments); this.renderSVG = (moreProps) => { const { onClick, fontFamily, fontSize, yAccessor, displayFormat, label } = this.props; const { className, options, appearance, labelFill } = this.props; const { displayValuesFor } = this.props; const { chartConfig: { width, height } } = moreProps; const currentItem = displayValuesFor(this.props, moreProps); const { stroke } = appearance; const stochastic = currentItem && yAccessor(currentItem); const K = (stochastic && stochastic.K && displayFormat(stochastic.K)) || "n/a"; const D = (stochastic && stochastic.D && displayFormat(stochastic.D)) || "n/a"; const { origin: originProp } = this.props; const origin = functor(originProp); const [x, y] = origin(width, height); return (React.createElement("g", { className: className, transform: `translate(${x}, ${y})`, onClick: onClick }, React.createElement(ToolTipText, { x: 0, y: 0, fontFamily: fontFamily, fontSize: fontSize }, React.createElement(ToolTipTSpanLabel, { fill: labelFill }, `${label} %K(`), React.createElement("tspan", { fill: stroke.kLine }, `${options.windowSize}, ${options.kWindowSize}`), React.createElement(ToolTipTSpanLabel, { fill: labelFill }, "): "), React.createElement("tspan", { fill: stroke.kLine }, K), React.createElement(ToolTipTSpanLabel, { fill: labelFill }, " %D ("), React.createElement("tspan", { fill: stroke.dLine }, options.dWindowSize), React.createElement(ToolTipTSpanLabel, { fill: labelFill }, "): "), React.createElement("tspan", { fill: stroke.dLine }, D)))); }; } render() { return (React.createElement(GenericChartComponent, { clip: false, svgDraw: this.renderSVG, drawOn: ["mousemove"] })); } } StochasticTooltip.defaultProps = { displayFormat: format(".2f"), displayValuesFor: defaultDisplayValuesFor, origin: [0, 0], className: "react-financial-charts-tooltip", label: "STO", }; //# sourceMappingURL=StochasticTooltip.js.map