From a273d82430e94a19697943c2352582ea61992450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Thu, 19 Aug 2021 17:52:38 +0500 Subject: [PATCH] Add dummy tvd --- src/pages/WellOperations/Tvd.jsx | 143 +++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/pages/WellOperations/Tvd.jsx diff --git a/src/pages/WellOperations/Tvd.jsx b/src/pages/WellOperations/Tvd.jsx new file mode 100644 index 0000000..43bced7 --- /dev/null +++ b/src/pages/WellOperations/Tvd.jsx @@ -0,0 +1,143 @@ +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' +import { invokeWebApiWrapper } from '../../components/factory' +import LoaderPortal from '../../components/LoaderPortal' +//import { TvdService} from '../../services/api' + +Chart.register(TimeScale, LinearScale, LineController, LineElement, PointElement, Legend, ChartDataLabels, zoomPlugin) + +const defaultOptions = { + responsive: true, + aspectRatio: 2.35, + interaction: { + intersect: false, + mode: 'index', + }, + scales: { + x:{ + display: true, + title: { + display: true + }, + type: 'linear', // был 'time' + его конфиг ниже + grid:{ + drawTicks: true, + }, + ticks: { + //count:24, + 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: true, + text: 'Value' + }, + } + }, + parsing: { + xAxisKey: 'date', + yAxisKey: 'depth' + }, + elements:{ + point:{ + radius:1.7, + }, + }, + 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 const Tvd = ({idWell}) =>{ + const chartRef = useRef(null) + const [chart, setChart] = useState() + const [data, setData] = useState({datasets: []}) + const [showLoader, setShowLoader] = useState(false) + + useEffect(() => invokeWebApiWrapper( + async() => { + const dataPlan = [] + const dataFact = [] + const dataPredict = [] + const data = { + datasets: [ + makeDataset(dataPlan, 'План', '#C004', 4), + makeDataset(dataFact, 'Факт', '#0A0'), + makeDataset(dataPredict, 'Прогноз', 'purple', 1, [7,3]), + ] + } + setData(data) + }, + setShowLoader, + `Не удалось загрузить данные TVD по скважине ${idWell}`), + [idWell]) + + useEffect(() => { + 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, data]) + + return + + +} \ No newline at end of file