react-financial-charts
Version:
React charts specific to finance.
39 lines • 2 kB
JavaScript
import { format } from "d3-format";
import * as React from "react";
import GenericChartComponent from "../GenericChartComponent";
import { default as defaultDisplayValuesFor } from "./displayValuesFor";
import { functor, isDefined } from "../utils";
import { ToolTipText } from "./ToolTipText";
import { ToolTipTSpanLabel } from "./ToolTipTSpanLabel";
export class RSITooltip extends React.Component {
constructor() {
super(...arguments);
this.renderSVG = (moreProps) => {
const { onClick, fontFamily, fontSize, yAccessor, displayFormat, className } = this.props;
const { options, labelFill, textFill } = this.props;
const { displayValuesFor } = this.props;
const { chartConfig: { width, height } } = moreProps;
const currentItem = displayValuesFor(this.props, moreProps);
const rsi = isDefined(currentItem) && yAccessor(currentItem);
const value = (rsi && displayFormat(rsi)) || "n/a";
const { origin: originProp } = this.props;
const origin = functor(originProp);
const [x, y] = origin(width, height);
const tooltipLabel = `RSI (${options.windowSize}): `;
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 }, tooltipLabel),
React.createElement("tspan", { fill: textFill }, value))));
};
}
render() {
return (React.createElement(GenericChartComponent, { clip: false, svgDraw: this.renderSVG, drawOn: ["mousemove"] }));
}
}
RSITooltip.defaultProps = {
displayFormat: format(".2f"),
displayValuesFor: defaultDisplayValuesFor,
origin: [0, 0],
className: "react-financial-charts-tooltip",
};
//# sourceMappingURL=RSITooltip.js.map