Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to display the last item as default OHLC #740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/lib/tooltip/OHLCTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { timeFormat } from "d3-time-format";
import displayValuesFor from "./displayValuesFor";
import GenericChartComponent from "../GenericChartComponent";

import { isDefined, functor } from "../utils";
import { isDefined, functor, last } from "../utils";
import ToolTipText from "./ToolTipText";
import ToolTipTSpanLabel from "./ToolTipTSpanLabel";

Expand All @@ -24,19 +24,21 @@ class OHLCTooltip extends Component {
volumeFormat,
ohlcFormat,
percentFormat,
displayTexts
displayTexts,
lastAsDefault
} = this.props;

const { chartConfig: { width, height } } = moreProps;
const { displayXAccessor } = moreProps;
const { displayXAccessor, fullData } = moreProps;

const currentItem = displayValuesFor(this.props, moreProps);
const displayItem = lastAsDefault ? currentItem || last(fullData) : currentItem;

let displayDate, open, high, low, close, volume, percent;
displayDate = open = high = low = close = volume = percent = displayTexts.na;

if (isDefined(currentItem) && isDefined(accessor(currentItem))) {
const item = accessor(currentItem);
if (isDefined(displayItem) && isDefined(accessor(displayItem))) {
const item = accessor(displayItem);
volume = isDefined(item.volume) ? volumeFormat(item.volume) : displayTexts.na;

displayDate = xDisplayFormat(displayXAccessor(item));
Expand Down Expand Up @@ -91,6 +93,7 @@ OHLCTooltip.propTypes = {
textFill: PropTypes.string,
labelFill: PropTypes.string,
displayTexts: PropTypes.object,
lastAsDefault: PropTypes.bool,
};

const displayTextsDefault = {
Expand Down Expand Up @@ -122,6 +125,7 @@ OHLCTooltip.defaultProps = {
origin: [0, 0],
children: defaultDisplay,
displayTexts: displayTextsDefault,
lastAsDefault: false,
};

function defaultDisplay(props, moreProps, itemsToDisplay) {
Expand Down