Исправлена работа TVD

This commit is contained in:
goodmice 2022-06-15 10:12:21 +05:00
parent 81961a92d0
commit 747f15095a

View File

@ -148,7 +148,7 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
) )
}, [idWell]) }, [idWell])
useEffect(() => { const chartData = useMemo(() => {
const withoutNpt = [] const withoutNpt = []
operations?.fact?.forEach((row) => { operations?.fact?.forEach((row) => {
if (row?.isNPT !== false) return if (row?.isNPT !== false) return
@ -160,39 +160,41 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
}) })
}) })
const data = { datasets: [ return { datasets: [
makeDataset(operations?.fact, 'Факт', '#0A0', 3), makeDataset(operations?.fact, 'Факт', '#0A0', 3),
makeDataset(operations?.predict, 'Прогноз', 'purple', 1, [7, 3]), makeDataset(operations?.predict, 'Прогноз', 'purple', 1, [7, 3]),
makeDataset(operations?.plan, 'План', '#F00', 3), makeDataset(operations?.plan, 'План', '#F00', 3),
makeDataset(withoutNpt, 'Факт без НПВ', '#00F', 3) makeDataset(withoutNpt, 'Факт без НПВ', '#00F', 3)
]} ]}
}, [operations])
if (chartRef.current && !chart) { useEffect(() => {
const thisOptions = {} if (!chartRef.current) return
Object.assign(thisOptions, defaultOptions) const options = {}
thisOptions.onClick = onPointClick Object.assign(options, defaultOptions)
thisOptions.scales.x = scaleTypes[xLabel]
thisOptions.parsing.xAxisKey = xLabel
const newChart = new Chart(chartRef.current, { const newChart = new Chart(chartRef.current, {
type: 'line', type: 'line',
plugins: [ChartDataLabels], plugins: [ChartDataLabels],
options: thisOptions, options: options,
data: data data: { datasets: [] },
}) })
setChart(newChart) setChart(newChart)
return () => chart?.destroy() return () => newChart?.destroy()
} else { }, [chartRef])
chart.data = data
useEffect(() => {
if (!chart) return
chart.data = chartData
chart.options.onClick = onPointClick
chart.options.scales.x = scaleTypes[xLabel] chart.options.scales.x = scaleTypes[xLabel]
chart.options.parsing.xAxisKey = xLabel chart.options.parsing.xAxisKey = xLabel
chart.update() chart.update()
// Обнуление ширины необходимо для уменьшения размена при resize после появления элементов // Обнуление ширины необходимо для уменьшения размена при resize после появления элементов
chart.canvas.parentNode.style.width = '0' chart.canvas.parentNode.style.width = '0'
chart.resize() chart.resize()
} }, [chart, chartData, xLabel, onPointClick])
}, [chart, operations, xLabel, onPointClick, other])
const toogleTable = useCallback(() => { const toogleTable = useCallback(() => {
setOperations(pre => ({ ...pre })) setOperations(pre => ({ ...pre }))