Улучшена работа контекстного меню

This commit is contained in:
goodmice 2022-06-30 11:32:19 +05:00
parent 4ccab4dec5
commit cd3c873368
2 changed files with 21 additions and 30 deletions

View File

@ -32,12 +32,15 @@ export const D3ContextMenu = memo<D3ContextMenuProps>(({
const overlay = useFunctionalValue(_overlay)
const menuItems = useMemo(() => {
const menuItems: ItemType[] = [
{ key: 'refresh', label: 'Обновить', onClick: onUpdate },
{ key: 'download', label: svg && (
const menuItems: ItemType[] = []
if (onUpdate)
menuItems.push({ key: 'refresh', label: 'Обновить', onClick: onUpdate })
if (svg)
menuItems.push({ key: 'download', label: (
<a href={svgToDataURL(svg)} download={`${downloadFilename}.svg`}>Сохранить</a>
)},
]
)})
if (additionalMenuItems)
menuItems.push(...additionalMenuItems)

View File

@ -1,4 +1,4 @@
import { memo, useCallback, useMemo, useState } from 'react'
import { memo, useMemo } from 'react'
import { D3Chart } from '@components/d3'
import { formatDate } from '@utils'
@ -71,20 +71,7 @@ const ticks = {
y: { visible: true },
}
export const OperationsChart = memo(({ data, yDomain, height }) => {
const [isChartLoading, setIsChartLoading] = useState(false)
const domain = useMemo(() => ({
y: { min: 0, max: yDomain },
// x: { min: new Date('2021-11-04 03:57'), max: new Date('2022-06-17 13:16') }
}), [yDomain])
const onChartUpdate = useCallback(() => {
setIsChartLoading(true)
setTimeout(() => setIsChartLoading(false), 2000)
}, [])
const plugins = useMemo(() => ({
const plugins = {
tooltip: {
enabled: true,
type: 'nearest',
@ -93,12 +80,14 @@ export const OperationsChart = memo(({ data, yDomain, height }) => {
},
cursor: {
enabled: true,
},
menu: {
enabled: false,
onUpdate: onChartUpdate,
}
}), [onChartUpdate])
}
export const OperationsChart = memo(({ data, yDomain, height, onDomainChanged }) => {
const domain = useMemo(() => ({
y: { min: 0, max: yDomain },
// x: { min: new Date('2021-11-04 03:57'), max: new Date('2022-06-17 13:16') }
}), [yDomain])
return (
<D3Chart
@ -106,7 +95,6 @@ export const OperationsChart = memo(({ data, yDomain, height }) => {
domain={domain}
datasets={chartDatasets}
data={data}
loading={isChartLoading}
height={height}
plugins={plugins}
ticks={ticks}