forked from ddrilling/asb_cloud_front
* Исправлено отображение тултипов
* Добавлен фильтр по уникальным значениям (не глубокое сравнение)
This commit is contained in:
parent
2ac12e026a
commit
c2338c98ab
@ -10,7 +10,8 @@ import {
|
|||||||
ChartData,
|
ChartData,
|
||||||
ChartOptions,
|
ChartOptions,
|
||||||
ChartType,
|
ChartType,
|
||||||
ChartDataset
|
ChartDataset,
|
||||||
|
Tooltip
|
||||||
} from 'chart.js'
|
} from 'chart.js'
|
||||||
import 'chartjs-adapter-moment'
|
import 'chartjs-adapter-moment'
|
||||||
import ChartDataLabels from 'chartjs-plugin-datalabels'
|
import ChartDataLabels from 'chartjs-plugin-datalabels'
|
||||||
@ -24,7 +25,8 @@ Chart.register(
|
|||||||
PointElement,
|
PointElement,
|
||||||
Legend,
|
Legend,
|
||||||
ChartDataLabels,
|
ChartDataLabels,
|
||||||
zoomPlugin
|
zoomPlugin,
|
||||||
|
Tooltip,
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultOptions: ChartOptions = {
|
const defaultOptions: ChartOptions = {
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
Legend,
|
Legend,
|
||||||
LineController,
|
LineController,
|
||||||
PointElement,
|
PointElement,
|
||||||
LineElement
|
LineElement,
|
||||||
|
Tooltip
|
||||||
} from 'chart.js'
|
} from 'chart.js'
|
||||||
import 'chartjs-adapter-moment'
|
import 'chartjs-adapter-moment'
|
||||||
import zoomPlugin from 'chartjs-plugin-zoom'
|
import zoomPlugin from 'chartjs-plugin-zoom'
|
||||||
@ -27,6 +28,7 @@ import AdditionalTables from './AdditionalTables'
|
|||||||
|
|
||||||
import '@styles/index.css'
|
import '@styles/index.css'
|
||||||
import '@styles/tvd.less'
|
import '@styles/tvd.less'
|
||||||
|
import { unique } from '@asb/utils/filters'
|
||||||
|
|
||||||
Chart.register(
|
Chart.register(
|
||||||
TimeScale,
|
TimeScale,
|
||||||
@ -36,7 +38,8 @@ Chart.register(
|
|||||||
PointElement,
|
PointElement,
|
||||||
Legend,
|
Legend,
|
||||||
ChartDataLabels,
|
ChartDataLabels,
|
||||||
zoomPlugin
|
zoomPlugin,
|
||||||
|
Tooltip,
|
||||||
)
|
)
|
||||||
|
|
||||||
const numericRender = (value) => Number.isFinite(value) ? (+value).toFixed(2) : '-'
|
const numericRender = (value) => Number.isFinite(value) ? (+value).toFixed(2) : '-'
|
||||||
@ -135,7 +138,7 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
|
|||||||
if (typeof datasetId === 'undefined') return
|
if (typeof datasetId === 'undefined') return
|
||||||
|
|
||||||
const datasetName = datasetId === 2 ? 'plan' : 'fact'
|
const datasetName = datasetId === 2 ? 'plan' : 'fact'
|
||||||
const ids = points.filter((p) => p?.raw?.id).map((p) => p.raw.id).join(',')
|
const ids = points.map((p) => p.raw.id).filter(Boolean).filter(unique).join(',')
|
||||||
navigate(`/well/${idWell}/operations/${datasetName}/?selectedId=${ids}`)
|
navigate(`/well/${idWell}/operations/${datasetName}/?selectedId=${ids}`)
|
||||||
}, [idWell, navigate])
|
}, [idWell, navigate])
|
||||||
|
|
||||||
@ -175,8 +178,8 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
|
|||||||
|
|
||||||
const newChart = new Chart(chartRef.current, {
|
const newChart = new Chart(chartRef.current, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
plugins: [ChartDataLabels],
|
|
||||||
options: options,
|
options: options,
|
||||||
|
plugins: [ChartDataLabels],
|
||||||
data: { datasets: [] },
|
data: { datasets: [] },
|
||||||
})
|
})
|
||||||
setChart(newChart)
|
setChart(newChart)
|
||||||
|
36
src/utils/filters/columnFilters.ts
Normal file
36
src/utils/filters/columnFilters.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
export const makeTextOnFilter = (key: string) =>
|
||||||
|
(value: string, record?: Record<string, unknown>) => String(record?.[key]).startsWith(value)
|
||||||
|
|
||||||
|
export const makeArrayOnFilter = (key: string) =>
|
||||||
|
(value: string, record?: Record<string, string[]>) => (!value && (record?.[key]?.length ?? 0) <= 0) || record?.[key]?.includes(value)
|
||||||
|
|
||||||
|
export const makeObjectOnFilter = (field: string, key: string) =>
|
||||||
|
(value: string, record?: Record<string, Record<string, unknown>>) => String(record?.[field]?.[key]).startsWith(value)
|
||||||
|
|
||||||
|
export const makeTextFilters = (array: Record<string, unknown>[], keys: string[]) => {
|
||||||
|
const filters: string[][] = Array(keys.length)
|
||||||
|
|
||||||
|
for (let i = 0; i < keys.length; filters[i++] = []);
|
||||||
|
|
||||||
|
array.forEach((row) => {
|
||||||
|
if (!row) return
|
||||||
|
keys.forEach((key, idx) => {
|
||||||
|
if (!row[key]) return
|
||||||
|
const value = String(row[key])
|
||||||
|
if (filters[idx].indexOf(value) < 0)
|
||||||
|
filters[idx].push(value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const out: Record<string, { value: string, text: string }[]> = {}
|
||||||
|
|
||||||
|
keys.forEach((key, idx) => {
|
||||||
|
filters[idx].sort()
|
||||||
|
out[key] = filters[idx].map((filter) => ({
|
||||||
|
value: filter,
|
||||||
|
text: filter,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
@ -1,36 +1,3 @@
|
|||||||
export const makeTextOnFilter = (key: string) =>
|
export * from './columnFilters'
|
||||||
(value: string, record?: Record<string, unknown>) => String(record?.[key]).startsWith(value)
|
|
||||||
|
|
||||||
export const makeArrayOnFilter = (key: string) =>
|
export const unique = <T,>(value: T, index: number, self: T[]) => self.indexOf(value) === index
|
||||||
(value: string, record?: Record<string, string[]>) => (!value && (record?.[key]?.length ?? 0) <= 0) || record?.[key]?.includes(value)
|
|
||||||
|
|
||||||
export const makeObjectOnFilter = (field: string, key: string) =>
|
|
||||||
(value: string, record?: Record<string, Record<string, unknown>>) => String(record?.[field]?.[key]).startsWith(value)
|
|
||||||
|
|
||||||
export const makeTextFilters = (array: Record<string, unknown>[], keys: string[]) => {
|
|
||||||
const filters: string[][] = Array(keys.length)
|
|
||||||
|
|
||||||
for (let i = 0; i < keys.length; filters[i++] = []);
|
|
||||||
|
|
||||||
array.forEach((row) => {
|
|
||||||
if (!row) return
|
|
||||||
keys.forEach((key, idx) => {
|
|
||||||
if (!row[key]) return
|
|
||||||
const value = String(row[key])
|
|
||||||
if (filters[idx].indexOf(value) < 0)
|
|
||||||
filters[idx].push(value)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
const out: Record<string, { value: string, text: string }[]> = {}
|
|
||||||
|
|
||||||
keys.forEach((key, idx) => {
|
|
||||||
filters[idx].sort()
|
|
||||||
out[key] = filters[idx].map((filter) => ({
|
|
||||||
value: filter,
|
|
||||||
text: filter,
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user