forked from ddrilling/asb_cloud_front
Исправлена ошибка отображения регуляторов
This commit is contained in:
parent
3216a90af3
commit
fc91cfc6ff
@ -242,7 +242,7 @@ const _D3MonitoringCharts = <DataType extends Record<string, unknown>>({
|
|||||||
if (!data) return
|
if (!data) return
|
||||||
|
|
||||||
const yAxis = d3.scaleTime()
|
const yAxis = d3.scaleTime()
|
||||||
.domain([yDomain?.min ?? 0, yDomain?.max ?? 0])
|
.domain([yDomain?.min || 0, yDomain?.max || 0])
|
||||||
.range([0, sizes.chartsHeight])
|
.range([0, sizes.chartsHeight])
|
||||||
|
|
||||||
return yAxis
|
return yAxis
|
||||||
@ -453,7 +453,7 @@ const _D3MonitoringCharts = <DataType extends Record<string, unknown>>({
|
|||||||
.tickSize(yTicks.visible ? -width + offset.left + offset.right : 0)
|
.tickSize(yTicks.visible ? -width + offset.left + offset.right : 0)
|
||||||
.ticks(yTicks.count) as any // TODO: Исправить тип
|
.ticks(yTicks.count) as any // TODO: Исправить тип
|
||||||
)
|
)
|
||||||
|
|
||||||
yAxisArea().selectAll('.tick line').attr('stroke', yTicks.color)
|
yAxisArea().selectAll('.tick line').attr('stroke', yTicks.color)
|
||||||
}, [yAxisArea, yAxis, animDurationMs, width, offset, yTicks])
|
}, [yAxisArea, yAxis, animDurationMs, width, offset, yTicks])
|
||||||
|
|
||||||
@ -463,8 +463,8 @@ const _D3MonitoringCharts = <DataType extends Record<string, unknown>>({
|
|||||||
groups.forEach((group, i) => {
|
groups.forEach((group, i) => {
|
||||||
group()
|
group()
|
||||||
.attr('transform', `translate(${sizes.groupLeft(group.key)}, 0)`)
|
.attr('transform', `translate(${sizes.groupLeft(group.key)}, 0)`)
|
||||||
.attr('clip-path', `url(#chart-clip)`)
|
.attr('clip-path', `url(#chart-group-clip)`)
|
||||||
|
|
||||||
group.charts.forEach((chart) => {
|
group.charts.forEach((chart) => {
|
||||||
chart()
|
chart()
|
||||||
.attr('color', chart.color || null)
|
.attr('color', chart.color || null)
|
||||||
@ -506,7 +506,7 @@ const _D3MonitoringCharts = <DataType extends Record<string, unknown>>({
|
|||||||
chart.afterDraw?.(chart)
|
chart.afterDraw?.(chart)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, [data, groups, height, offset, sizes, chartDomains])
|
}, [data, groups, height, offset, sizes, chartDomains, yAxis])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoaderPortal
|
<LoaderPortal
|
||||||
@ -530,7 +530,7 @@ const _D3MonitoringCharts = <DataType extends Record<string, unknown>>({
|
|||||||
>
|
>
|
||||||
<svg ref={setSvgRef} width={'100%'} height={'100%'}>
|
<svg ref={setSvgRef} width={'100%'} height={'100%'}>
|
||||||
<defs>
|
<defs>
|
||||||
<clipPath id={`chart-clip`}>
|
<clipPath id={`chart-group-clip`}>
|
||||||
{/* Сдвиг во все стороны на 1 px чтобы линии на краях было видно */}
|
{/* Сдвиг во все стороны на 1 px чтобы линии на краях было видно */}
|
||||||
<rect x={-1} y={-1} width={sizes.groupWidth + 2} height={sizes.chartsHeight + 2} />
|
<rect x={-1} y={-1} width={sizes.groupWidth + 2} height={sizes.chartsHeight + 2} />
|
||||||
</clipPath>
|
</clipPath>
|
||||||
|
@ -92,6 +92,15 @@ const _D3MonitoringLimitChart = <DataType extends TelemetryDataSaubDto>({
|
|||||||
const [ref, setRef] = useState<SVGGElement | null>(null)
|
const [ref, setRef] = useState<SVGGElement | null>(null)
|
||||||
const [selected, setSelected] = useState<LimitChartData & { x: number, y: number, visible: boolean }>()
|
const [selected, setSelected] = useState<LimitChartData & { x: number, y: number, visible: boolean }>()
|
||||||
|
|
||||||
|
const selectedRegulator = useMemo(() => {
|
||||||
|
if (!selected) return null
|
||||||
|
const out = regulators[selected.id] || {
|
||||||
|
label: `ID = ${selected.id}`,
|
||||||
|
color: 'black',
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}, [selected, regulators])
|
||||||
|
|
||||||
const data = useMemo(() => calcualteData(chartData), [chartData])
|
const data = useMemo(() => calcualteData(chartData), [chartData])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -105,7 +114,7 @@ const _D3MonitoringLimitChart = <DataType extends TelemetryDataSaubDto>({
|
|||||||
.attr('width', width)
|
.attr('width', width)
|
||||||
.attr('height', (d) => Math.max(yAxis(d.dateEnd) - yAxis(d.dateStart), 1))
|
.attr('height', (d) => Math.max(yAxis(d.dateEnd) - yAxis(d.dateStart), 1))
|
||||||
.attr('y', (d) => yAxis(d.dateStart))
|
.attr('y', (d) => yAxis(d.dateStart))
|
||||||
.attr('fill', (d) => regulators[d.id].color)
|
.attr('fill', (d) => regulators[d.id]?.color || 'black')
|
||||||
.on('mouseover', (_, d) => {
|
.on('mouseover', (_, d) => {
|
||||||
const y = yAxis(d.dateStart) - tooltipHeight
|
const y = yAxis(d.dateStart) - tooltipHeight
|
||||||
setSelected({ ...d, y, x: -tooltipWidth - 10, visible: true })
|
setSelected({ ...d, y, x: -tooltipWidth - 10, visible: true })
|
||||||
@ -130,14 +139,24 @@ const _D3MonitoringLimitChart = <DataType extends TelemetryDataSaubDto>({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<g transform={`translate(${left}, ${top})`} stroke={'#333'} strokeWidth={1} fill={'none'}>
|
<g transform={`translate(${left}, ${top})`} stroke={'#333'} strokeWidth={1} fill={'none'}>
|
||||||
<g ref={setRef} >
|
<defs>
|
||||||
<g className={'bars'} strokeWidth={0} />
|
<clipPath id={`chart-limit-clip`}>
|
||||||
|
{/* Сдвиг во все стороны на 1 px чтобы линии на краях было видно */}
|
||||||
|
<rect x={0} y={0} width={width} height={height} />
|
||||||
|
</clipPath>
|
||||||
|
<clipPath id={`chart-limit-fill-clip`}>
|
||||||
|
<rect x={-zoneWidth} y={0} width={zoneWidth} height={height} />
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
<g ref={setRef}>
|
||||||
|
<g className={'bars'} strokeWidth={0} clipPath={`url(#chart-limit-clip)`} />
|
||||||
{selected && (
|
{selected && (
|
||||||
<g
|
<g
|
||||||
style={opacityStyle}
|
style={opacityStyle}
|
||||||
pointerEvents={'none'}
|
pointerEvents={'none'}
|
||||||
strokeOpacity={0.4}
|
strokeOpacity={0.4}
|
||||||
stroke={regulators[selected.id].color}
|
stroke={selectedRegulator?.color}
|
||||||
|
clipPath={`url(#chart-limit-fill-clip)`}
|
||||||
>
|
>
|
||||||
<line x1={-zoneWidth} x2={0} y1={zoneY1} y2={zoneY1} />
|
<line x1={-zoneWidth} x2={0} y1={zoneY1} y2={zoneY1} />
|
||||||
<line x1={-zoneWidth} x2={0} y1={zoneY2} y2={zoneY2} />
|
<line x1={-zoneWidth} x2={0} y1={zoneY2} y2={zoneY2} />
|
||||||
@ -148,7 +167,7 @@ const _D3MonitoringLimitChart = <DataType extends TelemetryDataSaubDto>({
|
|||||||
y={zoneY1}
|
y={zoneY1}
|
||||||
width={zoneWidth}
|
width={zoneWidth}
|
||||||
height={zoneY2 - zoneY1}
|
height={zoneY2 - zoneY1}
|
||||||
fill={regulators[selected.id].color}
|
fill={selectedRegulator?.color}
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
)}
|
)}
|
||||||
@ -158,7 +177,7 @@ const _D3MonitoringLimitChart = <DataType extends TelemetryDataSaubDto>({
|
|||||||
<foreignObject width={tooltipWidth} height={tooltipHeight} x={selected.x} y={selected.y} pointerEvents={'none'}>
|
<foreignObject width={tooltipWidth} height={tooltipHeight} x={selected.x} y={selected.y} pointerEvents={'none'}>
|
||||||
<div className={'tooltip bottom'} style={tooltipStyle}>
|
<div className={'tooltip bottom'} style={tooltipStyle}>
|
||||||
<span>Ограничивающий параметр</span>
|
<span>Ограничивающий параметр</span>
|
||||||
<span>{regulators[selected.id].label}</span>
|
<span>{selectedRegulator?.label}</span>
|
||||||
<Grid style={{ margin: 0, padding: 0 }}>
|
<Grid style={{ margin: 0, padding: 0 }}>
|
||||||
<GridItem row={1} col={1}>Начало:</GridItem>
|
<GridItem row={1} col={1}>Начало:</GridItem>
|
||||||
<GridItem row={1} col={2}>{formatDate(selected.dateStart)}</GridItem>
|
<GridItem row={1} col={2}>{formatDate(selected.dateStart)}</GridItem>
|
||||||
|
Loading…
Reference in New Issue
Block a user