* Исправлено отображение тултипов

* Добавлен фильтр по уникальным значениям (не глубокое сравнение)
This commit is contained in:
goodmice 2022-06-15 11:56:31 +05:00
parent 2ac12e026a
commit c2338c98ab
4 changed files with 49 additions and 41 deletions

View File

@ -10,7 +10,8 @@ import {
ChartData,
ChartOptions,
ChartType,
ChartDataset
ChartDataset,
Tooltip
} from 'chart.js'
import 'chartjs-adapter-moment'
import ChartDataLabels from 'chartjs-plugin-datalabels'
@ -24,7 +25,8 @@ Chart.register(
PointElement,
Legend,
ChartDataLabels,
zoomPlugin
zoomPlugin,
Tooltip,
)
const defaultOptions: ChartOptions = {

View File

@ -10,7 +10,8 @@ import {
Legend,
LineController,
PointElement,
LineElement
LineElement,
Tooltip
} from 'chart.js'
import 'chartjs-adapter-moment'
import zoomPlugin from 'chartjs-plugin-zoom'
@ -27,6 +28,7 @@ import AdditionalTables from './AdditionalTables'
import '@styles/index.css'
import '@styles/tvd.less'
import { unique } from '@asb/utils/filters'
Chart.register(
TimeScale,
@ -36,7 +38,8 @@ Chart.register(
PointElement,
Legend,
ChartDataLabels,
zoomPlugin
zoomPlugin,
Tooltip,
)
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
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}`)
}, [idWell, navigate])
@ -175,8 +178,8 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
const newChart = new Chart(chartRef.current, {
type: 'line',
plugins: [ChartDataLabels],
options: options,
plugins: [ChartDataLabels],
data: { datasets: [] },
})
setChart(newChart)

View 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
}

View File

@ -1,36 +1,3 @@
export const makeTextOnFilter = (key: string) =>
(value: string, record?: Record<string, unknown>) => String(record?.[key]).startsWith(value)
export * from './columnFilters'
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
}
export const unique = <T,>(value: T, index: number, self: T[]) => self.indexOf(value) === index