forked from ddrilling/asb_cloud_front
Исправлена ширина всплывающей подсказки на графике Телеметрия - Мониторинг
This commit is contained in:
parent
2dbc9720bb
commit
bc8dbaf113
@ -30,6 +30,25 @@ export type D3HorizontalCursorProps<DataType> = D3HorizontalCursorSettings<DataT
|
||||
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> = {
|
||||
stroke: 'black',
|
||||
}
|
||||
@ -85,6 +104,8 @@ const _D3HorizontalCursor = <DataType,>({
|
||||
const [tooltipY, setTooltipY] = useState(0)
|
||||
const [fixed, setFixed] = useState(false)
|
||||
const [lineY, setLineY] = useState(0)
|
||||
const [tooltipWidth, setTooltipWidth] = useState(width)
|
||||
const [fontSize, setFontSize] = useState(FontSize.inherit)
|
||||
|
||||
const lineStyle = usePartialProps(_lineStyle, defaultLineStyle)
|
||||
|
||||
@ -170,6 +191,24 @@ const _D3HorizontalCursor = <DataType,>({
|
||||
setTooltipBodies(bodies)
|
||||
}, [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 (
|
||||
<g
|
||||
ref={zoneRef}
|
||||
@ -178,9 +217,9 @@ const _D3HorizontalCursor = <DataType,>({
|
||||
{groups.map((_, i) => (
|
||||
<foreignObject
|
||||
key={`${i}`}
|
||||
width={width}
|
||||
width={tooltipWidth}
|
||||
height={height}
|
||||
x={sizes.groupLeft(i) + (sizes.groupWidth - width) / 2}
|
||||
x={sizes.groupLeft(i) + (sizes.groupWidth - tooltipWidth) / 2}
|
||||
y={tooltipY}
|
||||
opacity={fixed || mouseState.visible ? 1 : 0}
|
||||
pointerEvents={fixed ? 'all' : 'none'}
|
||||
@ -189,7 +228,7 @@ const _D3HorizontalCursor = <DataType,>({
|
||||
<div className={`tooltip ${position} ${className}`}
|
||||
style={{height: 'auto', bottom: `${position === 'bottom' ? '0' : ''}`}}
|
||||
>
|
||||
<div className={'tooltip-content'}>
|
||||
<div className={'tooltip-content'} style={{fontSize: fontSize}}>
|
||||
{tooltipBodies[i]}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -295,7 +295,7 @@ const TelemetryView = memo(() => {
|
||||
plugins={{
|
||||
menu: { enabled: false },
|
||||
cursor: {
|
||||
width: 220,
|
||||
width: 230,
|
||||
render: cursorRender,
|
||||
},
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user