How to use the recharts.Tooltip.propTypes function in recharts

To help you get started, we’ve selected a few recharts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomiclabs / hyperdex / app / renderer / components / TimeSeriesChart.js View on Github external
import {format as formatDate, subMonths, subDays, subHours, subMinutes, getDaysInMonth} from 'date-fns';
import {formatCurrency} from '../util';
import './TimeSeriesChart.scss';

const CustomTooltip = ({payload}) => {
	// It's sometimes empty…
	if (!(payload && payload.length > 0)) {
		return null;
	}

	return (
		<div>{formatCurrency(payload[0].payload.value)}</div>
	);
};

CustomTooltip.propTypes = Tooltip.propTypes;

const resolutionToLabelFormat = new Map([
	['hour', 'HH:mm'],
	['day', 'HH:mm dddd'],
	['week', 'dddd DD/MM'],
	['month', 'DD/MM'],
	['year', 'MMMM'],
	['all', 'MMMM YYYY'],
]);

const makeTicks = (count, fn) =&gt; {
	const now = new Date();
	return [...new Array(count).keys()].map(index =&gt; fn(now, index)).reverse();
};

const getTicks = resolution =&gt; {
github atomiclabs / hyperdex / app / renderer / views / Dashboard / PieChart.js View on Github external
import './PieChart.scss';

const CustomTooltip = ({payload}) =&gt; {
	// It's sometimes empty…
	if (!(payload &amp;&amp; payload.length &gt; 0)) {
		return null;
	}

	const [data] = payload;

	return (
		<div>{data.name}: {formatCurrency(data.value)}</div>
	);
};

CustomTooltip.propTypes = Tooltip.propTypes;

const PieChart = () =&gt; {
	const {state: appState} = appContainer;
	const {currencies} = appState;

	const data = currencies.map(currency =&gt; ({
		name: currency.symbol,
		value: currency.cmcBalanceUsd,
	}));

	let PieChart = () =&gt; (
github atomiclabs / hyperdex / app / renderer / components / DepthChart.js View on Github external
// TODO(sindresorhus): The default behavior of tooltips is to follow the mouse.
// We should make it static: https://github.com/recharts/recharts/issues/488

const CustomTooltipContent = ({payload}) =&gt; {
	// No idea why it's sometimes empty
	if (payload.length === 0) {
		return null;
	}

	return (
		<div>{formatCurrency(payload[0].payload.price)}</div>
	);
};

CustomTooltipContent.propTypes = Tooltip.propTypes;

const DepthChart = props =&gt; {
	let {bids, asks} = props;

	const getDepths = orders =&gt; orders.map(order =&gt; order.depth);
	const maxDepth = Math.max(...getDepths(asks), ...getDepths(bids));
	const isEmpty = bids.length === 0 &amp;&amp; asks.length === 0;

	// We still supply values when it's empty so it will show the left/right border
	bids = bids.length &gt; 0 ? bids : [{price: 0, depth: 0}];
	asks = asks.length &gt; 0 ? asks : [{price: 0, depth: 0}];

	bids = _.orderBy(bids, ['depth'], ['desc']);
	asks = _.orderBy(asks, ['depth'], ['asc']);
	bids = roundPrice(bids);
	asks = roundPrice(asks);