From b2a8189ed8dbc77f8e1265af9b31e98667c348da Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Wed, 12 Jan 2022 23:51:39 +0500 Subject: [PATCH] =?UTF-8?q?TVD=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=BD=20*=20=D0=B2=20getOperations=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D0=B4=D0=BD?= =?UTF-8?q?=D1=8F=20=D1=81=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B0=20=D0=B1?= =?UTF-8?q?=D1=83=D1=80=D0=B5=D0=BD=D0=B8=D1=8F=20*=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=20=D0=B3=D0=BE=D1=80=D0=B8=D0=B7=D0=BE=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=BE=D1=81=D0=B8=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82=20=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D1=8C=20=D1=81=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B1=D1=83=D1=80=D0=B5=D0=BD=D0=B8=D1=8F=20*=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B7=D0=B8=D1=86=D0=B8=D1=8F=20tooltip=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20'nearest'=20*=20=D1=87=D0=B0=D1=81=D1=82=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B2=D0=B5=D1=80=D1=82=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BF=D0=BE=D0=BB=D0=BE=D1=81=20=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2?= =?UTF-8?q?=203=20=D0=B4=D0=BD=D1=8F=20*=20=D1=82=D0=B8=D0=BF=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=82=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BE=D1=81=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=91=D0=BD=20=D0=BD=D0=B0=20'linear'=20=D1=81=20min=200=20*?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=20ChartTvD=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=D1=91=D0=BD=20=D0=B2=20Tvd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Cluster/functions.jsx | 3 +- src/pages/WellOperations/ChartTvD.jsx | 133 ------------------------ src/pages/WellOperations/Tvd.jsx | 140 ++++++++++++++++++++++---- 3 files changed, 125 insertions(+), 151 deletions(-) delete mode 100644 src/pages/WellOperations/ChartTvD.jsx diff --git a/src/pages/Cluster/functions.jsx b/src/pages/Cluster/functions.jsx index a817859..6b40102 100644 --- a/src/pages/Cluster/functions.jsx +++ b/src/pages/Cluster/functions.jsx @@ -13,7 +13,8 @@ export const getOperations = async (idWell) => { const convert = wellOperationDto => ({ key: wellOperationDto?.id, depth: wellOperationDto?.depthStart, - date: wellOperationDto?.dateStart + date: wellOperationDto?.dateStart, + day: wellOperationDto?.day, }) const planData = ops diff --git a/src/pages/WellOperations/ChartTvD.jsx b/src/pages/WellOperations/ChartTvD.jsx deleted file mode 100644 index 499484f..0000000 --- a/src/pages/WellOperations/ChartTvD.jsx +++ /dev/null @@ -1,133 +0,0 @@ -import {useEffect, useRef, useState} from 'react'; -import { - Chart, - TimeScale, - LinearScale, - Legend, - LineController, - PointElement, - LineElement -} from 'chart.js' -import 'chartjs-adapter-moment'; -import ChartDataLabels from 'chartjs-plugin-datalabels'; -import zoomPlugin from 'chartjs-plugin-zoom'; - -Chart.register(TimeScale, LinearScale, LineController, LineElement, PointElement, Legend, ChartDataLabels, zoomPlugin); - -const defaultOptions = { - responsive: true, - aspectRatio: 2.6, - interaction: { - intersect: false, - mode: 'index', - }, - scales: { - x:{ - display: true, - title: { - display: true - }, - type: 'time', - time: { - unit: 'hour', - displayFormats: { - 'hour': 'MM.DD' - } - }, - grid:{ - drawTicks: true, - }, - ticks: { - stepSize:3, - major:{enabled:true,}, - z: 1, - display : true, - textStrokeColor : "#fff", - textStrokeWidth : 2, - color:"#000", - } - }, - - y:{ - type:'linear', - position:'top', - reverse:true, - display: true, - title: { - display: false, - text: '' - }, - } - }, - parsing: { - xAxisKey: 'date', - yAxisKey: 'depth' - }, - elements:{ - point:{ - radius:1.7, - //backgroundColor:'#aaa', - //pointStyle:'triangle', - }, - }, - plugins:{ - legend:{ - display: true, - }, - datalabels: { - display: false, - }, - tooltip: { - enabled: true, - callbacks: { - label(tooltipItem) { - return tooltipItem.yLabel; - } - } - }, - } -} - -const makeDataset = (data, label, color, width=1.5, dash) => ({ - label: label, - data: data, - backgroundColor: color, - borderColor: color, - borderWidth: width, - borderDash: dash, -}) - -export default function ChartTvD({dataPlan, dataFact, dataPredict}) { - const chartRef = useRef(null) - const [chart, setChart] = useState() - - useEffect(() => { - let data = { - datasets: [ - makeDataset(dataFact, 'Факт', '#0A0'), - makeDataset(dataPredict, 'Прогноз', 'purple', 1, [7,3]), - makeDataset(dataPlan, 'План', '#C004', 4), - ] - } - - if((chartRef.current)&&(!chart)) { - let thisOptions = {} - Object.assign(thisOptions, defaultOptions) - - let newChart = new Chart(chartRef.current, { - type: 'line', - plugins: [ChartDataLabels], - options: thisOptions, - data: data - }) - setChart(newChart) - - return () => chart?.destroy() - } else { - chart.data = data - chart.update() - } - }, [chart, dataPlan, dataFact, dataPredict]) - - return () -} \ No newline at end of file diff --git a/src/pages/WellOperations/Tvd.jsx b/src/pages/WellOperations/Tvd.jsx index 3045dbf..6f34c34 100644 --- a/src/pages/WellOperations/Tvd.jsx +++ b/src/pages/WellOperations/Tvd.jsx @@ -1,43 +1,149 @@ -import ChartTvD from './ChartTvD' -import { useState, useEffect } from 'react' +import { memo, useState, useRef, useEffect } from 'react' + +import { + Chart, + TimeScale, + LinearScale, + Legend, + LineController, + PointElement, + LineElement +} from 'chart.js' +import 'chartjs-adapter-moment' +import zoomPlugin from 'chartjs-plugin-zoom' +import ChartDataLabels from 'chartjs-plugin-datalabels' + import { invokeWebApiWrapperAsync } from '../../components/factory' import { getOperations } from '../Cluster/functions' import LoaderPortal from '../../components/LoaderPortal' +Chart.register(TimeScale, LinearScale, LineController, LineElement, PointElement, Legend, ChartDataLabels, zoomPlugin) -export const Tvd = ({ idWell, title }) => { - const [dataPlan, setDataPlan] = useState([]) - const [dataFact, setDataFact] = useState([]) - const [dataPredict, setDataPredict] = useState([]) +const defaultOptions = { + responsive: true, + aspectRatio: 2.6, + interaction: { + intersect: false, + mode: 'index', + }, + scales: { + x: { + min: 0, + type: 'linear', + display: true, + title: { + display: false, + text: '', + }, + ticks: { + stepSize: 1, + } + }, + + y:{ + type: 'linear', + position: 'top', + reverse: true, + display: true, + title: { + display: false, + text: '', + } + } + }, + parsing: { + xAxisKey: 'day', + yAxisKey: 'depth', + }, + elements: { + point: { + radius: 1.7, + //backgroundColor:'#aaa', + //pointStyle:'triangle', + }, + }, + plugins: { + legend: { + display: true, + }, + datalabels: { + display: false, + }, + tooltip: { + enabled: true, + callbacks: { + label: (tooltipItem) => tooltipItem.yLabel, + }, + position: 'nearest', + }, + } +} + +const makeDataset = (data, label, color, borderWidth = 1.5, borderDash) => ({ + label, + data, + backgroundColor: color, + borderColor: color, + borderWidth, + borderDash, +}) + +export const Tvd = memo(({ idWell, title }) => { + const [operations, setOperations] = useState([]) const [showLoader, setShowLoader] = useState(false) + const [chart, setChart] = useState() + + const chartRef = useRef(null) useEffect(() => { invokeWebApiWrapperAsync( async () => { const operations = await getOperations(idWell) - setDataPlan(operations.plan) - setDataFact(operations.fact) - setDataPredict(operations.predict) + setOperations(operations) }, setShowLoader, `Не удалось загрузить операции по скважине "${idWell}"`, ) }, [idWell]) + useEffect(() => { + const data = { + datasets: [ + makeDataset(operations?.fact, 'Факт', '#0A0'), + makeDataset(operations?.predict, 'Прогноз', 'purple', 1, [7, 3]), + makeDataset(operations?.plan, 'План', '#C004', 4), + ] + } + + if (chartRef.current && !chart) { + const thisOptions = {} + Object.assign(thisOptions, defaultOptions) + + const newChart = new Chart(chartRef.current, { + type: 'line', + plugins: [ChartDataLabels], + options: thisOptions, + data: data + }) + setChart(newChart) + + return () => chart?.destroy() + } else { + chart.data = data + chart.update() + } + }, [chart, operations]) + return ( -
+
- {title ? title : ( + {title || (

График Глубина-день

)} - +
) -} +})