Исправлена ширина всплывающей подсказки на графике Телеметрия - Мониторинг

This commit is contained in:
ts_salikhov 2022-09-05 17:17:39 +04:00
parent 2dbc9720bb
commit bc8dbaf113
2 changed files with 43 additions and 4 deletions

View File

@ -30,6 +30,25 @@ export type D3HorizontalCursorProps<DataType> = D3HorizontalCursorSettings<DataT
yAxis?: d3.ScaleTime<number, number> yAxis?: d3.ScaleTime<number, number>
} }
enum FontSize {
inherit = 'inherit',
large = '10px',
medium = '8px',
small = '7px',
}
enum TooltipWidth {
large = 190,
medium = 160,
small = 140,
}
enum InnerWidth {
large = 1800,
medium = 1600,
small = 1400,
}
const defaultLineStyle: SVGProps<SVGLineElement> = { const defaultLineStyle: SVGProps<SVGLineElement> = {
stroke: 'black', stroke: 'black',
} }
@ -85,6 +104,8 @@ const _D3HorizontalCursor = <DataType,>({
const [tooltipY, setTooltipY] = useState(0) const [tooltipY, setTooltipY] = useState(0)
const [fixed, setFixed] = useState(false) const [fixed, setFixed] = useState(false)
const [lineY, setLineY] = useState(0) const [lineY, setLineY] = useState(0)
const [tooltipWidth, setTooltipWidth] = useState(width)
const [fontSize, setFontSize] = useState(FontSize.inherit)
const lineStyle = usePartialProps(_lineStyle, defaultLineStyle) const lineStyle = usePartialProps(_lineStyle, defaultLineStyle)
@ -170,6 +191,24 @@ const _D3HorizontalCursor = <DataType,>({
setTooltipBodies(bodies) setTooltipBodies(bodies)
}, [groups, data, yAxis, lineY, fixed, mouseState.visible]) }, [groups, data, yAxis, lineY, fixed, mouseState.visible])
useEffect(() => {
const innerWidth = window.innerWidth
if (innerWidth < InnerWidth.small) {
setTooltipWidth(TooltipWidth.small)
setFontSize(FontSize.small)
} else if (innerWidth < InnerWidth.medium) {
setTooltipWidth(TooltipWidth.medium)
setFontSize(FontSize.medium)
} else if (innerWidth < InnerWidth.large) {
setTooltipWidth(TooltipWidth.large)
setFontSize(FontSize.large)
} else {
setTooltipWidth(width)
setFontSize(FontSize.inherit)
}
}, [window.innerWidth])
return ( return (
<g <g
ref={zoneRef} ref={zoneRef}
@ -178,9 +217,9 @@ const _D3HorizontalCursor = <DataType,>({
{groups.map((_, i) => ( {groups.map((_, i) => (
<foreignObject <foreignObject
key={`${i}`} key={`${i}`}
width={width} width={tooltipWidth}
height={height} height={height}
x={sizes.groupLeft(i) + (sizes.groupWidth - width) / 2} x={sizes.groupLeft(i) + (sizes.groupWidth - tooltipWidth) / 2}
y={tooltipY} y={tooltipY}
opacity={fixed || mouseState.visible ? 1 : 0} opacity={fixed || mouseState.visible ? 1 : 0}
pointerEvents={fixed ? 'all' : 'none'} pointerEvents={fixed ? 'all' : 'none'}
@ -189,7 +228,7 @@ const _D3HorizontalCursor = <DataType,>({
<div className={`tooltip ${position} ${className}`} <div className={`tooltip ${position} ${className}`}
style={{height: 'auto', bottom: `${position === 'bottom' ? '0' : ''}`}} style={{height: 'auto', bottom: `${position === 'bottom' ? '0' : ''}`}}
> >
<div className={'tooltip-content'}> <div className={'tooltip-content'} style={{fontSize: fontSize}}>
{tooltipBodies[i]} {tooltipBodies[i]}
</div> </div>
</div> </div>

View File

@ -295,7 +295,7 @@ const TelemetryView = memo(() => {
plugins={{ plugins={{
menu: { enabled: false }, menu: { enabled: false },
cursor: { cursor: {
width: 220, width: 230,
render: cursorRender, render: cursorRender,
}, },
}} }}