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

This commit is contained in:
ts_salikhov 2022-09-06 10:34:52 +04:00
parent bc8dbaf113
commit 2a490243d7
2 changed files with 34 additions and 41 deletions

View File

@ -30,24 +30,6 @@ 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',
@ -104,8 +86,6 @@ 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)
@ -191,24 +171,6 @@ 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}
@ -217,9 +179,9 @@ const _D3HorizontalCursor = <DataType,>({
{groups.map((_, i) => ( {groups.map((_, i) => (
<foreignObject <foreignObject
key={`${i}`} key={`${i}`}
width={tooltipWidth} width={width}
height={height} height={height}
x={sizes.groupLeft(i) + (sizes.groupWidth - tooltipWidth) / 2} x={sizes.groupLeft(i) + (sizes.groupWidth - width) / 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'}
@ -228,7 +190,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'} style={{fontSize: fontSize}}> <div className={'tooltip-content'}>
{tooltipBodies[i]} {tooltipBodies[i]}
</div> </div>
</div> </div>

View File

@ -9,6 +9,10 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
left: 0;
right: 0;
margin: 0 auto;
font-size: 13px; font-size: 13px;
color: @color; color: @color;
@ -110,3 +114,30 @@
height: 100%; height: 100%;
} }
} }
@media (max-width: 1800px) {
.asb-d3-chart {
& .tooltip {
width: 190px;
font-size: 10px;
}
}
}
@media (max-width: 1600px) {
.asb-d3-chart {
& .tooltip {
width: 160px;
font-size: 8px;
}
}
}
@media (max-width: 1400px) {
.asb-d3-chart {
& .tooltip {
width: 140px;
font-size: 7px;
}
}
}