forked from ddrilling/asb_cloud_front
CF2-1: Добавлены отметки глубины для графика 'Положение блока'
This commit is contained in:
parent
b53a1c667c
commit
bb0b3527b3
@ -11,7 +11,7 @@
|
|||||||
"antd": "^4.15.0",
|
"antd": "^4.15.0",
|
||||||
"chart.js": "^3.0.2",
|
"chart.js": "^3.0.2",
|
||||||
"chartjs-adapter-date-fns": "^1.1.0-beta.1",
|
"chartjs-adapter-date-fns": "^1.1.0-beta.1",
|
||||||
"chartjs-plugin-datalabels": "^2.0.0-beta.1",
|
"chartjs-plugin-datalabels": "^2.0.0-rc.1",
|
||||||
"craco-less": "^1.17.1",
|
"craco-less": "^1.17.1",
|
||||||
"date-fns": "^2.20.0",
|
"date-fns": "^2.20.0",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
|
@ -63,6 +63,7 @@ export const ChartTimeArchive: React.FC<ChartTimeProps> = (props) => {
|
|||||||
let points = props.data.map(dataItem => {
|
let points = props.data.map(dataItem => {
|
||||||
return {
|
return {
|
||||||
x: dataItem[lineCfg.xAccessorName],
|
x: dataItem[lineCfg.xAccessorName],
|
||||||
|
label:0,
|
||||||
y: new Date(dataItem[lineCfg.yAccessorName])
|
y: new Date(dataItem[lineCfg.yAccessorName])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -11,8 +11,9 @@ import {
|
|||||||
ChartTypeRegistry,
|
ChartTypeRegistry,
|
||||||
ChartOptions} from 'chart.js'
|
ChartOptions} from 'chart.js'
|
||||||
import 'chartjs-adapter-date-fns';
|
import 'chartjs-adapter-date-fns';
|
||||||
|
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
||||||
|
|
||||||
Chart.register( TimeScale, LinearScale, LineController, LineElement, PointElement, Legend );
|
Chart.register( TimeScale, LinearScale, LineController, LineElement, PointElement, Legend, ChartDataLabels );
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
//maintainAspectRatio: false,
|
//maintainAspectRatio: false,
|
||||||
@ -61,15 +62,11 @@ const defaultOptions = {
|
|||||||
hoverRadius:5,
|
hoverRadius:5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins:{
|
|
||||||
legend:{
|
|
||||||
display: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChartTimeData = ChartData<keyof ChartTypeRegistry, {
|
export type ChartTimeData = ChartData<keyof ChartTypeRegistry, {
|
||||||
x: number;
|
x: number;
|
||||||
|
label: number;
|
||||||
y: Date;
|
y: Date;
|
||||||
}[], unknown>
|
}[], unknown>
|
||||||
|
|
||||||
@ -82,7 +79,8 @@ export type ChartTimeDataParams = {
|
|||||||
|
|
||||||
export type ChartTimeBaseProps = {
|
export type ChartTimeBaseProps = {
|
||||||
dataParams: ChartTimeDataParams,
|
dataParams: ChartTimeDataParams,
|
||||||
options?: ChartOptions<keyof ChartTypeRegistry>,
|
// TODO: Create good type for options
|
||||||
|
options?: ChartOptions<keyof ChartTypeRegistry> | any,
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeUnitByInterval = (intervalSec:number):String =>{
|
const timeUnitByInterval = (intervalSec:number):String =>{
|
||||||
@ -109,7 +107,8 @@ export const ChartTimeBase: React.FC<ChartTimeBaseProps> = (props) => {
|
|||||||
Object.assign(thisOptions, defaultOptions, props.options)
|
Object.assign(thisOptions, defaultOptions, props.options)
|
||||||
|
|
||||||
let newChart = new Chart(chartRef.current, {
|
let newChart = new Chart(chartRef.current, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
|
plugins: [ChartDataLabels],
|
||||||
options: thisOptions,
|
options: thisOptions,
|
||||||
data: props.dataParams.data
|
data: props.dataParams.data
|
||||||
})
|
})
|
||||||
|
@ -19,6 +19,7 @@ function GetOrCreateDatasetByLineConfig (data: ChartTimeData, lineConfig: LineC
|
|||||||
borderColor: lineConfig.borderColor ?? color,
|
borderColor: lineConfig.borderColor ?? color,
|
||||||
borderWidth: lineConfig.borderWidth ?? 1,
|
borderWidth: lineConfig.borderWidth ?? 1,
|
||||||
borderDash: lineConfig.dash ?? [],
|
borderDash: lineConfig.dash ?? [],
|
||||||
|
showLine: lineConfig.showLine,
|
||||||
}
|
}
|
||||||
data.datasets.push(dataset);
|
data.datasets.push(dataset);
|
||||||
}
|
}
|
||||||
@ -37,6 +38,8 @@ export type LineConfig = {
|
|||||||
borderWidth?: number
|
borderWidth?: number
|
||||||
dash?:number[]
|
dash?:number[]
|
||||||
labels?: any[]
|
labels?: any[]
|
||||||
|
showLine: boolean
|
||||||
|
xConstValue?: number|null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChartTimeProps = {
|
export type ChartTimeProps = {
|
||||||
@ -64,7 +67,8 @@ export const ChartTimeOnline: React.FC<ChartTimeProps> = (props) => {
|
|||||||
props.lines.forEach(lineCfg => {
|
props.lines.forEach(lineCfg => {
|
||||||
let dataset = GetOrCreateDatasetByLineConfig(preDataParams.data, lineCfg)
|
let dataset = GetOrCreateDatasetByLineConfig(preDataParams.data, lineCfg)
|
||||||
let points = props.data.map(dataItem => {return{
|
let points = props.data.map(dataItem => {return{
|
||||||
x: dataItem[lineCfg.xAccessorName],
|
x: lineCfg.xConstValue ?? dataItem[lineCfg.xAccessorName],
|
||||||
|
label: dataItem[lineCfg.xAccessorName],
|
||||||
y: new Date(dataItem[lineCfg.yAccessorName])}
|
y: new Date(dataItem[lineCfg.yAccessorName])}
|
||||||
})
|
})
|
||||||
//dataset.data = [ ...dataset.data, ...points,].slice(-1024)
|
//dataset.data = [ ...dataset.data, ...points,].slice(-1024)
|
||||||
@ -75,7 +79,7 @@ export const ChartTimeOnline: React.FC<ChartTimeProps> = (props) => {
|
|||||||
data.splice(0, (1024 - data.length))
|
data.splice(0, (1024 - data.length))
|
||||||
dataset.data = data;
|
dataset.data = data;
|
||||||
});
|
});
|
||||||
|
|
||||||
preDataParams.yStart = new Date()
|
preDataParams.yStart = new Date()
|
||||||
preDataParams.yStart.setSeconds(preDataParams.yStart.getSeconds() - props.interval)
|
preDataParams.yStart.setSeconds(preDataParams.yStart.getSeconds() - props.interval)
|
||||||
preDataParams.yInterval = props.interval
|
preDataParams.yInterval = props.interval
|
||||||
@ -85,6 +89,31 @@ export const ChartTimeOnline: React.FC<ChartTimeProps> = (props) => {
|
|||||||
|
|
||||||
}, [ props.data, props.lines, props.interval, props.yDisplay])
|
}, [ props.data, props.lines, props.interval, props.yDisplay])
|
||||||
|
|
||||||
return(<ChartTimeBase dataParams = {dataParams} />)
|
const chartPluginsOptions = {
|
||||||
|
plugins:{
|
||||||
|
legend:{
|
||||||
|
display: false,
|
||||||
|
},
|
||||||
|
datalabels: {
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
borderRadius: 4,
|
||||||
|
color: '#000B',
|
||||||
|
display: function(context:any) {
|
||||||
|
return context.dataset.label === 'wellDepth'
|
||||||
|
? 'auto'
|
||||||
|
: false
|
||||||
|
},
|
||||||
|
formatter: function(value: any, context: any) {
|
||||||
|
return `${value.y.toLocaleTimeString()} ${value.label.toPrecision(4)}`
|
||||||
|
},
|
||||||
|
padding: 6,
|
||||||
|
align: 'left',
|
||||||
|
anchor: 'center',
|
||||||
|
clip: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return(<ChartTimeBase dataParams = {dataParams} options = { chartPluginsOptions } />)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ const dash = [7, 3]
|
|||||||
const blockHeightGroup = {
|
const blockHeightGroup = {
|
||||||
label: "Высота блока",
|
label: "Высота блока",
|
||||||
yDisplay: false,
|
yDisplay: false,
|
||||||
linePv: { label: "blockHeight", units: 'м', xAccessorName: "blockHeight", yAccessorName: "date", color: '#333' },
|
linePv: { label: "blockPosition", units: 'м', xAccessorName: "blockPosition", yAccessorName: "date", color: '#333' },
|
||||||
|
lineOther: { label: "wellDepth", units: 'м', xAccessorName: "wellDepth", yAccessorName: "date", color: '#333', showLine: false, xConstValue:30 },
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockSpeedGroup = {
|
const blockSpeedGroup = {
|
||||||
@ -84,6 +85,9 @@ export const Column = ({ lineGroup, data, interval }) => {
|
|||||||
if (lineGroup.lineSp)
|
if (lineGroup.lineSp)
|
||||||
lines.push(lineGroup.lineSp)
|
lines.push(lineGroup.lineSp)
|
||||||
|
|
||||||
|
if (lineGroup.lineOther)
|
||||||
|
lines.push(lineGroup.lineOther)
|
||||||
|
|
||||||
let dataLast = null
|
let dataLast = null
|
||||||
let pv = null
|
let pv = null
|
||||||
if (data?.length > 0) {
|
if (data?.length > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user