import * as React from 'react';
import { useMemo } from 'react';
import { Center, Stack, Text, Tooltip, useMantineTheme } from '@mantine/core';
import * as d3 from 'd3v7';
import { VIS_GRID_COLOR } from '../../general/constants';
import { ICorrelationConfig } from '../interfaces';
const marginRect = { top: 0, right: 0, bottom: 0, left: 0 };
export interface CorrelationPairProps {
xi: number;
yi: number;
cxLT: number;
cyLT: number;
cxUT: number;
cyUT: number;
correlation: number;
pValue: number;
xName: string;
yName: string;
radius: number;
}
export function CorrelationPair({
value,
fill,
boundingRect,
config,
}: {
value: CorrelationPairProps;
fill: string;
boundingRect: { width: number; height: number };
config: ICorrelationConfig;
}) {
const [isHover, setIsHover] = React.useState(false);
const theme = useMantineTheme();
const hoverColor = theme.colors.gray[1];
const format = useMemo(() => {
return d3.format('.3g');
}, []);
const correlationFormat = useMemo(() => {
return d3.format('.3g');
}, []);
const topRect = useMemo(() => {
return (
);
}, [boundingRect.height, boundingRect.width, fill, hoverColor, isHover, value]);
const bottomRect = useMemo(() => {
return (
{`r: ${correlationFormat(value.correlation)}`}
{`p: ${format(value.pValue)}`}
);
}, [boundingRect.height, boundingRect.width, correlationFormat, format, hoverColor, isHover, value.correlation, value.cxLT, value.cyLT, value.pValue]);
const label = useMemo(() => {
return (
{`${value.xName} / ${value.yName}`}
Correlation: {correlationFormat(value.correlation)}
P-value: {format(value.pValue)}
);
}, [correlationFormat, format, value]);
return (
setIsHover(true)} onMouseLeave={() => setIsHover(false)}>
setIsHover(false)} label={label}>
{topRect}
setIsHover(false)} label={label}>
{bottomRect}
);
}